Projects/laydi
Projects
/
laydi
Archived
7
0
Fork 0

About to change the way logging is normally called.

This commit is contained in:
Einar Ryeng 2007-12-11 01:02:47 +00:00
parent d0a7b1cbc2
commit 057e2a9f1d
4 changed files with 47 additions and 35 deletions

View File

@ -13,7 +13,8 @@ import gnome
import gnome.ui import gnome.ui
import scipy import scipy
import pango 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' PROGRAM_NAME = 'fluents'
@ -204,17 +205,14 @@ class FluentApp:
self['main_view'].connect('view-changed', self.on_view_changed) self['main_view'].connect('view-changed', self.on_view_changed)
# Log that we've set up the app now # Log that we've set up the app now
logger.log('debug', 'Program started') logger.debug('Program started')
# Add ViewFrame table size to toolbar # Add ViewFrame table size to toolbar
tb = ViewFrameToolButton() tb = ViewFrameToolButton()
self['toolbar'].add(tb) self['toolbar'].add(tb)
def set_project(self, proj): def set_project(self, proj):
logger.log('notice', 'Creating a new project') logger.notice('Welcome to your new project. Grasp That Data!')
# self.project = proj
# project.project = proj
# main.workflow.add_project(proj)
self.navigator_view.add_project(proj) self.navigator_view.add_project(proj)
self.dimlist_crt.set_project(proj) self.dimlist_crt.set_project(proj)
self.sellist_crt.set_project(proj) self.sellist_crt.set_project(proj)
@ -253,7 +251,7 @@ class FluentApp:
return return
self._last_view = view self._last_view = view
logger.log("debug", "view changed to %s" % view) logger.debug("view changed to %s" % view)
window = self['plot_toolbar_dock'] window = self['plot_toolbar_dock']
if self._plot_toolbar: if self._plot_toolbar:
@ -281,7 +279,7 @@ class FluentApp:
return handler(s1, s2, i1, i2) return handler(s1, s2, i1, i2)
def create_logview(self, str1, str2, int1, int2): def create_logview(self, str1, str2, int1, int2):
self.log_view = logger.LogView(logger.logger) self.log_view = LogView(logger)
self.log_view.show() self.log_view.show()
return self.log_view return self.log_view
@ -342,10 +340,10 @@ class FluentApp:
try: try:
reload(sys.modules[main.workflow.__class__.__module__]) reload(sys.modules[main.workflow.__class__.__module__])
except Exception, e: except Exception, e:
logger.log('warning', 'Cannot reload workflow') logger.warning('Cannot reload workflow')
logger.log('warning', e) logger.warning(e)
else: else:
logger.log('notice', 'Successfully reloaded workflow') logger.notice('Successfully reloaded workflow')
def on_view_changed(self, widget, vf): def on_view_changed(self, widget, vf):
self._update_toolbar(vf.get_view()) self._update_toolbar(vf.get_view())

View File

@ -28,6 +28,19 @@ class Logger:
def level_number(self, level): def level_number(self, level):
return self.levels.index(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): class LogView(gtk.TreeView):
def __init__(self, logger=None, level='notice'): def __init__(self, logger=None, level='notice'):
@ -152,3 +165,4 @@ class LogMenu(gtk.Menu):
logger = Logger() logger = Logger()
log = logger.log log = logger.log

View File

@ -1,10 +1,10 @@
import gtk import gtk
import gobject import gobject
import plots import plots
import time import time
import fluents import fluents
import dataset, logger, plots, project, workflow, main from logger import logger
import dataset, plots, project, workflow, main
import scipy import scipy
class NavigatorView (gtk.TreeView): class NavigatorView (gtk.TreeView):
@ -58,7 +58,7 @@ class NavigatorView (gtk.TreeView):
self.connect("drag-data-get",self.slot_drag_data) 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): def slot_drag_data(self, treeview, context, selection, target_id, etime):
"""Sets the data for a drag event.""" """Sets the data for a drag event."""
@ -96,10 +96,10 @@ class NavigatorView (gtk.TreeView):
objs = [obj for timestamp, obj in objs] objs = [obj for timestamp, obj in objs]
if objs and isinstance(objs[0], dataset.Dataset): if objs and isinstance(objs[0], dataset.Dataset):
logger.log('debug', 'Selecting dataset') logger.debug('Selecting dataset')
main.project.set_current_data(objs) main.project.set_current_data(objs)
else: else:
logger.log('debug', 'Deselecting dataset') logger.debug('Deselecting dataset')
main.project.set_current_data([]) main.project.set_current_data([])
def on_row_changed(self, treestore, pos, iter): 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) obj = self.data_tree.get_value(tree_iter, 2)
if isinstance(obj, plots.Plot): if isinstance(obj, plots.Plot):
logger.log('debug', 'Activating plot') logger.debug('Activating plot')
main.application.change_plot(obj) main.application.change_plot(obj)
elif isinstance(obj, dataset.Dataset): elif isinstance(obj, dataset.Dataset):
pass pass
@ -135,7 +135,7 @@ class NavigatorView (gtk.TreeView):
main.application.change_plots(children) main.application.change_plots(children)
else: else:
t = type(obj) 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): def popup_menu(self, *rest):
self.menu.popup(None, None, None, 0, 0) 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()) dialog.set_current_name("%s.ftsv" % self.dataset.get_name())
retval = dialog.run() retval = dialog.run()
if retval in [gtk.RESPONSE_CANCEL, gtk.RESPONSE_DELETE_EVENT]: 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: 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') fd = open(dialog.get_filename(), 'w')
dataset.write_ftsv(fd, self.dataset) dataset.write_ftsv(fd, self.dataset)
fd.close() fd.close()

View File

@ -3,8 +3,7 @@ import scipy
import gobject import gobject
import gtk import gtk
import fluents import fluents
import logger import logger, dataset, plots, main
import dataset, plots, main
class Project: class Project:
"""A Project contains datasets, selections etc. """A Project contains datasets, selections etc.
@ -14,7 +13,7 @@ class Project:
navigator. navigator.
""" """
def __init__(self,name="Testing"): def __init__(self, name="Testing"):
self.data_tree = gtk.TreeStore(str, self.data_tree = gtk.TreeStore(str,
str, str,
object, object,
@ -63,6 +62,7 @@ class Project:
return self.sel_obj return self.sel_obj
def delete_data(self, it): def delete_data(self, it):
"""Delete elements from the project."""
child = self.data_tree.iter_children(it) child = self.data_tree.iter_children(it)
while child != None: while child != None:
c = self.data_tree.iter_next(child) c = self.data_tree.iter_next(child)
@ -142,12 +142,12 @@ class Project:
self.notify_dataset_listeners() self.notify_dataset_listeners()
def object_at(self, path): def object_at(self, path):
"Returns the object at a given path in the tree." """Returns the object at a given path in the tree."""
iter = self.get_iter(path) it = self.get_iter(path)
object = self.get_value(iter, 2) obj = self[it][2]
if object: if obj:
object.show() obj.show()
return object return obj
def set_current_data(self, obj): def set_current_data(self, obj):
self.current_data = obj self.current_data = obj