diff --git a/fluents/fluents.py b/fluents/fluents.py index 9e8138f..e4a7e5f 100644 --- a/fluents/fluents.py +++ b/fluents/fluents.py @@ -13,7 +13,8 @@ import gnome import gnome.ui import scipy import pango -import project, workflow, dataset, logger, view, navigator, dialogs, selections, main +import project, workflow, dataset, view, navigator, dialogs, selections, main +from logger import logger, LogView PROGRAM_NAME = 'fluents' @@ -204,17 +205,14 @@ class FluentApp: self['main_view'].connect('view-changed', self.on_view_changed) # Log that we've set up the app now - logger.log('debug', 'Program started') + logger.debug('Program started') # Add ViewFrame table size to toolbar tb = ViewFrameToolButton() self['toolbar'].add(tb) def set_project(self, proj): - logger.log('notice', 'Creating a new project') -# self.project = proj -# project.project = proj -# main.workflow.add_project(proj) + logger.notice('Welcome to your new project. Grasp That Data!') self.navigator_view.add_project(proj) self.dimlist_crt.set_project(proj) self.sellist_crt.set_project(proj) @@ -253,7 +251,7 @@ class FluentApp: return self._last_view = view - logger.log("debug", "view changed to %s" % view) + logger.debug("view changed to %s" % view) window = self['plot_toolbar_dock'] if self._plot_toolbar: @@ -281,7 +279,7 @@ class FluentApp: return handler(s1, s2, i1, i2) def create_logview(self, str1, str2, int1, int2): - self.log_view = logger.LogView(logger.logger) + self.log_view = LogView(logger) self.log_view.show() return self.log_view @@ -342,10 +340,10 @@ class FluentApp: try: reload(sys.modules[main.workflow.__class__.__module__]) except Exception, e: - logger.log('warning', 'Cannot reload workflow') - logger.log('warning', e) + logger.warning('Cannot reload workflow') + logger.warning(e) else: - logger.log('notice', 'Successfully reloaded workflow') + logger.notice('Successfully reloaded workflow') def on_view_changed(self, widget, vf): self._update_toolbar(vf.get_view()) diff --git a/fluents/logger.py b/fluents/logger.py index 118b609..ff7c2e6 100644 --- a/fluents/logger.py +++ b/fluents/logger.py @@ -9,15 +9,15 @@ class Logger: gobject.TYPE_STRING, gobject.TYPE_STRING) self.levels = ['debug', 'notice', 'warning', 'error'] - self.level_text = {'debug': 'Debug', - 'notice': 'Notice', + self.level_text = {'debug': 'Debug', + 'notice': 'Notice', 'warning': 'Warning', - 'error': 'Error'} + 'error': 'Error'} self.components = {} - self.colors = { 'debug': 'grey', - 'notice': 'black', + self.colors = { 'debug': 'grey', + 'notice': 'black', 'warning': 'brown', - 'error': 'red' } + 'error': 'red' } def log(self, level, message): iter = self.store.append() @@ -28,6 +28,19 @@ class Logger: def level_number(self, level): return self.levels.index(level) + def debug(self, message): + self.log('debug', message) + + def notice(self, message): + self.log('notice', message) + + def warning(self, message): + self.log('warning', message) + + def error(self, message): + self.log('error', message) + + class LogView(gtk.TreeView): def __init__(self, logger=None, level='notice'): @@ -152,3 +165,4 @@ class LogMenu(gtk.Menu): logger = Logger() log = logger.log + diff --git a/fluents/navigator.py b/fluents/navigator.py index 4ec3024..c3e9d51 100644 --- a/fluents/navigator.py +++ b/fluents/navigator.py @@ -1,10 +1,10 @@ - import gtk import gobject import plots import time import fluents -import dataset, logger, plots, project, workflow, main +from logger import logger +import dataset, plots, project, workflow, main import scipy class NavigatorView (gtk.TreeView): @@ -58,7 +58,7 @@ class NavigatorView (gtk.TreeView): self.connect("drag-data-get",self.slot_drag_data) - logger.log('debug', 'Initializing navigator window.') + logger.debug('Initializing navigator window.') def slot_drag_data(self, treeview, context, selection, target_id, etime): """Sets the data for a drag event.""" @@ -96,10 +96,10 @@ class NavigatorView (gtk.TreeView): objs = [obj for timestamp, obj in objs] if objs and isinstance(objs[0], dataset.Dataset): - logger.log('debug', 'Selecting dataset') + logger.debug('Selecting dataset') main.project.set_current_data(objs) else: - logger.log('debug', 'Deselecting dataset') + logger.debug('Deselecting dataset') main.project.set_current_data([]) def on_row_changed(self, treestore, pos, iter): @@ -120,7 +120,7 @@ class NavigatorView (gtk.TreeView): obj = self.data_tree.get_value(tree_iter, 2) if isinstance(obj, plots.Plot): - logger.log('debug', 'Activating plot') + logger.debug('Activating plot') main.application.change_plot(obj) elif isinstance(obj, dataset.Dataset): pass @@ -135,7 +135,7 @@ class NavigatorView (gtk.TreeView): main.application.change_plots(children) else: t = type(obj) - logger.log('notice', 'Activated datatype was %s. Don\'t know what to do.' % t) + logger.notice('Activated datatype was %s. Don\'t know what to do.' % t) def popup_menu(self, *rest): self.menu.popup(None, None, None, 0, 0) @@ -303,9 +303,9 @@ class NavigatorMenu(gtk.Menu): dialog.set_current_name("%s.ftsv" % self.dataset.get_name()) retval = dialog.run() if retval in [gtk.RESPONSE_CANCEL, gtk.RESPONSE_DELETE_EVENT]: - logger.log("debug", "Cancelled save dataset") + logger.debug("Cancelled save dataset") elif retval == gtk.RESPONSE_OK: - logger.log("debug", "Saving dataset as: %s" % dialog.get_filename()) + logger.debug("Saving dataset as: %s" % dialog.get_filename()) fd = open(dialog.get_filename(), 'w') dataset.write_ftsv(fd, self.dataset) fd.close() diff --git a/fluents/project.py b/fluents/project.py index e794570..5d01d28 100644 --- a/fluents/project.py +++ b/fluents/project.py @@ -3,8 +3,7 @@ import scipy import gobject import gtk import fluents -import logger -import dataset, plots, main +import logger, dataset, plots, main class Project: """A Project contains datasets, selections etc. @@ -14,7 +13,7 @@ class Project: navigator. """ - def __init__(self,name="Testing"): + def __init__(self, name="Testing"): self.data_tree = gtk.TreeStore(str, str, object, @@ -63,6 +62,7 @@ class Project: return self.sel_obj def delete_data(self, it): + """Delete elements from the project.""" child = self.data_tree.iter_children(it) while child != None: c = self.data_tree.iter_next(child) @@ -142,12 +142,12 @@ class Project: self.notify_dataset_listeners() def object_at(self, path): - "Returns the object at a given path in the tree." - iter = self.get_iter(path) - object = self.get_value(iter, 2) - if object: - object.show() - return object + """Returns the object at a given path in the tree.""" + it = self.get_iter(path) + obj = self[it][2] + if obj: + obj.show() + return obj def set_current_data(self, obj): self.current_data = obj