#!/usr/bin/python import sys import pygtk pygtk.require('2.0') import gtk import gtk.gdk import gtk.glade import gnome import gnome.ui import scipy import pango from system import project, workflow, dataset, logger, plots, navigator, dialogs PROGRAM_NAME = 'fluent' VERSION = '0.1.0' GLADEFILENAME = 'system/fluent.glade' class FluentApp: def __init__(self, wf): # Application variables self.project = None self.current_data = None self._last_view = None self._plot_toolbar = None gtk.glade.set_custom_handler(self.custom_object_factory) 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._update_toolbar) 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) # Set up workflow self.wf_menu = workflow.WorkflowView(self.workflow) self.wf_menu.show() self['workflow_vbox'].pack_end(self.wf_menu) # Set up plot toolbar # self['plot_toolbar_dock'].add(plot.get_toolbar(self.app)) # Connect signals signals = {'on_quit1_activate' : (gtk.main_quit), 'on_appwindow_delete_event' : (gtk.main_quit), 'on_zoom_in_button_clicked' : (self.on_single_view), 'on_zoom_out_button_clicked' : (self.on_multiple_view), 'on_new1_activate' : (self.on_create_project), 'on_button_new_clicked' : (self.on_create_project), 'on_workflow_refresh_clicked' : (self.on_workflow_refresh_clicked), 'on_about1_activate' : (self.on_help_about)} self.widget_tree.signal_autoconnect(signals) # Log that we've set up the app now logger.log('debug', 'Program started') def change_plot(self, plot): pt = self.widget_tree.get_widget('main_view') pt.insert_view(plot) def on_single_view(self, button): nb = self.widget_tree.get_widget('main_view') nb.goto_large() def on_multiple_view(self, button): nb = self.widget_tree.get_widget('main_view') nb.goto_small() def __getitem__(self, key): return self.widget_tree.get_widget(key) def on_create_project(self, *rest): d = dialogs.CreateProjectDruid(self) d.run() def on_help_about(self, *rest): widget_tree = gtk.glade.XML(GLADEFILENAME, 'aboutdialog') about = widget_tree.get_widget('aboutdialog') about.run() def on_workflow_refresh_clicked(self, *ignored): try: reload(sys.modules[self.workflow.__class__.__module__]) except Exception, e: logger.log('warning', 'Cannot reload workflow') logger.log('warning', e) else: logger.log('notice', 'Successfully reloaded workflow')