+++ /dev/null
-#!/usr/bin/env python\r
-\r
-'''\r
-HOOKE - A force spectroscopy review & analysis tool\r
-\r
-Copyright 2008 by Massimo Sandal (University of Bologna, Italy)\r
-Copyright 2010 by Rolf Schmidt (Concordia University, Canada)\r
-\r
-This program is released under the GNU General Public License version 2.\r
-'''\r
-\r
-import lib.libhooke as lh\r
-import wxversion\r
-wxversion.select(lh.WX_GOOD)\r
-\r
-from configobj import ConfigObj\r
-import copy\r
-import os.path\r
-import platform\r
-import shutil\r
-import time\r
-\r
-import wx.html\r
-import wx.lib.agw.aui as aui\r
-import wx.lib.evtmgr as evtmgr\r
-import wx.propgrid as wxpg\r
-\r
-from matplotlib.ticker import FuncFormatter\r
-\r
-from configobj import __version__ as configobj_version\r
-from matplotlib import __version__ as mpl_version\r
-from numpy import __version__ as numpy_version\r
-from scipy import __version__ as scipy_version\r
-from sys import version as python_version\r
-from wx import __version__ as wx_version\r
-from wx.propgrid import PROPGRID_MAJOR\r
-from wx.propgrid import PROPGRID_MINOR\r
-from wx.propgrid import PROPGRID_RELEASE\r
-\r
-try:\r
- from agw import cubecolourdialog as CCD\r
-except ImportError: # if it's not there locally, try the wxPython lib.\r
- import wx.lib.agw.cubecolourdialog as CCD\r
-\r
-#set the Hooke directory\r
-lh.hookeDir = os.path.abspath(os.path.dirname(__file__))\r
-from config.config import config\r
-import drivers\r
-import lib.clickedpoint\r
-import lib.curve\r
-import lib.delta\r
-import lib.playlist\r
-import lib.plotmanipulator\r
-import lib.prettyformat\r
-import panels.commands\r
-import panels.note\r
-import panels.perspectives\r
-import panels.playlist\r
-import panels.plot\r
-import panels.propertyeditor\r
-import panels.results\r
-import plugins\r
-\r
-global __version__\r
-global __codename__\r
-global __releasedate__\r
-__version__ = lh.HOOKE_VERSION[0]\r
-__codename__ = lh.HOOKE_VERSION[1]\r
-__releasedate__ = lh.HOOKE_VERSION[2]\r
-__release_name__ = lh.HOOKE_VERSION[1]\r
-\r
-ID_About = wx.NewId()\r
-ID_Next = wx.NewId()\r
-ID_Previous = wx.NewId()\r
-\r
-ID_ViewAssistant = wx.NewId()\r
-ID_ViewCommands = wx.NewId()\r
-ID_ViewFolders = wx.NewId()\r
-ID_ViewNote = wx.NewId()\r
-ID_ViewOutput = wx.NewId()\r
-ID_ViewPlaylists = wx.NewId()\r
-ID_ViewProperties = wx.NewId()\r
-ID_ViewResults = wx.NewId()\r
-\r
-ID_DeletePerspective = wx.NewId()\r
-ID_SavePerspective = wx.NewId()\r
-\r
-ID_FirstPerspective = ID_SavePerspective + 1000\r
-#I hope we'll never have more than 1000 perspectives\r
-ID_FirstPlot = ID_SavePerspective + 2000\r
-\r
-class Hooke(wx.App):\r
-\r
- def OnInit(self):\r
- self.SetAppName('Hooke')\r
- self.SetVendorName('')\r
-\r
- window_height = config['main']['height']\r
- window_left= config['main']['left']\r
- window_top = config['main']['top']\r
- window_width = config['main']['width']\r
-\r
- #sometimes, the ini file gets confused and sets 'left'\r
- #and 'top' to large negative numbers\r
- #let's catch and fix this\r
- #keep small negative numbers, the user might want those\r
- if window_left < -window_width:\r
- window_left = 0\r
- if window_top < -window_height:\r
- window_top = 0\r
- window_position = (window_left, window_top)\r
- window_size = (window_width, window_height)\r
-\r
- #setup the splashscreen\r
- if config['splashscreen']['show']:\r
- filename = lh.get_file_path('hooke.jpg', ['resources'])\r
- if os.path.isfile(filename):\r
- bitmap = wx.Image(filename).ConvertToBitmap()\r
- splashStyle = wx.SPLASH_CENTRE_ON_SCREEN|wx.SPLASH_TIMEOUT\r
- splashDuration = config['splashscreen']['duration']\r
- wx.SplashScreen(bitmap, splashStyle, splashDuration, None, -1)\r
- wx.Yield()\r
- '''\r
- we need for the splash screen to disappear\r
- for whatever reason splashDuration and sleep do not correspond to each other\r
- at least not on Windows\r
- maybe it's because duration is in milliseconds and sleep in seconds\r
- thus we need to increase the sleep time a bit\r
- a factor of 1.2 seems to work quite well\r
- '''\r
- sleepFactor = 1.2\r
- time.sleep(sleepFactor * splashDuration / 1000)\r
-\r
- plugin_objects = []\r
- for plugin in config['plugins']:\r
- if config['plugins'][plugin]:\r
- filename = ''.join([plugin, '.py'])\r
- path = lh.get_file_path(filename, ['plugins'])\r
- if os.path.isfile(path):\r
- #get the corresponding filename and path\r
- plugin_name = ''.join(['plugins.', plugin])\r
- #import the module\r
- __import__(plugin_name)\r
- #get the file that contains the plugin\r
- class_file = getattr(plugins, plugin)\r
- #get the class that contains the commands\r
- class_object = getattr(class_file, plugin + 'Commands')\r
- plugin_objects.append(class_object)\r
-\r
- def make_command_class(*bases):\r
- #create metaclass with plugins and plotmanipulators\r
- return type(HookeFrame)("HookeFramePlugged", bases + (HookeFrame,), {})\r
- frame = make_command_class(*plugin_objects)(parent=None, id=wx.ID_ANY, title='Hooke', pos=window_position, size=window_size)\r
- frame.Show(True)\r
- self.SetTopWindow(frame)\r
-\r
- return True\r
-\r
- def OnExit(self):\r
- return True\r
-\r
-\r
-class HookeFrame(wx.Frame):\r
-\r
- def __init__(self, parent, id=-1, title='', pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE|wx.SUNKEN_BORDER|wx.CLIP_CHILDREN):\r
- #call parent constructor\r
- wx.Frame.__init__(self, parent, id, title, pos, size, style)\r
- self.config = config\r
- self.CreateApplicationIcon()\r
- #self.configs contains: {the name of the Commands file: corresponding ConfigObj}\r
- self.configs = {}\r
- #self.displayed_plot holds the currently displayed plot\r
- self.displayed_plot = None\r
- #self.playlists contains: {the name of the playlist: [playlist, tabIndex, plotID]}\r
- self.playlists = {}\r
- #list of all plotmanipulators\r
- self.plotmanipulators = []\r
- #self.plugins contains: {the name of the plugin: [caption, function]}\r
- self.plugins = {}\r
- #self.results_str contains the type of results we want to display\r
- self.results_str = 'wlc'\r
-\r
- #tell FrameManager to manage this frame\r
- self._mgr = aui.AuiManager()\r
- self._mgr.SetManagedWindow(self)\r
- #set the gradient style\r
- self._mgr.GetArtProvider().SetMetric(aui.AUI_DOCKART_GRADIENT_TYPE, aui.AUI_GRADIENT_NONE)\r
- #set transparent drag\r
- self._mgr.SetFlags(self._mgr.GetFlags() ^ aui.AUI_MGR_TRANSPARENT_DRAG)\r
-\r
- # set up default notebook style\r
- self._notebook_style = aui.AUI_NB_DEFAULT_STYLE | aui.AUI_NB_TAB_EXTERNAL_MOVE | wx.NO_BORDER\r
- self._notebook_theme = 0\r
-\r
- #holds the perspectives: {name, perspective_str}\r
- self._perspectives = {}\r
-\r
- # min size for the frame itself isn't completely done.\r
- # see the end up FrameManager::Update() for the test\r
- # code. For now, just hard code a frame minimum size\r
- self.SetMinSize(wx.Size(500, 500))\r
- #define the list of active drivers\r
- self.drivers = []\r
- for driver in self.config['drivers']:\r
- if self.config['drivers'][driver]:\r
- #get the corresponding filename and path\r
- filename = ''.join([driver, '.py'])\r
- path = lh.get_file_path(filename, ['drivers'])\r
- #the driver is active for driver[1] == 1\r
- if os.path.isfile(path):\r
- #driver files are located in the 'drivers' subfolder\r
- driver_name = ''.join(['drivers.', driver])\r
- __import__(driver_name)\r
- class_file = getattr(drivers, driver)\r
- for command in dir(class_file):\r
- if command.endswith('Driver'):\r
- self.drivers.append(getattr(class_file, command))\r
- #import all active plugins and plotmanips\r
- #add 'core.ini' to self.configs (this is not a plugin and thus must be imported separately)\r
- ini_path = lh.get_file_path('core.ini', ['plugins'])\r
- plugin_config = ConfigObj(ini_path)\r
- #self.config.merge(plugin_config)\r
- self.configs['core'] = plugin_config\r
- #existing_commands contains: {command: plugin}\r
- existing_commands = {}\r
- #make sure we execute _plug_init() for every command line plugin we import\r
- for plugin in self.config['plugins']:\r
- if self.config['plugins'][plugin]:\r
- filename = ''.join([plugin, '.py'])\r
- path = lh.get_file_path(filename, ['plugins'])\r
- if os.path.isfile(path):\r
- #get the corresponding filename and path\r
- plugin_name = ''.join(['plugins.', plugin])\r
- try:\r
- #import the module\r
- module = __import__(plugin_name)\r
- #prepare the ini file for inclusion\r
- ini_path = path.replace('.py', '.ini')\r
- #include ini file\r
- plugin_config = ConfigObj(ini_path)\r
- #self.config.merge(plugin_config)\r
- self.configs[plugin] = plugin_config\r
- #add to plugins\r
- commands = eval('dir(module.' + plugin+ '.' + plugin + 'Commands)')\r
- #keep only commands (ie names that start with 'do_')\r
- commands = [command for command in commands if command.startswith('do_')]\r
- if commands:\r
- for command in commands:\r
- if existing_commands.has_key(command):\r
- message_str = 'Adding "' + command + '" in plugin "' + plugin + '".\n\n'\r
- message_str += '"' + command + '" already exists in "' + str(existing_commands[command]) + '".\n\n'\r
- message_str += 'Only "' + command + '" in "' + str(existing_commands[command]) + '" will work.\n\n'\r
- message_str += 'Please rename one of the commands in the source code and restart Hooke or disable one of the plugins.'\r
- dialog = wx.MessageDialog(self, message_str, 'Warning', wx.OK|wx.ICON_WARNING|wx.CENTER)\r
- dialog.ShowModal()\r
- dialog.Destroy()\r
- existing_commands[command] = plugin\r
- self.plugins[plugin] = commands\r
- try:\r
- #initialize the plugin\r
- eval('module.' + plugin+ '.' + plugin + 'Commands._plug_init(self)')\r
- except AttributeError:\r
- pass\r
- except ImportError:\r
- pass\r
- #add commands from hooke.py i.e. 'core' commands\r
- commands = dir(HookeFrame)\r
- commands = [command for command in commands if command.startswith('do_')]\r
- if commands:\r
- self.plugins['core'] = commands\r
- #create panels here\r
- self.panelAssistant = self.CreatePanelAssistant()\r
- self.panelCommands = self.CreatePanelCommands()\r
- self.panelFolders = self.CreatePanelFolders()\r
- self.panelPlaylists = self.CreatePanelPlaylists()\r
- self.panelProperties = self.CreatePanelProperties()\r
- self.panelNote = self.CreatePanelNote()\r
- self.panelOutput = self.CreatePanelOutput()\r
- self.panelResults = self.CreatePanelResults()\r
- self.plotNotebook = self.CreateNotebook()\r
-\r
- # add panes\r
- self._mgr.AddPane(self.panelFolders, aui.AuiPaneInfo().Name('Folders').Caption('Folders').Left().CloseButton(True).MaximizeButton(False))\r
- self._mgr.AddPane(self.panelPlaylists, aui.AuiPaneInfo().Name('Playlists').Caption('Playlists').Left().CloseButton(True).MaximizeButton(False))\r
- self._mgr.AddPane(self.panelNote, aui.AuiPaneInfo().Name('Note').Caption('Note').Left().CloseButton(True).MaximizeButton(False))\r
- self._mgr.AddPane(self.plotNotebook, aui.AuiPaneInfo().Name('Plots').CenterPane().PaneBorder(False))\r
- self._mgr.AddPane(self.panelCommands, aui.AuiPaneInfo().Name('Commands').Caption('Settings and commands').Right().CloseButton(True).MaximizeButton(False))\r
- self._mgr.AddPane(self.panelProperties, aui.AuiPaneInfo().Name('Properties').Caption('Properties').Right().CloseButton(True).MaximizeButton(False))\r
- self._mgr.AddPane(self.panelAssistant, aui.AuiPaneInfo().Name('Assistant').Caption('Assistant').Right().CloseButton(True).MaximizeButton(False))\r
- self._mgr.AddPane(self.panelOutput, aui.AuiPaneInfo().Name('Output').Caption('Output').Bottom().CloseButton(True).MaximizeButton(False))\r
- self._mgr.AddPane(self.panelResults, aui.AuiPaneInfo().Name('Results').Caption('Results').Bottom().CloseButton(True).MaximizeButton(False))\r
- #self._mgr.AddPane(self.textCtrlCommandLine, aui.AuiPaneInfo().Name('CommandLine').CaptionVisible(False).Fixed().Bottom().Layer(2).CloseButton(False).MaximizeButton(False))\r
- #self._mgr.AddPane(panelBottom, aui.AuiPaneInfo().Name("panelCommandLine").Bottom().Position(1).CloseButton(False).MaximizeButton(False))\r
-\r
- # add the toolbars to the manager\r
- #self.toolbar=self.CreateToolBar()\r
- self.toolbarNavigation=self.CreateToolBarNavigation()\r
- #self._mgr.AddPane(self.toolbar, aui.AuiPaneInfo().Name('toolbar').Caption('Toolbar').ToolbarPane().Top().Layer(1).Row(1).LeftDockable(False).RightDockable(False))\r
- self._mgr.AddPane(self.toolbarNavigation, aui.AuiPaneInfo().Name('toolbarNavigation').Caption('Navigation').ToolbarPane().Top().Layer(1).Row(1).LeftDockable(False).RightDockable(False))\r
- # "commit" all changes made to FrameManager\r
- self._mgr.Update()\r
- #create the menubar after the panes so that the default perspective\r
- #is created with all panes open\r
- self.CreateMenuBar()\r
- self.statusbar = self.CreateStatusbar()\r
- self._BindEvents()\r
-\r
- name = self.config['perspectives']['active']\r
- menu_item = self.GetPerspectiveMenuItem(name)\r
- if menu_item is not None:\r
- self.OnRestorePerspective(menu_item)\r
- #TODO: config setting to remember playlists from last session\r
- self.playlists = self.panelPlaylists.Playlists\r
- #initialize the commands tree\r
- self.panelCommands.Initialize(self.plugins)\r
- for command in dir(self):\r
- if command.startswith('plotmanip_'):\r
- self.plotmanipulators.append(lib.plotmanipulator.Plotmanipulator(method=getattr(self, command), command=command))\r
-\r
- #load default list, if possible\r
- self.do_loadlist(self.GetStringFromConfig('core', 'preferences', 'playlist'))\r
-\r
- def _BindEvents(self):\r
- #TODO: figure out if we can use the eventManager for menu ranges\r
- #and events of 'self' without raising an assertion fail error\r
- self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)\r
- self.Bind(wx.EVT_SIZE, self.OnSize)\r
- self.Bind(wx.EVT_CLOSE, self.OnClose)\r
- # Show How To Use The Closing Panes Event\r
- self.Bind(aui.EVT_AUI_PANE_CLOSE, self.OnPaneClose)\r
- self.Bind(aui.EVT_AUINOTEBOOK_PAGE_CLOSE, self.OnNotebookPageClose)\r
- #menu\r
- evtmgr.eventManager.Register(self.OnAbout, wx.EVT_MENU, win=self, id=wx.ID_ABOUT)\r
- evtmgr.eventManager.Register(self.OnClose, wx.EVT_MENU, win=self, id=wx.ID_EXIT)\r
- #view\r
- self.Bind(wx.EVT_MENU_RANGE, self.OnView, id=ID_ViewAssistant, id2=ID_ViewResults)\r
- #perspectives\r
- self.Bind(wx.EVT_MENU, self.OnDeletePerspective, id=ID_DeletePerspective)\r
- self.Bind(wx.EVT_MENU, self.OnSavePerspective, id=ID_SavePerspective)\r
- self.Bind(wx.EVT_MENU_RANGE, self.OnRestorePerspective, id=ID_FirstPerspective, id2=ID_FirstPerspective+1000)\r
- #toolbar\r
- evtmgr.eventManager.Register(self.OnNext, wx.EVT_TOOL, win=self, id=ID_Next)\r
- evtmgr.eventManager.Register(self.OnPrevious, wx.EVT_TOOL, win=self, id=ID_Previous)\r
- #self.Bind(.EVT_AUITOOLBAR_TOOL_DROPDOWN, self.OnDropDownToolbarItem, id=ID_DropDownToolbarItem)\r
- #dir control\r
- treeCtrl = self.panelFolders.GetTreeCtrl()\r
- #tree.Bind(wx.EVT_LEFT_UP, self.OnDirCtrl1LeftUp)\r
- #tree.Bind(wx.EVT_LEFT_DOWN, self.OnGenericDirCtrl1LeftDown)\r
- treeCtrl.Bind(wx.EVT_LEFT_DCLICK, self.OnDirCtrlLeftDclick)\r
- #playlist tree\r
- self.panelPlaylists.PlaylistsTree.Bind(wx.EVT_LEFT_DOWN, self.OnPlaylistsLeftDown)\r
- self.panelPlaylists.PlaylistsTree.Bind(wx.EVT_LEFT_DCLICK, self.OnPlaylistsLeftDclick)\r
- #commands tree\r
- evtmgr.eventManager.Register(self.OnExecute, wx.EVT_BUTTON, self.panelCommands.ExecuteButton)\r
- evtmgr.eventManager.Register(self.OnTreeCtrlCommandsSelectionChanged, wx.EVT_TREE_SEL_CHANGED, self.panelCommands.CommandsTree)\r
- evtmgr.eventManager.Register(self.OnTreeCtrlItemActivated, wx.EVT_TREE_ITEM_ACTIVATED, self.panelCommands.CommandsTree)\r
- evtmgr.eventManager.Register(self.OnUpdateNote, wx.EVT_BUTTON, self.panelNote.UpdateButton)\r
- #property editor\r
- self.panelProperties.pg.Bind(wxpg.EVT_PG_CHANGED, self.OnPropGridChanged)\r
- #results panel\r
- self.panelResults.results_list.OnCheckItem = self.OnResultsCheck\r
-\r
- def _GetActiveFileIndex(self):\r
- lib.playlist.Playlist = self.GetActivePlaylist()\r
- #get the selected item from the tree\r
- selected_item = self.panelPlaylists.PlaylistsTree.GetSelection()\r
- #test if a playlist or a curve was double-clicked\r
- if self.panelPlaylists.PlaylistsTree.ItemHasChildren(selected_item):\r
- return -1\r
- else:\r
- count = 0\r
- selected_item = self.panelPlaylists.PlaylistsTree.GetPrevSibling(selected_item)\r
- while selected_item.IsOk():\r
- count += 1\r
- selected_item = self.panelPlaylists.PlaylistsTree.GetPrevSibling(selected_item)\r
- return count\r
-\r
- def _GetPlaylistTab(self, name):\r
- for index, page in enumerate(self.plotNotebook._tabs._pages):\r
- if page.caption == name:\r
- return index\r
- return -1\r
-\r
- def _GetUniquePlaylistName(self, name):\r
- playlist_name = name\r
- count = 1\r
- while playlist_name in self.playlists:\r
- playlist_name = ''.join([name, str(count)])\r
- count += 1\r
- return playlist_name\r
-\r
- def _RestorePerspective(self, name):\r
- self._mgr.LoadPerspective(self._perspectives[name])\r
- self.config['perspectives']['active'] = name\r
- self._mgr.Update()\r
- all_panes = self._mgr.GetAllPanes()\r
- for pane in all_panes:\r
- if not pane.name.startswith('toolbar'):\r
- if pane.name == 'Assistant':\r
- self.MenuBar.FindItemById(ID_ViewAssistant).Check(pane.window.IsShown())\r
- if pane.name == 'Folders':\r
- self.MenuBar.FindItemById(ID_ViewFolders).Check(pane.window.IsShown())\r
- if pane.name == 'Playlists':\r
- self.MenuBar.FindItemById(ID_ViewPlaylists).Check(pane.window.IsShown())\r
- if pane.name == 'Commands':\r
- self.MenuBar.FindItemById(ID_ViewCommands).Check(pane.window.IsShown())\r
- if pane.name == 'Note':\r
- self.MenuBar.FindItemById(ID_ViewNote).Check(pane.window.IsShown())\r
- if pane.name == 'Properties':\r
- self.MenuBar.FindItemById(ID_ViewProperties).Check(pane.window.IsShown())\r
- if pane.name == 'Output':\r
- self.MenuBar.FindItemById(ID_ViewOutput).Check(pane.window.IsShown())\r
- if pane.name == 'Results':\r
- self.MenuBar.FindItemById(ID_ViewResults).Check(pane.window.IsShown())\r
-\r
- def _SavePerspectiveToFile(self, name, perspective):\r
- filename = ''.join([name, '.txt'])\r
- filename = lh.get_file_path(filename, ['perspectives'])\r
- perspectivesFile = open(filename, 'w')\r
- perspectivesFile.write(perspective)\r
- perspectivesFile.close()\r
-\r
- def _UnbindEvents(self):\r
- #menu\r
- evtmgr.eventManager.DeregisterListener(self.OnAbout)\r
- evtmgr.eventManager.DeregisterListener(self.OnClose)\r
- #toolbar\r
- evtmgr.eventManager.DeregisterListener(self.OnNext)\r
- evtmgr.eventManager.DeregisterListener(self.OnPrevious)\r
- #commands tree\r
- evtmgr.eventManager.DeregisterListener(self.OnExecute)\r
- evtmgr.eventManager.DeregisterListener(self.OnTreeCtrlCommandsSelectionChanged)\r
- evtmgr.eventManager.DeregisterListener(self.OnTreeCtrlItemActivated)\r
- evtmgr.eventManager.DeregisterListener(self.OnUpdateNote)\r
-\r
- def AddPlaylist(self, playlist=None, name='Untitled'):\r
- if playlist and playlist.count > 0:\r
- playlist.name = self._GetUniquePlaylistName(name)\r
- playlist.reset()\r
- self.AddToPlaylists(playlist)\r
-\r
- def AddPlaylistFromFiles(self, files=[], name='Untitled'):\r
- if files:\r
- playlist = lib.playlist.Playlist(self, self.drivers)\r
- for item in files:\r
- playlist.add_curve(item)\r
- if playlist.count > 0:\r
- playlist.name = self._GetUniquePlaylistName(name)\r
- playlist.reset()\r
- self.AddTayliss(playlist)\r
-\r
- def AddToPlaylists(self, playlist):\r
- if playlist.count > 0:\r
- #setup the playlist in the Playlist tree\r
- tree_root = self.panelPlaylists.PlaylistsTree.GetRootItem()\r
- playlist_root = self.panelPlaylists.PlaylistsTree.AppendItem(tree_root, playlist.name, 0)\r
- #add all files to the Playlist tree\r
-# files = {}\r
- hide_curve_extension = self.GetBoolFromConfig('core', 'preferences', 'hide_curve_extension')\r
- for index, file_to_add in enumerate(playlist.files):\r
- #optionally remove the extension from the name of the curve\r
- if hide_curve_extension:\r
- file_to_add.name = lh.remove_extension(file_to_add.name)\r
- file_ID = self.panelPlaylists.PlaylistsTree.AppendItem(playlist_root, file_to_add.name, 1)\r
- if index == playlist.index:\r
- self.panelPlaylists.PlaylistsTree.SelectItem(file_ID)\r
- playlist.reset()\r
- #create the plot tab and add playlist to the dictionary\r
- plotPanel = panels.plot.PlotPanel(self, ID_FirstPlot + len(self.playlists))\r
- notebook_tab = self.plotNotebook.AddPage(plotPanel, playlist.name, True)\r
- #tab_index = self.plotNotebook.GetSelection()\r
- playlist.figure = plotPanel.get_figure()\r
- self.playlists[playlist.name] = playlist\r
- #self.playlists[playlist.name] = [playlist, figure]\r
- self.panelPlaylists.PlaylistsTree.Expand(playlist_root)\r
- self.statusbar.SetStatusText(playlist.get_status_string(), 0)\r
- self.UpdateNote()\r
- self.UpdatePlot()\r
-\r
- def AppendToOutput(self, text):\r
- self.panelOutput.AppendText(''.join([text, '\n']))\r
-\r
- def AppliesPlotmanipulator(self, name):\r
- '''\r
- Returns True if the plotmanipulator 'name' is applied, False otherwise\r
- name does not contain 'plotmanip_', just the name of the plotmanipulator (e.g. 'flatten')\r
- '''\r
- return self.GetBoolFromConfig('core', 'plotmanipulators', name)\r
-\r
- def ApplyPlotmanipulators(self, plot, plot_file):\r
- '''\r
- Apply all active plotmanipulators.\r
- '''\r
- if plot is not None and plot_file is not None:\r
- manipulated_plot = copy.deepcopy(plot)\r
- for plotmanipulator in self.plotmanipulators:\r
- if self.GetBoolFromConfig('core', 'plotmanipulators', plotmanipulator.name):\r
- manipulated_plot = plotmanipulator.method(manipulated_plot, plot_file)\r
- return manipulated_plot\r
-\r
- def CreateApplicationIcon(self):\r
- iconFile = 'resources' + os.sep + 'microscope.ico'\r
- icon = wx.Icon(iconFile, wx.BITMAP_TYPE_ICO)\r
- self.SetIcon(icon)\r
-\r
- def CreateCommandLine(self):\r
- return wx.TextCtrl(self, -1, '', style=wx.NO_BORDER|wx.EXPAND)\r
-\r
- def CreatePanelAssistant(self):\r
- panel = wx.TextCtrl(self, -1, '', wx.Point(0, 0), wx.Size(150, 90), wx.NO_BORDER|wx.TE_MULTILINE)\r
- panel.SetEditable(False)\r
- return panel\r
-\r
- def CreatePanelCommands(self):\r
- return panels.commands.Commands(self)\r
-\r
- def CreatePanelFolders(self):\r
- #set file filters\r
- filters = self.config['folders']['filters']\r
- index = self.config['folders'].as_int('filterindex')\r
- #set initial directory\r
- folder = self.GetStringFromConfig('core', 'preferences', 'workdir')\r
- return wx.GenericDirCtrl(self, -1, dir=folder, size=(200, 250), style=wx.DIRCTRL_SHOW_FILTERS, filter=filters, defaultFilter=index)\r
-\r
- def CreatePanelNote(self):\r
- return panels.note.Note(self)\r
-\r
- def CreatePanelOutput(self):\r
- return wx.TextCtrl(self, -1, '', wx.Point(0, 0), wx.Size(150, 90), wx.NO_BORDER|wx.TE_MULTILINE)\r
-\r
- def CreatePanelPlaylists(self):\r
- return panels.playlist.Playlists(self)\r
-\r
- def CreatePanelProperties(self):\r
- return panels.propertyeditor.PropertyEditor(self)\r
-\r
- def CreatePanelResults(self):\r
- return panels.results.Results(self)\r
-\r
- def CreatePanelWelcome(self):\r
- #TODO: move into panels.welcome\r
- ctrl = wx.html.HtmlWindow(self, -1, wx.DefaultPosition, wx.Size(400, 300))\r
- introStr = '<h1>Welcome to Hooke</h1>' + \\r
- '<h3>Features</h3>' + \\r
- '<ul>' + \\r
- '<li>View, annotate, measure force files</li>' + \\r
- '<li>Worm-like chain fit of force peaks</li>' + \\r
- '<li>Automatic convolution-based filtering of empty files</li>' + \\r
- '<li>Automatic fit and measurement of multiple force peaks</li>' + \\r
- '<li>Handles force-clamp force experiments (experimental)</li>' + \\r
- '<li>It is extensible by users by means of plugins and drivers</li>' + \\r
- '</ul>' + \\r
- '<p>See the <a href="http://code.google.com/p/hooke/wiki/DocumentationIndex">DocumentationIndex</a> for more information</p>'\r
- ctrl.SetPage(introStr)\r
- return ctrl\r
-\r
- def CreateMenuBar(self):\r
- menu_bar = wx.MenuBar()\r
- self.SetMenuBar(menu_bar)\r
- #file\r
- file_menu = wx.Menu()\r
- file_menu.Append(wx.ID_EXIT, 'Exit\tCtrl-Q')\r
-# edit_menu.AppendSeparator();\r
-# edit_menu.Append(ID_Config, 'Preferences')\r
- #view\r
- view_menu = wx.Menu()\r
- view_menu.AppendCheckItem(ID_ViewFolders, 'Folders\tF5')\r
- view_menu.AppendCheckItem(ID_ViewPlaylists, 'Playlists\tF6')\r
- view_menu.AppendCheckItem(ID_ViewCommands, 'Commands\tF7')\r
- view_menu.AppendCheckItem(ID_ViewProperties, 'Properties\tF8')\r
- view_menu.AppendCheckItem(ID_ViewAssistant, 'Assistant\tF9')\r
- view_menu.AppendCheckItem(ID_ViewResults, 'Results\tF10')\r
- view_menu.AppendCheckItem(ID_ViewOutput, 'Output\tF11')\r
- view_menu.AppendCheckItem(ID_ViewNote, 'Note\tF12')\r
- #perspectives\r
- perspectives_menu = wx.Menu()\r
-\r
- #help\r
- help_menu = wx.Menu()\r
- help_menu.Append(wx.ID_ABOUT, 'About Hooke')\r
- #put it all together\r
- menu_bar.Append(file_menu, 'File')\r
- menu_bar.Append(view_menu, 'View')\r
- menu_bar.Append(perspectives_menu, "Perspectives")\r
- self.UpdatePerspectivesMenu()\r
- menu_bar.Append(help_menu, 'Help')\r
-\r
- def CreateNotebook(self):\r
- # create the notebook off-window to avoid flicker\r
- client_size = self.GetClientSize()\r
- ctrl = aui.AuiNotebook(self, -1, wx.Point(client_size.x, client_size.y), wx.Size(430, 200), self._notebook_style)\r
- arts = [aui.AuiDefaultTabArt, aui.AuiSimpleTabArt, aui.VC71TabArt, aui.FF2TabArt, aui.VC8TabArt, aui.ChromeTabArt]\r
- art = arts[self._notebook_theme]()\r
- ctrl.SetArtProvider(art)\r
- #uncomment if we find a nice icon\r
- #page_bmp = wx.ArtProvider.GetBitmap(wx.ART_NORMAL_FILE, wx.ART_OTHER, wx.Size(16, 16))\r
- ctrl.AddPage(self.CreatePanelWelcome(), "Welcome", False)\r
- return ctrl\r
-\r
- def CreateStatusbar(self):\r
- statusbar = self.CreateStatusBar(2, wx.ST_SIZEGRIP)\r
- statusbar.SetStatusWidths([-2, -3])\r
- statusbar.SetStatusText('Ready', 0)\r
- welcomeString=u'Welcome to Hooke (version '+__version__+', '+__release_name__+')!'\r
- statusbar.SetStatusText(welcomeString, 1)\r
- return statusbar\r
-\r
- def CreateToolBarNavigation(self):\r
- toolbar = wx.ToolBar(self, -1, wx.DefaultPosition, wx.DefaultSize, wx.TB_FLAT | wx.TB_NODIVIDER)\r
- toolbar.SetToolBitmapSize(wx.Size(16,16))\r
- toolbar_bmpBack = wx.ArtProvider_GetBitmap(wx.ART_GO_BACK, wx.ART_OTHER, wx.Size(16, 16))\r
- toolbar_bmpForward = wx.ArtProvider_GetBitmap(wx.ART_GO_FORWARD, wx.ART_OTHER, wx.Size(16, 16))\r
- toolbar.AddLabelTool(ID_Previous, 'Previous', toolbar_bmpBack, shortHelp='Previous curve')\r
- toolbar.AddLabelTool(ID_Next, 'Next', toolbar_bmpForward, shortHelp='Next curve')\r
- toolbar.Realize()\r
- return toolbar\r
-\r
- def DeleteFromPlaylists(self, name):\r
- if name in self.playlists:\r
- del self.playlists[name]\r
- tree_root = self.panelPlaylists.PlaylistsTree.GetRootItem()\r
- item, cookie = self.panelPlaylists.PlaylistsTree.GetFirstChild(tree_root)\r
- while item.IsOk():\r
- playlist_name = self.panelPlaylists.PlaylistsTree.GetItemText(item)\r
- if playlist_name == name:\r
- try:\r
- self.panelPlaylists.PlaylistsTree.Delete(item)\r
- except:\r
- pass\r
- item = self.panelPlaylists.PlaylistsTree.GetNextSibling(item)\r
-\r
- def GetActiveFigure(self):\r
- playlist_name = self.GetActivePlaylistName()\r
- figure = self.playlists[playlist_name].figure\r
- if figure is not None:\r
- return figure\r
- return None\r
-\r
- def GetActiveFile(self):\r
- playlist = self.GetActivePlaylist()\r
- if playlist is not None:\r
- return playlist.get_active_file()\r
- return None\r
-\r
- def GetActivePlaylist(self):\r
- playlist_name = self.GetActivePlaylistName()\r
- if playlist_name in self.playlists:\r
- return self.playlists[playlist_name]\r
- return None\r
-\r
- def GetActivePlaylistName(self):\r
- #get the selected item from the tree\r
- selected_item = self.panelPlaylists.PlaylistsTree.GetSelection()\r
- #test if a playlist or a curve was double-clicked\r
- if self.panelPlaylists.PlaylistsTree.ItemHasChildren(selected_item):\r
- playlist_item = selected_item\r
- else:\r
- #get the name of the playlist\r
- playlist_item = self.panelPlaylists.PlaylistsTree.GetItemParent(selected_item)\r
- #now we have a playlist\r
- return self.panelPlaylists.PlaylistsTree.GetItemText(playlist_item)\r
-\r
- def GetActivePlot(self):\r
- playlist = self.GetActivePlaylist()\r
- if playlist is not None:\r
- return playlist.get_active_file().plot\r
- return None\r
-\r
- def GetDisplayedPlot(self):\r
- plot = copy.deepcopy(self.displayed_plot)\r
- #plot.curves = []\r
- #plot.curves = copy.deepcopy(plot.curves)\r
- return plot\r
-\r
- def GetDisplayedPlotCorrected(self):\r
- plot = copy.deepcopy(self.displayed_plot)\r
- plot.curves = []\r
- plot.curves = copy.deepcopy(plot.corrected_curves)\r
- return plot\r
-\r
- def GetDisplayedPlotRaw(self):\r
- plot = copy.deepcopy(self.displayed_plot)\r
- plot.curves = []\r
- plot.curves = copy.deepcopy(plot.raw_curves)\r
- return plot\r
-\r
- def GetDockArt(self):\r
- return self._mgr.GetArtProvider()\r
-\r
- def GetBoolFromConfig(self, *args):\r
- if len(args) == 2:\r
- plugin = args[0]\r
- section = args[0]\r
- key = args[1]\r
- elif len(args) == 3:\r
- plugin = args[0]\r
- section = args[1]\r
- key = args[2]\r
- if self.configs.has_key(plugin):\r
- config = self.configs[plugin]\r
- return config[section][key].as_bool('value')\r
- return None\r
-\r
- def GetColorFromConfig(self, *args):\r
- if len(args) == 2:\r
- plugin = args[0]\r
- section = args[0]\r
- key = args[1]\r
- elif len(args) == 3:\r
- plugin = args[0]\r
- section = args[1]\r
- key = args[2]\r
- if self.configs.has_key(plugin):\r
- config = self.configs[plugin]\r
- color_tuple = eval(config[section][key]['value'])\r
- color = [value / 255.0 for value in color_tuple]\r
- return color\r
- return None\r
-\r
- def GetFloatFromConfig(self, *args):\r
- if len(args) == 2:\r
- plugin = args[0]\r
- section = args[0]\r
- key = args[1]\r
- elif len(args) == 3:\r
- plugin = args[0]\r
- section = args[1]\r
- key = args[2]\r
- if self.configs.has_key(plugin):\r
- config = self.configs[plugin]\r
- return config[section][key].as_float('value')\r
- return None\r
-\r
- def GetIntFromConfig(self, *args):\r
- if len(args) == 2:\r
- plugin = args[0]\r
- section = args[0]\r
- key = args[1]\r
- elif len(args) == 3:\r
- plugin = args[0]\r
- section = args[1]\r
- key = args[2]\r
- if self.configs.has_key(plugin):\r
- config = self.configs[plugin]\r
- return config[section][key].as_int('value')\r
- return None\r
-\r
- def GetStringFromConfig(self, *args):\r
- if len(args) == 2:\r
- plugin = args[0]\r
- section = args[0]\r
- key = args[1]\r
- elif len(args) == 3:\r
- plugin = args[0]\r
- section = args[1]\r
- key = args[2]\r
- if self.configs.has_key(plugin):\r
- config = self.configs[plugin]\r
- return config[section][key]['value']\r
- return None\r
-\r
- def GetPlotmanipulator(self, name):\r
- '''\r
- Returns a plot manipulator function from its name\r
- '''\r
- for plotmanipulator in self.plotmanipulators:\r
- if plotmanipulator.name == name:\r
- return plotmanipulator\r
- return None\r
-\r
- def GetPerspectiveMenuItem(self, name):\r
- if self._perspectives.has_key(name):\r
- perspectives_list = [key for key, value in self._perspectives.iteritems()]\r
- perspectives_list.sort()\r
- index = perspectives_list.index(name)\r
- perspective_Id = ID_FirstPerspective + index\r
- menu_item = self.MenuBar.FindItemById(perspective_Id)\r
- return menu_item\r
- else:\r
- return None\r
-\r
- def HasPlotmanipulator(self, name):\r
- '''\r
- returns True if the plotmanipulator 'name' is loaded, False otherwise\r
- '''\r
- for plotmanipulator in self.plotmanipulators:\r
- if plotmanipulator.command == name:\r
- return True\r
- return False\r
-\r
- def OnAbout(self, event):\r
- message = 'Hooke\n\n'+\\r
- 'A free, open source data analysis platform\n\n'+\\r
- 'Copyright 2006-2008 by Massimo Sandal\n'+\\r
- 'Copyright 2010 by Dr. Rolf Schmidt\n\n'+\\r
- 'Hooke is released under the GNU General Public License version 2.'\r
- dialog = wx.MessageDialog(self, message, 'About Hooke', wx.OK | wx.ICON_INFORMATION)\r
- dialog.ShowModal()\r
- dialog.Destroy()\r
-\r
- def OnClose(self, event):\r
- #apply changes\r
- self.config['main']['height'] = str(self.GetSize().GetHeight())\r
- self.config['main']['left'] = str(self.GetPosition()[0])\r
- self.config['main']['top'] = str(self.GetPosition()[1])\r
- self.config['main']['width'] = str(self.GetSize().GetWidth())\r
- #save the configuration file to 'config/hooke.ini'\r
- self.config.write()\r
- #save all plugin config files\r
- for config in self.configs:\r
- plugin_config = self.configs[config]\r
- plugin_config.write()\r
- self._UnbindEvents()\r
- self._mgr.UnInit()\r
- del self._mgr\r
- self.Destroy()\r
-\r
- def OnDeletePerspective(self, event):\r
- dialog = panels.perspectives.Perspectives(self, -1, 'Delete perspective(s)')\r
- dialog.CenterOnScreen()\r
- dialog.ShowModal()\r
- dialog.Destroy()\r
- self.UpdatePerspectivesMenu()\r
- #unfortunately, there is a bug in wxWidgets (Ticket #3258) that\r
- #makes the radio item indicator in the menu disappear\r
- #the code should be fine once this issue is fixed\r
-\r
- def OnDirCtrlLeftDclick(self, event):\r
- file_path = self.panelFolders.GetPath()\r
- if os.path.isfile(file_path):\r
- if file_path.endswith('.hkp'):\r
- self.do_loadlist(file_path)\r
- event.Skip()\r
-\r
- def OnEraseBackground(self, event):\r
- event.Skip()\r
-\r
- def OnExecute(self, event):\r
- item = self.panelCommands.CommandsTree.GetSelection()\r
- if item.IsOk():\r
- if not self.panelCommands.CommandsTree.ItemHasChildren(item):\r
- item_text = self.panelCommands.CommandsTree.GetItemText(item)\r
- command = ''.join(['self.do_', item_text, '()'])\r
- #self.AppendToOutput(command + '\n')\r
- exec(command)\r
-\r
- def OnExit(self, event):\r
- self.Close()\r
-\r
- def OnNext(self, event):\r
- '''\r
- NEXT\r
- Go to the next curve in the playlist.\r
- If we are at the last curve, we come back to the first.\r
- -----\r
- Syntax: next, n\r
- '''\r
- selected_item = self.panelPlaylists.PlaylistsTree.GetSelection()\r
- if self.panelPlaylists.PlaylistsTree.ItemHasChildren(selected_item):\r
- #GetFirstChild returns a tuple\r
- #we only need the first element\r
- next_item = self.panelPlaylists.PlaylistsTree.GetFirstChild(selected_item)[0]\r
- else:\r
- next_item = self.panelPlaylists.PlaylistsTree.GetNextSibling(selected_item)\r
- if not next_item.IsOk():\r
- parent_item = self.panelPlaylists.PlaylistsTree.GetItemParent(selected_item)\r
- #GetFirstChild returns a tuple\r
- #we only need the first element\r
- next_item = self.panelPlaylists.PlaylistsTree.GetFirstChild(parent_item)[0]\r
- self.panelPlaylists.PlaylistsTree.SelectItem(next_item, True)\r
- if not self.panelPlaylists.PlaylistsTree.ItemHasChildren(selected_item):\r
- playlist = self.GetActivePlaylist()\r
- if playlist.count > 1:\r
- playlist.next()\r
- self.statusbar.SetStatusText(playlist.get_status_string(), 0)\r
- self.UpdateNote()\r
- self.UpdatePlot()\r
-\r
- def OnNotebookPageClose(self, event):\r
- ctrl = event.GetEventObject()\r
- playlist_name = ctrl.GetPageText(ctrl._curpage)\r
- self.DeleteFromPlaylists(playlist_name)\r
-\r
- def OnPaneClose(self, event):\r
- event.Skip()\r
-\r
- def OnPlaylistsLeftDclick(self, event):\r
- if self.panelPlaylists.PlaylistsTree.Count > 0:\r
- playlist_name = self.GetActivePlaylistName()\r
- #if that playlist already exists\r
- #we check if it is the active playlist (ie selected in panelPlaylists)\r
- #and switch to it if necessary\r
- if playlist_name in self.playlists:\r
- index = self.plotNotebook.GetSelection()\r
- current_playlist = self.plotNotebook.GetPageText(index)\r
- if current_playlist != playlist_name:\r
- index = self._GetPlaylistTab(playlist_name)\r
- self.plotNotebook.SetSelection(index)\r
- #if a curve was double-clicked\r
- item = self.panelPlaylists.PlaylistsTree.GetSelection()\r
- if not self.panelPlaylists.PlaylistsTree.ItemHasChildren(item):\r
- index = self._GetActiveFileIndex()\r
- else:\r
- index = 0\r
- if index >= 0:\r
- playlist = self.GetActivePlaylist()\r
- playlist.index = index\r
- self.statusbar.SetStatusText(playlist.get_status_string(), 0)\r
- self.UpdateNote()\r
- self.UpdatePlot()\r
- #if you uncomment the following line, the tree will collapse/expand as well\r
- #event.Skip()\r
-\r
- def OnPlaylistsLeftDown(self, event):\r
- hit_item, hit_flags = self.panelPlaylists.PlaylistsTree.HitTest(event.GetPosition())\r
- if (hit_flags & wx.TREE_HITTEST_ONITEM) != 0:\r
- self.panelPlaylists.PlaylistsTree.SelectItem(hit_item)\r
- playlist_name = self.GetActivePlaylistName()\r
- playlist = self.GetActivePlaylist()\r
- #if a curve was clicked\r
- item = self.panelPlaylists.PlaylistsTree.GetSelection()\r
- if not self.panelPlaylists.PlaylistsTree.ItemHasChildren(item):\r
- index = self._GetActiveFileIndex()\r
- if index >= 0:\r
- playlist.index = index\r
- self.playlists[playlist_name] = playlist\r
- event.Skip()\r
-\r
- def OnPrevious(self, event):\r
- '''\r
- PREVIOUS\r
- Go to the previous curve in the playlist.\r
- If we are at the first curve, we jump to the last.\r
- -------\r
- Syntax: previous, p\r
- '''\r
- #playlist = self.playlists[self.GetActivePlaylistName()][0]\r
- #select the previous curve and tell the user if we wrapped around\r
- #self.AppendToOutput(playlist.previous())\r
- selected_item = self.panelPlaylists.PlaylistsTree.GetSelection()\r
- if self.panelPlaylists.PlaylistsTree.ItemHasChildren(selected_item):\r
- previous_item = self.panelPlaylists.PlaylistsTree.GetLastChild(selected_item)\r
- else:\r
- previous_item = self.panelPlaylists.PlaylistsTree.GetPrevSibling(selected_item)\r
- if not previous_item.IsOk():\r
- parent_item = self.panelPlaylists.PlaylistsTree.GetItemParent(selected_item)\r
- previous_item = self.panelPlaylists.PlaylistsTree.GetLastChild(parent_item)\r
- self.panelPlaylists.PlaylistsTree.SelectItem(previous_item, True)\r
- playlist = self.GetActivePlaylist()\r
- if playlist.count > 1:\r
- playlist.previous()\r
- self.statusbar.SetStatusText(playlist.get_status_string(), 0)\r
- self.UpdateNote()\r
- self.UpdatePlot()\r
-\r
- def OnPropGridChanged (self, event):\r
- prop = event.GetProperty()\r
- if prop:\r
- item_section = self.panelProperties.SelectedTreeItem\r
- item_plugin = self.panelCommands.CommandsTree.GetItemParent(item_section)\r
- plugin = self.panelCommands.CommandsTree.GetItemText(item_plugin)\r
- config = self.configs[plugin]\r
- property_section = self.panelCommands.CommandsTree.GetItemText(item_section)\r
- property_key = prop.GetName()\r
- property_value = prop.GetDisplayedString()\r
-\r
- config[property_section][property_key]['value'] = property_value\r
-\r
- def OnRestorePerspective(self, event):\r
- name = self.MenuBar.FindItemById(event.GetId()).GetLabel()\r
- self._RestorePerspective(name)\r
-\r
- def OnResultsCheck(self, index, flag):\r
- results = self.GetActivePlot().results\r
- if results.has_key(self.results_str):\r
- results[self.results_str].results[index].visible = flag\r
- results[self.results_str].update()\r
- self.UpdatePlot()\r
-\r
- def OnSavePerspective(self, event):\r
-\r
- def nameExists(name):\r
- menu_position = self.MenuBar.FindMenu('Perspectives')\r
- menu = self.MenuBar.GetMenu(menu_position)\r
- for item in menu.GetMenuItems():\r
- if item.GetText() == name:\r
- return True\r
- return False\r
-\r
- done = False\r
- while not done:\r
- dialog = wx.TextEntryDialog(self, 'Enter a name for the new perspective:', 'Save perspective')\r
- dialog.SetValue('New perspective')\r
- if dialog.ShowModal() != wx.ID_OK:\r
- return\r
- else:\r
- name = dialog.GetValue()\r
-\r
- if nameExists(name):\r
- dialogConfirm = wx.MessageDialog(self, 'A file with this name already exists.\n\nDo you want to replace it?', 'Confirm', wx.YES_NO|wx.ICON_QUESTION|wx.CENTER)\r
- if dialogConfirm.ShowModal() == wx.ID_YES:\r
- done = True\r
- else:\r
- done = True\r
-\r
- perspective = self._mgr.SavePerspective()\r
- self._SavePerspectiveToFile(name, perspective)\r
- self.config['perspectives']['active'] = name\r
- self.UpdatePerspectivesMenu()\r
-# if nameExists(name):\r
-# #check the corresponding menu item\r
-# menu_item = self.GetPerspectiveMenuItem(name)\r
-# #replace the perspectiveStr in _pespectives\r
-# self._perspectives[name] = perspective\r
-# else:\r
-# #because we deal with radio items, we need to do some extra work\r
-# #delete all menu items from the perspectives menu\r
-# for item in self._perspectives_menu.GetMenuItems():\r
-# self._perspectives_menu.DeleteItem(item)\r
-# #recreate the perspectives menu\r
-# self._perspectives_menu.Append(ID_SavePerspective, 'Save Perspective')\r
-# self._perspectives_menu.Append(ID_DeletePerspective, 'Delete Perspective')\r
-# self._perspectives_menu.AppendSeparator()\r
-# #convert the perspectives dictionary into a list\r
-# # the list contains:\r
-# #[0]: name of the perspective\r
-# #[1]: perspective\r
-# perspectives_list = [key for key, value in self._perspectives.iteritems()]\r
-# perspectives_list.append(name)\r
-# perspectives_list.sort()\r
-# #add all previous perspectives\r
-# for index, item in enumerate(perspectives_list):\r
-# menu_item = self._perspectives_menu.AppendRadioItem(ID_FirstPerspective + index, item)\r
-# if item == name:\r
-# menu_item.Check()\r
-# #add the new perspective to _perspectives\r
-# self._perspectives[name] = perspective\r
-\r
- def OnSize(self, event):\r
- event.Skip()\r
-\r
- def OnTreeCtrlCommandsSelectionChanged(self, event):\r
- selected_item = event.GetItem()\r
- if selected_item is not None:\r
- plugin = ''\r
- section = ''\r
- #deregister/register the listener to avoid infinite loop\r
- evtmgr.eventManager.DeregisterListener(self.OnTreeCtrlCommandsSelectionChanged)\r
- self.panelCommands.CommandsTree.SelectItem(selected_item)\r
- evtmgr.eventManager.Register(self.OnTreeCtrlCommandsSelectionChanged, wx.EVT_TREE_SEL_CHANGED, self.panelCommands.CommandsTree)\r
- self.panelProperties.SelectedTreeItem = selected_item\r
- #if a command was clicked\r
- properties = []\r
- if not self.panelCommands.CommandsTree.ItemHasChildren(selected_item):\r
- item_plugin = self.panelCommands.CommandsTree.GetItemParent(selected_item)\r
- plugin = self.panelCommands.CommandsTree.GetItemText(item_plugin)\r
- if self.configs.has_key(plugin):\r
- #config = self.panelCommands.CommandsTree.GetPyData(item_plugin)\r
- config = self.configs[plugin]\r
- section = self.panelCommands.CommandsTree.GetItemText(selected_item)\r
- #display docstring in help window\r
- doc_string = eval('self.do_' + section + '.__doc__')\r
- if section in config:\r
- for option in config[section]:\r
- properties.append([option, config[section][option]])\r
- else:\r
- plugin = self.panelCommands.CommandsTree.GetItemText(selected_item)\r
- if plugin != 'core':\r
- doc_string = eval('plugins.' + plugin + '.' + plugin + 'Commands.__doc__')\r
- else:\r
- doc_string = 'The module "core" contains Hooke core functionality'\r
- if doc_string is not None:\r
- self.panelAssistant.ChangeValue(doc_string)\r
- else:\r
- self.panelAssistant.ChangeValue('')\r
- panels.propertyeditor.PropertyEditor.Initialize(self.panelProperties, properties)\r
- #save the currently selected command/plugin to the config file\r
- self.config['command']['command'] = section\r
- self.config['command']['plugin'] = plugin\r
-\r
- def OnTreeCtrlItemActivated(self, event):\r
- self.OnExecute(event)\r
-\r
- def OnUpdateNote(self, event):\r
- '''\r
- Saves the note to the active file.\r
- '''\r
- active_file = self.GetActiveFile()\r
- active_file.note = self.panelNote.Editor.GetValue()\r
-\r
- def OnView(self, event):\r
- menu_id = event.GetId()\r
- menu_item = self.MenuBar.FindItemById(menu_id)\r
- menu_label = menu_item.GetLabel()\r
-\r
- pane = self._mgr.GetPane(menu_label)\r
- pane.Show(not pane.IsShown())\r
- #if we don't do the following, the Folders pane does not resize properly on hide/show\r
- if pane.caption == 'Folders' and pane.IsShown() and pane.IsDocked():\r
- #folders_size = pane.GetSize()\r
- self.panelFolders.Fit()\r
- self._mgr.Update()\r
-\r
- def _clickize(self, xvector, yvector, index):\r
- '''\r
- Returns a ClickedPoint() object from an index and vectors of x, y coordinates\r
- '''\r
- point = lib.clickedpoint.ClickedPoint()\r
- point.index = index\r
- point.absolute_coords = xvector[index], yvector[index]\r
- point.find_graph_coords(xvector, yvector)\r
- return point\r
-\r
- def _delta(self, message='Click 2 points', whatset=lh.RETRACTION):\r
- '''\r
- Calculates the difference between two clicked points\r
- '''\r
- clicked_points = self._measure_N_points(N=2, message=message, whatset=whatset)\r
-\r
- plot = self.GetDisplayedPlotCorrected()\r
- curve = plot.curves[whatset]\r
-\r
- delta = lib.delta.Delta()\r
- delta.point1.x = clicked_points[0].graph_coords[0]\r
- delta.point1.y = clicked_points[0].graph_coords[1]\r
- delta.point2.x = clicked_points[1].graph_coords[0]\r
- delta.point2.y = clicked_points[1].graph_coords[1]\r
- delta.units.x = curve.units.x\r
- delta.units.y = curve.units.y\r
-\r
- return delta\r
-\r
- def _measure_N_points(self, N, message='', whatset=lh.RETRACTION):\r
- '''\r
- General helper function for N-points measurements\r
- By default, measurements are done on the retraction\r
- '''\r
- if message:\r
- dialog = wx.MessageDialog(None, message, 'Info', wx.OK)\r
- dialog.ShowModal()\r
-\r
- figure = self.GetActiveFigure()\r
-\r
- xvector = self.displayed_plot.curves[whatset].x\r
- yvector = self.displayed_plot.curves[whatset].y\r
-\r
- clicked_points = figure.ginput(N, timeout=-1, show_clicks=True)\r
-\r
- points = []\r
- for clicked_point in clicked_points:\r
- point = lib.clickedpoint.ClickedPoint()\r
- point.absolute_coords = clicked_point[0], clicked_point[1]\r
- point.dest = 0\r
- #TODO: make this optional?\r
- #so far, the clicked point is taken, not the corresponding data point\r
- point.find_graph_coords(xvector, yvector)\r
- point.is_line_edge = True\r
- point.is_marker = True\r
- points.append(point)\r
- return points\r
-\r
- def do_copylog(self):\r
- '''\r
- Copies all files in the current playlist that have a note to the destination folder.\r
- destination: select folder where you want the files to be copied\r
- use_LVDT_folder: when checked, the files will be copied to a folder called 'LVDT' in the destination folder (for MFP-1D files only)\r
- '''\r
- playlist = self.GetActivePlaylist()\r
- if playlist is not None:\r
- destination = self.GetStringFromConfig('core', 'copylog', 'destination')\r
- if not os.path.isdir(destination):\r
- os.makedirs(destination)\r
- for current_file in playlist.files:\r
- if current_file.note:\r
- shutil.copy(current_file.filename, destination)\r
- if current_file.driver.filetype == 'mfp1d':\r
- filename = current_file.filename.replace('deflection', 'LVDT', 1)\r
- path, name = os.path.split(filename)\r
- filename = os.path.join(path, 'lvdt', name)\r
- use_LVDT_folder = self.GetBoolFromConfig('core', 'copylog', 'use_LVDT_folder')\r
- if use_LVDT_folder:\r
- destination = os.path.join(destination, 'LVDT')\r
- shutil.copy(filename, destination)\r
-\r
- def do_plotmanipulators(self):\r
- '''\r
- Please select the plotmanipulators you would like to use\r
- and define the order in which they will be applied to the data.\r
-\r
- Click 'Execute' to apply your changes.\r
- '''\r
- self.UpdatePlot()\r
-\r
- def do_preferences(self):\r
- '''\r
- Please set general preferences for Hooke here.\r
- hide_curve_extension: hides the extension of the force curve files.\r
- not recommended for 'picoforce' files\r
- '''\r
- pass\r
-\r
- def do_test(self):\r
- '''\r
- Use this command for testing purposes. You find do_test in hooke.py.\r
- '''\r
- pass\r
-\r
- def do_version(self):\r
- '''\r
- VERSION\r
- ------\r
- Prints the current version and codename, plus library version. Useful for debugging.\r
- '''\r
- self.AppendToOutput('Hooke ' + __version__ + ' (' + __codename__ + ')')\r
- self.AppendToOutput('Released on: ' + __releasedate__)\r
- self.AppendToOutput('---')\r
- self.AppendToOutput('Python version: ' + python_version)\r
- self.AppendToOutput('WxPython version: ' + wx_version)\r
- self.AppendToOutput('Matplotlib version: ' + mpl_version)\r
- self.AppendToOutput('SciPy version: ' + scipy_version)\r
- self.AppendToOutput('NumPy version: ' + numpy_version)\r
- self.AppendToOutput('ConfigObj version: ' + configobj_version)\r
- self.AppendToOutput('wxPropertyGrid version: ' + '.'.join([str(PROPGRID_MAJOR), str(PROPGRID_MINOR), str(PROPGRID_RELEASE)]))\r
- self.AppendToOutput('---')\r
- self.AppendToOutput('Platform: ' + str(platform.uname()))\r
- self.AppendToOutput('******************************')\r
- self.AppendToOutput('Loaded plugins')\r
- self.AppendToOutput('---')\r
-\r
- #sort the plugins into alphabetical order\r
- plugins_list = [key for key, value in self.plugins.iteritems()]\r
- plugins_list.sort()\r
- for plugin in plugins_list:\r
- self.AppendToOutput(plugin)\r
-\r
- def UpdateNote(self):\r
- #update the note for the active file\r
- active_file = self.GetActiveFile()\r
- if active_file is not None:\r
- self.panelNote.Editor.SetValue(active_file.note)\r
-\r
- def UpdatePerspectivesMenu(self):\r
- #add perspectives to menubar and _perspectives\r
- perspectivesDirectory = os.path.join(lh.hookeDir, 'perspectives')\r
- self._perspectives = {}\r
- if os.path.isdir(perspectivesDirectory):\r
- perspectiveFileNames = os.listdir(perspectivesDirectory)\r
- for perspectiveFilename in perspectiveFileNames:\r
- filename = lh.get_file_path(perspectiveFilename, ['perspectives'])\r
- if os.path.isfile(filename):\r
- perspectiveFile = open(filename, 'rU')\r
- perspective = perspectiveFile.readline()\r
- perspectiveFile.close()\r
- if perspective:\r
- name, extension = os.path.splitext(perspectiveFilename)\r
- if extension == '.txt':\r
- self._perspectives[name] = perspective\r
-\r
- #in case there are no perspectives\r
- if not self._perspectives:\r
- perspective = self._mgr.SavePerspective()\r
- self._perspectives['Default'] = perspective\r
- self._SavePerspectiveToFile('Default', perspective)\r
-\r
- selected_perspective = self.config['perspectives']['active']\r
- if not self._perspectives.has_key(selected_perspective):\r
- self.config['perspectives']['active'] = 'Default'\r
- selected_perspective = 'Default'\r
-\r
- perspectives_list = [key for key, value in self._perspectives.iteritems()]\r
- perspectives_list.sort()\r
-\r
- #get the Perspectives menu\r
- menu_position = self.MenuBar.FindMenu('Perspectives')\r
- menu = self.MenuBar.GetMenu(menu_position)\r
- #delete all menu items\r
- for item in menu.GetMenuItems():\r
- menu.DeleteItem(item)\r
- #rebuild the menu by adding the standard menu items\r
- menu.Append(ID_SavePerspective, 'Save Perspective')\r
- menu.Append(ID_DeletePerspective, 'Delete Perspective')\r
- menu.AppendSeparator()\r
- #add all previous perspectives\r
- for index, label in enumerate(perspectives_list):\r
- menu_item = menu.AppendRadioItem(ID_FirstPerspective + index, label)\r
- if label == selected_perspective:\r
- self._RestorePerspective(label)\r
- menu_item.Check(True)\r
-\r
- def UpdatePlaylistsTreeSelection(self):\r
- playlist = self.GetActivePlaylist()\r
- if playlist is not None:\r
- if playlist.index >= 0:\r
- self.statusbar.SetStatusText(playlist.get_status_string(), 0)\r
- self.UpdateNote()\r
- self.UpdatePlot()\r
-\r
- def UpdatePlot(self, plot=None):\r
-\r
- def add_to_plot(curve, set_scale=True):\r
- if curve.visible and curve.x and curve.y:\r
- #get the index of the subplot to use as destination\r
- destination = (curve.destination.column - 1) * number_of_rows + curve.destination.row - 1\r
- #set all parameters for the plot\r
- axes_list[destination].set_title(curve.title)\r
- if set_scale:\r
- axes_list[destination].set_xlabel(curve.prefix.x + curve.units.x)\r
- axes_list[destination].set_ylabel(curve.prefix.y + curve.units.y)\r
- #set the formatting details for the scale\r
- formatter_x = lib.curve.PrefixFormatter(curve.decimals.x, curve.prefix.x, use_zero)\r
- formatter_y = lib.curve.PrefixFormatter(curve.decimals.y, curve.prefix.y, use_zero)\r
- axes_list[destination].xaxis.set_major_formatter(formatter_x)\r
- axes_list[destination].yaxis.set_major_formatter(formatter_y)\r
- if curve.style == 'plot':\r
- axes_list[destination].plot(curve.x, curve.y, color=curve.color, label=curve.label, lw=curve.linewidth, zorder=1)\r
- if curve.style == 'scatter':\r
- axes_list[destination].scatter(curve.x, curve.y, color=curve.color, label=curve.label, s=curve.size, zorder=2)\r
- #add the legend if necessary\r
- if curve.legend:\r
- axes_list[destination].legend()\r
-\r
- if plot is None:\r
- active_file = self.GetActiveFile()\r
- if not active_file.driver:\r
- #the first time we identify a file, the following need to be set\r
- active_file.identify(self.drivers)\r
- for curve in active_file.plot.curves:\r
- curve.decimals.x = self.GetIntFromConfig('core', 'preferences', 'x_decimals')\r
- curve.decimals.y = self.GetIntFromConfig('core', 'preferences', 'y_decimals')\r
- curve.legend = self.GetBoolFromConfig('core', 'preferences', 'legend')\r
- curve.prefix.x = self.GetStringFromConfig('core', 'preferences', 'x_prefix')\r
- curve.prefix.y = self.GetStringFromConfig('core', 'preferences', 'y_prefix')\r
- if active_file.driver is None:\r
- self.AppendToOutput('Invalid file: ' + active_file.filename)\r
- return\r
- self.displayed_plot = copy.deepcopy(active_file.plot)\r
- #add raw curves to plot\r
- self.displayed_plot.raw_curves = copy.deepcopy(self.displayed_plot.curves)\r
- #apply all active plotmanipulators\r
- self.displayed_plot = self.ApplyPlotmanipulators(self.displayed_plot, active_file)\r
- #add corrected curves to plot\r
- self.displayed_plot.corrected_curves = copy.deepcopy(self.displayed_plot.curves)\r
- else:\r
- active_file = None\r
- self.displayed_plot = copy.deepcopy(plot)\r
-\r
- figure = self.GetActiveFigure()\r
- figure.clear()\r
-\r
- #use '0' instead of e.g. '0.00' for scales\r
- use_zero = self.GetBoolFromConfig('core', 'preferences', 'use_zero')\r
- #optionally remove the extension from the title of the plot\r
- hide_curve_extension = self.GetBoolFromConfig('core', 'preferences', 'hide_curve_extension')\r
- if hide_curve_extension:\r
- title = lh.remove_extension(self.displayed_plot.title)\r
- else:\r
- title = self.displayed_plot.title\r
- figure.suptitle(title, fontsize=14)\r
- #create the list of all axes necessary (rows and columns)\r
- axes_list =[]\r
- number_of_columns = max([curve.destination.column for curve in self.displayed_plot.curves])\r
- number_of_rows = max([curve.destination.row for curve in self.displayed_plot.curves])\r
- for index in range(number_of_rows * number_of_columns):\r
- axes_list.append(figure.add_subplot(number_of_rows, number_of_columns, index + 1))\r
-\r
- #add all curves to the corresponding plots\r
- for curve in self.displayed_plot.curves:\r
- add_to_plot(curve)\r
-\r
- #make sure the titles of 'subplots' do not overlap with the axis labels of the 'main plot'\r
- figure.subplots_adjust(hspace=0.3)\r
-\r
- #display results\r
- self.panelResults.ClearResults()\r
- if self.displayed_plot.results.has_key(self.results_str):\r
- for curve in self.displayed_plot.results[self.results_str].results:\r
- add_to_plot(curve, set_scale=False)\r
- self.panelResults.DisplayResults(self.displayed_plot.results[self.results_str])\r
- else:\r
- self.panelResults.ClearResults()\r
- #refresh the plot\r
- figure.canvas.draw()\r
-\r
-if __name__ == '__main__':\r
-\r
- ## now, silence a deprecation warning for py2.3\r
- import warnings\r
- warnings.filterwarnings("ignore", "integer", DeprecationWarning, "wxPython.gdi")\r
-\r
- redirect = True\r
- if __debug__:\r
- redirect=False\r
-\r
- app = Hooke(redirect=redirect)\r
-\r
- app.MainLoop()\r
"""Defines :class:`GUI` providing a wxWindows interface to Hooke.\r
"""\r
\r
+import lib.libhooke as lh\r
+import wxversion\r
+wxversion.select(lh.WX_GOOD)\r
+\r
+from configobj import ConfigObj\r
+import copy\r
+import os.path\r
+import platform\r
+import shutil\r
+import time\r
+\r
+import wx.html\r
+import wx.lib.agw.aui as aui\r
+import wx.lib.evtmgr as evtmgr\r
+import wx.propgrid as wxpg\r
+\r
+from matplotlib.ticker import FuncFormatter\r
+\r
+from configobj import __version__ as configobj_version\r
+from matplotlib import __version__ as mpl_version\r
+from numpy import __version__ as numpy_version\r
+from scipy import __version__ as scipy_version\r
+from sys import version as python_version\r
+from wx import __version__ as wx_version\r
+from wx.propgrid import PROPGRID_MAJOR\r
+from wx.propgrid import PROPGRID_MINOR\r
+from wx.propgrid import PROPGRID_RELEASE\r
+\r
+try:\r
+ from agw import cubecolourdialog as CCD\r
+except ImportError: # if it's not there locally, try the wxPython lib.\r
+ import wx.lib.agw.cubecolourdialog as CCD\r
+\r
+#set the Hooke directory\r
+lh.hookeDir = os.path.abspath(os.path.dirname(__file__))\r
+from config.config import config\r
+import drivers\r
+import lib.clickedpoint\r
+import lib.curve\r
+import lib.delta\r
+import lib.playlist\r
+import lib.plotmanipulator\r
+import lib.prettyformat\r
+import panels.commands\r
+import panels.note\r
+import panels.perspectives\r
+import panels.playlist\r
+import panels.plot\r
+import panels.propertyeditor\r
+import panels.results\r
+import plugins\r
+\r
+global __version__\r
+global __codename__\r
+global __releasedate__\r
+__version__ = lh.HOOKE_VERSION[0]\r
+__codename__ = lh.HOOKE_VERSION[1]\r
+__releasedate__ = lh.HOOKE_VERSION[2]\r
+__release_name__ = lh.HOOKE_VERSION[1]\r
+\r
+ID_About = wx.NewId()\r
+ID_Next = wx.NewId()\r
+ID_Previous = wx.NewId()\r
+\r
+ID_ViewAssistant = wx.NewId()\r
+ID_ViewCommands = wx.NewId()\r
+ID_ViewFolders = wx.NewId()\r
+ID_ViewNote = wx.NewId()\r
+ID_ViewOutput = wx.NewId()\r
+ID_ViewPlaylists = wx.NewId()\r
+ID_ViewProperties = wx.NewId()\r
+ID_ViewResults = wx.NewId()\r
+\r
+ID_DeletePerspective = wx.NewId()\r
+ID_SavePerspective = wx.NewId()\r
+\r
+ID_FirstPerspective = ID_SavePerspective + 1000\r
+#I hope we'll never have more than 1000 perspectives\r
+ID_FirstPlot = ID_SavePerspective + 2000\r
+\r
+class Hooke(wx.App):\r
+\r
+ def OnInit(self):\r
+ self.SetAppName('Hooke')\r
+ self.SetVendorName('')\r
+\r
+ window_height = config['main']['height']\r
+ window_left= config['main']['left']\r
+ window_top = config['main']['top']\r
+ window_width = config['main']['width']\r
+\r
+ #sometimes, the ini file gets confused and sets 'left'\r
+ #and 'top' to large negative numbers\r
+ #let's catch and fix this\r
+ #keep small negative numbers, the user might want those\r
+ if window_left < -window_width:\r
+ window_left = 0\r
+ if window_top < -window_height:\r
+ window_top = 0\r
+ window_position = (window_left, window_top)\r
+ window_size = (window_width, window_height)\r
+\r
+ #setup the splashscreen\r
+ if config['splashscreen']['show']:\r
+ filename = lh.get_file_path('hooke.jpg', ['resources'])\r
+ if os.path.isfile(filename):\r
+ bitmap = wx.Image(filename).ConvertToBitmap()\r
+ splashStyle = wx.SPLASH_CENTRE_ON_SCREEN|wx.SPLASH_TIMEOUT\r
+ splashDuration = config['splashscreen']['duration']\r
+ wx.SplashScreen(bitmap, splashStyle, splashDuration, None, -1)\r
+ wx.Yield()\r
+ '''\r
+ we need for the splash screen to disappear\r
+ for whatever reason splashDuration and sleep do not correspond to each other\r
+ at least not on Windows\r
+ maybe it's because duration is in milliseconds and sleep in seconds\r
+ thus we need to increase the sleep time a bit\r
+ a factor of 1.2 seems to work quite well\r
+ '''\r
+ sleepFactor = 1.2\r
+ time.sleep(sleepFactor * splashDuration / 1000)\r
+\r
+ plugin_objects = []\r
+ for plugin in config['plugins']:\r
+ if config['plugins'][plugin]:\r
+ filename = ''.join([plugin, '.py'])\r
+ path = lh.get_file_path(filename, ['plugins'])\r
+ if os.path.isfile(path):\r
+ #get the corresponding filename and path\r
+ plugin_name = ''.join(['plugins.', plugin])\r
+ #import the module\r
+ __import__(plugin_name)\r
+ #get the file that contains the plugin\r
+ class_file = getattr(plugins, plugin)\r
+ #get the class that contains the commands\r
+ class_object = getattr(class_file, plugin + 'Commands')\r
+ plugin_objects.append(class_object)\r
+\r
+ def make_command_class(*bases):\r
+ #create metaclass with plugins and plotmanipulators\r
+ return type(HookeFrame)("HookeFramePlugged", bases + (HookeFrame,), {})\r
+ frame = make_command_class(*plugin_objects)(parent=None, id=wx.ID_ANY, title='Hooke', pos=window_position, size=window_size)\r
+ frame.Show(True)\r
+ self.SetTopWindow(frame)\r
+\r
+ return True\r
+\r
+ def OnExit(self):\r
+ return True\r
+\r
+\r
+class HookeFrame(wx.Frame):\r
+\r
+ def __init__(self, parent, id=-1, title='', pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE|wx.SUNKEN_BORDER|wx.CLIP_CHILDREN):\r
+ #call parent constructor\r
+ wx.Frame.__init__(self, parent, id, title, pos, size, style)\r
+ self.config = config\r
+ self.CreateApplicationIcon()\r
+ #self.configs contains: {the name of the Commands file: corresponding ConfigObj}\r
+ self.configs = {}\r
+ #self.displayed_plot holds the currently displayed plot\r
+ self.displayed_plot = None\r
+ #self.playlists contains: {the name of the playlist: [playlist, tabIndex, plotID]}\r
+ self.playlists = {}\r
+ #list of all plotmanipulators\r
+ self.plotmanipulators = []\r
+ #self.plugins contains: {the name of the plugin: [caption, function]}\r
+ self.plugins = {}\r
+ #self.results_str contains the type of results we want to display\r
+ self.results_str = 'wlc'\r
+\r
+ #tell FrameManager to manage this frame\r
+ self._mgr = aui.AuiManager()\r
+ self._mgr.SetManagedWindow(self)\r
+ #set the gradient style\r
+ self._mgr.GetArtProvider().SetMetric(aui.AUI_DOCKART_GRADIENT_TYPE, aui.AUI_GRADIENT_NONE)\r
+ #set transparent drag\r
+ self._mgr.SetFlags(self._mgr.GetFlags() ^ aui.AUI_MGR_TRANSPARENT_DRAG)\r
+\r
+ # set up default notebook style\r
+ self._notebook_style = aui.AUI_NB_DEFAULT_STYLE | aui.AUI_NB_TAB_EXTERNAL_MOVE | wx.NO_BORDER\r
+ self._notebook_theme = 0\r
+\r
+ #holds the perspectives: {name, perspective_str}\r
+ self._perspectives = {}\r
+\r
+ # min size for the frame itself isn't completely done.\r
+ # see the end up FrameManager::Update() for the test\r
+ # code. For now, just hard code a frame minimum size\r
+ self.SetMinSize(wx.Size(500, 500))\r
+ #define the list of active drivers\r
+ self.drivers = []\r
+ for driver in self.config['drivers']:\r
+ if self.config['drivers'][driver]:\r
+ #get the corresponding filename and path\r
+ filename = ''.join([driver, '.py'])\r
+ path = lh.get_file_path(filename, ['drivers'])\r
+ #the driver is active for driver[1] == 1\r
+ if os.path.isfile(path):\r
+ #driver files are located in the 'drivers' subfolder\r
+ driver_name = ''.join(['drivers.', driver])\r
+ __import__(driver_name)\r
+ class_file = getattr(drivers, driver)\r
+ for command in dir(class_file):\r
+ if command.endswith('Driver'):\r
+ self.drivers.append(getattr(class_file, command))\r
+ #import all active plugins and plotmanips\r
+ #add 'core.ini' to self.configs (this is not a plugin and thus must be imported separately)\r
+ ini_path = lh.get_file_path('core.ini', ['plugins'])\r
+ plugin_config = ConfigObj(ini_path)\r
+ #self.config.merge(plugin_config)\r
+ self.configs['core'] = plugin_config\r
+ #existing_commands contains: {command: plugin}\r
+ existing_commands = {}\r
+ #make sure we execute _plug_init() for every command line plugin we import\r
+ for plugin in self.config['plugins']:\r
+ if self.config['plugins'][plugin]:\r
+ filename = ''.join([plugin, '.py'])\r
+ path = lh.get_file_path(filename, ['plugins'])\r
+ if os.path.isfile(path):\r
+ #get the corresponding filename and path\r
+ plugin_name = ''.join(['plugins.', plugin])\r
+ try:\r
+ #import the module\r
+ module = __import__(plugin_name)\r
+ #prepare the ini file for inclusion\r
+ ini_path = path.replace('.py', '.ini')\r
+ #include ini file\r
+ plugin_config = ConfigObj(ini_path)\r
+ #self.config.merge(plugin_config)\r
+ self.configs[plugin] = plugin_config\r
+ #add to plugins\r
+ commands = eval('dir(module.' + plugin+ '.' + plugin + 'Commands)')\r
+ #keep only commands (ie names that start with 'do_')\r
+ commands = [command for command in commands if command.startswith('do_')]\r
+ if commands:\r
+ for command in commands:\r
+ if existing_commands.has_key(command):\r
+ message_str = 'Adding "' + command + '" in plugin "' + plugin + '".\n\n'\r
+ message_str += '"' + command + '" already exists in "' + str(existing_commands[command]) + '".\n\n'\r
+ message_str += 'Only "' + command + '" in "' + str(existing_commands[command]) + '" will work.\n\n'\r
+ message_str += 'Please rename one of the commands in the source code and restart Hooke or disable one of the plugins.'\r
+ dialog = wx.MessageDialog(self, message_str, 'Warning', wx.OK|wx.ICON_WARNING|wx.CENTER)\r
+ dialog.ShowModal()\r
+ dialog.Destroy()\r
+ existing_commands[command] = plugin\r
+ self.plugins[plugin] = commands\r
+ try:\r
+ #initialize the plugin\r
+ eval('module.' + plugin+ '.' + plugin + 'Commands._plug_init(self)')\r
+ except AttributeError:\r
+ pass\r
+ except ImportError:\r
+ pass\r
+ #add commands from hooke.py i.e. 'core' commands\r
+ commands = dir(HookeFrame)\r
+ commands = [command for command in commands if command.startswith('do_')]\r
+ if commands:\r
+ self.plugins['core'] = commands\r
+ #create panels here\r
+ self.panelAssistant = self.CreatePanelAssistant()\r
+ self.panelCommands = self.CreatePanelCommands()\r
+ self.panelFolders = self.CreatePanelFolders()\r
+ self.panelPlaylists = self.CreatePanelPlaylists()\r
+ self.panelProperties = self.CreatePanelProperties()\r
+ self.panelNote = self.CreatePanelNote()\r
+ self.panelOutput = self.CreatePanelOutput()\r
+ self.panelResults = self.CreatePanelResults()\r
+ self.plotNotebook = self.CreateNotebook()\r
+\r
+ # add panes\r
+ self._mgr.AddPane(self.panelFolders, aui.AuiPaneInfo().Name('Folders').Caption('Folders').Left().CloseButton(True).MaximizeButton(False))\r
+ self._mgr.AddPane(self.panelPlaylists, aui.AuiPaneInfo().Name('Playlists').Caption('Playlists').Left().CloseButton(True).MaximizeButton(False))\r
+ self._mgr.AddPane(self.panelNote, aui.AuiPaneInfo().Name('Note').Caption('Note').Left().CloseButton(True).MaximizeButton(False))\r
+ self._mgr.AddPane(self.plotNotebook, aui.AuiPaneInfo().Name('Plots').CenterPane().PaneBorder(False))\r
+ self._mgr.AddPane(self.panelCommands, aui.AuiPaneInfo().Name('Commands').Caption('Settings and commands').Right().CloseButton(True).MaximizeButton(False))\r
+ self._mgr.AddPane(self.panelProperties, aui.AuiPaneInfo().Name('Properties').Caption('Properties').Right().CloseButton(True).MaximizeButton(False))\r
+ self._mgr.AddPane(self.panelAssistant, aui.AuiPaneInfo().Name('Assistant').Caption('Assistant').Right().CloseButton(True).MaximizeButton(False))\r
+ self._mgr.AddPane(self.panelOutput, aui.AuiPaneInfo().Name('Output').Caption('Output').Bottom().CloseButton(True).MaximizeButton(False))\r
+ self._mgr.AddPane(self.panelResults, aui.AuiPaneInfo().Name('Results').Caption('Results').Bottom().CloseButton(True).MaximizeButton(False))\r
+ #self._mgr.AddPane(self.textCtrlCommandLine, aui.AuiPaneInfo().Name('CommandLine').CaptionVisible(False).Fixed().Bottom().Layer(2).CloseButton(False).MaximizeButton(False))\r
+ #self._mgr.AddPane(panelBottom, aui.AuiPaneInfo().Name("panelCommandLine").Bottom().Position(1).CloseButton(False).MaximizeButton(False))\r
+\r
+ # add the toolbars to the manager\r
+ #self.toolbar=self.CreateToolBar()\r
+ self.toolbarNavigation=self.CreateToolBarNavigation()\r
+ #self._mgr.AddPane(self.toolbar, aui.AuiPaneInfo().Name('toolbar').Caption('Toolbar').ToolbarPane().Top().Layer(1).Row(1).LeftDockable(False).RightDockable(False))\r
+ self._mgr.AddPane(self.toolbarNavigation, aui.AuiPaneInfo().Name('toolbarNavigation').Caption('Navigation').ToolbarPane().Top().Layer(1).Row(1).LeftDockable(False).RightDockable(False))\r
+ # "commit" all changes made to FrameManager\r
+ self._mgr.Update()\r
+ #create the menubar after the panes so that the default perspective\r
+ #is created with all panes open\r
+ self.CreateMenuBar()\r
+ self.statusbar = self.CreateStatusbar()\r
+ self._BindEvents()\r
+\r
+ name = self.config['perspectives']['active']\r
+ menu_item = self.GetPerspectiveMenuItem(name)\r
+ if menu_item is not None:\r
+ self.OnRestorePerspective(menu_item)\r
+ #TODO: config setting to remember playlists from last session\r
+ self.playlists = self.panelPlaylists.Playlists\r
+ #initialize the commands tree\r
+ self.panelCommands.Initialize(self.plugins)\r
+ for command in dir(self):\r
+ if command.startswith('plotmanip_'):\r
+ self.plotmanipulators.append(lib.plotmanipulator.Plotmanipulator(method=getattr(self, command), command=command))\r
+\r
+ #load default list, if possible\r
+ self.do_loadlist(self.GetStringFromConfig('core', 'preferences', 'playlist'))\r
+\r
+ def _BindEvents(self):\r
+ #TODO: figure out if we can use the eventManager for menu ranges\r
+ #and events of 'self' without raising an assertion fail error\r
+ self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)\r
+ self.Bind(wx.EVT_SIZE, self.OnSize)\r
+ self.Bind(wx.EVT_CLOSE, self.OnClose)\r
+ # Show How To Use The Closing Panes Event\r
+ self.Bind(aui.EVT_AUI_PANE_CLOSE, self.OnPaneClose)\r
+ self.Bind(aui.EVT_AUINOTEBOOK_PAGE_CLOSE, self.OnNotebookPageClose)\r
+ #menu\r
+ evtmgr.eventManager.Register(self.OnAbout, wx.EVT_MENU, win=self, id=wx.ID_ABOUT)\r
+ evtmgr.eventManager.Register(self.OnClose, wx.EVT_MENU, win=self, id=wx.ID_EXIT)\r
+ #view\r
+ self.Bind(wx.EVT_MENU_RANGE, self.OnView, id=ID_ViewAssistant, id2=ID_ViewResults)\r
+ #perspectives\r
+ self.Bind(wx.EVT_MENU, self.OnDeletePerspective, id=ID_DeletePerspective)\r
+ self.Bind(wx.EVT_MENU, self.OnSavePerspective, id=ID_SavePerspective)\r
+ self.Bind(wx.EVT_MENU_RANGE, self.OnRestorePerspective, id=ID_FirstPerspective, id2=ID_FirstPerspective+1000)\r
+ #toolbar\r
+ evtmgr.eventManager.Register(self.OnNext, wx.EVT_TOOL, win=self, id=ID_Next)\r
+ evtmgr.eventManager.Register(self.OnPrevious, wx.EVT_TOOL, win=self, id=ID_Previous)\r
+ #self.Bind(.EVT_AUITOOLBAR_TOOL_DROPDOWN, self.OnDropDownToolbarItem, id=ID_DropDownToolbarItem)\r
+ #dir control\r
+ treeCtrl = self.panelFolders.GetTreeCtrl()\r
+ #tree.Bind(wx.EVT_LEFT_UP, self.OnDirCtrl1LeftUp)\r
+ #tree.Bind(wx.EVT_LEFT_DOWN, self.OnGenericDirCtrl1LeftDown)\r
+ treeCtrl.Bind(wx.EVT_LEFT_DCLICK, self.OnDirCtrlLeftDclick)\r
+ #playlist tree\r
+ self.panelPlaylists.PlaylistsTree.Bind(wx.EVT_LEFT_DOWN, self.OnPlaylistsLeftDown)\r
+ self.panelPlaylists.PlaylistsTree.Bind(wx.EVT_LEFT_DCLICK, self.OnPlaylistsLeftDclick)\r
+ #commands tree\r
+ evtmgr.eventManager.Register(self.OnExecute, wx.EVT_BUTTON, self.panelCommands.ExecuteButton)\r
+ evtmgr.eventManager.Register(self.OnTreeCtrlCommandsSelectionChanged, wx.EVT_TREE_SEL_CHANGED, self.panelCommands.CommandsTree)\r
+ evtmgr.eventManager.Register(self.OnTreeCtrlItemActivated, wx.EVT_TREE_ITEM_ACTIVATED, self.panelCommands.CommandsTree)\r
+ evtmgr.eventManager.Register(self.OnUpdateNote, wx.EVT_BUTTON, self.panelNote.UpdateButton)\r
+ #property editor\r
+ self.panelProperties.pg.Bind(wxpg.EVT_PG_CHANGED, self.OnPropGridChanged)\r
+ #results panel\r
+ self.panelResults.results_list.OnCheckItem = self.OnResultsCheck\r
+\r
+ def _GetActiveFileIndex(self):\r
+ lib.playlist.Playlist = self.GetActivePlaylist()\r
+ #get the selected item from the tree\r
+ selected_item = self.panelPlaylists.PlaylistsTree.GetSelection()\r
+ #test if a playlist or a curve was double-clicked\r
+ if self.panelPlaylists.PlaylistsTree.ItemHasChildren(selected_item):\r
+ return -1\r
+ else:\r
+ count = 0\r
+ selected_item = self.panelPlaylists.PlaylistsTree.GetPrevSibling(selected_item)\r
+ while selected_item.IsOk():\r
+ count += 1\r
+ selected_item = self.panelPlaylists.PlaylistsTree.GetPrevSibling(selected_item)\r
+ return count\r
+\r
+ def _GetPlaylistTab(self, name):\r
+ for index, page in enumerate(self.plotNotebook._tabs._pages):\r
+ if page.caption == name:\r
+ return index\r
+ return -1\r
+\r
+ def _GetUniquePlaylistName(self, name):\r
+ playlist_name = name\r
+ count = 1\r
+ while playlist_name in self.playlists:\r
+ playlist_name = ''.join([name, str(count)])\r
+ count += 1\r
+ return playlist_name\r
+\r
+ def _RestorePerspective(self, name):\r
+ self._mgr.LoadPerspective(self._perspectives[name])\r
+ self.config['perspectives']['active'] = name\r
+ self._mgr.Update()\r
+ all_panes = self._mgr.GetAllPanes()\r
+ for pane in all_panes:\r
+ if not pane.name.startswith('toolbar'):\r
+ if pane.name == 'Assistant':\r
+ self.MenuBar.FindItemById(ID_ViewAssistant).Check(pane.window.IsShown())\r
+ if pane.name == 'Folders':\r
+ self.MenuBar.FindItemById(ID_ViewFolders).Check(pane.window.IsShown())\r
+ if pane.name == 'Playlists':\r
+ self.MenuBar.FindItemById(ID_ViewPlaylists).Check(pane.window.IsShown())\r
+ if pane.name == 'Commands':\r
+ self.MenuBar.FindItemById(ID_ViewCommands).Check(pane.window.IsShown())\r
+ if pane.name == 'Note':\r
+ self.MenuBar.FindItemById(ID_ViewNote).Check(pane.window.IsShown())\r
+ if pane.name == 'Properties':\r
+ self.MenuBar.FindItemById(ID_ViewProperties).Check(pane.window.IsShown())\r
+ if pane.name == 'Output':\r
+ self.MenuBar.FindItemById(ID_ViewOutput).Check(pane.window.IsShown())\r
+ if pane.name == 'Results':\r
+ self.MenuBar.FindItemById(ID_ViewResults).Check(pane.window.IsShown())\r
+\r
+ def _SavePerspectiveToFile(self, name, perspective):\r
+ filename = ''.join([name, '.txt'])\r
+ filename = lh.get_file_path(filename, ['perspectives'])\r
+ perspectivesFile = open(filename, 'w')\r
+ perspectivesFile.write(perspective)\r
+ perspectivesFile.close()\r
+\r
+ def _UnbindEvents(self):\r
+ #menu\r
+ evtmgr.eventManager.DeregisterListener(self.OnAbout)\r
+ evtmgr.eventManager.DeregisterListener(self.OnClose)\r
+ #toolbar\r
+ evtmgr.eventManager.DeregisterListener(self.OnNext)\r
+ evtmgr.eventManager.DeregisterListener(self.OnPrevious)\r
+ #commands tree\r
+ evtmgr.eventManager.DeregisterListener(self.OnExecute)\r
+ evtmgr.eventManager.DeregisterListener(self.OnTreeCtrlCommandsSelectionChanged)\r
+ evtmgr.eventManager.DeregisterListener(self.OnTreeCtrlItemActivated)\r
+ evtmgr.eventManager.DeregisterListener(self.OnUpdateNote)\r
+\r
+ def AddPlaylist(self, playlist=None, name='Untitled'):\r
+ if playlist and playlist.count > 0:\r
+ playlist.name = self._GetUniquePlaylistName(name)\r
+ playlist.reset()\r
+ self.AddToPlaylists(playlist)\r
+\r
+ def AddPlaylistFromFiles(self, files=[], name='Untitled'):\r
+ if files:\r
+ playlist = lib.playlist.Playlist(self, self.drivers)\r
+ for item in files:\r
+ playlist.add_curve(item)\r
+ if playlist.count > 0:\r
+ playlist.name = self._GetUniquePlaylistName(name)\r
+ playlist.reset()\r
+ self.AddTayliss(playlist)\r
+\r
+ def AddToPlaylists(self, playlist):\r
+ if playlist.count > 0:\r
+ #setup the playlist in the Playlist tree\r
+ tree_root = self.panelPlaylists.PlaylistsTree.GetRootItem()\r
+ playlist_root = self.panelPlaylists.PlaylistsTree.AppendItem(tree_root, playlist.name, 0)\r
+ #add all files to the Playlist tree\r
+# files = {}\r
+ hide_curve_extension = self.GetBoolFromConfig('core', 'preferences', 'hide_curve_extension')\r
+ for index, file_to_add in enumerate(playlist.files):\r
+ #optionally remove the extension from the name of the curve\r
+ if hide_curve_extension:\r
+ file_to_add.name = lh.remove_extension(file_to_add.name)\r
+ file_ID = self.panelPlaylists.PlaylistsTree.AppendItem(playlist_root, file_to_add.name, 1)\r
+ if index == playlist.index:\r
+ self.panelPlaylists.PlaylistsTree.SelectItem(file_ID)\r
+ playlist.reset()\r
+ #create the plot tab and add playlist to the dictionary\r
+ plotPanel = panels.plot.PlotPanel(self, ID_FirstPlot + len(self.playlists))\r
+ notebook_tab = self.plotNotebook.AddPage(plotPanel, playlist.name, True)\r
+ #tab_index = self.plotNotebook.GetSelection()\r
+ playlist.figure = plotPanel.get_figure()\r
+ self.playlists[playlist.name] = playlist\r
+ #self.playlists[playlist.name] = [playlist, figure]\r
+ self.panelPlaylists.PlaylistsTree.Expand(playlist_root)\r
+ self.statusbar.SetStatusText(playlist.get_status_string(), 0)\r
+ self.UpdateNote()\r
+ self.UpdatePlot()\r
+\r
+ def AppendToOutput(self, text):\r
+ self.panelOutput.AppendText(''.join([text, '\n']))\r
+\r
+ def AppliesPlotmanipulator(self, name):\r
+ '''\r
+ Returns True if the plotmanipulator 'name' is applied, False otherwise\r
+ name does not contain 'plotmanip_', just the name of the plotmanipulator (e.g. 'flatten')\r
+ '''\r
+ return self.GetBoolFromConfig('core', 'plotmanipulators', name)\r
+\r
+ def ApplyPlotmanipulators(self, plot, plot_file):\r
+ '''\r
+ Apply all active plotmanipulators.\r
+ '''\r
+ if plot is not None and plot_file is not None:\r
+ manipulated_plot = copy.deepcopy(plot)\r
+ for plotmanipulator in self.plotmanipulators:\r
+ if self.GetBoolFromConfig('core', 'plotmanipulators', plotmanipulator.name):\r
+ manipulated_plot = plotmanipulator.method(manipulated_plot, plot_file)\r
+ return manipulated_plot\r
+\r
+ def CreateApplicationIcon(self):\r
+ iconFile = 'resources' + os.sep + 'microscope.ico'\r
+ icon = wx.Icon(iconFile, wx.BITMAP_TYPE_ICO)\r
+ self.SetIcon(icon)\r
+\r
+ def CreateCommandLine(self):\r
+ return wx.TextCtrl(self, -1, '', style=wx.NO_BORDER|wx.EXPAND)\r
+\r
+ def CreatePanelAssistant(self):\r
+ panel = wx.TextCtrl(self, -1, '', wx.Point(0, 0), wx.Size(150, 90), wx.NO_BORDER|wx.TE_MULTILINE)\r
+ panel.SetEditable(False)\r
+ return panel\r
+\r
+ def CreatePanelCommands(self):\r
+ return panels.commands.Commands(self)\r
+\r
+ def CreatePanelFolders(self):\r
+ #set file filters\r
+ filters = self.config['folders']['filters']\r
+ index = self.config['folders'].as_int('filterindex')\r
+ #set initial directory\r
+ folder = self.GetStringFromConfig('core', 'preferences', 'workdir')\r
+ return wx.GenericDirCtrl(self, -1, dir=folder, size=(200, 250), style=wx.DIRCTRL_SHOW_FILTERS, filter=filters, defaultFilter=index)\r
+\r
+ def CreatePanelNote(self):\r
+ return panels.note.Note(self)\r
+\r
+ def CreatePanelOutput(self):\r
+ return wx.TextCtrl(self, -1, '', wx.Point(0, 0), wx.Size(150, 90), wx.NO_BORDER|wx.TE_MULTILINE)\r
+\r
+ def CreatePanelPlaylists(self):\r
+ return panels.playlist.Playlists(self)\r
+\r
+ def CreatePanelProperties(self):\r
+ return panels.propertyeditor.PropertyEditor(self)\r
+\r
+ def CreatePanelResults(self):\r
+ return panels.results.Results(self)\r
+\r
+ def CreatePanelWelcome(self):\r
+ #TODO: move into panels.welcome\r
+ ctrl = wx.html.HtmlWindow(self, -1, wx.DefaultPosition, wx.Size(400, 300))\r
+ introStr = '<h1>Welcome to Hooke</h1>' + \\r
+ '<h3>Features</h3>' + \\r
+ '<ul>' + \\r
+ '<li>View, annotate, measure force files</li>' + \\r
+ '<li>Worm-like chain fit of force peaks</li>' + \\r
+ '<li>Automatic convolution-based filtering of empty files</li>' + \\r
+ '<li>Automatic fit and measurement of multiple force peaks</li>' + \\r
+ '<li>Handles force-clamp force experiments (experimental)</li>' + \\r
+ '<li>It is extensible by users by means of plugins and drivers</li>' + \\r
+ '</ul>' + \\r
+ '<p>See the <a href="http://code.google.com/p/hooke/wiki/DocumentationIndex">DocumentationIndex</a> for more information</p>'\r
+ ctrl.SetPage(introStr)\r
+ return ctrl\r
+\r
+ def CreateMenuBar(self):\r
+ menu_bar = wx.MenuBar()\r
+ self.SetMenuBar(menu_bar)\r
+ #file\r
+ file_menu = wx.Menu()\r
+ file_menu.Append(wx.ID_EXIT, 'Exit\tCtrl-Q')\r
+# edit_menu.AppendSeparator();\r
+# edit_menu.Append(ID_Config, 'Preferences')\r
+ #view\r
+ view_menu = wx.Menu()\r
+ view_menu.AppendCheckItem(ID_ViewFolders, 'Folders\tF5')\r
+ view_menu.AppendCheckItem(ID_ViewPlaylists, 'Playlists\tF6')\r
+ view_menu.AppendCheckItem(ID_ViewCommands, 'Commands\tF7')\r
+ view_menu.AppendCheckItem(ID_ViewProperties, 'Properties\tF8')\r
+ view_menu.AppendCheckItem(ID_ViewAssistant, 'Assistant\tF9')\r
+ view_menu.AppendCheckItem(ID_ViewResults, 'Results\tF10')\r
+ view_menu.AppendCheckItem(ID_ViewOutput, 'Output\tF11')\r
+ view_menu.AppendCheckItem(ID_ViewNote, 'Note\tF12')\r
+ #perspectives\r
+ perspectives_menu = wx.Menu()\r
+\r
+ #help\r
+ help_menu = wx.Menu()\r
+ help_menu.Append(wx.ID_ABOUT, 'About Hooke')\r
+ #put it all together\r
+ menu_bar.Append(file_menu, 'File')\r
+ menu_bar.Append(view_menu, 'View')\r
+ menu_bar.Append(perspectives_menu, "Perspectives")\r
+ self.UpdatePerspectivesMenu()\r
+ menu_bar.Append(help_menu, 'Help')\r
+\r
+ def CreateNotebook(self):\r
+ # create the notebook off-window to avoid flicker\r
+ client_size = self.GetClientSize()\r
+ ctrl = aui.AuiNotebook(self, -1, wx.Point(client_size.x, client_size.y), wx.Size(430, 200), self._notebook_style)\r
+ arts = [aui.AuiDefaultTabArt, aui.AuiSimpleTabArt, aui.VC71TabArt, aui.FF2TabArt, aui.VC8TabArt, aui.ChromeTabArt]\r
+ art = arts[self._notebook_theme]()\r
+ ctrl.SetArtProvider(art)\r
+ #uncomment if we find a nice icon\r
+ #page_bmp = wx.ArtProvider.GetBitmap(wx.ART_NORMAL_FILE, wx.ART_OTHER, wx.Size(16, 16))\r
+ ctrl.AddPage(self.CreatePanelWelcome(), "Welcome", False)\r
+ return ctrl\r
+\r
+ def CreateStatusbar(self):\r
+ statusbar = self.CreateStatusBar(2, wx.ST_SIZEGRIP)\r
+ statusbar.SetStatusWidths([-2, -3])\r
+ statusbar.SetStatusText('Ready', 0)\r
+ welcomeString=u'Welcome to Hooke (version '+__version__+', '+__release_name__+')!'\r
+ statusbar.SetStatusText(welcomeString, 1)\r
+ return statusbar\r
+\r
+ def CreateToolBarNavigation(self):\r
+ toolbar = wx.ToolBar(self, -1, wx.DefaultPosition, wx.DefaultSize, wx.TB_FLAT | wx.TB_NODIVIDER)\r
+ toolbar.SetToolBitmapSize(wx.Size(16,16))\r
+ toolbar_bmpBack = wx.ArtProvider_GetBitmap(wx.ART_GO_BACK, wx.ART_OTHER, wx.Size(16, 16))\r
+ toolbar_bmpForward = wx.ArtProvider_GetBitmap(wx.ART_GO_FORWARD, wx.ART_OTHER, wx.Size(16, 16))\r
+ toolbar.AddLabelTool(ID_Previous, 'Previous', toolbar_bmpBack, shortHelp='Previous curve')\r
+ toolbar.AddLabelTool(ID_Next, 'Next', toolbar_bmpForward, shortHelp='Next curve')\r
+ toolbar.Realize()\r
+ return toolbar\r
+\r
+ def DeleteFromPlaylists(self, name):\r
+ if name in self.playlists:\r
+ del self.playlists[name]\r
+ tree_root = self.panelPlaylists.PlaylistsTree.GetRootItem()\r
+ item, cookie = self.panelPlaylists.PlaylistsTree.GetFirstChild(tree_root)\r
+ while item.IsOk():\r
+ playlist_name = self.panelPlaylists.PlaylistsTree.GetItemText(item)\r
+ if playlist_name == name:\r
+ try:\r
+ self.panelPlaylists.PlaylistsTree.Delete(item)\r
+ except:\r
+ pass\r
+ item = self.panelPlaylists.PlaylistsTree.GetNextSibling(item)\r
+\r
+ def GetActiveFigure(self):\r
+ playlist_name = self.GetActivePlaylistName()\r
+ figure = self.playlists[playlist_name].figure\r
+ if figure is not None:\r
+ return figure\r
+ return None\r
+\r
+ def GetActiveFile(self):\r
+ playlist = self.GetActivePlaylist()\r
+ if playlist is not None:\r
+ return playlist.get_active_file()\r
+ return None\r
+\r
+ def GetActivePlaylist(self):\r
+ playlist_name = self.GetActivePlaylistName()\r
+ if playlist_name in self.playlists:\r
+ return self.playlists[playlist_name]\r
+ return None\r
+\r
+ def GetActivePlaylistName(self):\r
+ #get the selected item from the tree\r
+ selected_item = self.panelPlaylists.PlaylistsTree.GetSelection()\r
+ #test if a playlist or a curve was double-clicked\r
+ if self.panelPlaylists.PlaylistsTree.ItemHasChildren(selected_item):\r
+ playlist_item = selected_item\r
+ else:\r
+ #get the name of the playlist\r
+ playlist_item = self.panelPlaylists.PlaylistsTree.GetItemParent(selected_item)\r
+ #now we have a playlist\r
+ return self.panelPlaylists.PlaylistsTree.GetItemText(playlist_item)\r
+\r
+ def GetActivePlot(self):\r
+ playlist = self.GetActivePlaylist()\r
+ if playlist is not None:\r
+ return playlist.get_active_file().plot\r
+ return None\r
+\r
+ def GetDisplayedPlot(self):\r
+ plot = copy.deepcopy(self.displayed_plot)\r
+ #plot.curves = []\r
+ #plot.curves = copy.deepcopy(plot.curves)\r
+ return plot\r
+\r
+ def GetDisplayedPlotCorrected(self):\r
+ plot = copy.deepcopy(self.displayed_plot)\r
+ plot.curves = []\r
+ plot.curves = copy.deepcopy(plot.corrected_curves)\r
+ return plot\r
+\r
+ def GetDisplayedPlotRaw(self):\r
+ plot = copy.deepcopy(self.displayed_plot)\r
+ plot.curves = []\r
+ plot.curves = copy.deepcopy(plot.raw_curves)\r
+ return plot\r
+\r
+ def GetDockArt(self):\r
+ return self._mgr.GetArtProvider()\r
+\r
+ def GetBoolFromConfig(self, *args):\r
+ if len(args) == 2:\r
+ plugin = args[0]\r
+ section = args[0]\r
+ key = args[1]\r
+ elif len(args) == 3:\r
+ plugin = args[0]\r
+ section = args[1]\r
+ key = args[2]\r
+ if self.configs.has_key(plugin):\r
+ config = self.configs[plugin]\r
+ return config[section][key].as_bool('value')\r
+ return None\r
+\r
+ def GetColorFromConfig(self, *args):\r
+ if len(args) == 2:\r
+ plugin = args[0]\r
+ section = args[0]\r
+ key = args[1]\r
+ elif len(args) == 3:\r
+ plugin = args[0]\r
+ section = args[1]\r
+ key = args[2]\r
+ if self.configs.has_key(plugin):\r
+ config = self.configs[plugin]\r
+ color_tuple = eval(config[section][key]['value'])\r
+ color = [value / 255.0 for value in color_tuple]\r
+ return color\r
+ return None\r
+\r
+ def GetFloatFromConfig(self, *args):\r
+ if len(args) == 2:\r
+ plugin = args[0]\r
+ section = args[0]\r
+ key = args[1]\r
+ elif len(args) == 3:\r
+ plugin = args[0]\r
+ section = args[1]\r
+ key = args[2]\r
+ if self.configs.has_key(plugin):\r
+ config = self.configs[plugin]\r
+ return config[section][key].as_float('value')\r
+ return None\r
+\r
+ def GetIntFromConfig(self, *args):\r
+ if len(args) == 2:\r
+ plugin = args[0]\r
+ section = args[0]\r
+ key = args[1]\r
+ elif len(args) == 3:\r
+ plugin = args[0]\r
+ section = args[1]\r
+ key = args[2]\r
+ if self.configs.has_key(plugin):\r
+ config = self.configs[plugin]\r
+ return config[section][key].as_int('value')\r
+ return None\r
+\r
+ def GetStringFromConfig(self, *args):\r
+ if len(args) == 2:\r
+ plugin = args[0]\r
+ section = args[0]\r
+ key = args[1]\r
+ elif len(args) == 3:\r
+ plugin = args[0]\r
+ section = args[1]\r
+ key = args[2]\r
+ if self.configs.has_key(plugin):\r
+ config = self.configs[plugin]\r
+ return config[section][key]['value']\r
+ return None\r
+\r
+ def GetPlotmanipulator(self, name):\r
+ '''\r
+ Returns a plot manipulator function from its name\r
+ '''\r
+ for plotmanipulator in self.plotmanipulators:\r
+ if plotmanipulator.name == name:\r
+ return plotmanipulator\r
+ return None\r
+\r
+ def GetPerspectiveMenuItem(self, name):\r
+ if self._perspectives.has_key(name):\r
+ perspectives_list = [key for key, value in self._perspectives.iteritems()]\r
+ perspectives_list.sort()\r
+ index = perspectives_list.index(name)\r
+ perspective_Id = ID_FirstPerspective + index\r
+ menu_item = self.MenuBar.FindItemById(perspective_Id)\r
+ return menu_item\r
+ else:\r
+ return None\r
+\r
+ def HasPlotmanipulator(self, name):\r
+ '''\r
+ returns True if the plotmanipulator 'name' is loaded, False otherwise\r
+ '''\r
+ for plotmanipulator in self.plotmanipulators:\r
+ if plotmanipulator.command == name:\r
+ return True\r
+ return False\r
+\r
+ def OnAbout(self, event):\r
+ message = 'Hooke\n\n'+\\r
+ 'A free, open source data analysis platform\n\n'+\\r
+ 'Copyright 2006-2008 by Massimo Sandal\n'+\\r
+ 'Copyright 2010 by Dr. Rolf Schmidt\n\n'+\\r
+ 'Hooke is released under the GNU General Public License version 2.'\r
+ dialog = wx.MessageDialog(self, message, 'About Hooke', wx.OK | wx.ICON_INFORMATION)\r
+ dialog.ShowModal()\r
+ dialog.Destroy()\r
+\r
+ def OnClose(self, event):\r
+ #apply changes\r
+ self.config['main']['height'] = str(self.GetSize().GetHeight())\r
+ self.config['main']['left'] = str(self.GetPosition()[0])\r
+ self.config['main']['top'] = str(self.GetPosition()[1])\r
+ self.config['main']['width'] = str(self.GetSize().GetWidth())\r
+ #save the configuration file to 'config/hooke.ini'\r
+ self.config.write()\r
+ #save all plugin config files\r
+ for config in self.configs:\r
+ plugin_config = self.configs[config]\r
+ plugin_config.write()\r
+ self._UnbindEvents()\r
+ self._mgr.UnInit()\r
+ del self._mgr\r
+ self.Destroy()\r
+\r
+ def OnDeletePerspective(self, event):\r
+ dialog = panels.perspectives.Perspectives(self, -1, 'Delete perspective(s)')\r
+ dialog.CenterOnScreen()\r
+ dialog.ShowModal()\r
+ dialog.Destroy()\r
+ self.UpdatePerspectivesMenu()\r
+ #unfortunately, there is a bug in wxWidgets (Ticket #3258) that\r
+ #makes the radio item indicator in the menu disappear\r
+ #the code should be fine once this issue is fixed\r
+\r
+ def OnDirCtrlLeftDclick(self, event):\r
+ file_path = self.panelFolders.GetPath()\r
+ if os.path.isfile(file_path):\r
+ if file_path.endswith('.hkp'):\r
+ self.do_loadlist(file_path)\r
+ event.Skip()\r
+\r
+ def OnEraseBackground(self, event):\r
+ event.Skip()\r
+\r
+ def OnExecute(self, event):\r
+ item = self.panelCommands.CommandsTree.GetSelection()\r
+ if item.IsOk():\r
+ if not self.panelCommands.CommandsTree.ItemHasChildren(item):\r
+ item_text = self.panelCommands.CommandsTree.GetItemText(item)\r
+ command = ''.join(['self.do_', item_text, '()'])\r
+ #self.AppendToOutput(command + '\n')\r
+ exec(command)\r
+\r
+ def OnExit(self, event):\r
+ self.Close()\r
+\r
+ def OnNext(self, event):\r
+ '''\r
+ NEXT\r
+ Go to the next curve in the playlist.\r
+ If we are at the last curve, we come back to the first.\r
+ -----\r
+ Syntax: next, n\r
+ '''\r
+ selected_item = self.panelPlaylists.PlaylistsTree.GetSelection()\r
+ if self.panelPlaylists.PlaylistsTree.ItemHasChildren(selected_item):\r
+ #GetFirstChild returns a tuple\r
+ #we only need the first element\r
+ next_item = self.panelPlaylists.PlaylistsTree.GetFirstChild(selected_item)[0]\r
+ else:\r
+ next_item = self.panelPlaylists.PlaylistsTree.GetNextSibling(selected_item)\r
+ if not next_item.IsOk():\r
+ parent_item = self.panelPlaylists.PlaylistsTree.GetItemParent(selected_item)\r
+ #GetFirstChild returns a tuple\r
+ #we only need the first element\r
+ next_item = self.panelPlaylists.PlaylistsTree.GetFirstChild(parent_item)[0]\r
+ self.panelPlaylists.PlaylistsTree.SelectItem(next_item, True)\r
+ if not self.panelPlaylists.PlaylistsTree.ItemHasChildren(selected_item):\r
+ playlist = self.GetActivePlaylist()\r
+ if playlist.count > 1:\r
+ playlist.next()\r
+ self.statusbar.SetStatusText(playlist.get_status_string(), 0)\r
+ self.UpdateNote()\r
+ self.UpdatePlot()\r
+\r
+ def OnNotebookPageClose(self, event):\r
+ ctrl = event.GetEventObject()\r
+ playlist_name = ctrl.GetPageText(ctrl._curpage)\r
+ self.DeleteFromPlaylists(playlist_name)\r
+\r
+ def OnPaneClose(self, event):\r
+ event.Skip()\r
+\r
+ def OnPlaylistsLeftDclick(self, event):\r
+ if self.panelPlaylists.PlaylistsTree.Count > 0:\r
+ playlist_name = self.GetActivePlaylistName()\r
+ #if that playlist already exists\r
+ #we check if it is the active playlist (ie selected in panelPlaylists)\r
+ #and switch to it if necessary\r
+ if playlist_name in self.playlists:\r
+ index = self.plotNotebook.GetSelection()\r
+ current_playlist = self.plotNotebook.GetPageText(index)\r
+ if current_playlist != playlist_name:\r
+ index = self._GetPlaylistTab(playlist_name)\r
+ self.plotNotebook.SetSelection(index)\r
+ #if a curve was double-clicked\r
+ item = self.panelPlaylists.PlaylistsTree.GetSelection()\r
+ if not self.panelPlaylists.PlaylistsTree.ItemHasChildren(item):\r
+ index = self._GetActiveFileIndex()\r
+ else:\r
+ index = 0\r
+ if index >= 0:\r
+ playlist = self.GetActivePlaylist()\r
+ playlist.index = index\r
+ self.statusbar.SetStatusText(playlist.get_status_string(), 0)\r
+ self.UpdateNote()\r
+ self.UpdatePlot()\r
+ #if you uncomment the following line, the tree will collapse/expand as well\r
+ #event.Skip()\r
+\r
+ def OnPlaylistsLeftDown(self, event):\r
+ hit_item, hit_flags = self.panelPlaylists.PlaylistsTree.HitTest(event.GetPosition())\r
+ if (hit_flags & wx.TREE_HITTEST_ONITEM) != 0:\r
+ self.panelPlaylists.PlaylistsTree.SelectItem(hit_item)\r
+ playlist_name = self.GetActivePlaylistName()\r
+ playlist = self.GetActivePlaylist()\r
+ #if a curve was clicked\r
+ item = self.panelPlaylists.PlaylistsTree.GetSelection()\r
+ if not self.panelPlaylists.PlaylistsTree.ItemHasChildren(item):\r
+ index = self._GetActiveFileIndex()\r
+ if index >= 0:\r
+ playlist.index = index\r
+ self.playlists[playlist_name] = playlist\r
+ event.Skip()\r
+\r
+ def OnPrevious(self, event):\r
+ '''\r
+ PREVIOUS\r
+ Go to the previous curve in the playlist.\r
+ If we are at the first curve, we jump to the last.\r
+ -------\r
+ Syntax: previous, p\r
+ '''\r
+ #playlist = self.playlists[self.GetActivePlaylistName()][0]\r
+ #select the previous curve and tell the user if we wrapped around\r
+ #self.AppendToOutput(playlist.previous())\r
+ selected_item = self.panelPlaylists.PlaylistsTree.GetSelection()\r
+ if self.panelPlaylists.PlaylistsTree.ItemHasChildren(selected_item):\r
+ previous_item = self.panelPlaylists.PlaylistsTree.GetLastChild(selected_item)\r
+ else:\r
+ previous_item = self.panelPlaylists.PlaylistsTree.GetPrevSibling(selected_item)\r
+ if not previous_item.IsOk():\r
+ parent_item = self.panelPlaylists.PlaylistsTree.GetItemParent(selected_item)\r
+ previous_item = self.panelPlaylists.PlaylistsTree.GetLastChild(parent_item)\r
+ self.panelPlaylists.PlaylistsTree.SelectItem(previous_item, True)\r
+ playlist = self.GetActivePlaylist()\r
+ if playlist.count > 1:\r
+ playlist.previous()\r
+ self.statusbar.SetStatusText(playlist.get_status_string(), 0)\r
+ self.UpdateNote()\r
+ self.UpdatePlot()\r
+\r
+ def OnPropGridChanged (self, event):\r
+ prop = event.GetProperty()\r
+ if prop:\r
+ item_section = self.panelProperties.SelectedTreeItem\r
+ item_plugin = self.panelCommands.CommandsTree.GetItemParent(item_section)\r
+ plugin = self.panelCommands.CommandsTree.GetItemText(item_plugin)\r
+ config = self.configs[plugin]\r
+ property_section = self.panelCommands.CommandsTree.GetItemText(item_section)\r
+ property_key = prop.GetName()\r
+ property_value = prop.GetDisplayedString()\r
+\r
+ config[property_section][property_key]['value'] = property_value\r
+\r
+ def OnRestorePerspective(self, event):\r
+ name = self.MenuBar.FindItemById(event.GetId()).GetLabel()\r
+ self._RestorePerspective(name)\r
+\r
+ def OnResultsCheck(self, index, flag):\r
+ results = self.GetActivePlot().results\r
+ if results.has_key(self.results_str):\r
+ results[self.results_str].results[index].visible = flag\r
+ results[self.results_str].update()\r
+ self.UpdatePlot()\r
+\r
+ def OnSavePerspective(self, event):\r
+\r
+ def nameExists(name):\r
+ menu_position = self.MenuBar.FindMenu('Perspectives')\r
+ menu = self.MenuBar.GetMenu(menu_position)\r
+ for item in menu.GetMenuItems():\r
+ if item.GetText() == name:\r
+ return True\r
+ return False\r
+\r
+ done = False\r
+ while not done:\r
+ dialog = wx.TextEntryDialog(self, 'Enter a name for the new perspective:', 'Save perspective')\r
+ dialog.SetValue('New perspective')\r
+ if dialog.ShowModal() != wx.ID_OK:\r
+ return\r
+ else:\r
+ name = dialog.GetValue()\r
+\r
+ if nameExists(name):\r
+ dialogConfirm = wx.MessageDialog(self, 'A file with this name already exists.\n\nDo you want to replace it?', 'Confirm', wx.YES_NO|wx.ICON_QUESTION|wx.CENTER)\r
+ if dialogConfirm.ShowModal() == wx.ID_YES:\r
+ done = True\r
+ else:\r
+ done = True\r
+\r
+ perspective = self._mgr.SavePerspective()\r
+ self._SavePerspectiveToFile(name, perspective)\r
+ self.config['perspectives']['active'] = name\r
+ self.UpdatePerspectivesMenu()\r
+# if nameExists(name):\r
+# #check the corresponding menu item\r
+# menu_item = self.GetPerspectiveMenuItem(name)\r
+# #replace the perspectiveStr in _pespectives\r
+# self._perspectives[name] = perspective\r
+# else:\r
+# #because we deal with radio items, we need to do some extra work\r
+# #delete all menu items from the perspectives menu\r
+# for item in self._perspectives_menu.GetMenuItems():\r
+# self._perspectives_menu.DeleteItem(item)\r
+# #recreate the perspectives menu\r
+# self._perspectives_menu.Append(ID_SavePerspective, 'Save Perspective')\r
+# self._perspectives_menu.Append(ID_DeletePerspective, 'Delete Perspective')\r
+# self._perspectives_menu.AppendSeparator()\r
+# #convert the perspectives dictionary into a list\r
+# # the list contains:\r
+# #[0]: name of the perspective\r
+# #[1]: perspective\r
+# perspectives_list = [key for key, value in self._perspectives.iteritems()]\r
+# perspectives_list.append(name)\r
+# perspectives_list.sort()\r
+# #add all previous perspectives\r
+# for index, item in enumerate(perspectives_list):\r
+# menu_item = self._perspectives_menu.AppendRadioItem(ID_FirstPerspective + index, item)\r
+# if item == name:\r
+# menu_item.Check()\r
+# #add the new perspective to _perspectives\r
+# self._perspectives[name] = perspective\r
+\r
+ def OnSize(self, event):\r
+ event.Skip()\r
+\r
+ def OnTreeCtrlCommandsSelectionChanged(self, event):\r
+ selected_item = event.GetItem()\r
+ if selected_item is not None:\r
+ plugin = ''\r
+ section = ''\r
+ #deregister/register the listener to avoid infinite loop\r
+ evtmgr.eventManager.DeregisterListener(self.OnTreeCtrlCommandsSelectionChanged)\r
+ self.panelCommands.CommandsTree.SelectItem(selected_item)\r
+ evtmgr.eventManager.Register(self.OnTreeCtrlCommandsSelectionChanged, wx.EVT_TREE_SEL_CHANGED, self.panelCommands.CommandsTree)\r
+ self.panelProperties.SelectedTreeItem = selected_item\r
+ #if a command was clicked\r
+ properties = []\r
+ if not self.panelCommands.CommandsTree.ItemHasChildren(selected_item):\r
+ item_plugin = self.panelCommands.CommandsTree.GetItemParent(selected_item)\r
+ plugin = self.panelCommands.CommandsTree.GetItemText(item_plugin)\r
+ if self.configs.has_key(plugin):\r
+ #config = self.panelCommands.CommandsTree.GetPyData(item_plugin)\r
+ config = self.configs[plugin]\r
+ section = self.panelCommands.CommandsTree.GetItemText(selected_item)\r
+ #display docstring in help window\r
+ doc_string = eval('self.do_' + section + '.__doc__')\r
+ if section in config:\r
+ for option in config[section]:\r
+ properties.append([option, config[section][option]])\r
+ else:\r
+ plugin = self.panelCommands.CommandsTree.GetItemText(selected_item)\r
+ if plugin != 'core':\r
+ doc_string = eval('plugins.' + plugin + '.' + plugin + 'Commands.__doc__')\r
+ else:\r
+ doc_string = 'The module "core" contains Hooke core functionality'\r
+ if doc_string is not None:\r
+ self.panelAssistant.ChangeValue(doc_string)\r
+ else:\r
+ self.panelAssistant.ChangeValue('')\r
+ panels.propertyeditor.PropertyEditor.Initialize(self.panelProperties, properties)\r
+ #save the currently selected command/plugin to the config file\r
+ self.config['command']['command'] = section\r
+ self.config['command']['plugin'] = plugin\r
+\r
+ def OnTreeCtrlItemActivated(self, event):\r
+ self.OnExecute(event)\r
+\r
+ def OnUpdateNote(self, event):\r
+ '''\r
+ Saves the note to the active file.\r
+ '''\r
+ active_file = self.GetActiveFile()\r
+ active_file.note = self.panelNote.Editor.GetValue()\r
+\r
+ def OnView(self, event):\r
+ menu_id = event.GetId()\r
+ menu_item = self.MenuBar.FindItemById(menu_id)\r
+ menu_label = menu_item.GetLabel()\r
+\r
+ pane = self._mgr.GetPane(menu_label)\r
+ pane.Show(not pane.IsShown())\r
+ #if we don't do the following, the Folders pane does not resize properly on hide/show\r
+ if pane.caption == 'Folders' and pane.IsShown() and pane.IsDocked():\r
+ #folders_size = pane.GetSize()\r
+ self.panelFolders.Fit()\r
+ self._mgr.Update()\r
+\r
+ def _clickize(self, xvector, yvector, index):\r
+ '''\r
+ Returns a ClickedPoint() object from an index and vectors of x, y coordinates\r
+ '''\r
+ point = lib.clickedpoint.ClickedPoint()\r
+ point.index = index\r
+ point.absolute_coords = xvector[index], yvector[index]\r
+ point.find_graph_coords(xvector, yvector)\r
+ return point\r
+\r
+ def _delta(self, message='Click 2 points', whatset=lh.RETRACTION):\r
+ '''\r
+ Calculates the difference between two clicked points\r
+ '''\r
+ clicked_points = self._measure_N_points(N=2, message=message, whatset=whatset)\r
+\r
+ plot = self.GetDisplayedPlotCorrected()\r
+ curve = plot.curves[whatset]\r
+\r
+ delta = lib.delta.Delta()\r
+ delta.point1.x = clicked_points[0].graph_coords[0]\r
+ delta.point1.y = clicked_points[0].graph_coords[1]\r
+ delta.point2.x = clicked_points[1].graph_coords[0]\r
+ delta.point2.y = clicked_points[1].graph_coords[1]\r
+ delta.units.x = curve.units.x\r
+ delta.units.y = curve.units.y\r
+\r
+ return delta\r
+\r
+ def _measure_N_points(self, N, message='', whatset=lh.RETRACTION):\r
+ '''\r
+ General helper function for N-points measurements\r
+ By default, measurements are done on the retraction\r
+ '''\r
+ if message:\r
+ dialog = wx.MessageDialog(None, message, 'Info', wx.OK)\r
+ dialog.ShowModal()\r
+\r
+ figure = self.GetActiveFigure()\r
+\r
+ xvector = self.displayed_plot.curves[whatset].x\r
+ yvector = self.displayed_plot.curves[whatset].y\r
+\r
+ clicked_points = figure.ginput(N, timeout=-1, show_clicks=True)\r
+\r
+ points = []\r
+ for clicked_point in clicked_points:\r
+ point = lib.clickedpoint.ClickedPoint()\r
+ point.absolute_coords = clicked_point[0], clicked_point[1]\r
+ point.dest = 0\r
+ #TODO: make this optional?\r
+ #so far, the clicked point is taken, not the corresponding data point\r
+ point.find_graph_coords(xvector, yvector)\r
+ point.is_line_edge = True\r
+ point.is_marker = True\r
+ points.append(point)\r
+ return points\r
+\r
+ def do_copylog(self):\r
+ '''\r
+ Copies all files in the current playlist that have a note to the destination folder.\r
+ destination: select folder where you want the files to be copied\r
+ use_LVDT_folder: when checked, the files will be copied to a folder called 'LVDT' in the destination folder (for MFP-1D files only)\r
+ '''\r
+ playlist = self.GetActivePlaylist()\r
+ if playlist is not None:\r
+ destination = self.GetStringFromConfig('core', 'copylog', 'destination')\r
+ if not os.path.isdir(destination):\r
+ os.makedirs(destination)\r
+ for current_file in playlist.files:\r
+ if current_file.note:\r
+ shutil.copy(current_file.filename, destination)\r
+ if current_file.driver.filetype == 'mfp1d':\r
+ filename = current_file.filename.replace('deflection', 'LVDT', 1)\r
+ path, name = os.path.split(filename)\r
+ filename = os.path.join(path, 'lvdt', name)\r
+ use_LVDT_folder = self.GetBoolFromConfig('core', 'copylog', 'use_LVDT_folder')\r
+ if use_LVDT_folder:\r
+ destination = os.path.join(destination, 'LVDT')\r
+ shutil.copy(filename, destination)\r
+\r
+ def do_plotmanipulators(self):\r
+ '''\r
+ Please select the plotmanipulators you would like to use\r
+ and define the order in which they will be applied to the data.\r
+\r
+ Click 'Execute' to apply your changes.\r
+ '''\r
+ self.UpdatePlot()\r
+\r
+ def do_preferences(self):\r
+ '''\r
+ Please set general preferences for Hooke here.\r
+ hide_curve_extension: hides the extension of the force curve files.\r
+ not recommended for 'picoforce' files\r
+ '''\r
+ pass\r
+\r
+ def do_test(self):\r
+ '''\r
+ Use this command for testing purposes. You find do_test in hooke.py.\r
+ '''\r
+ pass\r
+\r
+ def do_version(self):\r
+ '''\r
+ VERSION\r
+ ------\r
+ Prints the current version and codename, plus library version. Useful for debugging.\r
+ '''\r
+ self.AppendToOutput('Hooke ' + __version__ + ' (' + __codename__ + ')')\r
+ self.AppendToOutput('Released on: ' + __releasedate__)\r
+ self.AppendToOutput('---')\r
+ self.AppendToOutput('Python version: ' + python_version)\r
+ self.AppendToOutput('WxPython version: ' + wx_version)\r
+ self.AppendToOutput('Matplotlib version: ' + mpl_version)\r
+ self.AppendToOutput('SciPy version: ' + scipy_version)\r
+ self.AppendToOutput('NumPy version: ' + numpy_version)\r
+ self.AppendToOutput('ConfigObj version: ' + configobj_version)\r
+ self.AppendToOutput('wxPropertyGrid version: ' + '.'.join([str(PROPGRID_MAJOR), str(PROPGRID_MINOR), str(PROPGRID_RELEASE)]))\r
+ self.AppendToOutput('---')\r
+ self.AppendToOutput('Platform: ' + str(platform.uname()))\r
+ self.AppendToOutput('******************************')\r
+ self.AppendToOutput('Loaded plugins')\r
+ self.AppendToOutput('---')\r
+\r
+ #sort the plugins into alphabetical order\r
+ plugins_list = [key for key, value in self.plugins.iteritems()]\r
+ plugins_list.sort()\r
+ for plugin in plugins_list:\r
+ self.AppendToOutput(plugin)\r
+\r
+ def UpdateNote(self):\r
+ #update the note for the active file\r
+ active_file = self.GetActiveFile()\r
+ if active_file is not None:\r
+ self.panelNote.Editor.SetValue(active_file.note)\r
+\r
+ def UpdatePerspectivesMenu(self):\r
+ #add perspectives to menubar and _perspectives\r
+ perspectivesDirectory = os.path.join(lh.hookeDir, 'perspectives')\r
+ self._perspectives = {}\r
+ if os.path.isdir(perspectivesDirectory):\r
+ perspectiveFileNames = os.listdir(perspectivesDirectory)\r
+ for perspectiveFilename in perspectiveFileNames:\r
+ filename = lh.get_file_path(perspectiveFilename, ['perspectives'])\r
+ if os.path.isfile(filename):\r
+ perspectiveFile = open(filename, 'rU')\r
+ perspective = perspectiveFile.readline()\r
+ perspectiveFile.close()\r
+ if perspective:\r
+ name, extension = os.path.splitext(perspectiveFilename)\r
+ if extension == '.txt':\r
+ self._perspectives[name] = perspective\r
+\r
+ #in case there are no perspectives\r
+ if not self._perspectives:\r
+ perspective = self._mgr.SavePerspective()\r
+ self._perspectives['Default'] = perspective\r
+ self._SavePerspectiveToFile('Default', perspective)\r
+\r
+ selected_perspective = self.config['perspectives']['active']\r
+ if not self._perspectives.has_key(selected_perspective):\r
+ self.config['perspectives']['active'] = 'Default'\r
+ selected_perspective = 'Default'\r
+\r
+ perspectives_list = [key for key, value in self._perspectives.iteritems()]\r
+ perspectives_list.sort()\r
+\r
+ #get the Perspectives menu\r
+ menu_position = self.MenuBar.FindMenu('Perspectives')\r
+ menu = self.MenuBar.GetMenu(menu_position)\r
+ #delete all menu items\r
+ for item in menu.GetMenuItems():\r
+ menu.DeleteItem(item)\r
+ #rebuild the menu by adding the standard menu items\r
+ menu.Append(ID_SavePerspective, 'Save Perspective')\r
+ menu.Append(ID_DeletePerspective, 'Delete Perspective')\r
+ menu.AppendSeparator()\r
+ #add all previous perspectives\r
+ for index, label in enumerate(perspectives_list):\r
+ menu_item = menu.AppendRadioItem(ID_FirstPerspective + index, label)\r
+ if label == selected_perspective:\r
+ self._RestorePerspective(label)\r
+ menu_item.Check(True)\r
+\r
+ def UpdatePlaylistsTreeSelection(self):\r
+ playlist = self.GetActivePlaylist()\r
+ if playlist is not None:\r
+ if playlist.index >= 0:\r
+ self.statusbar.SetStatusText(playlist.get_status_string(), 0)\r
+ self.UpdateNote()\r
+ self.UpdatePlot()\r
+\r
+ def UpdatePlot(self, plot=None):\r
+\r
+ def add_to_plot(curve, set_scale=True):\r
+ if curve.visible and curve.x and curve.y:\r
+ #get the index of the subplot to use as destination\r
+ destination = (curve.destination.column - 1) * number_of_rows + curve.destination.row - 1\r
+ #set all parameters for the plot\r
+ axes_list[destination].set_title(curve.title)\r
+ if set_scale:\r
+ axes_list[destination].set_xlabel(curve.prefix.x + curve.units.x)\r
+ axes_list[destination].set_ylabel(curve.prefix.y + curve.units.y)\r
+ #set the formatting details for the scale\r
+ formatter_x = lib.curve.PrefixFormatter(curve.decimals.x, curve.prefix.x, use_zero)\r
+ formatter_y = lib.curve.PrefixFormatter(curve.decimals.y, curve.prefix.y, use_zero)\r
+ axes_list[destination].xaxis.set_major_formatter(formatter_x)\r
+ axes_list[destination].yaxis.set_major_formatter(formatter_y)\r
+ if curve.style == 'plot':\r
+ axes_list[destination].plot(curve.x, curve.y, color=curve.color, label=curve.label, lw=curve.linewidth, zorder=1)\r
+ if curve.style == 'scatter':\r
+ axes_list[destination].scatter(curve.x, curve.y, color=curve.color, label=curve.label, s=curve.size, zorder=2)\r
+ #add the legend if necessary\r
+ if curve.legend:\r
+ axes_list[destination].legend()\r
+\r
+ if plot is None:\r
+ active_file = self.GetActiveFile()\r
+ if not active_file.driver:\r
+ #the first time we identify a file, the following need to be set\r
+ active_file.identify(self.drivers)\r
+ for curve in active_file.plot.curves:\r
+ curve.decimals.x = self.GetIntFromConfig('core', 'preferences', 'x_decimals')\r
+ curve.decimals.y = self.GetIntFromConfig('core', 'preferences', 'y_decimals')\r
+ curve.legend = self.GetBoolFromConfig('core', 'preferences', 'legend')\r
+ curve.prefix.x = self.GetStringFromConfig('core', 'preferences', 'x_prefix')\r
+ curve.prefix.y = self.GetStringFromConfig('core', 'preferences', 'y_prefix')\r
+ if active_file.driver is None:\r
+ self.AppendToOutput('Invalid file: ' + active_file.filename)\r
+ return\r
+ self.displayed_plot = copy.deepcopy(active_file.plot)\r
+ #add raw curves to plot\r
+ self.displayed_plot.raw_curves = copy.deepcopy(self.displayed_plot.curves)\r
+ #apply all active plotmanipulators\r
+ self.displayed_plot = self.ApplyPlotmanipulators(self.displayed_plot, active_file)\r
+ #add corrected curves to plot\r
+ self.displayed_plot.corrected_curves = copy.deepcopy(self.displayed_plot.curves)\r
+ else:\r
+ active_file = None\r
+ self.displayed_plot = copy.deepcopy(plot)\r
+\r
+ figure = self.GetActiveFigure()\r
+ figure.clear()\r
+\r
+ #use '0' instead of e.g. '0.00' for scales\r
+ use_zero = self.GetBoolFromConfig('core', 'preferences', 'use_zero')\r
+ #optionally remove the extension from the title of the plot\r
+ hide_curve_extension = self.GetBoolFromConfig('core', 'preferences', 'hide_curve_extension')\r
+ if hide_curve_extension:\r
+ title = lh.remove_extension(self.displayed_plot.title)\r
+ else:\r
+ title = self.displayed_plot.title\r
+ figure.suptitle(title, fontsize=14)\r
+ #create the list of all axes necessary (rows and columns)\r
+ axes_list =[]\r
+ number_of_columns = max([curve.destination.column for curve in self.displayed_plot.curves])\r
+ number_of_rows = max([curve.destination.row for curve in self.displayed_plot.curves])\r
+ for index in range(number_of_rows * number_of_columns):\r
+ axes_list.append(figure.add_subplot(number_of_rows, number_of_columns, index + 1))\r
+\r
+ #add all curves to the corresponding plots\r
+ for curve in self.displayed_plot.curves:\r
+ add_to_plot(curve)\r
+\r
+ #make sure the titles of 'subplots' do not overlap with the axis labels of the 'main plot'\r
+ figure.subplots_adjust(hspace=0.3)\r
+\r
+ #display results\r
+ self.panelResults.ClearResults()\r
+ if self.displayed_plot.results.has_key(self.results_str):\r
+ for curve in self.displayed_plot.results[self.results_str].results:\r
+ add_to_plot(curve, set_scale=False)\r
+ self.panelResults.DisplayResults(self.displayed_plot.results[self.results_str])\r
+ else:\r
+ self.panelResults.ClearResults()\r
+ #refresh the plot\r
+ figure.canvas.draw()\r
+\r
+if __name__ == '__main__':\r
+\r
+ ## now, silence a deprecation warning for py2.3\r
+ import warnings\r
+ warnings.filterwarnings("ignore", "integer", DeprecationWarning, "wxPython.gdi")\r
+\r
+ redirect = True\r
+ if __debug__:\r
+ redirect=False\r
+\r
+ app = Hooke(redirect=redirect)\r
+\r
+ app.MainLoop()\r
+\r
from ..command import CommandExit, Exit, Command, Argument, StoreValue\r
from ..interaction import Request, BooleanRequest, ReloadUserInterfaceConfig\r
from ..ui import UserInterface, CommandMessage\r