Skip to content

Commit c4eefb8

Browse files
author
yxdragon
committed
myvi
1 parent 10b590e commit c4eefb8

File tree

1 file changed

+28
-25
lines changed

1 file changed

+28
-25
lines changed

imagepy/core/myvi/canvas3d.py

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import sys
1+
import sys, platform
22
import moderngl
33
import numpy as np
44
import wx, math
@@ -8,16 +8,13 @@
88
from wx.lib.pubsub import pub
99
from .util import *
1010

11-
#----------------------------------------------------------------------
12-
from wx.glcanvas import WX_GL_DEPTH_SIZE
13-
attribs=[WX_GL_DEPTH_SIZE,32,0,0];
14-
1511
class Canvas3D(glcanvas.GLCanvas):
1612
def __init__(self, parent, manager=None):
17-
attribList = attribs = (glcanvas.WX_GL_RGBA, glcanvas.WX_GL_DOUBLEBUFFER, glcanvas.WX_GL_DEPTH_SIZE, 24)
13+
attribList = attribs = (glcanvas.WX_GL_CORE_PROFILE, glcanvas.WX_GL_RGBA, glcanvas.WX_GL_DOUBLEBUFFER, glcanvas.WX_GL_DEPTH_SIZE, 24)
1814
glcanvas.GLCanvas.__init__(self, parent, -1, attribList=attribList)
1915
self.init = False
2016
self.context = glcanvas.GLContext(self)
17+
self.SetBackgroundStyle(wx.BG_STYLE_PAINT)
2118
self.manager = self.manager = Manager() if manager is None else manager
2219
self.size = None
2320

@@ -108,6 +105,11 @@ def OnMouseWheel(self, evt):
108105
self.Refresh(False)
109106
#self.update()
110107

108+
def make_bitmap(bmp):
109+
img = bmp.ConvertToImage()
110+
img.Resize((20, 20), (2, 2))
111+
return img.ConvertToBitmap()
112+
111113
class Viewer3D(wx.Panel):
112114
def __init__( self, parent, manager=None):
113115
wx.Panel.__init__(self, parent, id = wx.ID_ANY, pos = wx.DefaultPosition, size = wx.Size( 500,300 ), style = wx.TAB_TRAVERSAL )
@@ -121,26 +123,27 @@ def __init__( self, parent, manager=None):
121123

122124
#self.SetIcon(wx.Icon('data/logo.ico', wx.BITMAP_TYPE_ICO))
123125

124-
self.btn_x = wx.BitmapButton( self.toolbar, wx.ID_ANY, wx.Bitmap( osp.join(root, 'imgs/x-axis.png'), wx.BITMAP_TYPE_ANY ), wx.DefaultPosition, wx.DefaultSize, wx.BU_AUTODRAW )
125-
tsizer.Add( self.btn_x, 0, wx.ALL, 1 )
126-
self.btn_y = wx.BitmapButton( self.toolbar, wx.ID_ANY, wx.Bitmap( osp.join(root, 'imgs/y-axis.png'), wx.BITMAP_TYPE_ANY ), wx.DefaultPosition, wx.DefaultSize, wx.BU_AUTODRAW )
127-
tsizer.Add( self.btn_y, 0, wx.ALL, 1 )
128-
self.btn_z = wx.BitmapButton( self.toolbar, wx.ID_ANY, wx.Bitmap( osp.join(root, 'imgs/z-axis.png'), wx.BITMAP_TYPE_ANY ), wx.DefaultPosition, wx.DefaultSize, wx.BU_AUTODRAW )
129-
tsizer.Add( self.btn_z, 0, wx.ALL, 1 )
126+
self.btn_x = wx.BitmapButton( self.toolbar, wx.ID_ANY, make_bitmap(wx.Bitmap( osp.join(root, 'imgs/x-axis.png'), wx.BITMAP_TYPE_ANY )), wx.DefaultPosition, wx.DefaultSize, wx.BU_AUTODRAW )
127+
tsizer.Add( self.btn_x, 0, wx.ALIGN_CENTER|wx.ALL, 0 )
128+
self.btn_y = wx.BitmapButton( self.toolbar, wx.ID_ANY, make_bitmap(wx.Bitmap( osp.join(root, 'imgs/y-axis.png'), wx.BITMAP_TYPE_ANY )), wx.DefaultPosition, wx.DefaultSize, wx.BU_AUTODRAW )
129+
tsizer.Add( self.btn_y, 0, wx.ALIGN_CENTER|wx.ALL, 0 )
130+
self.btn_z = wx.BitmapButton( self.toolbar, wx.ID_ANY, make_bitmap(wx.Bitmap( osp.join(root, 'imgs/z-axis.png'), wx.BITMAP_TYPE_ANY )), wx.DefaultPosition, wx.DefaultSize, wx.BU_AUTODRAW )
131+
tsizer.Add( self.btn_z, 0, wx.ALIGN_CENTER|wx.ALL, 0 )
130132
tsizer.Add(wx.StaticLine( self.toolbar, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_VERTICAL), 0, wx.ALL|wx.EXPAND, 2 )
131-
self.btn_pers = wx.BitmapButton( self.toolbar, wx.ID_ANY, wx.Bitmap( osp.join(root, 'imgs/isometric.png'), wx.BITMAP_TYPE_ANY ), wx.DefaultPosition, wx.DefaultSize, wx.BU_AUTODRAW )
132-
tsizer.Add( self.btn_pers, 0, wx.ALL, 1 )
133-
self.btn_orth = wx.BitmapButton( self.toolbar, wx.ID_ANY, wx.Bitmap( osp.join(root, 'imgs/parallel.png'), wx.BITMAP_TYPE_ANY ), wx.DefaultPosition, wx.DefaultSize, wx.BU_AUTODRAW )
134-
tsizer.Add( self.btn_orth, 0, wx.ALL, 1 )
133+
self.btn_pers = wx.BitmapButton( self.toolbar, wx.ID_ANY, make_bitmap(wx.Bitmap( osp.join(root, 'imgs/isometric.png'), wx.BITMAP_TYPE_ANY )), wx.DefaultPosition, wx.DefaultSize, wx.BU_AUTODRAW )
134+
tsizer.Add( self.btn_pers, 0, wx.ALIGN_CENTER|wx.ALL, 0 )
135+
self.btn_orth = wx.BitmapButton( self.toolbar, wx.ID_ANY, make_bitmap(wx.Bitmap( osp.join(root, 'imgs/parallel.png'), wx.BITMAP_TYPE_ANY )), wx.DefaultPosition, wx.DefaultSize, wx.BU_AUTODRAW )
136+
tsizer.Add( self.btn_orth, 0, wx.ALIGN_CENTER|wx.ALL, 0 )
135137
tsizer.Add(wx.StaticLine( self.toolbar, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_VERTICAL), 0, wx.ALL|wx.EXPAND, 2 )
136-
self.btn_open = wx.BitmapButton( self.toolbar, wx.ID_ANY, wx.Bitmap(osp.join(root, 'imgs/open.png'), wx.BITMAP_TYPE_ANY ), wx.DefaultPosition, wx.DefaultSize, wx.BU_AUTODRAW )
137-
tsizer.Add( self.btn_open, 0, wx.ALL, 1 )
138-
self.btn_stl = wx.BitmapButton( self.toolbar, wx.ID_ANY, wx.Bitmap(osp.join(root, 'imgs/stl.png'), wx.BITMAP_TYPE_ANY ), wx.DefaultPosition, wx.DefaultSize, wx.BU_AUTODRAW )
139-
tsizer.Add( self.btn_stl, 0, wx.ALL, 1 )
140-
141-
self.btn_color = wx.ColourPickerCtrl( self.toolbar, wx.ID_ANY, wx.Colour( 128, 128, 128 ), wx.DefaultPosition, wx.DefaultSize, wx.CLRP_DEFAULT_STYLE )
142-
tsizer.Add( self.btn_color, 0, wx.ALIGN_CENTER|wx.ALL, 1 )
138+
self.btn_open = wx.BitmapButton( self.toolbar, wx.ID_ANY, make_bitmap(wx.Bitmap(osp.join(root, 'imgs/open.png'), wx.BITMAP_TYPE_ANY )), wx.DefaultPosition, wx.DefaultSize, wx.BU_AUTODRAW )
139+
tsizer.Add( self.btn_open, 0, wx.ALIGN_CENTER|wx.ALL, 0 )
140+
self.btn_stl = wx.BitmapButton( self.toolbar, wx.ID_ANY, make_bitmap(wx.Bitmap(osp.join(root, 'imgs/stl.png'), wx.BITMAP_TYPE_ANY )), wx.DefaultPosition, wx.DefaultSize, wx.BU_AUTODRAW )
141+
tsizer.Add( self.btn_stl, 0, wx.ALIGN_CENTER|wx.ALL, 0 )
142+
#pan = wx.Panel(self.toolbar, size=(50, 50))
143+
self.btn_color = wx.ColourPickerCtrl( self.toolbar, wx.ID_ANY, wx.Colour( 128, 128, 128 ), wx.DefaultPosition, [(33, 38), (-1, -1)][platform.system() in ['Windows', 'Linux']], wx.CLRP_DEFAULT_STYLE )
144+
tsizer.Add( self.btn_color, 0, wx.ALIGN_CENTER|wx.ALL|(0, wx.EXPAND)[platform.system() in ['Windows', 'Linux']], 0 )
143145
self.toolbar.SetSizer( tsizer )
146+
tsizer.Layout()
144147

145148
self.settingbar = wx.Panel( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
146149
ssizer = wx.BoxSizer( wx.HORIZONTAL )
@@ -152,7 +155,7 @@ def __init__( self, parent, manager=None):
152155
cho_objChoices = ['None']
153156
self.cho_obj = wx.Choice( self.settingbar, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, cho_objChoices, 0 )
154157
self.cho_obj.SetSelection( 0 )
155-
ssizer.Add( self.cho_obj, 0, wx.ALL, 1 )
158+
ssizer.Add( self.cho_obj, 0, wx.ALIGN_CENTER|wx.ALL, 1 )
156159

157160
self.chk_visible = wx.CheckBox( self.settingbar, wx.ID_ANY, u"visible", wx.DefaultPosition, wx.DefaultSize, 0 )
158161
ssizer.Add( self.chk_visible, 0, wx.ALIGN_CENTER|wx.LEFT, 10 )
@@ -175,7 +178,7 @@ def __init__( self, parent, manager=None):
175178
cho_objChoices = ['mesh', 'grid']
176179
self.cho_mode = wx.Choice( self.settingbar, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, cho_objChoices, 0 )
177180
self.cho_mode.SetSelection( 0 )
178-
ssizer.Add( self.cho_mode, 0, wx.ALL, 1 )
181+
ssizer.Add( self.cho_mode, 0, wx.ALIGN_CENTER|wx.ALL, 1 )
179182

180183
sizer.Add( self.toolbar, 0, wx.EXPAND |wx.ALL, 0 )
181184
sizer.Add( self.canvas, 1, wx.EXPAND |wx.ALL, 0)

0 commit comments

Comments
 (0)