Toolbars work again.
This commit is contained in:
parent
0670c42bd4
commit
aca9a47f56
|
@ -22,8 +22,7 @@ GLADEFILENAME = os.path.join(DATADIR, 'fluents.glade')
|
|||
|
||||
class FluentApp:
|
||||
|
||||
def __init__(self, wf):
|
||||
# Application variables
|
||||
def __init__(self, wf): # Application variables
|
||||
self.project = None
|
||||
self.current_data = None
|
||||
self._last_view = None
|
||||
|
@ -33,67 +32,6 @@ class FluentApp:
|
|||
self.widget_tree = gtk.glade.XML(GLADEFILENAME, 'appwindow')
|
||||
self.workflow = wf(self)
|
||||
|
||||
def set_project(self, project):
|
||||
logger.log('notice', 'Creating a new project')
|
||||
self.project = project
|
||||
self.workflow.add_project(self.project)
|
||||
self.navigator_view.add_project(self.project)
|
||||
|
||||
def set_workflow(self, workflow):
|
||||
self.workflow = workflow
|
||||
self.wf_menu.set_workflow(self.workflow)
|
||||
|
||||
def custom_object_factory(self, glade, function_name, widget_name,\
|
||||
str1, str2, int1, int2):
|
||||
handler = getattr(self, function_name)
|
||||
return handler(str1, str2, int1, int2)
|
||||
|
||||
def create_logview(self, str1, str2, int1, int2):
|
||||
# Set up log view
|
||||
self.log_view = logger.LogView(logger.logger)
|
||||
# self.log_view.set_level('notice')
|
||||
self.log_view.show()
|
||||
return self.log_view
|
||||
|
||||
def create_main_view(self, str1, str2, int1, int2):
|
||||
self.main_view = plots.MainView()
|
||||
self.main_view.show()
|
||||
return self.main_view
|
||||
|
||||
def _update_toolbar(self, view):
|
||||
logger.log("debug", "view changed to %s" % view)
|
||||
# don't do anything on no change
|
||||
if self._last_view == view:
|
||||
return
|
||||
self._last_view = view
|
||||
|
||||
window = self.widget_tree.get_widget('plot_toolbar_dock')
|
||||
if self._plot_toolbar:
|
||||
window.remove(self._plot_toolbar)
|
||||
|
||||
self._plot_toolbar = view.get_toolbar()
|
||||
if self._plot_toolbar:
|
||||
window.add(self._plot_toolbar)
|
||||
|
||||
def create_small_view(self, str1, str2, int1, int2):
|
||||
self.small_view = plots.SmallView()
|
||||
self.small_view.show()
|
||||
return self.small_view
|
||||
|
||||
def create_large_view(self, str1, str2, int1, int2,project):
|
||||
self.large_view = plots.LargeView()
|
||||
self.large_view.show()
|
||||
return self.large_view
|
||||
|
||||
def create_navigator_view(self, str1, str2, int1, int2):
|
||||
# tree = self.project.data_tree
|
||||
self.navigator_view = navigator.NavigatorView(None, self)
|
||||
self.navigator_view.show()
|
||||
return self.navigator_view
|
||||
|
||||
def show(self):
|
||||
self.init_gui()
|
||||
|
||||
def init_gui(self):
|
||||
self['appwindow'].set_size_request(800, 600)
|
||||
|
||||
|
@ -121,20 +59,80 @@ class FluentApp:
|
|||
}
|
||||
self.widget_tree.signal_autoconnect(signals)
|
||||
|
||||
self['main_view'].connect('view-changed', self.on_view_changed)
|
||||
|
||||
# Log that we've set up the app now
|
||||
logger.log('debug', 'Program started')
|
||||
|
||||
def set_project(self, project):
|
||||
logger.log('notice', 'Creating a new project')
|
||||
self.project = project
|
||||
self.workflow.add_project(self.project)
|
||||
self.navigator_view.add_project(self.project)
|
||||
|
||||
def set_workflow(self, workflow):
|
||||
self.workflow = workflow
|
||||
self.wf_menu.set_workflow(self.workflow)
|
||||
|
||||
def show(self):
|
||||
self.init_gui()
|
||||
|
||||
def change_plot(self, plot):
|
||||
pt = self.widget_tree.get_widget('main_view')
|
||||
pt.insert_view(plot)
|
||||
|
||||
def get_active_view_frame(self):
|
||||
return self['main_view'].get_active_view_frame()
|
||||
|
||||
def _update_toolbar(self, view):
|
||||
"Set the plot specific toolbar to the toolbar of the currently active plot."
|
||||
|
||||
# don't do anything on no change
|
||||
if self._last_view == view:
|
||||
return
|
||||
self._last_view = view
|
||||
|
||||
logger.log("debug", "view changed to %s" % view)
|
||||
|
||||
window = self.widget_tree.get_widget('plot_toolbar_dock')
|
||||
if self._plot_toolbar:
|
||||
window.remove(self._plot_toolbar)
|
||||
|
||||
self._plot_toolbar = view.get_toolbar()
|
||||
if self._plot_toolbar:
|
||||
window.add(self._plot_toolbar)
|
||||
|
||||
# Methods to create GUI widgets from CustomWidgets in the glade file.
|
||||
# The custom_object_factory calls other functions to generate specific
|
||||
# widgets.
|
||||
|
||||
def custom_object_factory(self, glade, fun_name, widget_name, s1, s2, i1, i2):
|
||||
"Called by the glade file reader to create custom GUI widgets."
|
||||
handler = getattr(self, fun_name)
|
||||
return handler(s1, s2, i1, i2)
|
||||
|
||||
def create_logview(self, str1, str2, int1, int2):
|
||||
self.log_view = logger.LogView(logger.logger)
|
||||
self.log_view.show()
|
||||
return self.log_view
|
||||
|
||||
def create_main_view(self, str1, str2, int1, int2):
|
||||
self.main_view = plots.MainView()
|
||||
self.main_view.show()
|
||||
return self.main_view
|
||||
|
||||
def create_navigator_view(self, str1, str2, int1, int2):
|
||||
self.navigator_view = navigator.NavigatorView(None, self)
|
||||
self.navigator_view.show()
|
||||
return self.navigator_view
|
||||
|
||||
# Event handlers.
|
||||
|
||||
def on_single_view(self, *ignored):
|
||||
nb = self.widget_tree.get_widget('main_view')
|
||||
nb.goto_large()
|
||||
self['main_view'].goto_large()
|
||||
|
||||
def on_multiple_view(self, *ignored):
|
||||
nb = self.widget_tree.get_widget('main_view')
|
||||
nb.goto_small()
|
||||
self['main_view'].goto_small()
|
||||
|
||||
def __getitem__(self, key):
|
||||
return self.widget_tree.get_widget(key)
|
||||
|
@ -162,3 +160,7 @@ class FluentApp:
|
|||
logger.log('warning', e)
|
||||
else:
|
||||
logger.log('notice', 'Successfully reloaded workflow')
|
||||
|
||||
def on_view_changed(self, widget, vf):
|
||||
self._update_toolbar(vf.get_view())
|
||||
|
||||
|
|
146
system/plots.py
146
system/plots.py
|
@ -1,5 +1,6 @@
|
|||
|
||||
import pygtk
|
||||
import gobject
|
||||
import gtk
|
||||
import matplotlib
|
||||
import scipy
|
||||
|
@ -46,6 +47,12 @@ class ObjectTable:
|
|||
|
||||
|
||||
class ViewFrame (gtk.Frame):
|
||||
"""
|
||||
A ViewFrame is a gtk bin that contains a view.
|
||||
The ViewFrame is either active or inactive, and belongs to a group of
|
||||
VeiwFrames of which only one can be active at any time.
|
||||
"""
|
||||
|
||||
def __init__(self, view_frames):
|
||||
gtk.Frame.__init__(self)
|
||||
self.focused = False
|
||||
|
@ -65,7 +72,6 @@ class ViewFrame (gtk.Frame):
|
|||
gtk.gdk.ACTION_LINK)
|
||||
self.connect("drag-data-received", self.on_drag_data_received)
|
||||
|
||||
|
||||
# Set view
|
||||
self._view = self.empty_view
|
||||
self._view.connect("button-press-event", self.on_button_press_event)
|
||||
|
@ -83,6 +89,7 @@ class ViewFrame (gtk.Frame):
|
|||
|
||||
self.set_shadow_type(gtk.SHADOW_IN)
|
||||
self.focused = True
|
||||
self.emit('focus-changed', self, True)
|
||||
return self
|
||||
|
||||
def unfocus(self):
|
||||
|
@ -92,6 +99,7 @@ class ViewFrame (gtk.Frame):
|
|||
|
||||
self.set_shadow_type(gtk.SHADOW_OUT)
|
||||
self.focused = False
|
||||
self.emit('focus-changed', self, False)
|
||||
|
||||
def set_view(self, view):
|
||||
"""Set view to view or to empty view if parameter is None"""
|
||||
|
@ -155,6 +163,9 @@ class MainView (gtk.Notebook):
|
|||
self._large_view = ViewFrame(list())
|
||||
self.update_small_views()
|
||||
|
||||
for vf in self._view_frames:
|
||||
vf.connect('focus-changed', self.on_view_focus_changed)
|
||||
|
||||
self.append_page(self._small_views)
|
||||
self.append_page(self._large_view)
|
||||
self.show()
|
||||
|
@ -205,6 +216,9 @@ class MainView (gtk.Notebook):
|
|||
self._small_views.show()
|
||||
gtk.Notebook.show(self)
|
||||
|
||||
def on_view_focus_changed(self, widget, vf, focused):
|
||||
if focused:
|
||||
self.emit('view-changed', vf)
|
||||
|
||||
class Plot (gtk.Frame):
|
||||
|
||||
|
@ -234,125 +248,6 @@ class Plot (gtk.Frame):
|
|||
return None
|
||||
|
||||
|
||||
class SmallView (gtk.Table):
|
||||
|
||||
def __init__(self):
|
||||
gtk.Table.__init__(self, 2, 2, True)
|
||||
|
||||
self.child_views = [[EmptyView(), EmptyView()],
|
||||
[EmptyView(), EmptyView()]]
|
||||
self.cols = 2
|
||||
self.rows = 2
|
||||
|
||||
self.active_x = 0
|
||||
self.active_y = 0
|
||||
|
||||
self.set_row_spacings(3)
|
||||
self.set_col_spacings(3)
|
||||
self._listener = None
|
||||
|
||||
for x in range(self.cols):
|
||||
for y in range(self.rows):
|
||||
child = self.child_views[x][y]
|
||||
child.parent_signalling = child.connect('button_press_event', self.__view_button_event__)
|
||||
self.attach(child, x, x+1, y, y+1)
|
||||
|
||||
# drag'n'drop
|
||||
for views in self.child_views:
|
||||
for view in views:
|
||||
view.drag_dest_set(gtk.DEST_DEFAULT_ALL,
|
||||
[("GTK_TREE_MODEL_ROW",gtk.TARGET_SAME_APP,7)],
|
||||
gtk.gdk.ACTION_LINK)
|
||||
view.connect("drag-data-received",self.drag_received_by_view,view)
|
||||
|
||||
|
||||
def drag_received_by_view(self, widget, drag_context, x, y, selection, info, timestamp, view):
|
||||
treestore, path = selection.tree_get_row_drag_data()
|
||||
iter = treestore.get_iter(path)
|
||||
obj = treestore.get_value(iter,2)
|
||||
|
||||
loc = self.find_child(view)
|
||||
|
||||
if loc and isinstance(obj, Plot) and (not self.find_child(obj)):
|
||||
self.set_child(obj,loc[0],loc[1])
|
||||
|
||||
|
||||
def set_view_listener(self, listener):
|
||||
self._listener = listener
|
||||
|
||||
def set_child(self, child, col, row):
|
||||
# urg, this probably belongs somewhere else
|
||||
child.drag_dest_set(gtk.DEST_DEFAULT_ALL,
|
||||
[("GTK_TREE_MODEL_ROW",gtk.TARGET_SAME_APP,7)],
|
||||
gtk.gdk.ACTION_LINK)
|
||||
child.connect("drag-data-received",self.drag_received_by_view,child)
|
||||
|
||||
cur_widget = self.child_views[col][row]
|
||||
cur_widget.disconnect(cur_widget.parent_signalling)
|
||||
self.remove(cur_widget)
|
||||
self.attach(child, col, col+1, row, row+1)
|
||||
child.parent_signalling = child.connect('button_press_event', self.__view_button_event__)
|
||||
self.child_views[col][row] = child
|
||||
if cur_widget.active:
|
||||
child.mark_active(True)
|
||||
cur_widget.mark_active(False)
|
||||
child.show()
|
||||
|
||||
def borrow_current(self):
|
||||
self.borrowed = self.child_views[self.active_x][self.active_y]
|
||||
self.remove_child(self.active_x, self.active_y)
|
||||
return self.borrowed
|
||||
|
||||
def return_current(self, view):
|
||||
self.set_child(view, self.active_x, self.active_y)
|
||||
|
||||
def remove_child(self, col, row):
|
||||
self.remove(self.child_views[col][row])
|
||||
self.attach(EmptyView(), col, col+1, row, row+1)
|
||||
|
||||
def insert_view(self, child):
|
||||
if not self.find_child(child):
|
||||
self.set_child(child, self.active_x, self.active_y)
|
||||
|
||||
def show(self):
|
||||
for x in self.child_views:
|
||||
for y in x:
|
||||
y.show()
|
||||
gtk.Table.show(self)
|
||||
|
||||
def hide(self):
|
||||
for x in self.child_views:
|
||||
for y in x:
|
||||
y.hide()
|
||||
gtk.Table.hide(self)
|
||||
|
||||
def set_active(self, x, y):
|
||||
old_focus = self.child_views[self.active_x][self.active_y]
|
||||
new_focus = self.child_views[x][y]
|
||||
old_focus.mark_active(False)
|
||||
new_focus.mark_active(True)
|
||||
self.active_x = x
|
||||
self.active_y = y
|
||||
if self._listener:
|
||||
logger.log("debug", "emitting")
|
||||
self._listener(new_focus)
|
||||
|
||||
def find_child(self, child):
|
||||
for i, row in enumerate(self.child_views):
|
||||
for j, v in enumerate(row):
|
||||
if v == child:
|
||||
return (i, j)
|
||||
return None
|
||||
|
||||
def __view_button_event__(self, view, *rest):
|
||||
loc = self.find_child(view)
|
||||
if loc:
|
||||
self.set_active(loc[0], loc[1])
|
||||
|
||||
def get_view(self, x, y):
|
||||
return self.child_views[x][y]
|
||||
|
||||
|
||||
class EmptyView (Plot):
|
||||
def __init__(self):
|
||||
Plot.__init__(self, 'Empty view')
|
||||
|
@ -600,3 +495,14 @@ class ScatterPlot(Plot):
|
|||
self.ax.plot(xdata_new,ydata_new,'or')
|
||||
self.canvas.draw()
|
||||
|
||||
# Create a view-changed signal that should be emitted every time
|
||||
# the active view changes.
|
||||
gobject.signal_new('view-changed', MainView, gobject.SIGNAL_RUN_LAST,
|
||||
gobject.TYPE_NONE,
|
||||
(gobject.TYPE_PYOBJECT,))
|
||||
|
||||
# Create focus-changed signal
|
||||
gobject.signal_new('focus-changed', ViewFrame, gobject.SIGNAL_RUN_LAST,
|
||||
gobject.TYPE_NONE,
|
||||
(gobject.TYPE_PYOBJECT, gobject.TYPE_BOOLEAN,))
|
||||
|
||||
|
|
Reference in New Issue