Skip to content

Commit

Permalink
Initial port to wxPython 4
Browse files Browse the repository at this point in the history
  • Loading branch information
hroncok committed Feb 13, 2018
1 parent 20c18cc commit 98f66bd
Show file tree
Hide file tree
Showing 19 changed files with 73 additions and 70 deletions.
11 changes: 5 additions & 6 deletions printrun/excluder.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ class ExcluderWindow(gviz.GvizWindow):
def __init__(self, excluder, *args, **kwargs):
super(ExcluderWindow, self).__init__(*args, **kwargs)
self.SetTitle(_("Part excluder: draw rectangles where print instructions should be ignored"))
self.toolbar.AddLabelTool(128, " " + _("Reset selection"),
wx.Image(imagefile('reset.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(),
shortHelp = _("Reset selection"),
longHelp = "")
self.toolbar.AddTool(128, " " + _("Reset selection"),
wx.Image(imagefile('reset.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(),
_("Reset selection"))
self.Bind(wx.EVT_TOOL, self.reset_selection, id = 128)
self.parent = excluder
self.p.paint_overlay = self.paint_selection
Expand All @@ -46,7 +45,7 @@ def mouse(self, event):
or event.ButtonUp(wx.MOUSE_BTN_RIGHT):
self.initpos = None
elif event.Dragging() and event.RightIsDown():
e = event.GetPositionTuple()
e = event.GetPosition()
if not self.initpos or not hasattr(self, "basetrans"):
self.initpos = e
self.basetrans = self.p.translate
Expand All @@ -55,7 +54,7 @@ def mouse(self, event):
self.p.dirty = 1
wx.CallAfter(self.p.Refresh)
elif event.Dragging() and event.LeftIsDown():
x, y = event.GetPositionTuple()
x, y = event.GetPosition()
if not self.initpos:
self.basetrans = self.p.translate
x = (x - self.basetrans[0]) / self.p.scale[0]
Expand Down
2 changes: 1 addition & 1 deletion printrun/gcview.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def handle_wheel(self, event):
if delta > 0: self.layerup()
else: self.layerdown()
return
x, y = event.GetPositionTuple()
x, y = event.GetPosition()
x, y, _ = self.mouse_to_3d(x, y)
if delta > 0:
self.zoom(factor, (x, y))
Expand Down
10 changes: 5 additions & 5 deletions printrun/gl/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def processSizeEvent(self, event):
if self.IsFrozen():
event.Skip()
return
if (wx.VERSION > (2, 9) and self.canvas.IsShownOnScreen()) or self.canvas.GetContext():
if self.canvas.IsShownOnScreen():
# Make sure the frame is shown before calling SetCurrent.
self.canvas.SetCurrent(self.context)
self.OnReshape()
Expand Down Expand Up @@ -326,10 +326,10 @@ def zoom_to_center(self, factor):

def handle_rotation(self, event):
if self.initpos is None:
self.initpos = event.GetPositionTuple()
self.initpos = event.GetPosition()
else:
p1 = self.initpos
p2 = event.GetPositionTuple()
p2 = event.GetPosition()
sz = self.GetClientSize()
p1x = float(p1[0]) / (sz[0] / 2) - 1
p1y = 1 - float(p1[1]) / (sz[1] / 2)
Expand All @@ -342,10 +342,10 @@ def handle_rotation(self, event):

def handle_translation(self, event):
if self.initpos is None:
self.initpos = event.GetPositionTuple()
self.initpos = event.GetPosition()
else:
p1 = self.initpos
p2 = event.GetPositionTuple()
p2 = event.GetPosition()
if self.orthographic:
x1, y1, _ = self.mouse_to_3d(p1[0], p1[1])
x2, y2, _ = self.mouse_to_3d(p2[0], p2[1])
Expand Down
11 changes: 5 additions & 6 deletions printrun/gui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@

try:
import wx
if wx.VERSION < (4,):
raise ImportError()
except:
logging.error(_("WX is not installed. This program requires WX to run."))
logging.error(_("WX >= 4 is not installed. This program requires WX >= 4 to run."))
raise

from printrun.utils import install_locale
Expand Down Expand Up @@ -202,9 +204,7 @@ def createTabbedGui(self):
self.Bind(wx.EVT_CLOSE, self.kill)

# Custom buttons
if wx.VERSION > (2, 9): self.cbuttonssizer = wx.WrapSizer(wx.HORIZONTAL)
else: self.cbuttonssizer = wx.GridBagSizer()
self.cbuttonssizer = wx.GridBagSizer()
self.cbuttonssizer = wx.WrapSizer(wx.HORIZONTAL)
self.centerpanel = self.newPanel(page1panel2)
self.centerpanel.SetSizer(self.cbuttonssizer)
rightsizer.Add(self.centerpanel, 0, wx.ALIGN_CENTER)
Expand Down Expand Up @@ -255,8 +255,7 @@ def createGui(self, compact = False, mini = False):
logpanel = self.newPanel(left_real_panel)
viz_pane = VizPane(self, vizpanel)
# Custom buttons
if wx.VERSION > (2, 9): self.cbuttonssizer = wx.WrapSizer(wx.HORIZONTAL)
else: self.cbuttonssizer = wx.GridBagSizer()
self.cbuttonssizer = wx.WrapSizer(wx.HORIZONTAL)
self.centerpanel = self.newPanel(vizpanel)
self.centerpanel.SetSizer(self.cbuttonssizer)
viz_pane.Add(self.centerpanel, 0, flag = wx.ALIGN_CENTER)
Expand Down
4 changes: 2 additions & 2 deletions printrun/gui/bufferedcanvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def update(self):
self.Refresh()

def getWidthHeight(self):
width, height = self.GetClientSizeTuple()
width, height = self.GetClientSize()
if width == 0:
width = 1
if height == 0:
Expand All @@ -103,7 +103,7 @@ def getWidthHeight(self):

def onPaint(self, event):
# Blit the front buffer to the screen
w, h = self.GetClientSizeTuple()
w, h = self.GetClientSize()
if not w or not h:
return
else:
Expand Down
2 changes: 1 addition & 1 deletion printrun/gui/toolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def MainToolbar(root, parentpanel = None, use_wrapsizer = False):
parentpanel = root.newPanel(parentpanel)
glob.Add(parentpanel, 1, flag = wx.EXPAND)
glob.Add(root.locker, 0, flag = wx.ALIGN_CENTER)
ToolbarSizer = wx.WrapSizer if use_wrapsizer and wx.VERSION > (2, 9) else wx.BoxSizer
ToolbarSizer = wx.WrapSizer if use_wrapsizer else wx.BoxSizer
self = ToolbarSizer(wx.HORIZONTAL)
root.rescanbtn = make_autosize_button(parentpanel, _("Port"), root.rescanports, _("Communication Settings\nClick to rescan ports"))
self.Add(root.rescanbtn, 0, wx.TOP | wx.LEFT, 0)
Expand Down
6 changes: 3 additions & 3 deletions printrun/gui/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def __init__(self, parent, size = (200, 22), title = "",
self.Bind(wx.EVT_PAINT, self.paint)
self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
self.bgcolor = wx.Colour()
self.bgcolor.SetFromName(bgcolor)
self.bgcolor.Set(bgcolor)
self.width, self.height = size
self.title = title
self.max = maxval
Expand Down Expand Up @@ -292,13 +292,13 @@ def interpolatedColour(self, val, vmin, vmid, vmax, cmin, cmid, cmax):
return wx.Colour(*map(int, rgb))

def paint(self, ev):
self.width, self.height = self.GetClientSizeTuple()
self.width, self.height = self.GetClientSize()
self.recalc()
x0, y0, x1, y1, xE, yE = 1, 1, self.ypt + 1, 1, self.width + 1 - 2, 20
dc = wx.PaintDC(self)
dc.SetBackground(wx.Brush(self.bgcolor))
dc.Clear()
cold, medium, hot = wx.Colour(0, 167, 223), wx.Colour(239, 233, 119), wx.Colour(210, 50.100)
cold, medium, hot = wx.Colour(0, 167, 223), wx.Colour(239, 233, 119), wx.Colour(210, 50, 0)
# gauge1, gauge2 = wx.Colour(255, 255, 210), (self.gaugeColour or wx.Colour(234, 82, 0))
gauge1 = wx.Colour(255, 255, 210)
shadow1, shadow2 = wx.Colour(110, 110, 110), self.bgcolor
Expand Down
4 changes: 2 additions & 2 deletions printrun/gui/xybuttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def __init__(self, parent, moveCallback = None, cornerCallback = None, spacebarC
self.lastCorner = None

self.bgcolor = wx.Colour()
self.bgcolor.SetFromName(bgcolor)
self.bgcolor.Set(bgcolor)
self.bgcolormask = wx.Colour(self.bgcolor.Red(), self.bgcolor.Green(), self.bgcolor.Blue(), 128)

BufferedCanvas.__init__(self, parent, ID, size=self.bg_bmp.GetSize())
Expand Down Expand Up @@ -218,7 +218,7 @@ def highlightCorner(self, gc, corner = 0):
w, h = self.corner_size
xinset, yinset = self.corner_inset
cx, cy = self.center
ww, wh = self.GetSizeTuple()
ww, wh = self.GetSize()

if corner == 0:
x, y = (cx - ww / 2 + xinset + 1, cy - wh / 2 + yinset)
Expand Down
2 changes: 1 addition & 1 deletion printrun/gui/zbuttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __init__(self, parent, moveCallback = None, bgcolor = "#FFFFFF", ID=-1):
self.lastValue = None

self.bgcolor = wx.Colour()
self.bgcolor.SetFromName(bgcolor)
self.bgcolor.Set(bgcolor)
self.bgcolormask = wx.Colour(self.bgcolor.Red(), self.bgcolor.Green(), self.bgcolor.Blue(), 128)

BufferedCanvas.__init__(self, parent, ID, size=self.bg_bmp.GetSize())
Expand Down
30 changes: 15 additions & 15 deletions printrun/gviz.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ def create_base_ui(self):

vbox = wx.BoxSizer(wx.VERTICAL)
self.toolbar = wx.ToolBar(panel, -1, style = wx.TB_HORIZONTAL | wx.NO_BORDER | wx.TB_HORZ_TEXT)
self.toolbar.AddSimpleTool(1, wx.Image(imagefile('zoom_in.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(), _("Zoom In [+]"), '')
self.toolbar.AddSimpleTool(2, wx.Image(imagefile('zoom_out.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(), _("Zoom Out [-]"), '')
self.toolbar.AddTool(1, '', wx.Image(imagefile('zoom_in.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(), _("Zoom In [+]"),)
self.toolbar.AddTool(2, '', wx.Image(imagefile('zoom_out.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(), _("Zoom Out [-]"))
self.toolbar.AddSeparator()
self.toolbar.AddSimpleTool(3, wx.Image(imagefile('arrow_up.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(), _("Move Up a Layer [U]"), '')
self.toolbar.AddSimpleTool(4, wx.Image(imagefile('arrow_down.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(), _("Move Down a Layer [D]"), '')
self.toolbar.AddLabelTool(5, " " + _("Reset view"), wx.Image(imagefile('reset.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(), shortHelp = _("Reset view"), longHelp = '')
self.toolbar.AddTool(3, '', wx.Image(imagefile('arrow_up.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(), _("Move Up a Layer [U]"))
self.toolbar.AddTool(4, '', wx.Image(imagefile('arrow_down.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(), _("Move Down a Layer [D]"))
self.toolbar.AddTool(5, " " + _("Reset view"), wx.Image(imagefile('reset.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(), shortHelp = _("Reset view"))
self.toolbar.AddSeparator()
self.toolbar.AddSimpleTool(6, wx.Image(imagefile('inject.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(), shortHelpString = _("Inject G-Code"), longHelpString = _("Insert code at the beginning of this layer"))
self.toolbar.AddSimpleTool(7, wx.Image(imagefile('edit.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(), shortHelpString = _("Edit layer"), longHelpString = _("Edit the G-Code of this layer"))
self.toolbar.AddTool(6, '', wx.Image(imagefile('inject.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(), wx.NullBitmap, shortHelp = _("Inject G-Code"), longHelp = _("Insert code at the beginning of this layer"))
self.toolbar.AddTool(7, '', wx.Image(imagefile('edit.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(), wx.NullBitmap, shortHelp = _("Edit layer"), longHelp = _("Edit the G-Code of this layer"))

vbox.Add(self.toolbar, 0, border = 5)

Expand Down Expand Up @@ -120,7 +120,7 @@ def mouse(self, event):
if self.initpos is not None:
self.initpos = None
elif event.Dragging():
e = event.GetPositionTuple()
e = event.GetPosition()
if self.initpos is None:
self.initpos = e
self.basetrans = self.p.translate
Expand Down Expand Up @@ -197,19 +197,19 @@ def __init__(self, parent, size = (200, 200), build_dimensions = [200, 200, 100,
self.arcpen = wx.Pen(wx.Colour(255, 0, 0), penwidth)
self.travelpen = wx.Pen(wx.Colour(10, 80, 80), penwidth)
self.hlpen = wx.Pen(wx.Colour(200, 50, 50), penwidth)
self.fades = [wx.Pen(wx.Colour(250 - 0.6 ** i * 100, 250 - 0.6 ** i * 100, 200 - 0.4 ** i * 50), penwidth) for i in xrange(6)]
self.fades = [wx.Pen(wx.Colour(int(250 - 0.6 ** i * 100), int(250 - 0.6 ** i * 100), int(200 - 0.4 ** i * 50)), penwidth) for i in xrange(6)]
self.penslist = [self.mainpen, self.travelpen, self.hlpen] + self.fades
self.bgcolor = wx.Colour()
self.bgcolor.SetFromName(bgcolor)
self.blitmap = wx.EmptyBitmap(self.GetClientSize()[0], self.GetClientSize()[1], -1)
self.bgcolor.Set(bgcolor)
self.blitmap = wx.Bitmap(self.GetClientSize()[0], self.GetClientSize()[1], -1)
self.paint_overlay = None

def inject(self):
layer = self.layers.index(self.layerindex)
layer = self.layers[self.layerindex]
injector(self.gcode, self.layerindex, layer)

def editlayer(self):
layer = self.layers.index(self.layerindex)
layer = self.layers[self.layerindex]
injector_edit(self.gcode, self.layerindex, layer)

def clearhilights(self):
Expand Down Expand Up @@ -275,7 +275,7 @@ def update_basescale(self):

def resize(self, event):
old_basescale = self.basescale
width, height = self.GetClientSizeTuple()
width, height = self.GetClientSize()
if width < 1 or height < 1:
return
self.size = (width, height)
Expand Down Expand Up @@ -325,7 +325,7 @@ def _drawarcs(self, dc, arcs, pens):
def repaint_everything(self):
width = self.scale[0] * self.build_dimensions[0]
height = self.scale[1] * self.build_dimensions[1]
self.blitmap = wx.EmptyBitmap(width + 1, height + 1, -1)
self.blitmap = wx.Bitmap(width + 1, height + 1, -1)
dc = wx.MemoryDC()
dc.SelectObject(self.blitmap)
dc.SetBackground(wx.Brush((250, 250, 200)))
Expand Down
4 changes: 2 additions & 2 deletions printrun/objectplater.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ def set_viewer(self, viewer):
if hasattr(viewer, "handle_rotation"):
def handle_rotation(self, event, orig_handler):
if self.initpos is None:
self.initpos = event.GetPositionTuple()
self.initpos = event.GetPosition()
else:
if event.ShiftDown():
p1 = self.initpos
p2 = event.GetPositionTuple()
p2 = event.GetPosition()
x1, y1, _ = self.mouse_to_3d(p1[0], p1[1])
x2, y2, _ = self.mouse_to_3d(p2[0], p2[1])
self.parent.move_shape((x2 - x1, y2 - y1))
Expand Down
10 changes: 5 additions & 5 deletions printrun/projectlayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ def __init__(self, parent, title, res = (1024, 768), printer = None, scale = 1.0
self.printer = printer
self.control_frame = parent
self.pic = wx.StaticBitmap(self)
self.bitmap = wx.EmptyBitmap(*res)
self.bbitmap = wx.EmptyBitmap(*res)
self.bitmap = wx.Bitmap(*res)
self.bbitmap = wx.Bitmap(*res)
self.slicer = 'bitmap'
self.dpi = 96
dc = wx.MemoryDC()
Expand Down Expand Up @@ -73,8 +73,8 @@ def clear_layer(self):
pass

def resize(self, res = (1024, 768)):
self.bitmap = wx.EmptyBitmap(*res)
self.bbitmap = wx.EmptyBitmap(*res)
self.bitmap = wx.Bitmap(*res)
self.bbitmap = wx.Bitmap(*res)
dc = wx.MemoryDC()
dc.SelectObject(self.bbitmap)
dc.SetBackground(wx.Brush("black"))
Expand Down Expand Up @@ -624,7 +624,7 @@ def present_calibrate(self, event):
resolution_x_pixels = int(self.X.GetValue())
resolution_y_pixels = int(self.Y.GetValue())

gridBitmap = wx.EmptyBitmap(resolution_x_pixels, resolution_y_pixels)
gridBitmap = wx.Bitmap(resolution_x_pixels, resolution_y_pixels)
dc = wx.MemoryDC()
dc.SelectObject(gridBitmap)
dc.SetBackground(wx.Brush("black"))
Expand Down
11 changes: 7 additions & 4 deletions printrun/pronterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@

try:
import wx
import wx.adv
if wx.VERSION < (4,):
raise ImportError()
except:
logging.error(_("WX is not installed. This program requires WX to run."))
logging.error(_("WX >= 4 is not installed. This program requires WX >= 4 to run."))
raise

from .gui.widgets import SpecialButton, MacroEditor, PronterOptions, ButtonEdit
Expand Down Expand Up @@ -725,7 +728,7 @@ def create_menu(self):
self.filehistory.UseMenu(recent)
self.Bind(wx.EVT_MENU_RANGE, self.load_recent_file,
id = wx.ID_FILE1, id2 = wx.ID_FILE9)
m.AppendMenu(wx.ID_ANY, _("&Recent Files"), recent)
m.Append(wx.ID_ANY, _("&Recent Files"), recent)
self.Bind(wx.EVT_MENU, self.clear_log, m.Append(-1, _("Clear console"), _(" Clear output console")))
self.Bind(wx.EVT_MENU, self.on_exit, m.Append(wx.ID_EXIT, _("E&xit"), _(" Closes the Window")))
self.menustrip.Append(m, _("&File"))
Expand Down Expand Up @@ -814,7 +817,7 @@ def show_spool_manager(self, event):
def about(self, event):
"""Show about dialog"""

info = wx.AboutDialogInfo()
info = wx.adv.AboutDialogInfo()

info.SetIcon(wx.Icon(iconfile("pronterface.png"), wx.BITMAP_TYPE_PNG))
info.SetName('Printrun')
Expand Down Expand Up @@ -848,7 +851,7 @@ def about(self, event):
info.AddDeveloper('Kliment Yanev')
info.AddDeveloper('Guillaume Seguin')

wx.AboutBox(info)
wx.adv.AboutBox(info)

# --------------------------------------------------------------
# Settings & command line handling (including update callbacks)
Expand Down
2 changes: 1 addition & 1 deletion printrun/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def decorator(self, *args, **kwargs):
deftxt += repr(self.default) + " " + resethelp
helptxt += sep + deftxt
if len(helptxt):
widget.SetToolTipString(helptxt)
widget.SetToolTip(helptxt)
return widget
return decorator

Expand Down
Loading

0 comments on commit 98f66bd

Please sign in to comment.