def __on_getting_started(self,event): helpframe = wx.Frame(self,-1,'Add modules: Getting Started',size=(640,480)) sizer = wx.BoxSizer() helpframe.SetSizer(sizer) window = wx.html.HtmlWindow(helpframe) sizer.Add(window,1,wx.EXPAND) window.AppendToPage(BUILDING_A_PIPELINE_HELP) helpframe.SetIcon(get_cp_icon()) helpframe.Layout() helpframe.Show()
def display_helpframe(self, help, title): helpframe = wx.Frame(self, -1, title, size=(640, 480)) sizer = wx.BoxSizer() helpframe.SetSizer(sizer) window = wx.html.HtmlWindow(helpframe) sizer.Add(window, 1, wx.EXPAND) window.AppendToPage(help) helpframe.SetIcon(get_cp_icon()) helpframe.Layout() helpframe.Show()
def display_helpframe(self, help, title): helpframe = wx.Frame(self, -1,title, size=(640,480)) sizer = wx.BoxSizer() helpframe.SetSizer(sizer) window = wx.html.HtmlWindow(helpframe) sizer.Add(window,1,wx.EXPAND) window.AppendToPage(help) helpframe.SetIcon(get_cp_icon()) helpframe.Layout() helpframe.Show()
def display_helpframe(self, help, title): from cellprofiler.gui.html.htmlwindow import HtmlClickableWindow helpframe = wx.Frame(self, -1, title, size=(640, 480)) sizer = wx.BoxSizer() helpframe.SetSizer(sizer) window = HtmlClickableWindow(helpframe) sizer.Add(window, 1, wx.EXPAND) window.AppendToPage(help) helpframe.SetIcon(get_cp_icon()) helpframe.Layout() helpframe.Show()
def display_helpframe(self, help, title): from cellprofiler.gui.html.htmlwindow import HtmlClickableWindow helpframe = wx.Frame(self, -1,title, size=(640,480)) sizer = wx.BoxSizer() helpframe.SetSizer(sizer) window = HtmlClickableWindow(helpframe) sizer.Add(window,1,wx.EXPAND) window.AppendToPage(help) helpframe.SetIcon(get_cp_icon()) helpframe.Layout() helpframe.Show()
def __on_getting_started(self, event): helpframe = wx.Frame(self, -1, 'Add modules: Getting Started', size=(640, 480)) sizer = wx.BoxSizer() helpframe.SetSizer(sizer) window = wx.html.HtmlWindow(helpframe) sizer.Add(window, 1, wx.EXPAND) window.AppendToPage(BUILDING_A_PIPELINE_HELP) helpframe.SetIcon(get_cp_icon()) helpframe.Layout() helpframe.Show()
def run_as_data_tool(self, workspace): m = workspace.measurements assert isinstance(m, cpmeas.Measurements) m.is_first_image = True image_set_count = m.image_set_count for i in range(image_set_count): self.run(workspace) img_stats = workspace.display_data.statistics if i == 0: header = ["Image set"] for flag_name, object_name, feature, value, pf in img_stats: header.append(flag_name) header.append("Pass/Fail") statistics = [header] row = [str(i+1)] ok = True for flag_name, object_name, feature, value, pf in img_stats: ok = ok and (pf == "Pass") row.append(str(value)) row.append("Pass" if ok else "Fail") statistics.append(row) if i < image_set_count - 1: m.next_image_set() self.show_window = False if image_set_count > 0: import wx from wx.grid import Grid, PyGridTableBase, EVT_GRID_LABEL_LEFT_CLICK from cellprofiler.gui import get_cp_icon frame = wx.Frame(workspace.frame, -1, "Flag image results") sizer = wx.BoxSizer(wx.VERTICAL) frame.SetSizer(sizer) grid = Grid(frame, -1) sizer.Add(grid, 1, wx.EXPAND) # # The flag table supplies the statistics to the grid # using the grid table interface # sort_order = np.arange(len(statistics)-1) sort_col = [None] sort_ascending = [None] def on_label_clicked(event): col = event.GetCol() if sort_col[0] == col: sort_ascending[0] = not sort_ascending[0] else: sort_ascending[0] = True sort_col[0] = col data = [x[col] for x in statistics[1:]] try: data = np.array(data,float) except ValueError: data = np.array(data) if sort_ascending[0]: sort_order[:] = np.lexsort((data,)) else: sort_order[::-1] = np.lexsort((data,)) grid.ForceRefresh() grid.Bind(EVT_GRID_LABEL_LEFT_CLICK, on_label_clicked) class FlagTable(PyGridTableBase): def __init__(self): PyGridTableBase.__init__(self) def GetColLabelValue(self, col): if col == sort_col[0]: if sort_ascending[0]: return statistics[0][col]+" v" else: return statistics[0][col]+" ^" return statistics[0][col] def GetNumberRows(self): return len(statistics)-1 def GetNumberCols(self): return len(statistics[0]) def GetValue(self, row, col): return statistics[sort_order[row]+1][col] grid.SetTable(FlagTable()) frame.Fit() max_size = int(wx.SystemSettings.GetMetric(wx.SYS_SCREEN_Y) * 3 / 4) if frame.Size[1] > max_size: frame.SetSize((frame.Size[0], max_size)) frame.SetIcon(get_cp_icon()) frame.Show()
def __init__(self, *args, **kwds): if sys.platform.startswith("win"): kwds["style"] = wx.DEFAULT_FRAME_STYLE | wx.STAY_ON_TOP wx.Frame.__init__(self, *args, **kwds) self.Show() if wx.Platform == '__WXMAC__' and hasattr(self, 'MacGetTopLevelWindowRef'): try: from AppKit import NSWindow, NSApp, NSFloatingWindowLevel window_ref = self.MacGetTopLevelWindowRef() nsw = NSWindow.alloc().initWithWindowRef_(window_ref) nsw.setLevel_(NSFloatingWindowLevel) except ImportError: print "No AppKit module => can't make progress window stay on top." self.start_time = time.time() self.end_times = None self.current_module = None self.pause_start_time = None self.previous_pauses_duration = 0. # GUI stuff self.BackgroundColour = cellprofiler.preferences.get_background_color() self.tbicon = wx.TaskBarIcon() self.tbicon.SetIcon(get_cp_icon(), "CellProfiler2.0") self.SetTitle("CellProfiler %s"%(version.title_string)) self.SetSize((640, 480)) self.panel = wx.Panel(self, wx.ID_ANY) sizer = wx.BoxSizer(wx.VERTICAL) times_sizer = wx.BoxSizer(wx.HORIZONTAL) self.elapsed_control = wx.StaticText(self.panel, -1, label=self.elapsed_label(), style=wx.ALIGN_LEFT) self.remaining_control = wx.StaticText(self.panel, -1, label=self.remaining_label(), style=wx.ALIGN_RIGHT) times_sizer.Add(self.elapsed_control, 1, wx.ALIGN_LEFT | wx.ALL, 5) times_sizer.Add(self.remaining_control, 1, wx.ALIGN_RIGHT | wx.ALL, 5) sizer.Add(times_sizer, 0, wx.EXPAND) self.gauge = wx.Gauge(self.panel, -1, style=wx.GA_HORIZONTAL) self.gauge.SetValue(0) self.gauge.SetRange(100) sizer.Add(self.gauge, 0, wx.ALL | wx.EXPAND, 5) self.image_set_control = wx.StaticText(self.panel, -1, label=image_set_label(None, None)) sizer.Add(self.image_set_control, 0, wx.LEFT | wx.RIGHT, 5) self.current_module_control = wx.StaticText(self.panel, -1, label=module_label(None)) sizer.Add(self.current_module_control, 0, wx.LEFT | wx.RIGHT | wx.BOTTOM, 5) buttons_sizer = wx.BoxSizer(wx.HORIZONTAL) self.play_pause_button = wx.BitmapButton(self.panel, -1, bitmap=wx.BitmapFromImage(get_builtin_image('pause'))) self.play_pause_button.SetToolTipString("Pause") buttons_sizer.Add(self.play_pause_button, 0, wx.ALL, 5) self.stop_button = wx.BitmapButton(self.panel, -1, bitmap=wx.BitmapFromImage(get_builtin_image('stop'))) self.stop_button.SetToolTipString("Stop") buttons_sizer.Add(self.stop_button, 0, wx.ALL, 5) save_bitmap = wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE, wx.ART_CMN_DIALOG, (16,16)) self.save_button = wx.BitmapButton(self.panel, -1, bitmap = save_bitmap) self.save_button.SetToolTipString("Save measurements") buttons_sizer.Add(self.save_button, 0, wx.ALL, 5) sizer.Add(buttons_sizer, 0, wx.CENTER) self.panel.SetSizer(sizer) sizer.Fit(self) # Timer that updates elapsed timer_id = wx.NewId() self.timer = wx.Timer(self.panel, timer_id) self.timer.Start(500) wx.EVT_TIMER(self.panel, timer_id, self.on_timer)
def run_as_data_tool(self): '''Run the module as a data tool''' import wx from wx.lib.mixins.listctrl import ListCtrlAutoWidthMixin from cellprofiler.gui import get_cp_icon # # Portions of this were cribbed from the wx listctrl demo code # which is part of the wx source distribution # class AWListCtrl(wx.ListCtrl, ListCtrlAutoWidthMixin): '''A list control with autosizing of the last column''' def __init__(self, parent, ID=wx.ID_ANY, pos=wx.DefaultPosition, size=wx.DefaultSize, style=0): wx.ListCtrl.__init__(self, parent, ID, pos, size, style) ListCtrlAutoWidthMixin.__init__(self) dlg = wx.Dialog(None, title="Merge output files", size=(640, 480), style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER | wx.THICK_FRAME) dlg.SetIcon(get_cp_icon()) # # Layout: # Dialog box # sizer (vertical) # list-control # sizer (horizontal) # Add... # Remove # Up # Down # button sizer # OK # Cancel # dlg.Sizer = sizer = wx.BoxSizer(wx.VERTICAL) subsizer = wx.BoxSizer(wx.HORIZONTAL) sizer.Add(subsizer, 0, wx.EXPAND | wx.ALL, 5) subsizer.Add(wx.StaticText(dlg, -1, "Destination file:"), 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.LEFT, 3) dest_file_ctrl = wx.TextCtrl(dlg) subsizer.Add(dest_file_ctrl, 1, wx.EXPAND | wx.LEFT, 3) browse_button = wx.Button(dlg, -1, "Browse...") subsizer.Add(browse_button, 0, wx.EXPAND) list_control = AWListCtrl(dlg, style=wx.LC_REPORT) if sys.platform == 'darwin': list_control.InsertColumn(0, "Folder", width=200) list_control.InsertColumn(1, "File", width=-1) else: list_control.InsertColumn(0, "Folder", format=wx.LC_ALIGN_LEFT, width=200) list_control.InsertColumn(1, "File", format=wx.LC_ALIGN_LEFT, width=-1) sizer.Add(list_control, 1, wx.EXPAND | wx.ALL, 5) sizer.Add(wx.StaticLine(dlg), 0, wx.EXPAND) subsizer = wx.BoxSizer(wx.HORIZONTAL) sizer.Add(subsizer, 0, wx.EXPAND | wx.ALL, 5) add_button = wx.Button(dlg, -1, "Add...") subsizer.Add(add_button, 0, wx.ALIGN_CENTER_HORIZONTAL) remove_button = wx.Button(dlg, wx.ID_REMOVE, "Remove selected") subsizer.Add(remove_button, 0, wx.ALIGN_CENTER_HORIZONTAL) up_button = wx.Button(dlg, wx.ID_UP, "Up") subsizer.Add(up_button, 0, wx.ALIGN_CENTER_HORIZONTAL) down_button = wx.Button(dlg, wx.ID_DOWN, "Down") subsizer.Add(down_button, 0, wx.ALIGN_CENTER_HORIZONTAL) button_sizer = wx.StdDialogButtonSizer() button_sizer.AddButton(wx.Button(dlg, wx.ID_OK)) button_sizer.AddButton(wx.Button(dlg, wx.ID_CANCEL)) help_button = wx.Button(dlg, wx.ID_HELP) button_sizer.AddButton(help_button) button_sizer.Realize() subsizer.Add(button_sizer, 0, wx.ALIGN_RIGHT) dlg.Layout() # # Order is a map of item ID to its position in the list control # order = {} add_button.Bind(wx.EVT_BUTTON, lambda event: self.on_add(event, list_control, order)) remove_button.Bind( wx.EVT_BUTTON, lambda event: self.on_remove(event, list_control, order)) browse_button.Bind(wx.EVT_BUTTON, lambda event: self.on_browse(event, dest_file_ctrl)) up_button.Bind(wx.EVT_BUTTON, lambda event: self.on_up(event, list_control, order)) down_button.Bind( wx.EVT_BUTTON, lambda event: self.on_down(event, list_control, order)) help_button.Bind(wx.EVT_BUTTON, lambda event: self.on_help(event, list_control)) if dlg.ShowModal() == wx.ID_OK: sources = [] for i in range(list_control.ItemCount): item_id = list_control.GetItemData(i) path = list_control.GetItem(i, 0).GetText() filename = list_control.GetItem(i, 1).GetText() sources.append(os.path.join(path, filename)) self.merge_files(dest_file_ctrl.Value, sources) dlg.Destroy()
def __set_icon(self): icon = get_cp_icon() self.SetIcon(icon)
def run_as_data_tool(self): '''Run the module as a data tool''' import wx from wx.lib.mixins.listctrl import ListCtrlAutoWidthMixin from cellprofiler.gui import get_cp_icon # # Portions of this were cribbed from the wx listctrl demo code # which is part of the wx source distribution # class AWListCtrl(wx.ListCtrl, ListCtrlAutoWidthMixin): '''A list control with autosizing of the last column''' def __init__(self, parent, ID=wx.ID_ANY, pos=wx.DefaultPosition, size=wx.DefaultSize, style=0): wx.ListCtrl.__init__(self, parent, ID, pos, size, style) ListCtrlAutoWidthMixin.__init__(self) dlg = wx.Dialog(None, title = "Merge output files", size=(640,480), style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER | wx.THICK_FRAME) dlg.SetIcon(get_cp_icon()) # # Layout: # Dialog box # sizer (vertical) # list-control # sizer (horizontal) # Add... # Remove # Up # Down # button sizer # OK # Cancel # dlg.Sizer = sizer = wx.BoxSizer(wx.VERTICAL) subsizer = wx.BoxSizer(wx.HORIZONTAL) sizer.Add(subsizer, 0, wx.EXPAND | wx.ALL, 5) subsizer.Add(wx.StaticText(dlg, -1, "Destination file:"), 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.LEFT, 3) dest_file_ctrl = wx.TextCtrl(dlg) subsizer.Add(dest_file_ctrl, 1, wx.EXPAND | wx.LEFT, 3) browse_button = wx.Button(dlg, -1, "Browse...") subsizer.Add(browse_button, 0, wx.EXPAND) list_control = AWListCtrl(dlg, style=wx.LC_REPORT) if sys.platform == 'darwin': list_control.InsertColumn(0, "Folder", width=200) list_control.InsertColumn(1, "File", width=-1) else: list_control.InsertColumn(0, "Folder", format=wx.LC_ALIGN_LEFT, width=200) list_control.InsertColumn(1, "File", format=wx.LC_ALIGN_LEFT, width=-1) sizer.Add(list_control, 1, wx.EXPAND | wx.ALL, 5) sizer.Add(wx.StaticLine(dlg), 0, wx.EXPAND) subsizer = wx.BoxSizer(wx.HORIZONTAL) sizer.Add(subsizer, 0, wx.EXPAND | wx.ALL, 5) add_button = wx.Button(dlg, -1, "Add...") subsizer.Add(add_button, 0, wx.ALIGN_CENTER_HORIZONTAL) remove_button = wx.Button(dlg, wx.ID_REMOVE, "Remove selected") subsizer.Add(remove_button, 0, wx.ALIGN_CENTER_HORIZONTAL) up_button = wx.Button(dlg, wx.ID_UP, "Up") subsizer.Add(up_button, 0, wx.ALIGN_CENTER_HORIZONTAL) down_button = wx.Button(dlg, wx.ID_DOWN, "Down") subsizer.Add(down_button, 0, wx.ALIGN_CENTER_HORIZONTAL) button_sizer = wx.StdDialogButtonSizer() button_sizer.AddButton(wx.Button(dlg, wx.ID_OK)) button_sizer.AddButton(wx.Button(dlg, wx.ID_CANCEL)) help_button = wx.Button(dlg, wx.ID_HELP) button_sizer.AddButton(help_button) button_sizer.Realize() subsizer.Add(button_sizer, 0, wx.ALIGN_RIGHT ) dlg.Layout() # # Order is a map of item ID to its position in the list control # order = {} add_button.Bind(wx.EVT_BUTTON, lambda event: self.on_add(event, list_control, order)) remove_button.Bind(wx.EVT_BUTTON, lambda event: self.on_remove(event, list_control, order)) browse_button.Bind(wx.EVT_BUTTON, lambda event: self.on_browse(event, dest_file_ctrl)) up_button.Bind(wx.EVT_BUTTON, lambda event: self.on_up(event, list_control, order)) down_button.Bind(wx.EVT_BUTTON, lambda event: self.on_down(event, list_control, order)) help_button.Bind(wx.EVT_BUTTON, lambda event: self.on_help(event, list_control)) if dlg.ShowModal() == wx.ID_OK: sources = [] for i in range(list_control.ItemCount): item_id = list_control.GetItemData(i) path = list_control.GetItem(i, 0).GetText() filename = list_control.GetItem(i, 1).GetText() sources.append(os.path.join(path, filename)) self.merge_files(dest_file_ctrl.Value, sources) dlg.Destroy()
def run_as_data_tool(self, workspace): m = workspace.measurements assert isinstance(m, cpmeas.Measurements) m.is_first_image = True image_set_count = m.image_set_count for i in range(image_set_count): self.run(workspace) img_stats = workspace.display_data.statistics if i == 0: header = ["Image set"] for flag_name, object_name, feature, value, pf in img_stats: header.append(flag_name) header.append("Pass/Fail") statistics = [header] row = [str(i + 1)] ok = True for flag_name, object_name, feature, value, pf in img_stats: ok = ok and (pf == "Pass") row.append(str(value)) row.append("Pass" if ok else "Fail") statistics.append(row) if i < image_set_count - 1: m.next_image_set() self.show_window = False if image_set_count > 0: import wx from wx.grid import Grid, PyGridTableBase, EVT_GRID_LABEL_LEFT_CLICK from cellprofiler.gui import get_cp_icon frame = wx.Frame(workspace.frame, -1, "Flag image results") sizer = wx.BoxSizer(wx.VERTICAL) frame.SetSizer(sizer) grid = Grid(frame, -1) sizer.Add(grid, 1, wx.EXPAND) # # The flag table supplies the statistics to the grid # using the grid table interface # sort_order = np.arange(len(statistics) - 1) sort_col = [None] sort_ascending = [None] def on_label_clicked(event): col = event.GetCol() if sort_col[0] == col: sort_ascending[0] = not sort_ascending[0] else: sort_ascending[0] = True sort_col[0] = col data = [x[col] for x in statistics[1:]] try: data = np.array(data, float) except ValueError: data = np.array(data) if sort_ascending[0]: sort_order[:] = np.lexsort((data, )) else: sort_order[::-1] = np.lexsort((data, )) grid.ForceRefresh() grid.Bind(EVT_GRID_LABEL_LEFT_CLICK, on_label_clicked) class FlagTable(PyGridTableBase): def __init__(self): PyGridTableBase.__init__(self) def GetColLabelValue(self, col): if col == sort_col[0]: if sort_ascending[0]: return statistics[0][col] + " v" else: return statistics[0][col] + " ^" return statistics[0][col] def GetNumberRows(self): return len(statistics) - 1 def GetNumberCols(self): return len(statistics[0]) def GetValue(self, row, col): return statistics[sort_order[row] + 1][col] grid.SetTable(FlagTable()) frame.Fit() max_size = int( wx.SystemSettings.GetMetric(wx.SYS_SCREEN_Y) * 3 / 4) if frame.Size[1] > max_size: frame.SetSize((frame.Size[0], max_size)) frame.SetIcon(get_cp_icon()) frame.Show()
def __init__(self, *args, **kwds): '''Instantiate a data tool frame module_name: name of module to instantiate measurements_file_name: name of measurements file ''' assert kwds.has_key("module_name"), "DataToolFrame() needs a module_name argument" assert kwds.has_key("measurements_file_name"), "DataToolFrame() needs a measurements_file_name argument" module_name = kwds["module_name"] measurements_file_name = kwds["measurements_file_name"] kwds_copy = kwds.copy() del kwds_copy["module_name"] del kwds_copy["measurements_file_name"] kwds_copy["title"]="%s data tool"%module_name wx.Frame.__init__(self, *args, **kwds_copy) self.module = instantiate_module(module_name) self.pipeline = cpp.Pipeline() if h5py.is_hdf5(measurements_file_name): self.workspace = cpw.Workspace(self.pipeline, self.module, None, None, None, None) self.workspace.load(measurements_file_name, True) self.measurements = self.workspace.measurements else: self.pipeline.load(measurements_file_name) self.load_measurements(measurements_file_name) self.workspace = cpw.Workspace(self.pipeline, self.module, None, None, self.measurements, None) self.module.module_num = len(self.pipeline.modules())+1 self.pipeline.add_module(self.module) self.sizer = wx.BoxSizer(wx.VERTICAL) module_panel = wx.lib.scrolledpanel.ScrolledPanel(self,-1,style=wx.SUNKEN_BORDER) module_panel.BackgroundColour = cpprefs.get_background_color() self.BackgroundColour = cpprefs.get_background_color() self.module_view = ModuleView(module_panel, self.workspace, True) self.module_view.set_selection(self.module.module_num) def on_change(caller, event): setting = event.get_setting() proposed_value = event.get_proposed_value() setting.value = proposed_value self.pipeline.edit_module(event.get_module().module_num, False) self.module_view.reset_view() self.module_view.add_listener(on_change) # # Add a panel for the "run" button # panel = wx.Panel(self) panel_sizer = wx.BoxSizer(wx.HORIZONTAL) button = wx.Button(panel, label = "Run") self.sizer.Add(module_panel, 1, wx.EXPAND) self.sizer.Add(panel, 0, wx.EXPAND) panel_sizer.AddStretchSpacer() panel_sizer.Add(button, 0, wx.RIGHT, button.Size[1]) panel.SetSizer(panel_sizer) wx.EVT_BUTTON(self, button.Id, self.on_run) # # Add a file menu # file_menu = wx.Menu() file_menu.Append(ID_FILE_LOAD_MEASUREMENTS, "&Load measurements") file_menu.Append(ID_FILE_SAVE_MEASUREMENTS, "&Save measurements") file_menu.Append(ID_FILE_EXIT, "E&xit") self.MenuBar = wx.MenuBar() self.MenuBar.Append(file_menu, "&File") self.Bind(wx.EVT_MENU, self.on_load_measurements, id=ID_FILE_LOAD_MEASUREMENTS) self.Bind(wx.EVT_MENU, self.on_save_measurements, id=ID_FILE_SAVE_MEASUREMENTS) self.Bind(wx.EVT_MENU, self.on_exit, id=ID_FILE_EXIT) accelerators = wx.AcceleratorTable([ (wx.ACCEL_CMD, ord("W"), ID_FILE_EXIT), (wx.ACCEL_CMD, ord("O"), ID_FILE_LOAD_MEASUREMENTS), (wx.ACCEL_CMD, ord("S"), ID_FILE_SAVE_MEASUREMENTS)]) self.SetAcceleratorTable(accelerators) # # Add an image menu # image_menu = wx.Menu() image_menu.Append(ID_IMAGE_CHOOSE, "&Choose") self.MenuBar.Append(image_menu, "&Image") self.Bind(wx.EVT_MENU, self.on_image_choose, id=ID_IMAGE_CHOOSE) self.SetSizer(self.sizer) self.Size = (self.module_view.get_max_width(), self.Size[1]) module_panel.Layout() self.Show() self.tbicon = wx.TaskBarIcon() self.tbicon.SetIcon(get_cp_icon(), "CellProfiler2.0") self.SetIcon(get_cp_icon())
def __init__(self, *args, **kwds): '''Instantiate a data tool frame module_name: name of module to instantiate measurements_file_name: name of measurements file ''' assert kwds.has_key( "module_name"), "DataToolFrame() needs a module_name argument" assert kwds.has_key( "measurements_file_name" ), "DataToolFrame() needs a measurements_file_name argument" module_name = kwds["module_name"] measurements_file_name = kwds["measurements_file_name"] kwds_copy = kwds.copy() del kwds_copy["module_name"] del kwds_copy["measurements_file_name"] kwds_copy["title"] = "%s data tool" % module_name wx.Frame.__init__(self, *args, **kwds_copy) self.module = instantiate_module(module_name) self.module.use_as_data_tool = True self.pipeline = cpp.Pipeline() if h5py.is_hdf5(measurements_file_name): self.workspace = cpw.Workspace(self.pipeline, self.module, None, None, None, None) self.workspace.load(measurements_file_name, True) self.measurements = self.workspace.measurements else: self.pipeline.load(measurements_file_name) self.load_measurements(measurements_file_name) self.workspace = cpw.Workspace(self.pipeline, self.module, None, None, self.measurements, None) self.module.module_num = len(self.pipeline.modules()) + 1 self.pipeline.add_module(self.module) self.sizer = wx.BoxSizer(wx.VERTICAL) module_panel = wx.lib.scrolledpanel.ScrolledPanel( self, -1, style=wx.SUNKEN_BORDER) module_panel.BackgroundColour = cpprefs.get_background_color() self.BackgroundColour = cpprefs.get_background_color() self.module_view = ModuleView(module_panel, self.workspace, True) self.module_view.set_selection(self.module.module_num) def on_change(caller, event): setting = event.get_setting() proposed_value = event.get_proposed_value() setting.value = proposed_value self.pipeline.edit_module(event.get_module().module_num, False) self.module_view.reset_view() self.module_view.request_validation() self.module_view.add_listener(on_change) # # Add a panel for the "run" button # panel = wx.Panel(self) panel_sizer = wx.BoxSizer(wx.HORIZONTAL) button = wx.Button(panel, label="Run") self.sizer.Add(module_panel, 1, wx.EXPAND) self.sizer.Add(panel, 0, wx.EXPAND) panel_sizer.AddStretchSpacer() panel_sizer.Add(button, 0, wx.RIGHT, button.Size[1]) panel.SetSizer(panel_sizer) wx.EVT_BUTTON(self, button.Id, self.on_run) # # Add a file menu # file_menu = wx.Menu() file_menu.Append(ID_FILE_LOAD_MEASUREMENTS, "&Load measurements") file_menu.Append(ID_FILE_SAVE_MEASUREMENTS, "&Save measurements") file_menu.Append(ID_FILE_EXIT, "E&xit") self.MenuBar = wx.MenuBar() self.MenuBar.Append(file_menu, "&File") self.Bind(wx.EVT_MENU, self.on_load_measurements, id=ID_FILE_LOAD_MEASUREMENTS) self.Bind(wx.EVT_MENU, self.on_save_measurements, id=ID_FILE_SAVE_MEASUREMENTS) self.Bind(wx.EVT_MENU, self.on_exit, id=ID_FILE_EXIT) accelerators = wx.AcceleratorTable([ (wx.ACCEL_CMD, ord("W"), ID_FILE_EXIT), (wx.ACCEL_CMD, ord("O"), ID_FILE_LOAD_MEASUREMENTS), (wx.ACCEL_CMD, ord("S"), ID_FILE_SAVE_MEASUREMENTS) ]) self.SetAcceleratorTable(accelerators) # # Add an image menu # image_menu = wx.Menu() image_menu.Append(ID_IMAGE_CHOOSE, "&Choose") self.MenuBar.Append(image_menu, "&Image") self.Bind(wx.EVT_MENU, self.on_image_choose, id=ID_IMAGE_CHOOSE) self.SetSizer(self.sizer) self.Size = (self.module_view.get_max_width(), self.Size[1]) module_panel.Layout() self.Show() self.tbicon = wx.TaskBarIcon() self.tbicon.SetIcon(get_cp_icon(), "CellProfiler2.0") self.SetIcon(get_cp_icon())
def __init__(self, *args, **kwds): if sys.platform.startswith("win"): kwds["style"] = wx.DEFAULT_FRAME_STYLE | wx.STAY_ON_TOP wx.Frame.__init__(self, *args, **kwds) self.Show() if wx.Platform == '__WXMAC__' and hasattr(self, 'MacGetTopLevelWindowRef'): try: from AppKit import NSWindow, NSApp, NSFloatingWindowLevel window_ref = self.MacGetTopLevelWindowRef() nsw = NSWindow.alloc().initWithWindowRef_(window_ref) nsw.setLevel_(NSFloatingWindowLevel) except ImportError: print "No AppKit module => can't make progress window stay on top." self.start_time = time.time() self.end_times = None self.current_module = None self.pause_start_time = None self.previous_pauses_duration = 0. # GUI stuff self.BackgroundColour = cellprofiler.preferences.get_background_color() self.tbicon = wx.TaskBarIcon() self.tbicon.SetIcon(get_cp_icon(), "CellProfiler2.0") self.SetTitle("CellProfiler %s" % (version.title_string)) self.SetSize((640, 480)) self.panel = wx.Panel(self, wx.ID_ANY) sizer = wx.BoxSizer(wx.VERTICAL) times_sizer = wx.BoxSizer(wx.HORIZONTAL) self.elapsed_control = wx.StaticText(self.panel, -1, label=self.elapsed_label(), style=wx.ALIGN_LEFT) self.remaining_control = wx.StaticText(self.panel, -1, label=self.remaining_label(), style=wx.ALIGN_RIGHT) times_sizer.Add(self.elapsed_control, 1, wx.ALIGN_LEFT | wx.ALL, 5) times_sizer.Add(self.remaining_control, 1, wx.ALIGN_RIGHT | wx.ALL, 5) sizer.Add(times_sizer, 0, wx.EXPAND) self.gauge = wx.Gauge(self.panel, -1, style=wx.GA_HORIZONTAL) self.gauge.SetValue(0) self.gauge.SetRange(100) sizer.Add(self.gauge, 0, wx.ALL | wx.EXPAND, 5) self.image_set_control = wx.StaticText(self.panel, -1, label=image_set_label( None, None)) sizer.Add(self.image_set_control, 0, wx.LEFT | wx.RIGHT, 5) self.current_module_control = wx.StaticText(self.panel, -1, label=module_label(None)) sizer.Add(self.current_module_control, 0, wx.LEFT | wx.RIGHT | wx.BOTTOM, 5) buttons_sizer = wx.BoxSizer(wx.HORIZONTAL) self.play_pause_button = wx.BitmapButton( self.panel, -1, bitmap=wx.BitmapFromImage(get_builtin_image('pause'))) self.play_pause_button.SetToolTipString("Pause") buttons_sizer.Add(self.play_pause_button, 0, wx.ALL, 5) self.stop_button = wx.BitmapButton(self.panel, -1, bitmap=wx.BitmapFromImage( get_builtin_image('stop'))) self.stop_button.SetToolTipString("Stop") buttons_sizer.Add(self.stop_button, 0, wx.ALL, 5) save_bitmap = wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE, wx.ART_CMN_DIALOG, (16, 16)) self.save_button = wx.BitmapButton(self.panel, -1, bitmap=save_bitmap) self.save_button.SetToolTipString("Save measurements") buttons_sizer.Add(self.save_button, 0, wx.ALL, 5) sizer.Add(buttons_sizer, 0, wx.CENTER) self.panel.SetSizer(sizer) sizer.Fit(self) # Timer that updates elapsed timer_id = wx.NewId() self.timer = wx.Timer(self.panel, timer_id) self.timer.Start(500) wx.EVT_TIMER(self.panel, timer_id, self.on_timer)