X-Git-Url: http://git.tremily.us/?p=hooke.git;a=blobdiff_plain;f=hooke%2Fhooke.py;h=5fbc40bcd85cc0820df950e7ddab8c3c9151ee65;hp=6046847bb54c767b8745a2219c42a037beaac1e4;hb=41ef0130e16c0cf8d2c0f1acc9e06986d62f7607;hpb=5c9e831f851ddb1cb9d0b06ff18c9d63ddf02aea diff --git a/hooke/hooke.py b/hooke/hooke.py old mode 100755 new mode 100644 index 6046847..5fbc40b --- a/hooke/hooke.py +++ b/hooke/hooke.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +# -*- coding: utf-8 -*- ''' HOOKE - A force spectroscopy review & analysis tool @@ -10,8 +11,7 @@ Copyright (C) 2008 Massimo Sandal (University of Bologna, Italy). This program is released under the GNU General Public License version 2. ''' -from libhooke import HOOKE_VERSION -from libhooke import WX_GOOD +from .libhooke import HOOKE_VERSION, WX_GOOD import os @@ -24,12 +24,12 @@ from wx.lib.newevent import NewEvent import matplotlib.numerix as nx import scipy as sp -from threading import * +from threading import Thread import Queue -from hooke_cli import HookeCli -from libhooke import * -import libhookecurve as lhc +from .hooke_cli import HookeCli +from .libhooke import HookeConfig, ClickedPoint +from . import libhookecurve as lhc #import file versions, just to know with what we're working... from hooke_cli import __version__ as hookecli_version @@ -64,15 +64,20 @@ plugin_commands_namespaces=[] plugin_gui_namespaces=[] for plugin_name in config['plugins']: try: - plugin=__import__(plugin_name) + hooke_module=__import__('hooke.plugin.'+plugin_name) + plugin = getattr(hooke_module.plugin, plugin_name) try: - eval('CLI_PLUGINS.append(plugin.'+plugin_name+'Commands)') #take Command plugin classes - plugin_commands_namespaces.append(dir(eval('plugin.'+plugin_name+'Commands'))) + #take Command plugin classes + commands = getattr(plugin, plugin_name+'Commands') + CLI_PLUGINS.append(commands) + plugin_commands_namespaces.append(dir(commands)) except: pass try: - eval('GUI_PLUGINS.append(plugin.'+plugin_name+'Gui)') #take Gui plugin classes - plugin_gui_namespaces.append(dir(eval('plugin.'+plugin_name+'Gui'))) + #take Gui plugin classes + gui = getattr(plugin, plugin_name+'Gui') + GUI_PLUGINS.append(gui) + plugin_gui_namespaces.append(dir(gui)) except: pass except ImportError: @@ -82,8 +87,11 @@ for plugin_name in config['plugins']: print 'Imported plugin ',plugin_name #eliminate names common to all namespaces -for i in range(len(plugin_commands_namespaces)): - plugin_commands_namespaces[i]=[item for item in plugin_commands_namespaces[i] if (item != '__doc__' and item != '__module__' and item != '_plug_init')] +for i,namespace in enumerate(plugin_commands_namespaces): + plugin_commands_namespaces[i] = \ + filter(lambda item : not (item.startswith('__') + or item == '_plug_init'), + namespace) #check for conflicts in namespaces between plugins #FIXME: only in commands now, because I don't have Gui plugins to check #FIXME: how to check for plugin-defined variables (self.stuff) ?? @@ -94,7 +102,8 @@ for namespace,plugin_name in zip(plugin_commands_namespaces, config['plugins']): for item in namespace: if item in plugin_commands_names: i=plugin_commands_names.index(item) #we exploit the fact index gives the *first* occurrence of a name... - print 'Error. Plugin ',plugin_name,' defines a function already defined by ',whatplugin_defines[i],'!' + print 'Error. Plugin %s defines a function %s already defined by %s!' \ + % (plugin_name, item, whatplugin_defines[i]) print 'This should not happen. Please disable one or both plugins and contact the plugin authors to solve the conflict.' print 'Hooke cannot continue.' exit() @@ -110,9 +119,10 @@ FILE_DRIVERS=[] LOADED_DRIVERS=[] for driver_name in config['drivers']: try: - driver=__import__(driver_name) + hooke_module=__import__('hooke.driver.'+driver_name) + driver = getattr(hooke_module.driver, driver_name) try: - eval('FILE_DRIVERS.append(driver.'+driver_name+'Driver)') + FILE_DRIVERS.append(getattr(driver, driver_name+'Driver')) except: pass except ImportError: @@ -260,6 +270,11 @@ class MainWindow(wx.Frame): self.figures=[control.get_figure() for control in self.controls] self.axes=[figure.gca() for figure in self.figures] + for i in range(len(self.axes)): + self.axes[i].xaxis.set_major_formatter(EngrFormatter()) + self.axes[i].yaxis.set_major_formatter(EngrFormatter(2)) + + self.cpanels[1].Hide() self.mainpanel.splitter.Initialize(self.cpanels[0]) @@ -353,7 +368,8 @@ class MainWindow(wx.Frame): #make sure we execute _plug_init() for every command line plugin we import for plugin_name in config['plugins']: try: - plugin=__import__(plugin_name) + hooke_module=__import__('hooke.plugin.'+plugin_name) + plugin = getattr(hooke_module.plugin, plugin_name) try: eval('plugin.'+plugin_name+'Gui._plug_init(self)') pass @@ -540,6 +556,11 @@ class MainWindow(wx.Frame): ylim=self.axes[dest].get_ylim() self.axes[dest].set_ylim((ylim[1],ylim[0])) + for i in range(len(self.axes)): + self.axes[i].xaxis.set_major_formatter(EngrFormatter()) + self.axes[i].yaxis.set_major_formatter(EngrFormatter(2)) + + self.controls[dest].draw() @@ -677,12 +698,15 @@ class MainWindow(wx.Frame): ''' if dest==None: dest=self.current_plot_dest - - plot=None - for aplot in self.plots: - if aplot.destination == dest: - plot=aplot - return plot + try: + plot=None + for aplot in self.plots: + if aplot.destination == dest: + plot=aplot + return plot + except: + print "No curve available" + return None def _replot(self): ''' @@ -760,7 +784,9 @@ class MySplashScreen(wx.SplashScreen): # This is a recipe to a the screen. # Modify the following variables as necessary. #aBitmap = wx.Image(name = "wxPyWiki.jpg").ConvertToBitmap() - aBitmap=wx.Image(name='hooke.jpg').ConvertToBitmap() + aBitmap=wx.Image(name=os.path.join( + config['install']['docpath'], + 'hooke.jpg')).ConvertToBitmap() splashStyle = wx.SPLASH_CENTRE_ON_SCREEN | wx.SPLASH_TIMEOUT splashDuration = 2000 # milliseconds splashCallback = None @@ -783,16 +809,6 @@ class MySplashScreen(wx.SplashScreen): #------------------------------------------------------------------------------ def main(): - - #save the directory where Hooke is located - config['hookedir']=os.getcwd() - - #now change to the working directory. - try: - os.chdir(config['workdir']) - except OSError: - print "Warning: Invalid work directory." - app=wx.PySimpleApp() def make_gui_class(*bases): @@ -808,7 +824,7 @@ def main(): my_cmdline=CliThread(main_frame, list_of_events) my_cmdline.start() - app.MainLoop() -main() +if __name__ == '__main__': + main()