Sfoglia il codice sorgente

PlotCanvas now stores reference to app.

Juan Pablo Caram 10 anni fa
parent
commit
2bf78920ae
2 ha cambiato i file con 34 aggiunte e 8 eliminazioni
  1. 20 4
      FlatCAMApp.py
  2. 14 4
      PlotCanvas.py

+ 20 - 4
FlatCAMApp.py

@@ -72,11 +72,26 @@ class App(QtCore.QObject):
     ## Manual URL
     manual_url = "http://flatcam.org/manual/index.html"
 
-    ## Signals
-    inform = QtCore.pyqtSignal(str)  # Message
-    worker_task = QtCore.pyqtSignal(dict)  # Worker task
+    ##################
+    ##    Signals   ##
+    ##################
+
+    # Inform the user
+    # Handled by:
+    #  * App.info() --> Print on the status bar
+    inform = QtCore.pyqtSignal(str)
+
+    # General purpose background task
+    worker_task = QtCore.pyqtSignal(dict)
+
+    # File opened
+    # Handled by:
+    #  * register_folder()
+    #  * register_recent()
     file_opened = QtCore.pyqtSignal(str, str)  # File type and filename
+
     progress = QtCore.pyqtSignal(int)  # Percentage of progress
+
     plots_updated = QtCore.pyqtSignal()
 
     # Emitted by new_object() and passes the new object as argument.
@@ -87,6 +102,7 @@ class App(QtCore.QObject):
     # Emitted when a new object has been added to the collection
     # and is ready to be used.
     new_object_available = QtCore.pyqtSignal(object)
+
     message = QtCore.pyqtSignal(str, str, str)
 
     def __init__(self, user_defaults=True, post_gui=None):
@@ -161,7 +177,7 @@ class App(QtCore.QObject):
 
         #### Plot Area ####
         # self.plotcanvas = PlotCanvas(self.ui.splitter)
-        self.plotcanvas = PlotCanvas(self.ui.right_layout)
+        self.plotcanvas = PlotCanvas(self.ui.right_layout, self)
         self.plotcanvas.mpl_connect('button_press_event', self.on_click_over_plot)
         self.plotcanvas.mpl_connect('motion_notify_event', self.on_mouse_move_over_plot)
         self.plotcanvas.mpl_connect('key_press_event', self.on_key_over_plot)

+ 14 - 4
PlotCanvas.py

@@ -42,10 +42,12 @@ class CanvasCache(QtCore.QObject):
     # A bitmap is ready to be displayed.
     new_screen = QtCore.pyqtSignal()
 
-    def __init__(self, plotcanvas, dpi=50):
+    def __init__(self, plotcanvas, app, dpi=50):
 
         super(CanvasCache, self).__init__()
 
+        self.app = app
+
         self.plotcanvas = plotcanvas
         self.dpi = dpi
 
@@ -66,6 +68,8 @@ class CanvasCache(QtCore.QObject):
 
         self.plotcanvas.update_screen_request.connect(self.on_update_req)
 
+        self.app.new_object_available.connect(self.on_new_object_available)
+
     def on_update_req(self, extents):
         """
         Event handler for an updated display request.
@@ -75,7 +79,7 @@ class CanvasCache(QtCore.QObject):
 
         log.debug("Canvas update requested: %s" % str(extents))
 
-        # Note: This information here might be out of date. Establish
+        # Note: This information below might be out of date. Establish
         # a protocol regarding when to change the canvas in the main
         # thread and when to check these values here in the background,
         # or pass this data in the signal (safer).
@@ -89,6 +93,10 @@ class CanvasCache(QtCore.QObject):
 
         # Continue to update the cache.
 
+    def on_new_object_available(self):
+
+        log.debug("A new object is available. Should plot it!")
+
 
 class PlotCanvas(QtCore.QObject):
     """
@@ -100,7 +108,7 @@ class PlotCanvas(QtCore.QObject):
     # is a list with [xmin, xmax, ymin, ymax, zoom(optional)]
     update_screen_request = QtCore.pyqtSignal(list)
 
-    def __init__(self, container):
+    def __init__(self, container, app):
         """
         The constructor configures the Matplotlib figure that
         will contain all plots, creates the base axes and connects
@@ -112,6 +120,8 @@ class PlotCanvas(QtCore.QObject):
 
         super(PlotCanvas, self).__init__()
 
+        self.app = app
+
         # Options
         self.x_margin = 15  # pixels
         self.y_margin = 25  # Pixels
@@ -147,7 +157,7 @@ class PlotCanvas(QtCore.QObject):
         self.background = self.canvas.copy_from_bbox(self.axes.bbox)
 
         ### Bitmap Cache
-        self.cache = CanvasCache(self)
+        self.cache = CanvasCache(self, self.app)
         self.cache_thread = QtCore.QThread()
         self.cache.moveToThread(self.cache_thread)
         super(PlotCanvas, self).connect(self.cache_thread, QtCore.SIGNAL("started()"), self.cache.run)