This repository has been archived on 2024-07-04. You can view files and clone it, but cannot push or open issues or pull requests.
laydi/system/fluents.py

213 lines
7.4 KiB
Python
Executable File

#!/usr/bin/python
import os
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, selections
PROGRAM_NAME = 'fluents'
VERSION = '0.1.0'
DATADIR = os.path.dirname(sys.modules['system'].__file__)
ICONDIR = os.path.join(DATADIR,"..","icons")
GLADEFILENAME = os.path.join(DATADIR, 'fluents.glade')
class FluentApp:
def __init__(self, wf): # Application variables
self.project = None
self.current_data = None
self._last_view = None
self._plot_toolbar = None
self._toolbar_state = None
gtk.glade.set_custom_handler(self.custom_object_factory)
self.widget_tree = gtk.glade.XML(GLADEFILENAME, 'appwindow')
self.workflow = wf(self)
# self['selection_tree'].set_identifier_list(self['identifier_list'])
self.dimlistcontroller = selections.DimListController(self['dim_list'],
self['selection_tree'],
self['identifier_list'])
# self['dim_list'].set_selection_tree(self['selection_tree'])
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_index1_activate' : (self.on_help_index),
'on_about1_activate' : (self.on_help_about),
'on_report_bug1_activate' : (self.on_help_report_bug),
'on_small_view1_activate' : (self.on_multiple_view),
'on_large_view1_activate' : (self.on_single_view),
}
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)
self.dimlistcontroller.set_project(project)
# self['selection_tree'].set_project(self.project)
# self['dim_list'].set_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):
"""Sets the plot in the currently active ViewFrame. If the plot is
already shown in another ViewFrame it will be moved from there."""
# Set current selection in the plot before showing it.
plot.selection_changed(self.project.get_selection())
self['main_view'].insert_view(plot)
self._update_toolbar(plot)
def change_plots(self, plots):
"""Changes all plots."""
self['main_view'].set_all_plots(plots)
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['plot_toolbar_dock']
if self._plot_toolbar:
toolbar_state = self._plot_toolbar.get_mode()
window.remove(self._plot_toolbar)
else:
"Setting DEAULT in fluents"
toolbar_state = "DEFAULT"
if view:
self._plot_toolbar = view.get_toolbar()
self._plot_toolbar.set_mode(toolbar_state)
else:
self._plot_toolbar = None
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
def create_dim_list(self, str1, str2, int1, int2):
self.dim_list = selections.DimList()
self.dim_list.show()
return self.dim_list
def create_selection_tree(self, str1, str2, int1, int2):
self.selection_tree = selections.SelectionTree()
self.selection_tree.show()
return self.selection_tree
def create_identifier_list(self, str1, str2, int1, int2):
self.identifier_list = selections.IdentifierList()
self.identifier_list.show()
return self.identifier_list
def __getitem__(self, key):
return self.widget_tree.get_widget(key)
# Event handlers.
# These methods are called by the gtk framework in response to events and
# should not be called directly.
def on_single_view(self, *ignored):
self['main_view'].goto_large()
def on_multiple_view(self, *ignored):
self['main_view'].goto_small()
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_help_index(self, *ignored):
gnome.help_display_uri('https://dev.pvv.org/projects/fluent/wiki/help')
def on_help_report_bug(self, *ignored):
gnome.help_display_uri('https://dev.pvv.org/projects/fluent/newticket')
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')
def on_view_changed(self, widget, vf):
self._update_toolbar(vf.get_view())