4 Hooke - A force spectroscopy review & analysis tool.
9 import ConfigParser as configparser
11 import multiprocessing
13 from . import config as config_mod
14 from . import plugin as plugin_mod
15 from . import driver as driver_mod
25 #import libhooke as lh
30 #import hookepropertyeditor
35 def __init__(self, config=None, debug=0):
37 default_settings = (config_mod.DEFAULT_SETTINGS
38 + plugin_mod.default_settings()
39 + driver_mod.default_settings())
41 config = config_mod.HookeConfigParser(
42 paths=config_mod.DEFAULT_PATHS,
43 default_settings=default_settings)
49 def load_plugins(self):
52 for plugin_name,include in self.config.items('plugins'):
54 plugin = plugin_mod.PLUGINS[plugin_name]
57 self.config.items(plugin.setting_section))
58 except configparser.NoSectionError:
60 self.plugins.append(plugin_mod.PLUGINS[plugin_name])
61 self.commands.extend(plugin.commands())
63 def load_drivers(self):
65 for driver_name,include in self.config.items('drivers'):
67 driver = driver_mod.DRIVERS[driver_name]
70 self.config.items(driver.setting_section))
71 except configparser.NoSectionError:
73 self.drivers.append(driver_mod.DRIVERS[driver_name])
76 if self.config.changed:
77 self.config.write() # Does not preserve original comments
79 # def _GetActiveCurveIndex(self):
80 # playlist = self.GetActivePlaylist()
81 # #get the selected item from the tree
82 # selected_item = self.panelPlaylists.PlaylistsTree.GetSelection()
83 # #test if a playlist or a curve was double-clicked
84 # if self.panelPlaylists.PlaylistsTree.ItemHasChildren(selected_item):
88 # selected_item = self.panelPlaylists.PlaylistsTree.GetPrevSibling(selected_item)
89 # while selected_item.IsOk():
91 # selected_item = self.panelPlaylists.PlaylistsTree.GetPrevSibling(selected_item)
94 # def _GetActivePlaylistName(self):
95 # #get the selected item from the tree
96 # selected_item = self.panelPlaylists.PlaylistsTree.GetSelection()
97 # #test if a playlist or a curve was double-clicked
98 # if self.panelPlaylists.PlaylistsTree.ItemHasChildren(selected_item):
99 # playlist_item = selected_item
101 # #get the name of the playlist
102 # playlist_item = self.panelPlaylists.PlaylistsTree.GetItemParent(selected_item)
103 # #now we have a playlist
104 # return self.panelPlaylists.PlaylistsTree.GetItemText(playlist_item)
106 # def _GetPlaylistTab(self, name):
107 # for index, page in enumerate(self.plotNotebook._tabs._pages):
108 # if page.caption == name:
112 # def _GetUniquePlaylistName(self, name):
113 # playlist_name = name
115 # while playlist_name in self.playlists:
116 # playlist_name = ''.join([name, str(count)])
118 # return playlist_name
120 # def _SavePerspectiveToFile(self, name, perspective):
121 # filename = ''.join([name, '.txt'])
122 # filename = lh.get_file_path(filename, ['perspectives'])
123 # perspectivesFile = open(filename, 'w')
124 # perspectivesFile.write(perspective)
125 # perspectivesFile.close()
127 # def AddPlaylist(self, playlist=None, name='Untitled'):
128 # #TODO: change cursor or progressbar (maybe in statusbar)
129 # #self.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))
130 # if playlist and playlist.count > 0:
131 # playlist.name = self._GetUniquePlaylistName(name)
133 # self.AddToPlaylists(playlist)
135 # def AddPlaylistFromFiles(self, files=[], name='Untitled'):
136 # #TODO: change cursor or progressbar (maybe in statusbar)
137 # #self.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))
139 # playlist = Playlist.Playlist(self.drivers)
141 # playlist.add_curve(item)
142 # if playlist.count > 0:
143 # playlist.name = self._GetUniquePlaylistName(name)
145 # self.AddToPlaylists(playlist)
147 # def AddToPlaylists(self, playlist):
148 # if playlist.has_curves:
149 # #setup the playlist in the Playlist tree
150 # tree_root = self.panelPlaylists.PlaylistsTree.GetRootItem()
151 # playlist_root = self.panelPlaylists.PlaylistsTree.AppendItem(tree_root, playlist.name, 0)
152 # #add all curves to the Playlist tree
154 # for index, curve in enumerate(playlist.curves):
155 # ##remove the extension from the name of the curve
157 # #item_text, extension = os.path.splitext(curve.name)
158 # #curve_ID = self.panelPlaylists.PlaylistsTree.AppendItem(playlist_root, item_text, 1)
159 # curve_ID = self.panelPlaylists.PlaylistsTree.AppendItem(playlist_root, curve.name, 1)
160 # if index == playlist.index:
161 # self.panelPlaylists.PlaylistsTree.SelectItem(curve_ID)
163 # #create the plot tab and add playlist to the dictionary
164 # plotPanel = wxmpl.PlotPanel(self, ID_FirstPlot + len(self.playlists))
165 # notebook_tab = self.plotNotebook.AddPage(plotPanel, playlist.name, True)
166 # tab_index = self.plotNotebook.GetSelection()
167 # figure = plotPanel.get_figure()
168 # self.playlists[playlist.name] = [playlist, figure]
169 # self.panelPlaylists.PlaylistsTree.Expand(playlist_root)
170 # self.statusbar.SetStatusText(playlist.get_status_string(), 0)
173 # def AppendToOutput(self, text):
174 # self.panelOutput.AppendText(''.join([text, '\n']))
176 # def CreateApplicationIcon(self):
177 # iconFile = 'resources' + os.sep + 'microscope.ico'
178 # icon = wx.Icon(iconFile, wx.BITMAP_TYPE_ICO)
181 # def CreateCommandLine(self):
182 # return wx.TextCtrl(self, -1, '', style=wx.NO_BORDER|wx.EXPAND)
184 # def CreatePanelAssistant(self):
185 # panel = wx.TextCtrl(self, -1, '', wx.Point(0, 0), wx.Size(150, 90), wx.NO_BORDER|wx.TE_MULTILINE)
186 # panel.SetEditable(False)
189 # def CreatePanelCommands(self):
190 # return hookecommands.Commands(self)
192 # def CreatePanelFolders(self):
194 # filters = self.config['folders']['filters']
195 # index = self.config['folders'].as_int('filterindex')
196 # #set initial directory
197 # folder = self.config['general']['workdir']
198 # return wx.GenericDirCtrl(self, -1, dir=folder, size=(200, 250), style=wx.DIRCTRL_SHOW_FILTERS, filter=filters, defaultFilter=index)
200 # def CreatePanelOutput(self):
201 # return wx.TextCtrl(self, -1, '', wx.Point(0, 0), wx.Size(150, 90), wx.NO_BORDER|wx.TE_MULTILINE)
203 # def CreatePanelPlaylists(self):
204 # return hookeplaylist.Playlists(self)
206 # def CreatePanelProperties(self):
207 # return hookepropertyeditor.PropertyEditor(self)
209 # def CreatePanelResults(self):
210 # return hookeresults.Results(self)
212 # def CreatePanelWelcome(self):
213 # ctrl = wx.html.HtmlWindow(self, -1, wx.DefaultPosition, wx.Size(400, 300))
214 # introStr = '<h1>Welcome to Hooke</h1>' + \
215 # '<h3>Features</h3>' + \
217 # '<li>View, annotate, measure force curves</li>' + \
218 # '<li>Worm-like chain fit of force peaks</li>' + \
219 # '<li>Automatic convolution-based filtering of empty curves</li>' + \
220 # '<li>Automatic fit and measurement of multiple force peaks</li>' + \
221 # '<li>Handles force-clamp force experiments (experimental)</li>' + \
222 # '<li>It is extensible by users by means of plugins and drivers</li>' + \
224 # '<p>See the <a href="/p/hooke/wiki/DocumentationIndex">DocumentationIndex</a> for more information</p>'
225 # ctrl.SetPage(introStr)
228 # def CreateMenuBar(self):
229 # menu_bar = wx.MenuBar()
231 # file_menu = wx.Menu()
232 # file_menu.Append(wx.ID_OPEN, '&Open playlist\tCtrl-O')
233 # file_menu.Append(wx.ID_SAVE, 'Save playlist\tCtrl-S')
234 # file_menu.AppendSeparator()
235 # file_menu.Append(wx.ID_EXIT, 'Exit\tCtrl-Q')
237 # edit_menu = wx.Menu()
238 # edit_menu.Append(ID_ExportText, 'Export text...')
239 # edit_menu.Append(ID_ExportImage, 'Export image...')
240 # edit_menu.AppendSeparator();
241 # edit_menu.Append(ID_Config, 'Preferences')
243 # view_menu = wx.Menu()
244 # view_menu.AppendCheckItem(ID_ViewFolders, 'Folders\tF5')
245 # view_menu.AppendCheckItem(ID_ViewPlaylists, 'Playlists\tF6')
246 # view_menu.AppendCheckItem(ID_ViewCommands, 'Commands\tF7')
247 # view_menu.AppendCheckItem(ID_ViewProperties, 'Properties\tF8')
248 # view_menu.AppendCheckItem(ID_ViewAssistant, 'Assistant\tF9')
249 # view_menu.AppendCheckItem(ID_ViewResults, 'Results\tF10')
250 # view_menu.AppendCheckItem(ID_ViewOutput, 'Output\tF11')
252 # self._perspectives_menu = self.CreatePerspectivesMenu()
254 # help_menu = wx.Menu()
255 # help_menu.Append(wx.ID_ABOUT, 'About Hooke')
256 # #put it all together
257 # menu_bar.Append(file_menu, 'File')
258 # menu_bar.Append(edit_menu, 'Edit')
259 # menu_bar.Append(view_menu, 'View')
260 # menu_bar.Append(self._perspectives_menu, "Perspectives")
261 # menu_bar.Append(help_menu, 'Help')
263 # self.SetMenuBar(menu_bar)
265 # def CreateNotebook(self):
266 # # create the notebook off-window to avoid flicker
267 # client_size = self.GetClientSize()
268 # ctrl = aui.AuiNotebook(self, -1, wx.Point(client_size.x, client_size.y), wx.Size(430, 200), self._notebook_style)
269 # arts = [aui.AuiDefaultTabArt, aui.AuiSimpleTabArt, aui.VC71TabArt, aui.FF2TabArt, aui.VC8TabArt, aui.ChromeTabArt]
270 # art = arts[self._notebook_theme]()
271 # ctrl.SetArtProvider(art)
272 # #uncomment if we find a nice icon
273 # #page_bmp = wx.ArtProvider.GetBitmap(wx.ART_NORMAL_FILE, wx.ART_OTHER, wx.Size(16, 16))
274 # ctrl.AddPage(self.CreatePanelWelcome(), "Welcome", False)
277 # def CreatePerspectivesMenu(self):
279 # menu.Append(ID_SavePerspective, "Save Perspective")
280 # menu.Append(ID_DeletePerspective, "Delete Perspective")
281 # menu.AppendSeparator()
282 # #add perspectives to menubar and _perspectives
283 # perspectivesDirectory = os.path.join(lh.hookeDir, 'perspectives')
284 # if os.path.isdir(perspectivesDirectory):
285 # perspectiveFileNames = os.listdir(perspectivesDirectory)
286 # for perspectiveFilename in perspectiveFileNames:
287 # filename = lh.get_file_path(perspectiveFilename, ['perspectives'])
288 # if os.path.isfile(filename):
289 # perspectiveFile = open(filename, 'rU')
290 # perspective = perspectiveFile.readline()
291 # perspectiveFile.close()
292 # if perspective != '':
293 # name, extension = os.path.splitext(perspectiveFilename)
294 # if extension == '.txt':
295 # menuItem = menu.AppendRadioItem(ID_FirstPerspective + len(self._perspectives), name)
296 # self._perspectives[name] = [len(self._perspectives), perspective]
297 # if self.config['perspectives']['active'] == name:
299 # #in case there are no perspectives
300 # if not self._perspectives:
301 # perspective = self._mgr.SavePerspective()
302 # self.config['perspectives']['default'] = 'Default'
303 # self._perspectives['Default'] = [0, perspective]
304 # menuItem = menu.AppendRadioItem(ID_FirstPerspective, 'Default')
306 # self._SavePerspectiveToFile('Default', perspective)
309 # def CreateStatusbar(self):
310 # statusbar = self.CreateStatusBar(2, wx.ST_SIZEGRIP)
311 # statusbar.SetStatusWidths([-2, -3])
312 # statusbar.SetStatusText('Ready', 0)
313 # welcomeString=u'Welcome to Hooke (version '+__version__+', '+__release_name__+')!'
314 # statusbar.SetStatusText(welcomeString, 1)
317 # def CreateToolBar(self):
318 # toolbar = wx.ToolBar(self, -1, wx.DefaultPosition, wx.DefaultSize, wx.TB_FLAT | wx.TB_NODIVIDER)
319 # toolbar.SetToolBitmapSize(wx.Size(16,16))
320 # toolbar_bmp1 = wx.ArtProvider_GetBitmap(wx.ART_QUESTION, wx.ART_OTHER, wx.Size(16, 16))
321 # toolbar_bmpOpen = wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN, wx.ART_OTHER, wx.Size(16, 16))
322 # toolbar_bmpSave = wx.ArtProvider_GetBitmap(wx.ART_FILE_SAVE, wx.ART_OTHER, wx.Size(16, 16))
323 # toolbar_bmpExportText = wx.ArtProvider_GetBitmap(wx.ART_NORMAL_FILE, wx.ART_OTHER, wx.Size(16, 16))
324 # toolbar_bmpExportImage = wx.ArtProvider_GetBitmap(wx.ART_MISSING_IMAGE, wx.ART_OTHER, wx.Size(16, 16))
325 # toolbar.AddLabelTool(101, 'Open', toolbar_bmpOpen)
326 # toolbar.AddLabelTool(102, 'Save', toolbar_bmpSave)
327 # toolbar.AddSeparator()
328 # toolbar.AddLabelTool(ID_ExportText, 'Export text...', toolbar_bmpExportText)
329 # toolbar.AddLabelTool(ID_ExportImage, 'Export image...', toolbar_bmpExportImage)
333 # def CreateToolBarNavigation(self):
334 # toolbar = wx.ToolBar(self, -1, wx.DefaultPosition, wx.DefaultSize, wx.TB_FLAT | wx.TB_NODIVIDER)
335 # toolbar.SetToolBitmapSize(wx.Size(16,16))
336 # toolbar_bmpBack = wx.ArtProvider_GetBitmap(wx.ART_GO_BACK, wx.ART_OTHER, wx.Size(16, 16))
337 # toolbar_bmpForward = wx.ArtProvider_GetBitmap(wx.ART_GO_FORWARD, wx.ART_OTHER, wx.Size(16, 16))
338 # toolbar.AddLabelTool(ID_Previous, 'Previous', toolbar_bmpBack, shortHelp='Previous curve')
339 # toolbar.AddLabelTool(ID_Next, 'Next', toolbar_bmpForward, shortHelp='Next curve')
343 # def DeleteFromPlaylists(self, name):
344 # if name in self.playlists:
345 # del self.playlists[name]
346 # tree_root = self.panelPlaylists.PlaylistsTree.GetRootItem()
347 # item, cookie = self.panelPlaylists.PlaylistsTree.GetFirstChild(tree_root)
349 # playlist_name = self.panelPlaylists.PlaylistsTree.GetItemText(item)
350 # if playlist_name == name:
352 # self.panelPlaylists.PlaylistsTree.Delete(item)
355 # item = self.panelPlaylists.PlaylistsTree.GetNextSibling(item)
356 # self.OnPlaylistsLeftDclick(None)
358 # def DeletePlotPage(self, name):
359 # index = self._GetPlaylistTab(name)
360 # plot = self.playlists[name][1]
362 # self.plotNotebook.RemovePage(index)
363 # self.DeleteFromPlaylists(name)
365 # def GetActiveCurve(self):
366 # playlist = self.GetActivePlaylist()
367 # if playlist is not None:
368 # return playlist.get_active_curve()
371 # def GetActivePlaylist(self):
372 # playlist_name = self._GetActivePlaylistName()
373 # if playlist_name in self.playlists:
374 # return self.playlists[playlist_name][0]
377 # def GetActivePlot(self):
378 # curve = self.GetActiveCurve()
379 # if curve is not None:
380 # return curve.plots[0]
383 # def GetDockArt(self):
384 # return self._mgr.GetArtProvider()
386 # def GetBoolFromConfig(self, *args):
391 # elif len(args) == 3:
395 # if self.configs.has_key(plugin):
396 # config = self.configs[plugin]
397 # return config[section][key].as_bool('value')
400 # def GetFloatFromConfig(self, *args):
405 # elif len(args) == 3:
409 # if self.configs.has_key(plugin):
410 # config = self.configs[plugin]
411 # return config[section][key].as_float('value')
414 # def GetIntFromConfig(self, *args):
419 # elif len(args) == 3:
423 # if self.configs.has_key(plugin):
424 # config = self.configs[plugin]
425 # return config[section][key].as_int('value')
428 # def GetStringFromConfig(self, *args):
433 # elif len(args) == 3:
437 # if self.configs.has_key(plugin):
438 # config = self.configs[plugin]
439 # return config[section][key]['value']
442 # def GetPerspectiveMenuItem(self, name):
443 # index = self._perspectives[name][0]
444 # perspective_Id = ID_FirstPerspective + index
445 # menu_item = self.MenuBar.FindItemById(perspective_Id)
448 # def HasPlotmanipulator(self, name):
450 # returns True if the plotmanipulator 'name' is loaded, False otherwise
452 # for plotmanipulator in self.plotmanipulators:
453 # if plotmanipulator[0] == name:
457 # def OnAbout(self, event):
458 # msg = 'Hooke\n\n'+\
459 # 'A free, open source data analysis platform\n'+\
460 # '(c) 2006-2008 Massimo Sandal\n\n'+\
461 # '(c) 2009 Dr. Rolf Schmidt\n\n'+\
462 # 'Released under the GNU GPL v2'
463 # dialog = wx.MessageDialog(self, msg, "About Hooke", wx.OK | wx.ICON_INFORMATION)
467 # def OnClose(self, event):
469 # self.config['main']['height'] = str(self.GetSize().GetHeight())
470 # self.config['main']['left'] = str(self.GetPosition()[0])
471 # self.config['main']['top'] = str(self.GetPosition()[1])
472 # self.config['main']['width'] = str(self.GetSize().GetWidth())
473 # # Writing the configuration file to 'hooke.ini'
474 # self.config.write()
479 # def OnDeletePerspective(self, event):
482 # def OnDirCtrlLeftDclick(self, event):
483 # file_path = self.panelFolders.GetPath()
484 # if os.path.isfile(file_path):
485 # if file_path.endswith('.hkp'):
486 # self.do_loadlist(file_path)
491 # def OnEraseBackground(self, event):
494 # def OnExecute(self, event):
495 # item = self.panelCommands.CommandsTree.GetSelection()
497 # if self.panelCommands.CommandsTree.ItemHasChildren(item):
501 # parent = self.panelCommands.CommandsTree.GetItemParent(item)
502 # if not self.panelCommands.CommandsTree.ItemHasChildren(item):
503 # parent_text = self.panelCommands.CommandsTree.GetItemText(parent)
504 # item_text = self.panelCommands.CommandsTree.GetItemText(item)
505 # if item_text in ['genlist', 'loadlist', 'savelist']:
506 # property_values = self.panelProperties.GetPropertyValues()
508 # for item in property_values:
509 # arg_str = ''.join([arg_str, item, '=r"', str(property_values[item]), '", '])
510 # command = ''.join(['self.do_', item_text, '(', arg_str, ')'])
512 # command = ''.join(['self.do_', item_text, '()'])
516 # def OnExit(self, event):
519 # def OnExportImage(self, event):
522 # def OnNext(self, event):
525 # Go to the next curve in the playlist.
526 # If we are at the last curve, we come back to the first.
530 # selected_item = self.panelPlaylists.PlaylistsTree.GetSelection()
531 # if self.panelPlaylists.PlaylistsTree.ItemHasChildren(selected_item):
532 # #GetFirstChild returns a tuple
533 # #we only need the first element
534 # next_item = self.panelPlaylists.PlaylistsTree.GetFirstChild(selected_item)[0]
536 # next_item = self.panelPlaylists.PlaylistsTree.GetNextSibling(selected_item)
537 # if not next_item.IsOk():
538 # parent_item = self.panelPlaylists.PlaylistsTree.GetItemParent(selected_item)
539 # #GetFirstChild returns a tuple
540 # #we only need the first element
541 # next_item = self.panelPlaylists.PlaylistsTree.GetFirstChild(parent_item)[0]
542 # self.panelPlaylists.PlaylistsTree.SelectItem(next_item, True)
543 # playlist = self.playlists[self._GetActivePlaylistName()][0]
544 # if playlist.count > 1:
546 # self.statusbar.SetStatusText(playlist.get_status_string(), 0)
549 # def OnNotebookPageClose(self, event):
550 # ctrl = event.GetEventObject()
551 # playlist_name = ctrl.GetPageText(ctrl._curpage)
552 # self.DeleteFromPlaylists(playlist_name)
554 # def OnPaneClose(self, event):
557 # def OnPlaylistsLeftDclick(self, event):
558 # playlist_name = self._GetActivePlaylistName()
559 # #if that playlist already exists
560 # #we check if it is the active playlist (ie selected in panelPlaylists)
561 # #and switch to it if necessary
562 # if playlist_name in self.playlists:
563 # index = self.plotNotebook.GetSelection()
564 # current_playlist = self.plotNotebook.GetPageText(index)
565 # #new_playlist = self.playlists[playlist_name][0]
566 # #if current_playlist != new_playlist:
567 # if current_playlist != playlist_name:
568 # index = self._GetPlaylistTab(playlist_name)
569 # self.plotNotebook.SetSelection(index)
570 # #if a curve was double-clicked
571 # item = self.panelPlaylists.PlaylistsTree.GetSelection()
572 # #TODO: fix with get_active_curve
573 # if not self.panelPlaylists.PlaylistsTree.ItemHasChildren(item):
574 # index = self._GetActiveCurveIndex()
578 # playlist = self.playlists[playlist_name][0]
579 # playlist.index = index
580 # self.statusbar.SetStatusText(playlist.get_status_string(), 0)
582 # #if you uncomment the following line, the tree will collapse/expand as well
585 # def OnPlaylistsLeftDown(self, event):
586 # hit_item, hit_flags = self.panelPlaylists.PlaylistsTree.HitTest(event.GetPosition())
587 # if (hit_flags & wx.TREE_HITTEST_ONITEM) != 0:
589 # self.panelPlaylists.PlaylistsTree.SelectItem(hit_item)
590 # playlist_name = self._GetActivePlaylistName()
591 # playlist = self.playlists[playlist_name][0]
592 # #if a curve was clicked
593 # item = self.panelPlaylists.PlaylistsTree.GetSelection()
594 # if not self.panelPlaylists.PlaylistsTree.ItemHasChildren(item):
595 # #TODO: fix with get_active_curve
596 # index = self._GetActiveCurveIndex()
598 # #playlist = self.playlists[playlist_name][0]
599 # playlist.index = index
600 # #self.playlists[playlist_name][0].index = index
602 # ##self.playlists[playlist_name][0].index = 0
603 # #playlist.index = index
604 # self.playlists[playlist_name][0] = playlist
607 # def OnPrevious(self, event):
610 # Go to the previous curve in the playlist.
611 # If we are at the first curve, we jump to the last.
613 # Syntax: previous, p
615 # #playlist = self.playlists[self._GetActivePlaylistName()][0]
616 # #select the previous curve and tell the user if we wrapped around
617 # #self.AppendToOutput(playlist.previous())
618 # selected_item = self.panelPlaylists.PlaylistsTree.GetSelection()
619 # if self.panelPlaylists.PlaylistsTree.ItemHasChildren(selected_item):
620 # previous_item = self.panelPlaylists.PlaylistsTree.GetLastChild(selected_item)
622 # previous_item = self.panelPlaylists.PlaylistsTree.GetPrevSibling(selected_item)
623 # if not previous_item.IsOk():
624 # parent_item = self.panelPlaylists.PlaylistsTree.GetItemParent(selected_item)
625 # previous_item = self.panelPlaylists.PlaylistsTree.GetLastChild(parent_item)
626 # self.panelPlaylists.PlaylistsTree.SelectItem(previous_item, True)
627 # playlist = self.playlists[self._GetActivePlaylistName()][0]
628 # if playlist.count > 1:
629 # playlist.previous()
630 # self.statusbar.SetStatusText(playlist.get_status_string(), 0)
633 # def OnPropGridChanged (self, event):
634 # prop = event.GetProperty()
636 # item_section = self.panelProperties.SelectedTreeItem
637 # item_plugin = self.panelCommands.CommandsTree.GetItemParent(item_section)
638 # plugin = self.panelCommands.CommandsTree.GetItemText(item_plugin)
639 # config = self.configs[plugin]
640 # property_section = self.panelCommands.CommandsTree.GetItemText(item_section)
641 # property_key = prop.GetName()
642 # property_value = prop.GetValue()
643 # config[property_section][property_key]['value'] = property_value
645 # def OnPropGridSelect(self, event):
648 # def OnRestorePerspective(self, event):
649 # name = self.MenuBar.FindItemById(event.GetId()).GetLabel()
650 # self._mgr.LoadPerspective(self._perspectives[name][1])
651 # self.config['perspectives']['active'] = name
653 # all_panes = self._mgr.GetAllPanes()
654 # for pane in all_panes:
655 # if not pane.name.startswith('toolbar'):
656 # if pane.name == 'Assistant':
657 # self.MenuBar.FindItemById(ID_ViewAssistant).Check(pane.window.IsShown())
658 # if pane.name == 'Folders':
659 # self.MenuBar.FindItemById(ID_ViewFolders).Check(pane.window.IsShown())
660 # if pane.name == 'Playlists':
661 # self.MenuBar.FindItemById(ID_ViewPlaylists).Check(pane.window.IsShown())
662 # if pane.name == 'Commands':
663 # self.MenuBar.FindItemById(ID_ViewCommands).Check(pane.window.IsShown())
664 # if pane.name == 'Properties':
665 # self.MenuBar.FindItemById(ID_ViewProperties).Check(pane.window.IsShown())
666 # if pane.name == 'Output':
667 # self.MenuBar.FindItemById(ID_ViewOutput).Check(pane.window.IsShown())
668 # if pane.name == 'Results':
669 # self.MenuBar.FindItemById(ID_ViewResults).Check(pane.window.IsShown())
671 # def OnResultsCheck(self, index, flag):
672 # curve = self.GetActiveCurve()
673 # result = curve.data['results'][index]['visible'] = flag
676 # def OnSavePerspective(self, event):
677 # def nameExists(name):
678 # for item in self._perspectives_menu.GetMenuItems():
679 # if item.GetText() == name:
685 # dialog = wx.TextEntryDialog(self, 'Enter a name for the new perspective:', 'Save perspective')
686 # dialog.SetValue('New perspective')
687 # if dialog.ShowModal() != wx.ID_OK:
690 # name = dialog.GetValue()
692 # if nameExists(name):
693 # 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)
694 # if dialogConfirm.ShowModal() == wx.ID_YES:
699 # perspective = self._mgr.SavePerspective()
701 # if nameExists(name):
702 # #check the corresponding menu item
703 # menuItem = self.GetPerspectiveMenuItem(name)
704 # #replace the perspectiveStr in _pespectives
705 # index = self._perspectives[name][0]
706 # self._perspectives[name] = [index, perspective]
708 # #simply add the new perspective to _perspectives
709 # index = len(self._perspectives)
710 # self._perspectives[name] = [len(self._perspectives), perspective]
711 # menuItem = self._perspectives_menu.AppendRadioItem(ID_FirstPerspective + len(self._perspectives), name)
714 # self._SavePerspectiveToFile(name, perspective)
715 # #uncheck all perspective menu items
716 # #as these are radio items, one item has to be checked at all times
717 # #the line 'menuItem.Check()' above actually checks a second item
718 # #but does not toggle
719 # #so we need to uncheck all other items afterwards
720 # #weirdly enough, menuitem.Toggle() doesn't do this properly either
721 # for item in self._perspectives_menu.GetMenuItems():
722 # if item.IsCheckable():
723 # if item.GetLabel() != name:
726 # def OnView(self, event):
727 # menu_id = event.GetId()
728 # menu_item = self.MenuBar.FindItemById(menu_id)
729 # menu_label = menu_item.GetLabel()
731 # pane = self._mgr.GetPane(menu_label)
732 # pane.Show(not pane.IsShown())
733 # #if we don't do the following, the Folders pane does not resize properly on hide/show
734 # if pane.caption == 'Folders' and pane.IsShown() and pane.IsDocked():
735 # #folders_size = pane.GetSize()
736 # self.panelFolders.Fit()
739 # def OnSize(self, event):
742 # def OnTreeCtrlCommandsLeftDown(self, event):
743 # hit_item, hit_flags = self.panelCommands.CommandsTree.HitTest(event.GetPosition())
744 # if (hit_flags & wx.TREE_HITTEST_ONITEM) != 0:
745 # self.panelCommands.CommandsTree.SelectItem(hit_item)
746 # self.panelProperties.SelectedTreeItem = hit_item
747 # #if a command was clicked
749 # if not self.panelCommands.CommandsTree.ItemHasChildren(hit_item):
750 # item_plugin = self.panelCommands.CommandsTree.GetItemParent(hit_item)
751 # plugin = self.panelCommands.CommandsTree.GetItemText(item_plugin)
752 # if self.configs.has_key(plugin):
753 # #config = self.panelCommands.CommandsTree.GetPyData(item_plugin)
754 # config = self.configs[plugin]
755 # section = self.panelCommands.CommandsTree.GetItemText(hit_item)
756 # #display docstring in help window
757 # doc_string = eval('self.do_' + section + '.__doc__')
758 # if section in config:
759 # for option in config[section]:
760 # properties.append([option, config[section][option]])
762 # module = self.panelCommands.CommandsTree.GetItemText(hit_item)
763 # if module != 'general':
764 # doc_string = eval('plugins.' + module + '.' + module + 'Commands.__doc__')
766 # doc_string = 'The module "general" contains Hooke core functionality'
767 # if doc_string is not None:
768 # self.panelAssistant.ChangeValue(doc_string)
769 # hookepropertyeditor.PropertyEditor.Initialize(self.panelProperties, properties)
772 # def UpdatePlaylists(self):
773 # #setup the playlist in the Playlist tree
774 # tree_root = self.panelPlaylists.PlaylistsTree.GetRootItem()
775 # playlist_root = self.panelPlaylists.PlaylistsTree.AppendItem(tree_root, playlist.name, 0)
776 # #add all curves to the Playlist tree
778 # for index, curve in enumerate(playlist.curves):
779 # ##remove the extension from the name of the curve
781 # #item_text, extension = os.path.splitext(curve.name)
782 # #curve_ID = self.panelPlaylists.PlaylistsTree.AppendItem(playlist_root, item_text, 1)
783 # curve_ID = self.panelPlaylists.PlaylistsTree.AppendItem(playlist_root, curve.name, 1)
784 # if index == playlist.index:
785 # self.panelPlaylists.PlaylistsTree.SelectItem(curve_ID)
786 # #create the plot tab and add playlist to the dictionary
787 # plotPanel = wxmpl.PlotPanel(self, ID_FirstPlot + len(self.playlists))
788 # notebook_tab = self.plotNotebook.AddPage(plotPanel, playlist.name, True)
789 # #tab_index = self.plotNotebook.GetSelection()
790 # figure = plotPanel.get_figure()
791 # #self.playlists[playlist.name] = [playlist, tab_index, figure]
792 # self.playlists[playlist.name] = [playlist, figure]
793 # self.panelPlaylists.PlaylistsTree.Expand(playlist_root)
794 # self.statusbar.SetStatusText(playlist.get_status_string(), 0)
798 ##Everything sending an event should be here
799 # def _measure_N_points(self, N, whatset=1):
801 # general helper function for N-points measures
803 # wx.PostEvent(self.frame,self.list_of_events['measure_points'](num_of_points=N, set=whatset))
806 # points=self.frame.events_from_gui.get()
812 # def _clickize(self, xvector, yvector, index):
814 # returns a ClickedPoint() object from an index and vectors of x, y coordinates
816 # point = lh.ClickedPoint()
817 # point.index = index
818 # point.absolute_coords = xvector[index], yvector[index]
819 # point.find_graph_coords(xvector, yvector)
822 ##PLAYLIST INTERACTION COMMANDS
823 ##-------------------------------
824 # def do_genlist(self, folder=lh.hookeDir, filemask='*.*'):
827 # Generates a file playlist.
828 # Note it doesn't *save* it: see savelist for this.
830 # If [input files] is a directory, it will use all files in the directory for playlist.
836 # are all equivalent syntax.
838 # Syntax: genlist [input files]
840 # #args list is: input folder, file mask
841 # if os.path.isdir(folder):
842 # path = os.path.join(folder, filemask)
843 # #expanding correctly the input list with the glob module :)
844 # files = glob.glob(path)
846 # #TODO: change cursor or progressbar (maybe in statusbar)
847 # #self.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))
848 # playlist = playlist.Playlist(self.drivers)
850 # curve = playlist.add_curve(item)
851 # plot = copy.deepcopy(curve.plots[0])
852 # #add the 'raw' data
853 # curve.add_data('raw', plot.vectors[0][0], plot.vectors[0][1], color=plot.colors[0], style='plot')
854 # curve.add_data('raw', plot.vectors[1][0], plot.vectors[1][1], color=plot.colors[1], style='plot')
855 # #apply all active plotmanipulators and add the 'manipulated' data
856 # for plotmanipulator in self.plotmanipulators:
857 # plot = plotmanipulator[1](plot, curve)
858 # curve.set_data('manipulated', plot.vectors[0][0], plot.vectors[0][1], color=plot.colors[0], style='plot')
859 # curve.add_data('manipulated', plot.vectors[1][0], plot.vectors[1][1], color=plot.colors[1], style='plot')
860 # if playlist.count > 0:
861 # playlist.name = self._GetUniquePlaylistName(os.path.basename(folder))
863 # self.AddToPlaylists(playlist)
864 # self.AppendToOutput(playlist.get_status_string())
866 # self.AppendToOutput(''.join(['Cannot find folder ', folder]))
868 # def do_loadlist(self, filename):
871 # Loads a file playlist
873 # Syntax: loadlist [playlist file]
875 # #TODO: check for duplicate playlists, ask the user for a unique name
876 # #if self.playlist_name in self.playlists:
878 # #add hkp extension if necessary
879 # if not filename.endswith('.hkp'):
880 # filename = ''.join([filename, '.hkp'])
881 # #prefix with 'hookeDir' if just a filename or a relative path
882 # filename = lh.get_file_path(filename)
883 # if os.path.isfile(filename):
884 # #TODO: change cursor
885 # #self.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))
886 # playlist_new = playlist.Playlist(self.drivers)
887 # playlist_new.load(filename)
888 # if playlist_new.count > 0:
889 # for curve in playlist_new.curves:
890 # plot = copy.deepcopy(curve.plots[0])
891 # for plotmanip in self.plotmanipulators:
892 # #to_plot = plotmanip[1](to_plot, curve)
893 # plot = plotmanip[1](plot, curve)
894 # curve.set_data('manipulated', plot.vectors[0][0], plot.vectors[0][1], color=plot.colors[0], style='plot')
895 # curve.add_data('manipulated', plot.vectors[1][0], plot.vectors[1][1], color=plot.colors[1], style='plot')
896 # self.AddToPlaylists(playlist_new)
898 # ##TODO: display dialog
899 # self.AppendToOutput(playlist_new.get_status_string())
900 # #TODO: change cursor
901 # #self.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))
903 # #TODO: display dialog
904 # self.AppendToOutput(''.join['File ', filename, ' not found.\n'])
907 # def do_savelist(self, filename):
910 # Saves the current file playlist on disk.
912 # Syntax: savelist [filename]
915 # #self.playlist_generics['pointer'] = self._GetActiveCurveIndex
916 # pointer = self._GetActiveCurveIndex()
917 # #autocomplete filename if not specified
918 # if not filename.endswith('.hkp'):
919 # filename = filename.join(['.hkp'])
921 # playlist = self.GetActivePlaylist()
923 # playlist.save(filename)
925 ##PLOT INTERACTION COMMANDS
926 ##-------------------------------
927 # def UpdatePlot(self):
928 # def add_plot(plot):
929 # if plot['visible'] and plot['x'] and plot['y']:
930 # color = plot['color']
931 # style = plot['style']
932 # if style == 'plot':
933 # axes.plot(plot['x'], plot['y'], color=color, zorder=1)
934 # if style == 'scatter':
935 # axes.scatter(plot['x'], plot['y'], color=color, s=0.5, zorder=2)
937 # def add_plot2(plot):
938 # if plot.visible and plot.x and plot.y:
939 # if plot.style == 'plot':
940 # axes.plot(plot.x, plot.y, color=plot.color, zorder=1)
941 # if plot.style == 'scatter':
942 # axes.scatter(plot.x, plot.y, color=plot.color, s=0.5, zorder=2)
944 # playlist_name = self._GetActivePlaylistName()
945 # index = self._GetActiveCurveIndex()
946 # playlist = self.playlists[playlist_name][0]
947 # curve = playlist.get_active_curve()
948 # plot = playlist.get_active_plot()
949 # figure = self.playlists[playlist_name][1]
953 # if curve.data.has_key('manipulated'):
955 # elif curve.data.has_key('raw'):
956 # exclude = 'manipulated'
958 # if exclude is not None:
959 # #TODO: what is this good for?
960 # if not hasattr(self, 'subplot'):
961 # axes = figure.add_subplot(111)
963 # axes.set_title(plot.title)
964 # axes.set_xlabel(plot.units[0])
965 # axes.set_ylabel(plot.units[1])
967 # for set_of_plots in curve.data:
968 # if set_of_plots != exclude:
969 # plots = curve.data[set_of_plots]
970 # for each_plot in plots:
971 # add_plot(each_plot)
973 # #TODO: add multiple results support
974 # #for fit in curve.fits:
975 # if curve.fits.has_key('wlc'):
976 # for plot in curve.fits['wlc'].results:
978 # self.panelResults.DisplayResults(curve.fits['wlc'])
980 # self.panelResults.ClearResults()
982 # axes.figure.canvas.draw()
984 # self.AppendToOutput('Not able to plot.')
987 app = Hooke(debug=__debug__)
990 if __name__ == '__main__':