printrun-src/printrun/stlplater.py

changeset 46
cce0af6351f0
parent 15
0bbb006204fc
--- a/printrun-src/printrun/stlplater.py	Tue Jan 19 20:45:09 2021 +0100
+++ b/printrun-src/printrun/stlplater.py	Wed Jan 20 10:15:13 2021 +0100
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 # This file is part of the Printrun suite.
 #
@@ -36,12 +36,12 @@
 from printrun import stltool
 from printrun.objectplater import make_plater, PlaterPanel
 
-glview = False
-if "-nogl" not in sys.argv:
+glview = '--no-gl' not in sys.argv
+if glview:
     try:
         from printrun import stlview
-        glview = True
     except:
+        glview = False
         logging.warning("Could not load 3D viewer for plater:"
                         + "\n" + traceback.format_exc())
 
@@ -61,7 +61,7 @@
 
 class showstl(wx.Window):
     def __init__(self, parent, size, pos):
-        wx.Window.__init__(self, parent, size = size, pos = pos)
+        super().__init__(parent, size = size, pos = pos)
         self.i = 0
         self.parent = parent
         self.previ = 0
@@ -74,7 +74,7 @@
         self.prevsel = -1
 
     def prepare_model(self, m, scale):
-        m.bitmap = wx.EmptyBitmap(800, 800, 32)
+        m.bitmap = wx.Bitmap(800, 800, 32)
         dc = wx.MemoryDC()
         dc.SelectObject(m.bitmap)
         dc.SetBackground(wx.Brush((0, 0, 0, 0)))
@@ -105,7 +105,7 @@
     def move(self, event):
         if event.ButtonUp(wx.MOUSE_BTN_LEFT):
             if self.initpos is not None:
-                currentpos = event.GetPositionTuple()
+                currentpos = event.GetPosition()
                 delta = (0.5 * (currentpos[0] - self.initpos[0]),
                          -0.5 * (currentpos[1] - self.initpos[1])
                          )
@@ -116,10 +116,10 @@
             self.parent.right(event)
         elif event.Dragging():
             if self.initpos is None:
-                self.initpos = event.GetPositionTuple()
+                self.initpos = event.GetPosition()
             self.Refresh()
             dc = wx.ClientDC(self)
-            p = event.GetPositionTuple()
+            p = event.GetPosition()
             dc.DrawLine(self.initpos[0], self.initpos[1], p[0], p[1])
             del dc
         else:
@@ -181,10 +181,7 @@
         if self.prevsel != s:
             self.i = 0
             self.prevsel = s
-        if z < 0:
-            self.rotate_shape(-1)
-        else:
-            self.rotate_shape(1)
+        self.rotate_shape(-1 if z < 0 else 1) #TEST
 
     def repaint(self, event):
         dc = wx.PaintDC(self)
@@ -195,11 +192,11 @@
             dc = wx.ClientDC(self)
         scale = 2
         dc.SetPen(wx.Pen(wx.Colour(100, 100, 100)))
-        for i in xrange(20):
+        for i in range(20):
             dc.DrawLine(0, i * scale * 10, 400, i * scale * 10)
             dc.DrawLine(i * scale * 10, 0, i * scale * 10, 400)
         dc.SetPen(wx.Pen(wx.Colour(0, 0, 0)))
-        for i in xrange(4):
+        for i in range(4):
             dc.DrawLine(0, i * scale * 50, 400, i * scale * 50)
             dc.DrawLine(i * scale * 50, 0, i * scale * 50, 400)
         dc.SetBrush(wx.Brush(wx.Colour(128, 255, 128)))
@@ -224,12 +221,12 @@
     def prepare_ui(self, filenames = [], callback = None,
                    parent = None, build_dimensions = None, circular_platform = False,
                    simarrange_path = None, antialias_samples = 0):
-        super(StlPlaterPanel, self).prepare_ui(filenames, callback, parent, build_dimensions)
+        super().prepare_ui(filenames, callback, parent, build_dimensions)
         self.cutting = False
         self.cutting_axis = None
         self.cutting_dist = None
         if glview:
-            viewer = stlview.StlViewPanel(self, (580, 580),
+            viewer = stlview.StlViewPanel(self, wx.DefaultSize,
                                           build_dimensions = self.build_dimensions,
                                           circular = circular_platform,
                                           antialias_samples = antialias_samples)
@@ -242,7 +239,7 @@
             cutconfirmbutton.Disable()
             self.cutconfirmbutton = cutconfirmbutton
             self.menusizer.Add(cutconfirmbutton, pos = (nrows, 1), span = (1, 1), flag = wx.EXPAND)
-            cutpanel = wx.Panel(self.menupanel, -1)
+            cutpanel = wx.Panel(self.menupanel)
             cutsizer = self.cutsizer = wx.BoxSizer(wx.HORIZONTAL)
             cutpanel.SetSizer(cutsizer)
             cutxplusbutton = wx.ToggleButton(cutpanel, label = _(">X"), style = wx.BU_EXACTFIT)
@@ -270,22 +267,20 @@
         self.set_viewer(viewer)
 
     def start_cutting_tool(self, event, axis, direction):
-        toggle = event.GetEventObject()
-        if toggle.GetValue():
+        toggle = event.EventObject
+        self.cutting = toggle.Value
+        if toggle.Value:
             # Disable the other toggles
-            for child in self.cutsizer.GetChildren():
-                child = child.GetWindow()
+            for child in self.cutsizer.Children:
+                child = child.Window
                 if child != toggle:
-                    child.SetValue(False)
-            self.cutting = True
+                    child.Value = False
             self.cutting_axis = axis
-            self.cutting_dist = None
             self.cutting_direction = direction
         else:
-            self.cutting = False
             self.cutting_axis = None
-            self.cutting_dist = None
             self.cutting_direction = None
+        self.cutting_dist = None
 
     def cut_confirm(self, event):
         name = self.l.GetSelection()
@@ -335,7 +330,7 @@
         best_match = None
         best_facet = None
         best_dist = float("inf")
-        for key, model in self.models.iteritems():
+        for key, model in self.models.items():
             transformation = transformation_matrix(model)
             transformed = model.transform(transformation)
             if not transformed.intersect_box(ray_near, ray_far):
@@ -478,7 +473,7 @@
         if self.simarrange_path:
             try:
                 self.autoplate_simarrange()
-            except Exception, e:
+            except Exception as e:
                 logging.warning(_("Failed to use simarrange for plating, "
                                   "falling back to the standard method. "
                                   "The error was: ") + e)
@@ -494,7 +489,7 @@
                    "-m",  # Pack around center
                    "-x", str(int(self.build_dimensions[0])),
                    "-y", str(int(self.build_dimensions[1]))] + files
-        p = subprocess.Popen(command, stdout = subprocess.PIPE)
+        p = subprocess.Popen(command, stdout = subprocess.PIPE, universal_newlines = True)
 
         pos_regexp = re.compile("File: (.*) minx: ([0-9]+), miny: ([0-9]+), minrot: ([0-9]+)")
         for line in p.stdout:
@@ -510,7 +505,7 @@
                 x = float(bits[1])
                 y = float(bits[2])
                 rot = -float(bits[3])
-                for name, model in models.items():
+                for name, model in list(models.items()):
                     # FIXME: not sure this is going to work superwell with utf8
                     if model.filename == filename:
                         model.offsets[0] = x + self.build_dimensions[3]

mercurial