Explorar el Código

Another fixed bug introduced to clear_poly() in previous commit. Added process widget.

jpcaram hace 11 años
padre
commit
87fdf0a581
Se han modificado 4 ficheros con 141 adiciones y 4 borrados
  1. 32 0
      FlatCAMGUI.py
  2. 73 0
      FlatCAMProcess.py
  3. 16 4
      camlib.py
  4. 20 0
      sandbox/process_widget.py

+ 32 - 0
FlatCAMGUI.py

@@ -218,6 +218,9 @@ class FlatCAMGUI(QtGui.QMainWindow):
         self.progress_bar.setMaximum(100)
         infobar.addWidget(self.progress_bar)
 
+        self.activity_view = FlatCAMActivityView()
+        infobar.addWidget(self.activity_view)
+
         #############
         ### Icons ###
         #############
@@ -238,6 +241,35 @@ class FlatCAMGUI(QtGui.QMainWindow):
         QtGui.qApp.quit()
 
 
+class FlatCAMActivityView(QtGui.QWidget):
+
+    def __init__(self, parent=None):
+        super(FlatCAMActivityView, self).__init__(parent=parent)
+
+        self.icon = QtGui.QLabel(self)
+        self.icon.setGeometry(0, 0, 12, 12)
+        self.movie = QtGui.QMovie("share/717.GIF")
+        self.icon.setMovie(self.movie)
+        #self.movie.start()
+
+        layout = QtGui.QHBoxLayout()
+        layout.setContentsMargins(5, 0, 5, 0)
+        self.setLayout(layout)
+
+        layout.addWidget(self.icon)
+        self.text = QtGui.QLabel(self)
+        self.text.setText("Idle.")
+
+        layout.addWidget(self.text)
+
+    def set_idle(self):
+        self.movie.stop()
+        self.text.setText("Idle.")
+
+    def set_busy(self, msg):
+        self.movie.start()
+        self.text.setText(msg)
+
 class FlatCAMInfoBar(QtGui.QWidget):
 
     def __init__(self, parent=None):

+ 73 - 0
FlatCAMProcess.py

@@ -0,0 +1,73 @@
+from FlatCAMGUI import FlatCAMActivityView
+
+class FCProcess(object):
+
+    def __init__(self, descr):
+        self.callbacks = {
+            "done": []
+        }
+        self.descr = descr
+
+    def done(self):
+        for fcn in self.callbacks["done"]:
+            fcn(self)
+
+    def connect(self, callback, event="done"):
+        if callback not in self.callbacks[event]:
+            self.callbacks[event].append(callback)
+
+    def disconnect(self, callback, event="done"):
+        try:
+            self.callbacks[event].remove(callback)
+        except ValueError:
+            pass
+
+    def status_msg(self):
+        return self.descr
+
+
+class FCProcessContainer(object):
+
+    def __init__(self):
+
+        self.procs = []
+
+    def add(self, proc):
+
+        self.procs.append(proc)
+
+    def new(self, descr):
+        proc = FCProcess(descr)
+        proc.connect(self.on_done, event="done")
+
+    def on_done(self, proc):
+        pass
+
+    def remove(self, proc):
+
+        if proc in self.procs:
+            self.procs.remove(proc)
+
+
+class FCVisibleProcessContainer(FCProcessContainer):
+
+    def __init__(self, view):
+        assert isinstance(view, FlatCAMActivityView)
+
+        super(FCVisibleProcessContainer, self).__init__()
+
+        self.view = view
+
+    def on_done(self, proc):
+        super(FCVisibleProcessContainer, self).on_done(proc)
+
+        self.update_view()
+
+    def update_view(self):
+
+        if len(self.procs) == 0:
+            self.view.set_idle()
+        elif len(self.procs) == 1:
+            self.view.set_busy(self.procs[0].status_msg())
+        else:
+            self.view.set_busy("%d processes running." % len(self.procs))

+ 16 - 4
camlib.py

@@ -340,13 +340,25 @@ class Geometry(object):
         geoms = FlatCAMRTreeStorage()
         geoms.get_points = get_pts
 
+        # Can only result in a Polygon or MultiPolygon
         current = polygon.buffer(-tooldia / 2.0)
 
-        geoms.insert(current.exterior)
-        for i in current.interiors:
-            geoms.insert(i)
+        # current can be a MultiPolygon
+        try:
+            for p in current:
+                geoms.insert(p.exterior)
+                for i in p.interiors:
+                    geoms.insert(i)
+
+        # Not a Multipolygon. Must be a Polygon
+        except TypeError:
+            geoms.insert(current.exterior)
+            for i in current.interiors:
+                geoms.insert(i)
 
         while True:
+
+            # Can only result in a Polygon or MultiPolygon
             current = current.buffer(-tooldia * (1 - overlap))
             if current.area > 0:
 
@@ -357,7 +369,7 @@ class Geometry(object):
                         for i in p.interiors:
                             geoms.insert(i)
 
-                # Not a Multipolygon.
+                # Not a Multipolygon. Must be a Polygon
                 except TypeError:
                     geoms.insert(current.exterior)
                     for i in current.interiors:

+ 20 - 0
sandbox/process_widget.py

@@ -0,0 +1,20 @@
+import sys
+from PyQt4.QtGui import *
+
+app = QApplication(sys.argv)
+
+top = QWidget()
+halign = QHBoxLayout()
+top.setLayout(halign)
+busy_anim = QMovie("../share/busy16.gif")
+busy_anim.start()
+busy_anim_label = QLabel()
+busy_anim_label.setMovie(busy_anim)
+halign.addWidget(busy_anim_label)
+
+message_label = QLabel("Processing...")
+halign.addWidget(message_label)
+
+top.show()
+
+sys.exit(app.exec_())