|
|
@@ -1,4 +1,7 @@
|
|
|
from FlatCAMGUI import FlatCAMActivityView
|
|
|
+from PyQt4 import QtCore
|
|
|
+import weakref
|
|
|
+
|
|
|
|
|
|
class FCProcess(object):
|
|
|
|
|
|
@@ -8,7 +11,11 @@ class FCProcess(object):
|
|
|
}
|
|
|
self.descr = descr
|
|
|
|
|
|
+ def __del__(self):
|
|
|
+ self.done()
|
|
|
+
|
|
|
def done(self):
|
|
|
+ print "FCProcess.done()"
|
|
|
for fcn in self.callbacks["done"]:
|
|
|
fcn(self)
|
|
|
|
|
|
@@ -34,40 +41,74 @@ class FCProcessContainer(object):
|
|
|
|
|
|
def add(self, proc):
|
|
|
|
|
|
- self.procs.append(proc)
|
|
|
+ self.procs.append(weakref.ref(proc))
|
|
|
|
|
|
def new(self, descr):
|
|
|
proc = FCProcess(descr)
|
|
|
+
|
|
|
proc.connect(self.on_done, event="done")
|
|
|
|
|
|
- def on_done(self, proc):
|
|
|
+ # if proc not in self.procs:
|
|
|
+ # self.procs.append(proc)
|
|
|
+ self.add(proc)
|
|
|
+
|
|
|
+ self.on_change(proc)
|
|
|
+
|
|
|
+ return proc
|
|
|
+
|
|
|
+ def on_change(self, proc):
|
|
|
pass
|
|
|
|
|
|
+ def on_done(self, proc):
|
|
|
+ self.remove(proc)
|
|
|
+
|
|
|
def remove(self, proc):
|
|
|
|
|
|
- if proc in self.procs:
|
|
|
- self.procs.remove(proc)
|
|
|
+ to_be_removed = []
|
|
|
|
|
|
+ for pref in self.procs:
|
|
|
+ if pref() == proc or pref() is None:
|
|
|
+ to_be_removed.append(pref)
|
|
|
|
|
|
-class FCVisibleProcessContainer(FCProcessContainer):
|
|
|
+ for pref in to_be_removed:
|
|
|
+ self.procs.remove(pref)
|
|
|
+
|
|
|
+
|
|
|
+class FCVisibleProcessContainer(QtCore.QObject, FCProcessContainer):
|
|
|
+ something_changed = QtCore.pyqtSignal()
|
|
|
|
|
|
def __init__(self, view):
|
|
|
assert isinstance(view, FlatCAMActivityView)
|
|
|
|
|
|
- super(FCVisibleProcessContainer, self).__init__()
|
|
|
+ #super(FCVisibleProcessContainer, self).__init__()
|
|
|
+ FCProcessContainer.__init__(self)
|
|
|
+ QtCore.QObject.__init__(self)
|
|
|
|
|
|
self.view = view
|
|
|
|
|
|
+ self.something_changed.connect(self.update_view)
|
|
|
+
|
|
|
def on_done(self, proc):
|
|
|
+ print "FCVisibleProcessContainer.on_done()"
|
|
|
super(FCVisibleProcessContainer, self).on_done(proc)
|
|
|
|
|
|
- self.update_view()
|
|
|
+ #self.update_view()
|
|
|
+ self.something_changed.emit()
|
|
|
|
|
|
- def update_view(self):
|
|
|
+ def on_change(self, proc):
|
|
|
+ print "FCVisibleProcessContainer.on_change()"
|
|
|
+ super(FCVisibleProcessContainer, self).on_change(proc)
|
|
|
|
|
|
+ #self.update_view()
|
|
|
+ self.something_changed.emit()
|
|
|
+
|
|
|
+ def update_view(self):
|
|
|
+ print "FCVisibleProcessContainer.update_view()"
|
|
|
if len(self.procs) == 0:
|
|
|
self.view.set_idle()
|
|
|
+
|
|
|
elif len(self.procs) == 1:
|
|
|
- self.view.set_busy(self.procs[0].status_msg())
|
|
|
+ self.view.set_busy(self.procs[0]().status_msg())
|
|
|
+
|
|
|
else:
|
|
|
self.view.set_busy("%d processes running." % len(self.procs))
|