diff --git a/FlatCAMGUI.py b/FlatCAMGUI.py index 25462f3e..86e89b6b 100644 --- a/FlatCAMGUI.py +++ b/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): diff --git a/FlatCAMProcess.py b/FlatCAMProcess.py new file mode 100644 index 00000000..cfd4801d --- /dev/null +++ b/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)) \ No newline at end of file diff --git a/camlib.py b/camlib.py index 31cee105..1283cf11 100644 --- a/camlib.py +++ b/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: diff --git a/sandbox/process_widget.py b/sandbox/process_widget.py new file mode 100644 index 00000000..9b4790d5 --- /dev/null +++ b/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_()) \ No newline at end of file