--- a/printrun-src/printrun/objectplater.py Tue Jan 19 20:45:09 2021 +0100 +++ b/printrun-src/printrun/objectplater.py Wed Jan 20 10:15:13 2021 +0100 @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # This file is part of the Printrun suite. # # Printrun is free software: you can redistribute it and/or modify @@ -35,14 +33,22 @@ def __init__(self, **kwargs): self.destroy_on_done = False parent = kwargs.get("parent", None) - super(PlaterPanel, self).__init__(parent = parent) + super().__init__(parent = parent) self.prepare_ui(**kwargs) def prepare_ui(self, filenames = [], callback = None, parent = None, build_dimensions = None): self.filenames = filenames - self.mainsizer = wx.BoxSizer(wx.HORIZONTAL) - panel = self.menupanel = wx.Panel(self, -1) + panel = self.menupanel = wx.Panel(self) sizer = self.menusizer = wx.GridBagSizer() + # Load button + loadbutton = wx.Button(panel, label = _("Load")) + loadbutton.Bind(wx.EVT_BUTTON, self.load) + sizer.Add(loadbutton, pos = (0, 0), span = (1, 1), flag = wx.EXPAND) + # Export button + exportbutton = wx.Button(panel, label = _("Export")) + exportbutton.Bind(wx.EVT_BUTTON, self.export) + sizer.Add(exportbutton, pos = (0, 1), span = (1, 1), flag = wx.EXPAND) + self.l = wx.ListBox(panel) sizer.Add(self.l, pos = (1, 0), span = (1, 2), flag = wx.EXPAND) sizer.AddGrowableRow(1, 1) @@ -50,10 +56,6 @@ clearbutton = wx.Button(panel, label = _("Clear")) clearbutton.Bind(wx.EVT_BUTTON, self.clear) sizer.Add(clearbutton, pos = (2, 0), span = (1, 2), flag = wx.EXPAND) - # Load button - loadbutton = wx.Button(panel, label = _("Load")) - loadbutton.Bind(wx.EVT_BUTTON, self.load) - sizer.Add(loadbutton, pos = (0, 0), span = (1, 1), flag = wx.EXPAND) # Snap to Z = 0 button snapbutton = wx.Button(panel, label = _("Snap to Z = 0")) snapbutton.Bind(wx.EVT_BUTTON, self.snap) @@ -70,10 +72,6 @@ autobutton = wx.Button(panel, label = _("Auto arrange")) autobutton.Bind(wx.EVT_BUTTON, self.autoplate) sizer.Add(autobutton, pos = (5, 0), span = (1, 2), flag = wx.EXPAND) - # Export button - exportbutton = wx.Button(panel, label = _("Export")) - exportbutton.Bind(wx.EVT_BUTTON, self.export) - sizer.Add(exportbutton, pos = (0, 1), span = (1, 1), flag = wx.EXPAND) if callback is not None: donebutton = wx.Button(panel, label = _("Done")) donebutton.Bind(wx.EVT_BUTTON, lambda e: self.done(e, callback)) @@ -83,24 +81,22 @@ sizer.Add(cancelbutton, pos = (6, 1), span = (1, 1), flag = wx.EXPAND) self.basedir = "." self.models = {} - panel.SetSizerAndFit(sizer) + panel.SetSizer(sizer) + self.mainsizer = wx.BoxSizer(wx.HORIZONTAL) self.mainsizer.Add(panel, flag = wx.EXPAND) self.SetSizer(self.mainsizer) - if build_dimensions: - self.build_dimensions = build_dimensions - else: - self.build_dimensions = [200, 200, 100, 0, 0, 0] + self.build_dimensions = build_dimensions or [200, 200, 100, 0, 0, 0] def set_viewer(self, viewer): # Patch handle_rotation on the fly 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)) @@ -112,12 +108,10 @@ if hasattr(viewer, "handle_wheel"): def handle_wheel(self, event, orig_handler): if event.ShiftDown(): - delta = event.GetWheelRotation() angle = 10 - if delta > 0: - self.parent.rotate_shape(angle / 2) - else: - self.parent.rotate_shape(-angle / 2) + if event.GetWheelRotation() < 0: + angle = -angle + self.parent.rotate_shape(angle / 2) else: orig_handler(event) patch_method(viewer, "handle_wheel", handle_wheel) @@ -246,8 +240,8 @@ def add_model(self, name, model): newname = os.path.split(name.lower())[1] - if not isinstance(newname, unicode): - newname = unicode(newname, "utf-8") + if not isinstance(newname, str): + newname = str(newname, "utf-8") c = 1 while newname in self.models: newname = os.path.split(name.lower())[1]