PlotCanvas now stores reference to app.

This commit is contained in:
Juan Pablo Caram 2016-01-03 16:38:24 -05:00
parent 3b206493a3
commit 2bf78920ae
2 changed files with 34 additions and 8 deletions

View File

@ -72,11 +72,26 @@ class App(QtCore.QObject):
## Manual URL ## Manual URL
manual_url = "http://flatcam.org/manual/index.html" manual_url = "http://flatcam.org/manual/index.html"
## Signals ##################
inform = QtCore.pyqtSignal(str) # Message ## Signals ##
worker_task = QtCore.pyqtSignal(dict) # Worker task ##################
# 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 file_opened = QtCore.pyqtSignal(str, str) # File type and filename
progress = QtCore.pyqtSignal(int) # Percentage of progress progress = QtCore.pyqtSignal(int) # Percentage of progress
plots_updated = QtCore.pyqtSignal() plots_updated = QtCore.pyqtSignal()
# Emitted by new_object() and passes the new object as argument. # 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 # Emitted when a new object has been added to the collection
# and is ready to be used. # and is ready to be used.
new_object_available = QtCore.pyqtSignal(object) new_object_available = QtCore.pyqtSignal(object)
message = QtCore.pyqtSignal(str, str, str) message = QtCore.pyqtSignal(str, str, str)
def __init__(self, user_defaults=True, post_gui=None): def __init__(self, user_defaults=True, post_gui=None):
@ -161,7 +177,7 @@ class App(QtCore.QObject):
#### Plot Area #### #### Plot Area ####
# self.plotcanvas = PlotCanvas(self.ui.splitter) # 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('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('motion_notify_event', self.on_mouse_move_over_plot)
self.plotcanvas.mpl_connect('key_press_event', self.on_key_over_plot) self.plotcanvas.mpl_connect('key_press_event', self.on_key_over_plot)

View File

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