<s> """<STR_LIT>""" <EOL> import cellprofiler . icons <EOL> import cellprofiler . pipeline <EOL> import cellprofiler . preferences <EOL> import cellprofiler . settings <EOL> import cornerbuttonmixin <EOL> import htmldialog <EOL> import logging <EOL> import matplotlib . cm <EOL> import metadatactrl <EOL> import namesubscriber <EOL> import numpy <EOL> import os <EOL> import Queue <EOL> import regexp_editor <EOL> import stat <EOL> import sys <EOL> import threading <EOL> import time <EOL> import treecheckboxdialog <EOL> import uuid <EOL> import weakref <EOL> import wx <EOL> import wx . grid <EOL> import wx . lib . colourselect <EOL> import wx . lib . rcsizer <EOL> import wx . lib . resizewidget <EOL> import wx . lib . scrolledpanel <EOL> logger = logging . getLogger ( __name__ ) <EOL> WARNING_COLOR = wx . Colour ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:255> ) <EOL> RANGE_TEXT_WIDTH = <NUM_LIT> <EOL> ABSOLUTE = "<STR_LIT>" <EOL> FROM_EDGE = "<STR_LIT>" <EOL> CHECK_TIMEOUT_SEC = <NUM_LIT:2> <EOL> EDIT_TIMEOUT_SEC = <NUM_LIT:5> <EOL> PRI_VALIDATE_DISPLAY = <NUM_LIT:0> <EOL> PRI_VALIDATE_BACKGROUND = <NUM_LIT:1> <EOL> class SettingEditedEvent ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , setting , module , proposed_value , event ) : <EOL> self . __module = module <EOL> self . __setting = setting <EOL> self . __proposed_value = proposed_value <EOL> self . __event = event <EOL> self . __accept_change = True <EOL> def get_setting ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . __setting <EOL> def get_proposed_value ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . __proposed_value <EOL> def get_module ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . __module <EOL> def cancel ( self ) : <EOL> self . __accept_change = False <EOL> def accept_change ( self ) : <EOL> return self . __accept_change <EOL> def ui_event ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . __event <EOL> def text_control_name ( v ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" % ( str ( v . key ( ) ) ) <EOL> def button_control_name ( v , idx = None ) : <EOL> """<STR_LIT>""" <EOL> if idx is None : <EOL> return "<STR_LIT>" % ( str ( v . key ( ) ) ) <EOL> else : <EOL> return "<STR_LIT>" % ( str ( v . key ( ) ) , idx ) <EOL> def edit_control_name ( v ) : <EOL> """<STR_LIT>""" <EOL> return str ( v . key ( ) ) <EOL> def min_control_name ( v ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" % ( str ( v . key ( ) ) ) <EOL> def max_control_name ( v ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" % ( str ( v . key ( ) ) ) <EOL> def absrel_control_name ( v ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" % ( str ( v . key ( ) ) ) <EOL> def x_control_name ( v ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" % ( str ( v . key ( ) ) ) <EOL> def y_control_name ( v ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" % ( str ( v . key ( ) ) ) <EOL> def category_control_name ( v ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" % ( str ( v . key ( ) ) ) <EOL> def category_text_control_name ( v ) : <EOL> return "<STR_LIT>" % ( str ( v . key ( ) ) ) <EOL> def feature_control_name ( v ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" % ( str ( v . key ( ) ) ) <EOL> def feature_text_control_name ( v ) : <EOL> return "<STR_LIT>" % ( str ( v . key ( ) ) ) <EOL> def image_control_name ( v ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" % ( str ( v . key ( ) ) ) <EOL> def image_text_control_name ( v ) : <EOL> return "<STR_LIT>" % ( str ( v . key ( ) ) ) <EOL> def object_control_name ( v ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" % ( str ( v . key ( ) ) ) <EOL> def object_text_control_name ( v ) : <EOL> return "<STR_LIT>" % ( str ( v . key ( ) ) ) <EOL> def scale_control_name ( v ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" % ( str ( v . key ( ) ) ) <EOL> def scale_text_ctrl_name ( v ) : <EOL> return "<STR_LIT>" % ( str ( v . key ( ) ) ) <EOL> def combobox_ctrl_name ( v ) : <EOL> return "<STR_LIT>" % ( str ( v . key ( ) ) ) <EOL> def colorbar_ctrl_name ( v ) : <EOL> return "<STR_LIT>" % ( str ( v . key ( ) ) ) <EOL> def help_ctrl_name ( v ) : <EOL> return "<STR_LIT>" % str ( v . key ( ) ) <EOL> def subedit_control_name ( v ) : <EOL> return "<STR_LIT>" % str ( v . key ( ) ) <EOL> def grid_control_name ( v ) : <EOL> return "<STR_LIT>" % str ( v . key ( ) ) <EOL> def custom_label_name ( v ) : <EOL> return "<STR_LIT>" % str ( v . key ( ) ) <EOL> def folder_label_name ( v ) : <EOL> return "<STR_LIT>" % str ( v . key ( ) ) <EOL> def encode_label ( text ) : <EOL> """<STR_LIT>""" <EOL> return text . replace ( '<STR_LIT:&>' , '<STR_LIT>' ) <EOL> class ModuleView ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , top_panel , <EOL> workspace , <EOL> as_datatool = False , <EOL> frame = None , <EOL> notes_panel = None ) : <EOL> """<STR_LIT>""" <EOL> pipeline = workspace . pipeline <EOL> self . __workspace = workspace <EOL> self . __module = None <EOL> self . refresh_pending = False <EOL> self . notes_panel = notes_panel <EOL> self . __frame = frame <EOL> self . top_panel = top_panel <EOL> background_color = cellprofiler . preferences . get_background_color ( ) <EOL> top_panel . Sizer = wx . BoxSizer ( ) <EOL> self . module_settings_box = wx . StaticBox ( <EOL> top_panel , label = self . get_module_settings_label ( ) ) <EOL> module_settings_box_sizer = wx . StaticBoxSizer ( self . module_settings_box ) <EOL> top_panel . Sizer . Add ( module_settings_box_sizer , <NUM_LIT:1> , wx . EXPAND ) <EOL> self . __module_panel = wx . lib . scrolledpanel . ScrolledPanel ( top_panel ) <EOL> self . __module_panel . SetupScrolling ( ) <EOL> module_settings_box_sizer . Add ( self . __module_panel , <NUM_LIT:1> , wx . EXPAND ) <EOL> self . __sizer = ModuleSizer ( <NUM_LIT:0> , <NUM_LIT:3> ) <EOL> self . module_panel . Sizer = self . __sizer <EOL> self . module_panel . Bind ( wx . EVT_CHILD_FOCUS , self . skip_event ) <EOL> if notes_panel is not None : <EOL> self . make_notes_gui ( ) <EOL> self . __pipeline = pipeline <EOL> self . __as_datatool = as_datatool <EOL> self . __listeners = [ ] <EOL> self . __value_listeners = [ ] <EOL> self . __inside_notify = False <EOL> self . __handle_change = True <EOL> self . __notes_text = None <EOL> self . __started = False <EOL> self . __validation_request = None <EOL> def start ( self ) : <EOL> """<STR_LIT>""" <EOL> self . __pipeline . add_listener ( self . __on_pipeline_event ) <EOL> self . __workspace . add_notification_callback ( <EOL> self . __on_workspace_event ) <EOL> self . __started = True <EOL> @ staticmethod <EOL> def skip_event ( event ) : <EOL> event . Skip ( False ) <EOL> def get_module_panel ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . __module_panel <EOL> module_panel = property ( get_module_panel ) <EOL> def get_current_module ( self ) : <EOL> return self . __module <EOL> def clear_selection ( self ) : <EOL> if self . __module : <EOL> for listener in self . __value_listeners : <EOL> listener [ '<STR_LIT>' ] . remove_listener ( listener [ '<STR_LIT>' ] ) <EOL> self . __value_listeners = [ ] <EOL> self . __module = None <EOL> self . __sizer . Reset ( <NUM_LIT:0> ) <EOL> if self . notes_panel is not None : <EOL> self . notes_panel . Hide ( ) <EOL> self . module_settings_box . Label = self . get_module_settings_label ( ) <EOL> def get_module_settings_label ( self ) : <EOL> if self . __module is None : <EOL> return "<STR_LIT>" <EOL> return "<STR_LIT>" % ( <EOL> self . __module . module_name , self . __module . module_num ) <EOL> def hide_settings ( self ) : <EOL> for child in self . __module_panel . Children : <EOL> child . Hide ( ) <EOL> def check_settings ( self , module_name , settings ) : <EOL> try : <EOL> assert len ( settings ) > <NUM_LIT:0> <EOL> except : <EOL> wx . MessageBox ( "<STR_LIT>" % ( module_name , settings ) , <EOL> "<STR_LIT>" , wx . ICON_ERROR , self . __module_panel ) <EOL> settings = [ ] <EOL> try : <EOL> assert all ( [ isinstance ( s , cellprofiler . settings . Setting ) for s in settings ] ) <EOL> except : <EOL> wx . MessageBox ( <EOL> "<STR_LIT>" % ( <EOL> module_name , settings ) , <EOL> "<STR_LIT>" , wx . ICON_ERROR , self . __module_panel ) <EOL> settings = [ ] <EOL> return settings <EOL> DO_FREEZE = wx . VERSION < ( <NUM_LIT:2> , <NUM_LIT:9> , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> def set_selection ( self , module_num ) : <EOL> """<STR_LIT>""" <EOL> if self . DO_FREEZE : <EOL> self . module_panel . Freeze ( ) <EOL> self . __handle_change = False <EOL> imageset_control = None <EOL> path_control = None <EOL> table_control = None <EOL> try : <EOL> new_module = self . __pipeline . module ( module_num ) <EOL> reselecting = ( self . __module and <EOL> self . __module . id == new_module . id ) <EOL> if not reselecting : <EOL> if self . __module is not None : <EOL> self . __module . on_deactivated ( ) <EOL> self . module_settings_box . Label = self . get_module_settings_label ( ) <EOL> self . clear_selection ( ) <EOL> self . request_validation ( new_module ) <EOL> try : <EOL> new_module . test_valid ( self . __pipeline ) <EOL> except : <EOL> pass <EOL> self . __module = new_module <EOL> self . __controls = [ ] <EOL> self . __static_texts = [ ] <EOL> data = [ ] <EOL> if reselecting : <EOL> self . hide_settings ( ) <EOL> else : <EOL> self . __module . on_activated ( self . __workspace ) <EOL> if self . notes_panel is not None : <EOL> self . notes_panel . Show ( True ) <EOL> settings = self . check_settings ( self . __module . module_name , <EOL> self . __module . visible_settings ( ) ) <EOL> self . __sizer . Reset ( len ( settings ) , <NUM_LIT:3> , False ) <EOL> sizer = self . __sizer <EOL> if self . notes_panel is not None : <EOL> self . module_notes_control . Value = u"<STR_LIT:\n>" . join ( <EOL> [ _ . decode ( "<STR_LIT:utf-8>" ) for _ in self . __module . notes ] ) <EOL> for i , v in enumerate ( settings ) : <EOL> if isinstance ( v , cellprofiler . settings . PathListDisplay ) : <EOL> path_control = v <EOL> self . __frame . pipeline_controller . set_path_list_filtering ( v . using_filter ) <EOL> continue <EOL> if isinstance ( v , cellprofiler . settings . ImageSetDisplay ) : <EOL> v . on_event_fired = self . __frame . reset_imageset_ctrl <EOL> imageset_control = v <EOL> continue <EOL> flag = wx . EXPAND <EOL> border = <NUM_LIT:0> <EOL> control_name = edit_control_name ( v ) <EOL> text_name = text_control_name ( v ) <EOL> static_text = self . __module_panel . FindWindowByName ( text_name ) <EOL> control = self . __module_panel . FindWindowByName ( control_name ) <EOL> if static_text : <EOL> static_text . Show ( ) <EOL> static_text . Label = encode_label ( v . text ) <EOL> else : <EOL> static_text = wx . StaticText ( self . __module_panel , <EOL> - <NUM_LIT:1> , <EOL> encode_label ( v . text ) , <EOL> style = wx . ALIGN_RIGHT , <EOL> name = text_name ) <EOL> text_sizer_item = sizer . Add ( static_text , <NUM_LIT:3> , wx . EXPAND | wx . ALL , <NUM_LIT:2> ) <EOL> if control : <EOL> control . Show ( ) <EOL> self . __static_texts . append ( static_text ) <EOL> if isinstance ( v , cellprofiler . settings . Binary ) : <EOL> control = self . make_binary_control ( v , control_name , control ) <EOL> flag = wx . ALIGN_LEFT <EOL> text_sizer_item . Flag = wx . ALIGN_RIGHT | wx . ALIGN_CENTER_VERTICAL | wx . ALL <EOL> elif isinstance ( v , cellprofiler . settings . MeasurementMultiChoice ) : <EOL> control = self . make_measurement_multichoice_control ( <EOL> v , control_name , control ) <EOL> elif isinstance ( v , cellprofiler . settings . SubdirectoryFilter ) : <EOL> control = self . make_subdirectory_filter_control ( <EOL> v , control_name , control ) <EOL> elif isinstance ( v , cellprofiler . settings . MultiChoice ) : <EOL> control = self . make_multichoice_control ( v , control_name , <EOL> control ) <EOL> elif isinstance ( v , cellprofiler . settings . CustomChoice ) : <EOL> control = self . make_choice_control ( v , v . get_choices ( ) , <EOL> control_name , <EOL> wx . CB_DROPDOWN , <EOL> control ) <EOL> elif isinstance ( v , cellprofiler . settings . Colormap ) : <EOL> control = self . make_colormap_control ( v , control_name , <EOL> control ) <EOL> elif isinstance ( v , cellprofiler . settings . Choice ) : <EOL> control = self . make_choice_control ( v , v . get_choices ( ) , <EOL> control_name , <EOL> wx . CB_READONLY , <EOL> control ) <EOL> flag = wx . ALIGN_LEFT <EOL> elif isinstance ( v , cellprofiler . settings . NameSubscriber ) : <EOL> choices = v . get_choices ( self . __pipeline ) <EOL> control = self . make_name_subscriber_control ( v , choices , <EOL> control_name , <EOL> control ) <EOL> flag = wx . ALIGN_LEFT <EOL> elif isinstance ( v , cellprofiler . settings . FigureSubscriber ) : <EOL> choices = v . get_choices ( self . __pipeline ) <EOL> control = self . make_choice_control ( v , choices , <EOL> control_name , <EOL> wx . CB_DROPDOWN , <EOL> control ) <EOL> flag = wx . ALIGN_LEFT <EOL> elif isinstance ( v , cellprofiler . settings . DoSomething ) : <EOL> if ( isinstance ( v , cellprofiler . settings . PathListRefreshButton ) and <EOL> v . callback is None ) : <EOL> v . callback = self . __frame . pipeline_controller . on_update_pathlist <EOL> control = self . make_callback_control ( v , control_name , <EOL> control ) <EOL> flag = wx . ALIGN_LEFT <EOL> elif isinstance ( v , cellprofiler . settings . DoThings ) : <EOL> control = self . make_callback_controls ( <EOL> v , control_name , control ) <EOL> elif isinstance ( v , <EOL> cellprofiler . settings . IntegerOrUnboundedRange ) : <EOL> control = self . make_unbounded_range_control ( v , control ) <EOL> elif isinstance ( v , cellprofiler . settings . IntegerRange ) or isinstance ( v , cellprofiler . settings . FloatRange ) : <EOL> control = self . make_range_control ( v , control ) <EOL> elif isinstance ( v , cellprofiler . settings . Coordinates ) : <EOL> control = self . make_coordinates_control ( v , control ) <EOL> elif isinstance ( v , cellprofiler . settings . RegexpText ) : <EOL> control = self . make_regexp_control ( v , control ) <EOL> elif isinstance ( v , cellprofiler . settings . Measurement ) : <EOL> control = self . make_measurement_control ( v , control ) <EOL> elif isinstance ( v , cellprofiler . settings . Divider ) : <EOL> if control is None : <EOL> if v . line : <EOL> control = wx . StaticLine ( self . __module_panel , <EOL> name = control_name ) <EOL> else : <EOL> control = wx . StaticText ( self . __module_panel , <EOL> name = control_name ) <EOL> flag = wx . EXPAND | wx . ALL <EOL> border = <NUM_LIT:2> <EOL> elif isinstance ( v , cellprofiler . settings . FilenameText ) : <EOL> control = self . make_filename_text_control ( v , control ) <EOL> elif isinstance ( v , cellprofiler . settings . DirectoryPath ) : <EOL> control = self . make_directory_path_control ( v , control_name , <EOL> control ) <EOL> elif isinstance ( v , cellprofiler . settings . Pathname ) : <EOL> control = self . make_pathname_control ( v , control ) <EOL> elif isinstance ( v , cellprofiler . settings . ImagePlane ) : <EOL> control = self . make_image_plane_control ( v , control ) <EOL> elif isinstance ( v , cellprofiler . settings . Color ) : <EOL> control = self . make_color_control ( v , control_name , control ) <EOL> elif isinstance ( v , cellprofiler . settings . TreeChoice ) : <EOL> control = self . make_tree_choice_control ( v , control_name , control ) <EOL> flag = wx . ALIGN_LEFT <EOL> elif isinstance ( v , cellprofiler . settings . Filter ) : <EOL> if control is not None : <EOL> control . filter_panel_controller . update ( ) <EOL> else : <EOL> fc = FilterPanelController ( self , v , control ) <EOL> control = fc . panel <EOL> control . filter_panel_controller = fc <EOL> elif isinstance ( v , cellprofiler . settings . FileCollectionDisplay ) : <EOL> if control is not None : <EOL> pass <EOL> else : <EOL> fcd = FileCollectionDisplayController ( <EOL> self , v , self . __pipeline ) <EOL> control = fcd . panel <EOL> fcd . panel . file_collection_display = fcd <EOL> elif isinstance ( v , cellprofiler . settings . Table ) : <EOL> if v . use_sash : <EOL> table_control = v <EOL> grid = self . __frame . get_grid_ctrl ( ) <EOL> table = grid . GetTable ( ) <EOL> if isinstance ( table , TableController ) and table . v is v : <EOL> table . update_grid ( ) <EOL> self . __frame . show_grid_ctrl ( ) <EOL> continue <EOL> else : <EOL> table = TableController ( v ) <EOL> table . bind_to_grid ( grid ) <EOL> self . __frame . show_grid_ctrl ( table ) <EOL> continue <EOL> control = self . make_table_control ( v , control ) <EOL> flag = wx . EXPAND <EOL> elif isinstance ( v , cellprofiler . settings . HTMLText ) : <EOL> control = self . make_html_control ( v , control ) <EOL> flag = wx . EXPAND | wx . ALL <EOL> elif isinstance ( v , cellprofiler . settings . Joiner ) : <EOL> control = JoinerController . update_control ( self , v ) <EOL> flag = wx . ALIGN_LEFT <EOL> elif isinstance ( v , cellprofiler . settings . BinaryMatrix ) : <EOL> control = BinaryMatrixController . update_control ( self , v ) <EOL> flag = wx . ALIGN_LEFT <EOL> elif isinstance ( v , cellprofiler . settings . DataTypes ) : <EOL> control = DataTypeController . update_control ( self , v ) <EOL> flag = wx . ALIGN_LEFT <EOL> else : <EOL> control = self . make_text_control ( v , control_name , control ) <EOL> sizer . Add ( control , <NUM_LIT:0> , flag , border ) <EOL> self . __controls . append ( control ) <EOL> help_name = help_ctrl_name ( v ) <EOL> help_control = self . module_panel . FindWindowByName ( help_name ) <EOL> if help_control is None : <EOL> if v . doc is None : <EOL> help_control = wx . StaticText ( self . __module_panel , <EOL> - <NUM_LIT:1> , "<STR_LIT>" , <EOL> name = help_name ) <EOL> else : <EOL> help_control = self . make_help_control ( v . doc , v . text , <EOL> name = help_name ) <EOL> else : <EOL> help_control . Show ( ) <EOL> sizer . Add ( help_control , <NUM_LIT:0> , wx . LEFT , <NUM_LIT:2> ) <EOL> finally : <EOL> self . __handle_change = True <EOL> if self . __as_datatool : <EOL> self . module_panel . Layout ( ) <EOL> if self . DO_FREEZE : <EOL> self . module_panel . Thaw ( ) <EOL> elif self . __frame is not None : <EOL> if self . __started : <EOL> self . __frame . show_module_ui ( True ) <EOL> if imageset_control is not None : <EOL> self . __frame . show_imageset_ctrl ( ) <EOL> self . __frame . reset_imageset_ctrl ( refresh_image_set = False ) <EOL> elif table_control is None : <EOL> self . __frame . show_imageset_sash ( False ) <EOL> self . __frame . show_path_list_ctrl ( path_control is not None ) <EOL> self . __frame . layout_pmi_panel ( ) <EOL> self . top_panel . Layout ( ) <EOL> self . module_panel . FitInside ( ) <EOL> if self . DO_FREEZE : <EOL> self . module_panel . Thaw ( ) <EOL> else : <EOL> if self . DO_FREEZE : <EOL> self . module_panel . Thaw ( ) <EOL> def make_notes_gui ( self ) : <EOL> """<STR_LIT>""" <EOL> notes_sizer = wx . StaticBoxSizer ( <EOL> wx . StaticBox ( self . notes_panel , - <NUM_LIT:1> , "<STR_LIT>" ) , <EOL> wx . VERTICAL ) <EOL> self . notes_panel . SetSizer ( notes_sizer ) <EOL> self . module_notes_control = wx . TextCtrl ( <EOL> self . notes_panel , - <NUM_LIT:1> , style = wx . TE_MULTILINE | wx . TE_PROCESS_ENTER ) <EOL> height = self . module_notes_control . GetTextExtent ( "<STR_LIT:M>" ) [ <NUM_LIT:1> ] * <NUM_LIT:2> + <NUM_LIT:4> <EOL> height = self . module_notes_control . ClientToWindowSize ( <EOL> wx . Size ( <NUM_LIT:1> , height ) ) [ <NUM_LIT:1> ] <EOL> self . module_notes_control . SetInitialSize ( wx . Size ( <NUM_LIT:100> , height ) ) <EOL> notes_sizer . Add ( self . module_notes_control , <NUM_LIT:1> , wx . EXPAND ) <EOL> def on_notes_changed ( event ) : <EOL> if not self . __handle_change : <EOL> return <EOL> if self . __module is not None : <EOL> notes = self . module_notes_control . Value . encode ( '<STR_LIT:utf-8>' ) <EOL> self . __module . notes = notes . split ( '<STR_LIT:\n>' ) <EOL> self . notes_panel . Bind ( wx . EVT_TEXT , on_notes_changed , <EOL> self . module_notes_control ) <EOL> def make_binary_control ( self , v , control_name , control ) : <EOL> """<STR_LIT>""" <EOL> if not control : <EOL> control = wx . RadioBox ( <EOL> self . __module_panel , <EOL> choices = [ cellprofiler . settings . YES , cellprofiler . settings . NO ] , <EOL> name = control_name ) <EOL> def callback ( event , setting = v , control = control ) : <EOL> self . __on_radiobox_change ( event , setting , control ) <EOL> control . Bind ( wx . EVT_RADIOBOX , callback ) <EOL> current_selection = control . GetStringSelection ( ) <EOL> if current_selection != v . value_text : <EOL> control . SetStringSelection ( v . value_text ) <EOL> return control <EOL> def make_name_subscriber_control ( self , v , choices , control_name , control ) : <EOL> """<STR_LIT>""" <EOL> if v . value not in [ c [ <NUM_LIT:0> ] for c in choices ] : <EOL> choices = choices + [ ( v . value , "<STR_LIT>" , <NUM_LIT:0> , False ) ] <EOL> if not control : <EOL> control = namesubscriber . NameSubscriberComboBox ( self . __module_panel , <EOL> value = v . value , <EOL> choices = choices , <EOL> name = control_name ) <EOL> def callback ( event , setting = v , control = control ) : <EOL> self . __on_combobox_change ( event , setting , control ) <EOL> control . add_callback ( callback ) <EOL> else : <EOL> if list ( choices ) != list ( control . Items ) : <EOL> control . Items = choices <EOL> if ( getattr ( v , '<STR_LIT>' , False ) and <EOL> v . has_tooltips and ( control . Value in v . tooltips ) ) : <EOL> control . SetToolTip ( wx . ToolTip ( v . tooltips [ control . Value ] ) ) <EOL> return control <EOL> def make_choice_control ( self , v , choices , control_name , style , control ) : <EOL> """<STR_LIT>""" <EOL> assert isinstance ( v , ( cellprofiler . settings . Choice , cellprofiler . settings . FigureSubscriber ) ) <EOL> try : <EOL> v . test_valid ( self . __pipeline ) <EOL> except : <EOL> pass <EOL> if v . value not in choices and style == wx . CB_READONLY : <EOL> choices = choices + [ v . value ] <EOL> if not control : <EOL> control = wx . ComboBox ( self . __module_panel , - <NUM_LIT:1> , v . value , <EOL> choices = choices , <EOL> style = style , <EOL> name = control_name ) <EOL> def callback ( event , setting = v , control = control ) : <EOL> self . __on_combobox_change ( event , setting , control ) <EOL> self . __module_panel . Bind ( wx . EVT_COMBOBOX , callback , control ) <EOL> if style == wx . CB_DROPDOWN : <EOL> def on_cell_change ( event , setting = v , control = control ) : <EOL> self . __on_cell_change ( event , setting , control ) <EOL> self . __module_panel . Bind ( wx . EVT_TEXT , on_cell_change , control ) <EOL> else : <EOL> old_choices = control . Items <EOL> if len ( choices ) != len ( old_choices ) or not all ( [ x == y for x , y in zip ( choices , old_choices ) ] ) : <EOL> if v . value in old_choices : <EOL> control . Value = v . value <EOL> control . Items = choices <EOL> try : <EOL> i_am_different = ( control . Value != v . value ) <EOL> except : <EOL> i_am_different = True <EOL> if len ( choices ) > <NUM_LIT:0> and i_am_different : <EOL> control . Value = v . value <EOL> if ( getattr ( v , '<STR_LIT>' , False ) and <EOL> v . has_tooltips and v . tooltips . has_key ( control . Value ) ) : <EOL> control . SetToolTip ( wx . ToolTip ( v . tooltips [ control . Value ] ) ) <EOL> return control <EOL> def make_measurement_multichoice_control ( self , v , control_name , control ) : <EOL> """<STR_LIT>""" <EOL> if control is None : <EOL> control = wx . Button ( self . module_panel , - <NUM_LIT:1> , <EOL> "<STR_LIT>" ) <EOL> def on_press ( event ) : <EOL> d = { } <EOL> assert isinstance ( v , cellprofiler . settings . MeasurementMultiChoice ) <EOL> if len ( v . choices ) == <NUM_LIT:0> : <EOL> v . populate_choices ( self . __pipeline ) <EOL> choices = set ( v . choices ) <EOL> for choice in choices : <EOL> object_name , feature = v . split_choice ( choice ) <EOL> pieces = [ object_name ] + feature . split ( '<STR_LIT:_>' ) <EOL> d1 = d <EOL> for piece in pieces : <EOL> if not d1 . has_key ( piece ) : <EOL> d1 [ piece ] = { } <EOL> d1 [ None ] = <NUM_LIT:0> <EOL> d1 = d1 [ piece ] <EOL> d1 [ None ] = False <EOL> for selection in v . selections : <EOL> if selection not in choices : <EOL> continue <EOL> object_name , feature = v . split_choice ( selection ) <EOL> pieces = [ object_name ] + feature . split ( '<STR_LIT:_>' ) <EOL> d1 = d <EOL> for piece in pieces : <EOL> if not d1 . has_key ( piece ) : <EOL> break <EOL> d1 = d1 [ piece ] <EOL> d1 [ None ] = True <EOL> def get_state ( d ) : <EOL> leaf_state = d [ None ] <EOL> for subtree_key in [ x for x in d . keys ( ) if x is not None ] : <EOL> subtree_state = get_state ( d [ subtree_key ] ) <EOL> if leaf_state is <NUM_LIT:0> : <EOL> leaf_state = subtree_state <EOL> elif leaf_state != subtree_state : <EOL> leaf_state = None <EOL> d [ None ] = leaf_state <EOL> return leaf_state <EOL> get_state ( d ) <EOL> dlg = treecheckboxdialog . TreeCheckboxDialog ( self . module_panel , d , size = ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> dlg . Title = "<STR_LIT>" <EOL> if dlg . ShowModal ( ) == wx . ID_OK : <EOL> def collect_state ( object_name , prefix , d ) : <EOL> if d [ None ] is False : <EOL> return [ ] <EOL> result = [ ] <EOL> if d [ None ] is True and prefix is not None : <EOL> name = v . make_measurement_choice ( object_name , prefix ) <EOL> if name in choices : <EOL> result . append ( name ) <EOL> for key in [ x for x in d . keys ( ) if x is not None ] : <EOL> if prefix is None : <EOL> sub_prefix = key <EOL> else : <EOL> sub_prefix = '<STR_LIT:_>' . join ( ( prefix , key ) ) <EOL> result += collect_state ( object_name , sub_prefix , <EOL> d [ key ] ) <EOL> return result <EOL> selections = [ ] <EOL> for object_name in [ x for x in d . keys ( ) if x is not None ] : <EOL> selections += collect_state ( object_name , None , <EOL> d [ object_name ] ) <EOL> proposed_value = v . get_value_string ( selections ) <EOL> setting_edited_event = SettingEditedEvent ( v , self . __module , <EOL> proposed_value , <EOL> event ) <EOL> self . notify ( setting_edited_event ) <EOL> self . reset_view ( ) <EOL> control . Bind ( wx . EVT_BUTTON , on_press ) <EOL> else : <EOL> control . Show ( ) <EOL> return control <EOL> def make_subdirectory_filter_control ( self , v , control_name , control ) : <EOL> if control is None : <EOL> control = wx . Button ( self . module_panel , - <NUM_LIT:1> , <EOL> "<STR_LIT>" ) <EOL> def on_press ( event ) : <EOL> assert isinstance ( v , cellprofiler . settings . SubdirectoryFilter ) <EOL> root = v . directory_path . get_absolute_path ( ) <EOL> self . module_panel . SetCursor ( wx . StockCursor ( wx . CURSOR_WAIT ) ) <EOL> try : <EOL> def fn_populate ( root ) : <EOL> d = { None : True } <EOL> try : <EOL> for dirname in os . listdir ( root ) : <EOL> dirpath = os . path . join ( root , dirname ) <EOL> dirstat = os . stat ( dirpath ) <EOL> if not stat . S_ISDIR ( dirstat . st_mode ) : <EOL> continue <EOL> if stat . S_ISLNK ( dirstat . st_mode ) : <EOL> continue <EOL> if ( stat . S_IREAD & dirstat . st_mode ) == <NUM_LIT:0> : <EOL> continue <EOL> d [ dirname ] = lambda dirpath = dirpath : fn_populate ( dirpath ) <EOL> except : <EOL> print "<STR_LIT>" % root <EOL> return d <EOL> d = fn_populate ( root ) <EOL> selections = v . get_selections ( ) <EOL> def populate_selection ( d , selection , root ) : <EOL> s0 = selection [ <NUM_LIT:0> ] <EOL> if not d . has_key ( s0 ) : <EOL> d [ s0 ] = fn_populate ( os . path . join ( root , s0 ) ) <EOL> elif hasattr ( d [ s0 ] , "<STR_LIT>" ) : <EOL> d [ s0 ] = d [ s0 ] ( ) <EOL> if len ( selection ) == <NUM_LIT:1> : <EOL> d [ s0 ] [ None ] = False <EOL> else : <EOL> if d [ s0 ] [ None ] is not False : <EOL> populate_selection ( d [ s0 ] , selection [ <NUM_LIT:1> : ] , <EOL> os . path . join ( root , s0 ) ) <EOL> if d [ s0 ] [ None ] is False : <EOL> d [ None ] = None <EOL> def split_all ( x ) : <EOL> head , tail = os . path . split ( x ) <EOL> if ( len ( head ) == <NUM_LIT:0> ) or ( len ( tail ) == <NUM_LIT:0> ) : <EOL> return [ x ] <EOL> else : <EOL> return split_all ( head ) + [ tail ] <EOL> for selection in selections : <EOL> selection_parts = split_all ( selection ) <EOL> populate_selection ( d , selection_parts , root ) <EOL> finally : <EOL> self . module_panel . SetCursor ( wx . NullCursor ) <EOL> dlg = treecheckboxdialog . TreeCheckboxDialog ( self . module_panel , d , size = ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> dlg . set_parent_reflects_child ( False ) <EOL> dlg . Title = "<STR_LIT>" <EOL> if dlg . ShowModal ( ) == wx . ID_OK : <EOL> def collect_state ( prefix , d ) : <EOL> if d is None : <EOL> return [ ] <EOL> if hasattr ( d , "<STR_LIT>" ) or d [ None ] : <EOL> return [ ] <EOL> elif d [ None ] is False : <EOL> return [ prefix ] <EOL> result = [ ] <EOL> for key in d . keys ( ) : <EOL> if key is None : <EOL> continue <EOL> result += collect_state ( os . path . join ( prefix , key ) , <EOL> d [ key ] ) <EOL> return result <EOL> selections = [ ] <EOL> for object_name in [ x for x in d . keys ( ) if x is not None ] : <EOL> selections += collect_state ( object_name , d [ object_name ] ) <EOL> proposed_value = v . get_value_string ( selections ) <EOL> setting_edited_event = SettingEditedEvent ( v , self . __module , <EOL> proposed_value , <EOL> event ) <EOL> self . notify ( setting_edited_event ) <EOL> self . reset_view ( ) <EOL> control . Bind ( wx . EVT_BUTTON , on_press ) <EOL> else : <EOL> control . Show ( ) <EOL> return control <EOL> def make_multichoice_control ( self , v , control_name , control ) : <EOL> selections = v . selections <EOL> assert isinstance ( v , cellprofiler . settings . MultiChoice ) <EOL> if isinstance ( v , cellprofiler . settings . SubscriberMultiChoice ) : <EOL> v . load_choices ( self . __pipeline ) <EOL> choices = v . choices + [ selection for selection in selections <EOL> if selection not in v . choices ] <EOL> if not control : <EOL> control = wx . ListBox ( self . __module_panel , - <NUM_LIT:1> , choices = choices , <EOL> style = wx . LB_EXTENDED , <EOL> name = control_name ) <EOL> for selection in selections : <EOL> index = choices . index ( selection ) <EOL> control . SetSelection ( index ) <EOL> if selection not in v . choices : <EOL> control . SetItemForegroundColour ( <EOL> index , cellprofiler . preferences . get_error_color ( ) ) <EOL> def callback ( event , setting = v , control = control ) : <EOL> self . __on_multichoice_change ( event , setting , control ) <EOL> self . __module_panel . Bind ( wx . EVT_LISTBOX , callback , control ) <EOL> else : <EOL> old_choices = control . Items <EOL> if ( len ( choices ) != len ( old_choices ) or <EOL> not all ( [ x == y for x , y in zip ( choices , old_choices ) ] ) ) : <EOL> control . Items = choices <EOL> for i in range ( len ( choices ) ) : <EOL> if control . IsSelected ( i ) : <EOL> if choices [ i ] not in selections : <EOL> control . Deselect ( i ) <EOL> elif choices [ i ] in selections : <EOL> control . Select ( i ) <EOL> if choices [ i ] not in v . choices : <EOL> control . SetItemForegroundColour ( <EOL> i , cellprofiler . preferences . get_error_color ( ) ) <EOL> return control <EOL> def make_colormap_control ( self , v , control_name , control ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> if v . value == cellprofiler . settings . DEFAULT : <EOL> cmap_name = cellprofiler . preferences . get_default_colormap ( ) <EOL> else : <EOL> cmap_name = v . value <EOL> cm = matplotlib . cm . get_cmap ( cmap_name ) <EOL> sm = matplotlib . cm . ScalarMappable ( cmap = cm ) <EOL> i , j = numpy . mgrid [ <NUM_LIT:0> : <NUM_LIT:12> , <NUM_LIT:0> : <NUM_LIT> ] <EOL> if cm . N < <NUM_LIT> : <EOL> j *= int ( ( cm . N + <NUM_LIT> ) / <NUM_LIT> ) <EOL> image = ( sm . to_rgba ( j ) * <NUM_LIT:255> ) . astype ( numpy . uint8 ) <EOL> bitmap = wx . BitmapFromBufferRGBA ( <NUM_LIT> , <NUM_LIT:12> , image . tostring ( ) ) <EOL> except : <EOL> logger . warning ( "<STR_LIT>" % cmap_name ) <EOL> bitmap = None <EOL> if not control : <EOL> control = wx . Panel ( self . __module_panel , - <NUM_LIT:1> , <EOL> name = control_name ) <EOL> sizer = wx . BoxSizer ( wx . VERTICAL ) <EOL> control . SetSizer ( sizer ) <EOL> colorbar = wx . StaticBitmap ( control , - <NUM_LIT:1> , <EOL> name = colorbar_ctrl_name ( v ) ) <EOL> if not bitmap is None : <EOL> colorbar . SetBitmap ( bitmap ) <EOL> sizer . Add ( colorbar , <NUM_LIT:0> , wx . EXPAND | wx . BOTTOM , <NUM_LIT:2> ) <EOL> combo = wx . ComboBox ( control , - <NUM_LIT:1> , v . value , <EOL> choices = v . choices , <EOL> style = wx . CB_READONLY , <EOL> name = combobox_ctrl_name ( v ) ) <EOL> sizer . Add ( combo , <NUM_LIT:1> , wx . EXPAND ) <EOL> def callback ( event , setting = v , control = combo ) : <EOL> self . __on_combobox_change ( event , setting , combo ) <EOL> self . __module_panel . Bind ( wx . EVT_COMBOBOX , callback , combo ) <EOL> else : <EOL> combo = control . FindWindowByName ( combobox_ctrl_name ( v ) ) <EOL> colorbar = control . FindWindowByName ( colorbar_ctrl_name ( v ) ) <EOL> old_choices = combo . Items <EOL> if len ( v . choices ) != len ( old_choices ) or not all ( [ x == y for x , y in zip ( v . choices , old_choices ) ] ) : <EOL> combo . Items = v . choices <EOL> if combo . Value != v . value : <EOL> combo . Value = v . value <EOL> if not bitmap is None : <EOL> colorbar . SetBitmap ( bitmap ) <EOL> return control <EOL> def make_color_control ( self , v , control_name , control ) : <EOL> try : <EOL> color = wx . Colour ( ) <EOL> color . SetFromName ( v . value ) <EOL> except : <EOL> color = wx . BLACK <EOL> if ( not hasattr ( control , "<STR_LIT>" ) or <EOL> control . bad_color_name != v . value ) : <EOL> logger . warn ( "<STR_LIT>" % v . value ) <EOL> control . bad_color_name = v . value <EOL> if control is None : <EOL> control = wx . lib . colourselect . ColourSelect ( <EOL> self . __module_panel , <EOL> colour = color ) <EOL> control . SetName ( control_name ) <EOL> def on_press ( event , v = v , control = control ) : <EOL> proposed_value = control . GetColour ( ) . GetAsString ( <EOL> wx . C2S_NAME | wx . C2S_HTML_SYNTAX ) <EOL> setting_edited_event = SettingEditedEvent ( <EOL> v , self . __module , proposed_value , event ) <EOL> self . notify ( setting_edited_event ) <EOL> self . reset_view ( ) <EOL> def on_size ( event , control = control ) : <EOL> control . SetBitmap ( control . MakeBitmap ( ) ) <EOL> control . Bind ( wx . lib . colourselect . EVT_COLOURSELECT , on_press ) <EOL> control . Bind ( wx . EVT_SIZE , on_size ) <EOL> else : <EOL> control . SetColour ( color ) <EOL> return control <EOL> def make_tree_choice_control ( self , v , control_name , control ) : <EOL> new_label = "<STR_LIT:>>" . join ( v . get_path_parts ( ) ) <EOL> def make_bitmap ( control , flags ) : <EOL> assert isinstance ( control , wx . BitmapButton ) <EOL> text_width , text_height = control . GetTextExtent ( new_label ) <EOL> gap = <NUM_LIT:4> <EOL> drop_width = wx . SystemSettings . GetMetric ( wx . SYS_VSCROLL_ARROW_X ) <EOL> drop_height = wx . SystemSettings . GetMetric ( wx . SYS_VSCROLL_ARROW_Y ) <EOL> width = text_width + <NUM_LIT:2> * gap + drop_width <EOL> height = max ( text_height , drop_height ) + <NUM_LIT:4> <EOL> bitmap = wx . EmptyBitmap ( width , height ) <EOL> dc = wx . MemoryDC ( bitmap ) <EOL> dc . Font = control . Font <EOL> brush = wx . Brush ( control . BackgroundColour ) <EOL> dc . Background = brush <EOL> dc . Clear ( ) <EOL> wx . RendererNative . Get ( ) . DrawComboBox ( <EOL> control , dc , wx . Rect ( <NUM_LIT:0> , <NUM_LIT:0> , width , height ) , flags ) <EOL> dc . DrawText ( new_label , <NUM_LIT:2> , <NUM_LIT:2> ) <EOL> return bitmap <EOL> if control is None : <EOL> control = wx . BitmapButton ( self . module_panel , <EOL> style = wx . BU_EXACTFIT ) <EOL> control . label_text = None <EOL> def on_press ( event , v = v , control = control ) : <EOL> id_dict = { } <EOL> def on_event ( event , v = v , control = control , id_dict = id_dict ) : <EOL> new_path = v . encode_path_parts ( id_dict [ event . GetId ( ) ] ) <EOL> self . on_value_change ( v , control , new_path , event ) <EOL> def make_menu ( tree , id_dict = id_dict , path = None ) : <EOL> if path is None : <EOL> path = [ ] <EOL> menu = wx . Menu ( ) <EOL> for node in tree : <EOL> text , subtree = node [ : <NUM_LIT:2> ] <EOL> subpath = path + [ text ] <EOL> if v . fn_is_leaf ( node ) : <EOL> item = menu . Append ( - <NUM_LIT:1> , text ) <EOL> id_dict [ item . GetId ( ) ] = subpath <EOL> if wx . VERSION >= ( <NUM_LIT:2> , <NUM_LIT:9> ) and sys . platform != '<STR_LIT:win32>' : <EOL> wx . EVT_MENU ( menu , item . GetId ( ) , on_event ) <EOL> if subtree is not None and len ( subtree ) > <NUM_LIT:0> : <EOL> submenu = make_menu ( subtree , path = subpath ) <EOL> menu . AppendMenu ( - <NUM_LIT:1> , text , submenu ) <EOL> return menu <EOL> menu = make_menu ( v . get_tree ( ) ) <EOL> assert isinstance ( control , wx . Window ) <EOL> if wx . VERSION < ( <NUM_LIT:2> , <NUM_LIT:9> ) or sys . platform == '<STR_LIT:win32>' : <EOL> menu . Bind ( wx . EVT_MENU , on_event ) <EOL> control . PopupMenuXY ( menu , <NUM_LIT:0> , control . GetSize ( ) [ <NUM_LIT:1> ] ) <EOL> menu . Destroy ( ) <EOL> control . Bind ( wx . EVT_BUTTON , on_press ) <EOL> old_label = control . label_text <EOL> if old_label != new_label : <EOL> control . label_text = new_label <EOL> for getter , setter , flags in ( <EOL> ( control . GetBitmapLabel , control . SetBitmapLabel , <NUM_LIT:0> ) , <EOL> ( control . GetBitmapFocus , control . SetBitmapFocus , <EOL> wx . CONTROL_FOCUSED ) , <EOL> ( control . GetBitmapSelected , control . SetBitmapSelected , <EOL> wx . CONTROL_SELECTED ) ) : <EOL> old_bitmap = getter ( ) <EOL> setter ( make_bitmap ( control , flags ) ) <EOL> if old_bitmap is not None : <EOL> old_bitmap . Destroy ( ) <EOL> return control <EOL> def make_callback_control ( self , v , control_name , control ) : <EOL> """<STR_LIT>""" <EOL> if not control : <EOL> control = wx . Button ( self . module_panel , - <NUM_LIT:1> , <EOL> v . label , name = control_name ) <EOL> def callback ( event , setting = v ) : <EOL> self . __on_do_something ( event , setting ) <EOL> self . module_panel . Bind ( wx . EVT_BUTTON , callback , control ) <EOL> else : <EOL> control . Label = v . label <EOL> return control <EOL> def make_callback_controls ( self , v , control_name , control ) : <EOL> """<STR_LIT>""" <EOL> assert isinstance ( v , cellprofiler . settings . DoThings ) <EOL> if not control : <EOL> control = wx . Panel ( self . module_panel , name = control_name ) <EOL> control . Sizer = wx . BoxSizer ( wx . HORIZONTAL ) <EOL> for i in range ( v . count ) : <EOL> if i != <NUM_LIT:0> : <EOL> control . Sizer . AddSpacer ( <NUM_LIT:2> ) <EOL> button = wx . Button ( control , <EOL> name = button_control_name ( v , i ) ) <EOL> control . Sizer . Add ( button , <NUM_LIT:0> , wx . ALIGN_LEFT ) <EOL> def callback ( event , index = i ) : <EOL> v . on_event_fired ( index ) <EOL> setting_edited_event = SettingEditedEvent ( <EOL> v , self . __module , None , event ) <EOL> self . notify ( setting_edited_event ) <EOL> self . __module . on_setting_changed ( v , self . __pipeline ) <EOL> self . reset_view ( ) <EOL> button . Bind ( wx . EVT_BUTTON , callback ) <EOL> for i in range ( v . count ) : <EOL> button = control . FindWindowByName ( button_control_name ( v , i ) ) <EOL> button . Label = v . get_label ( i ) <EOL> return control <EOL> def make_regexp_control ( self , v , control ) : <EOL> """<STR_LIT>""" <EOL> if not control : <EOL> panel = wx . Panel ( self . __module_panel , <EOL> - <NUM_LIT:1> , <EOL> name = edit_control_name ( v ) ) <EOL> control = panel <EOL> sizer = wx . BoxSizer ( wx . HORIZONTAL ) <EOL> panel . SetSizer ( sizer ) <EOL> text_ctrl = wx . TextCtrl ( panel , - <NUM_LIT:1> , str ( v . value ) , <EOL> name = text_control_name ( v ) ) <EOL> sizer . Add ( text_ctrl , <NUM_LIT:1> , wx . EXPAND | wx . RIGHT , <NUM_LIT:1> ) <EOL> bitmap = wx . ArtProvider . GetBitmap ( wx . ART_FIND , wx . ART_TOOLBAR , ( <NUM_LIT:16> , <NUM_LIT:16> ) ) <EOL> bitmap_button = wx . BitmapButton ( panel , bitmap = bitmap , <EOL> name = button_control_name ( v ) ) <EOL> sizer . Add ( bitmap_button , <NUM_LIT:0> , wx . EXPAND ) <EOL> def on_cell_change ( event , setting = v , control = text_ctrl ) : <EOL> self . __on_cell_change ( event , setting , control ) <EOL> def on_button_pressed ( event , setting = v , control = text_ctrl ) : <EOL> filename = "<STR_LIT>" <EOL> try : <EOL> if setting . get_example_fn is None : <EOL> path = cellprofiler . preferences . get_default_image_directory ( ) <EOL> filenames = [ x for x in os . listdir ( path ) <EOL> if x . find ( '<STR_LIT:.>' ) != - <NUM_LIT:1> and <EOL> os . path . splitext ( x ) [ <NUM_LIT:1> ] . upper ( ) in <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> if len ( filenames ) : <EOL> filename = filenames [ <NUM_LIT:0> ] <EOL> else : <EOL> filename = setting . get_example_fn ( ) <EOL> except : <EOL> pass <EOL> if v . guess == cellprofiler . settings . RegexpText . GUESS_FOLDER : <EOL> guess_file = cellprofiler . preferences . get_pathname_re_guess_file ( ) <EOL> guesses = regexp_editor . RE_FOLDER_GUESSES <EOL> else : <EOL> guess_file = cellprofiler . preferences . get_filename_re_guess_file ( ) <EOL> guesses = regexp_editor . RE_FILENAME_GUESSES <EOL> if guess_file is not None and os . path . exists ( guess_file ) : <EOL> with open ( guess_file ) as fd : <EOL> guesses = [ x . strip ( ) for x in fd . readlines ( ) ] <EOL> new_value = regexp_editor . edit_regexp ( panel , control . Value , filename , guesses ) <EOL> if new_value : <EOL> control . Value = new_value <EOL> self . __on_cell_change ( event , setting , control ) <EOL> def on_kill_focus ( event , setting = v , control = text_ctrl ) : <EOL> if self . __module is not None : <EOL> self . set_selection ( self . __module . module_num ) <EOL> self . __module_panel . Bind ( wx . EVT_TEXT , on_cell_change , text_ctrl ) <EOL> self . __module_panel . Bind ( wx . EVT_BUTTON , on_button_pressed , bitmap_button ) <EOL> text_ctrl . Bind ( wx . EVT_KILL_FOCUS , on_kill_focus ) <EOL> else : <EOL> text_control = control . FindWindowByName ( text_control_name ( v ) ) <EOL> if v . value != text_control . Value : <EOL> text_control . Value = v . value <EOL> return control <EOL> def make_filename_text_control ( self , v , control ) : <EOL> """<STR_LIT>""" <EOL> edit_name = subedit_control_name ( v ) <EOL> control_name = edit_control_name ( v ) <EOL> button_name = button_control_name ( v ) <EOL> if control is None : <EOL> control = wx . Panel ( self . module_panel , - <NUM_LIT:1> , <EOL> name = control_name ) <EOL> sizer = wx . BoxSizer ( wx . HORIZONTAL ) <EOL> control . SetSizer ( sizer ) <EOL> if v . metadata_display : <EOL> edit_control = metadatactrl . MetadataControl ( <EOL> self . __pipeline , <EOL> self . __module , <EOL> control , <EOL> value = v . value , <EOL> name = edit_name ) <EOL> else : <EOL> edit_control = wx . TextCtrl ( control , - <NUM_LIT:1> , str ( v ) , <EOL> name = edit_name ) <EOL> sizer . Add ( edit_control , <NUM_LIT:1> , wx . ALIGN_LEFT | wx . ALIGN_TOP ) <EOL> def on_cell_change ( event , setting = v , control = edit_control ) : <EOL> self . __on_cell_change ( event , setting , control ) <EOL> self . __module_panel . Bind ( wx . EVT_TEXT , on_cell_change , edit_control ) <EOL> bitmap = wx . ArtProvider . GetBitmap ( wx . ART_FILE_OPEN , <EOL> wx . ART_BUTTON , ( <NUM_LIT:16> , <NUM_LIT:16> ) ) <EOL> button_control = wx . BitmapButton ( control , bitmap = bitmap , <EOL> name = button_name ) <EOL> def on_press ( event ) : <EOL> """<STR_LIT>""" <EOL> if v . mode == cellprofiler . settings . FilenameText . MODE_OPEN : <EOL> mode = wx . FD_OPEN <EOL> elif v . mode == cellprofiler . settings . FilenameText . MODE_APPEND : <EOL> mode = wx . FD_SAVE <EOL> else : <EOL> mode = wx . FD_SAVE | wx . FD_OVERWRITE_PROMPT <EOL> dlg = wx . FileDialog ( control , v . browse_msg , style = mode ) <EOL> if v . get_directory_fn is not None : <EOL> dlg . Directory = v . get_directory_fn ( ) <EOL> if v . exts is not None : <EOL> dlg . Wildcard = "<STR_LIT:|>" . join ( [ "<STR_LIT:|>" . join ( tuple ( x ) ) for x in v . exts ] ) <EOL> if dlg . ShowModal ( ) == wx . ID_OK : <EOL> if v . set_directory_fn is not None : <EOL> v . set_directory_fn ( dlg . Directory ) <EOL> v . value = dlg . Filename <EOL> setting_edited_event = SettingEditedEvent ( <EOL> v , self . __module , v . value , event ) <EOL> self . notify ( setting_edited_event ) <EOL> self . reset_view ( ) <EOL> button_control . Bind ( wx . EVT_BUTTON , on_press ) <EOL> sizer . Add ( button_control , <NUM_LIT:0> , wx . EXPAND | wx . LEFT , <NUM_LIT:2> ) <EOL> else : <EOL> edit_control = self . module_panel . FindWindowByName ( edit_name ) <EOL> button_control = self . module_panel . FindWindowByName ( button_name ) <EOL> if edit_control . Value != v . value : <EOL> edit_control . Value = v . value <EOL> button_control . Show ( v . browsable ) <EOL> return control <EOL> def make_directory_path_control ( self , v , control_name , control ) : <EOL> assert isinstance ( v , cellprofiler . settings . DirectoryPath ) <EOL> dir_ctrl_name = combobox_ctrl_name ( v ) <EOL> custom_ctrl_name = subedit_control_name ( v ) <EOL> custom_ctrl_label_name = custom_label_name ( v ) <EOL> browse_ctrl_name = button_control_name ( v ) <EOL> folder_label_ctrl_name = folder_label_name ( v ) <EOL> if control is None : <EOL> control = wx . Panel ( self . module_panel , <EOL> style = wx . TAB_TRAVERSAL , <EOL> name = control_name ) <EOL> sizer = wx . BoxSizer ( wx . VERTICAL ) <EOL> control . SetSizer ( sizer ) <EOL> choice_sizer = wx . BoxSizer ( wx . HORIZONTAL ) <EOL> sizer . Add ( choice_sizer , <NUM_LIT:0> , wx . ALIGN_TOP | wx . ALIGN_LEFT ) <EOL> dir_ctrl = wx . Choice ( control , choices = v . dir_choices , <EOL> name = dir_ctrl_name ) <EOL> choice_sizer . Add ( dir_ctrl , <NUM_LIT:0> , wx . ALIGN_LEFT | wx . BOTTOM , <NUM_LIT:2> ) <EOL> choice_sizer . AddSpacer ( <NUM_LIT:3> ) <EOL> folder_label = wx . StaticText ( <EOL> control , name = folder_label_ctrl_name ) <EOL> choice_sizer . Add ( folder_label , <NUM_LIT:0> , wx . ALIGN_CENTER_VERTICAL ) <EOL> custom_sizer = wx . BoxSizer ( wx . HORIZONTAL ) <EOL> sizer . Add ( custom_sizer , <NUM_LIT:1> , wx . EXPAND ) <EOL> custom_label = wx . StaticText ( control , name = custom_ctrl_label_name ) <EOL> custom_sizer . Add ( custom_label , <NUM_LIT:0> , wx . ALIGN_CENTER_VERTICAL ) <EOL> if v . allow_metadata : <EOL> custom_ctrl = metadatactrl . MetadataControl ( self . __pipeline , <EOL> self . __module , <EOL> control , value = v . custom_path , <EOL> name = custom_ctrl_name ) <EOL> else : <EOL> custom_ctrl = wx . TextCtrl ( control , - <NUM_LIT:1> , v . custom_path , <EOL> name = custom_ctrl_name ) <EOL> custom_sizer . Add ( custom_ctrl , <NUM_LIT:1> , wx . ALIGN_CENTER_VERTICAL ) <EOL> browse_bitmap = wx . ArtProvider . GetBitmap ( wx . ART_FOLDER , <EOL> wx . ART_CMN_DIALOG , <EOL> ( <NUM_LIT:16> , <NUM_LIT:16> ) ) <EOL> browse_ctrl = wx . BitmapButton ( control , bitmap = browse_bitmap , <EOL> name = browse_ctrl_name ) <EOL> custom_sizer . Add ( browse_ctrl , <NUM_LIT:0> , wx . ALIGN_CENTER | wx . LEFT , <NUM_LIT:2> ) <EOL> def on_dir_choice_change ( event , v = v , dir_ctrl = dir_ctrl ) : <EOL> """<STR_LIT>""" <EOL> if not self . __handle_change : <EOL> return <EOL> proposed_value = v . join_string ( dir_choice = dir_ctrl . StringSelection ) <EOL> setting_edited_event = SettingEditedEvent ( <EOL> v , self . __module , proposed_value , event ) <EOL> self . notify ( setting_edited_event ) <EOL> self . reset_view ( ) <EOL> def on_custom_path_change ( event , v = v , custom_ctrl = custom_ctrl ) : <EOL> """<STR_LIT>""" <EOL> if not self . __handle_change : <EOL> return <EOL> proposed_value = v . join_string ( custom_path = custom_ctrl . Value ) <EOL> setting_edited_event = SettingEditedEvent ( <EOL> v , self . __module , proposed_value , event ) <EOL> self . notify ( setting_edited_event ) <EOL> self . reset_view ( <NUM_LIT:1000> ) <EOL> def on_browse_pressed ( event , v = v , dir_ctrl = dir_ctrl , <EOL> custom_ctrl = custom_ctrl ) : <EOL> """<STR_LIT>""" <EOL> dlg = wx . DirDialog ( self . module_panel , <EOL> v . text , <EOL> v . get_absolute_path ( ) ) <EOL> if dlg . ShowModal ( ) == wx . ID_OK : <EOL> dir_choice , custom_path = v . get_parts_from_path ( dlg . Path ) <EOL> proposed_value = v . join_string ( dir_choice , custom_path ) <EOL> if v . allow_metadata : <EOL> proposed_value = proposed_value . replace ( '<STR_LIT:\\>' , '<STR_LIT>' ) <EOL> setting_edited_event = SettingEditedEvent ( <EOL> v , self . __module , proposed_value , event ) <EOL> self . notify ( setting_edited_event ) <EOL> self . reset_view ( ) <EOL> dir_ctrl . Bind ( wx . EVT_CHOICE , on_dir_choice_change ) <EOL> custom_ctrl . Bind ( wx . EVT_TEXT , on_custom_path_change ) <EOL> browse_ctrl . Bind ( wx . EVT_BUTTON , on_browse_pressed ) <EOL> else : <EOL> dir_ctrl = self . module_panel . FindWindowByName ( dir_ctrl_name ) <EOL> custom_ctrl = self . module_panel . FindWindowByName ( custom_ctrl_name ) <EOL> custom_label = self . module_panel . FindWindowByName ( custom_ctrl_label_name ) <EOL> browse_ctrl = self . module_panel . FindWindowByName ( browse_ctrl_name ) <EOL> folder_label = self . module_panel . FindWindowByName ( folder_label_ctrl_name ) <EOL> if dir_ctrl . StringSelection != v . dir_choice : <EOL> dir_ctrl . StringSelection = v . dir_choice <EOL> if v . is_custom_choice : <EOL> if not custom_ctrl . IsShown ( ) : <EOL> custom_ctrl . Show ( ) <EOL> if not custom_label . IsShown ( ) : <EOL> custom_label . Show ( ) <EOL> if not browse_ctrl . IsShown ( ) : <EOL> browse_ctrl . Show ( ) <EOL> if v . dir_choice in ( cellprofiler . settings . DEFAULT_INPUT_SUBFOLDER_NAME , <EOL> cellprofiler . settings . DEFAULT_OUTPUT_SUBFOLDER_NAME ) : <EOL> custom_label . Label = "<STR_LIT>" <EOL> elif v . dir_choice == cellprofiler . settings . URL_FOLDER_NAME : <EOL> if v . support_urls == cellprofiler . settings . SUPPORT_URLS_SHOW_DIR : <EOL> custom_label . Label = "<STR_LIT>" <EOL> custom_label . Show ( ) <EOL> custom_ctrl . Show ( ) <EOL> else : <EOL> custom_label . Hide ( ) <EOL> custom_ctrl . Hide ( ) <EOL> browse_ctrl . Hide ( ) <EOL> if custom_ctrl . Value != v . custom_path : <EOL> custom_ctrl . Value = v . custom_path <EOL> else : <EOL> custom_label . Hide ( ) <EOL> custom_ctrl . Hide ( ) <EOL> browse_ctrl . Hide ( ) <EOL> if v . dir_choice in ( cellprofiler . settings . DEFAULT_INPUT_FOLDER_NAME , <EOL> cellprofiler . settings . DEFAULT_INPUT_SUBFOLDER_NAME ) : <EOL> folder_label . Label = "<STR_LIT>" % cellprofiler . preferences . get_default_image_directory ( ) <EOL> elif v . dir_choice in ( cellprofiler . settings . DEFAULT_OUTPUT_FOLDER_NAME , <EOL> cellprofiler . settings . DEFAULT_OUTPUT_SUBFOLDER_NAME ) : <EOL> folder_label . Label = "<STR_LIT>" % cellprofiler . preferences . get_default_output_directory ( ) <EOL> else : <EOL> folder_label . Label = wx . EmptyString <EOL> dir_ctrl . SetToolTipString ( folder_label . Label ) <EOL> return control <EOL> def make_pathname_control ( self , v , control ) : <EOL> if control is None : <EOL> control = wx . Panel ( self . module_panel , - <NUM_LIT:1> , <EOL> name = edit_control_name ( v ) ) <EOL> control . Sizer = wx . BoxSizer ( wx . HORIZONTAL ) <EOL> text_control = wx . TextCtrl ( control , - <NUM_LIT:1> , <EOL> name = subedit_control_name ( v ) ) <EOL> text_control . Bind ( <EOL> wx . EVT_TEXT , <EOL> lambda event : self . __on_cell_change ( event , v , text_control ) ) <EOL> browse_bitmap = wx . ArtProvider . GetBitmap ( wx . ART_FOLDER , <EOL> wx . ART_CMN_DIALOG , <EOL> ( <NUM_LIT:16> , <NUM_LIT:16> ) ) <EOL> browse_ctrl = wx . BitmapButton ( control , bitmap = browse_bitmap , <EOL> name = button_control_name ( v ) ) <EOL> control . Sizer . Add ( text_control , <NUM_LIT:1> , wx . EXPAND ) <EOL> control . Sizer . AddSpacer ( ( <NUM_LIT:3> , <NUM_LIT:0> ) ) <EOL> control . Sizer . Add ( browse_ctrl , <NUM_LIT:0> , wx . EXPAND ) <EOL> def on_browse ( event ) : <EOL> dlg = wx . FileDialog ( self . module_panel ) <EOL> try : <EOL> dlg . Title = "<STR_LIT>" <EOL> dlg . Wildcard = v . wildcard <EOL> if dlg . ShowModal ( ) == wx . ID_OK : <EOL> self . on_value_change ( v , control , dlg . Path , event ) <EOL> finally : <EOL> dlg . Destroy ( ) <EOL> browse_ctrl . Bind ( wx . EVT_BUTTON , on_browse ) <EOL> else : <EOL> text_control = control . FindWindowByName ( subedit_control_name ( v ) ) <EOL> if text_control . Value != v . value : <EOL> text_control . Value = v . value <EOL> return control <EOL> def make_image_plane_control ( self , v , control ) : <EOL> """<STR_LIT>""" <EOL> from cellprofiler . modules . loadimages import url2pathname <EOL> assert isinstance ( v , cellprofiler . settings . ImagePlane ) <EOL> if not control : <EOL> control = wx . Panel ( self . module_panel , <EOL> name = edit_control_name ( v ) ) <EOL> control . Sizer = wx . BoxSizer ( wx . HORIZONTAL ) <EOL> url_control = wx . TextCtrl ( <EOL> control , <EOL> style = wx . TE_READONLY , <EOL> name = text_control_name ( v ) ) <EOL> control . Sizer . Add ( url_control , <NUM_LIT:1> , wx . EXPAND ) <EOL> control . Sizer . AddSpacer ( <NUM_LIT:2> ) <EOL> browse_button = wx . Button ( control , label = "<STR_LIT>" , <EOL> name = button_control_name ( v ) ) <EOL> control . Sizer . Add ( browse_button , <NUM_LIT:0> , wx . EXPAND ) <EOL> def on_button ( event ) : <EOL> url = self . __frame . pipeline_controller . pick_from_pathlist ( <EOL> v . url , instructions = "<STR_LIT>" ) <EOL> if url is not None : <EOL> value = v . build ( url ) <EOL> self . on_value_change ( v , control , value , event ) <EOL> browse_button . Bind ( wx . EVT_BUTTON , on_button ) <EOL> else : <EOL> url_control = control . FindWindowByName ( text_control_name ( v ) ) <EOL> label = v . url or "<STR_LIT>" <EOL> if label . startswith ( "<STR_LIT>" ) : <EOL> label = url2pathname ( label ) <EOL> url_control . Value = label <EOL> return control <EOL> def make_text_control ( self , v , control_name , control ) : <EOL> """<STR_LIT>""" <EOL> text = None <EOL> if not control : <EOL> if v . metadata_display : <EOL> control = metadatactrl . MetadataControl ( <EOL> self . __pipeline , <EOL> self . __module , <EOL> self . __module_panel , <EOL> value = v . value , <EOL> name = control_name <EOL> ) <EOL> else : <EOL> style = <NUM_LIT:0> <EOL> text = v . get_value_text ( ) <EOL> if not isinstance ( text , ( unicode , str ) ) : <EOL> text = str ( text ) <EOL> if getattr ( v , "<STR_LIT>" , False ) : <EOL> style = wx . TE_MULTILINE | wx . TE_PROCESS_ENTER <EOL> lines = text . split ( "<STR_LIT:\n>" ) <EOL> else : <EOL> lines = [ text ] <EOL> control = wx . TextCtrl ( self . __module_panel , <EOL> - <NUM_LIT:1> , <EOL> text , <EOL> name = control_name , <EOL> style = style ) <EOL> def on_cell_change ( event , setting = v , control = control ) : <EOL> self . __on_cell_change ( event , setting , control ) <EOL> self . __module_panel . Bind ( wx . EVT_TEXT , on_cell_change , control ) <EOL> elif not ( v . get_value_text ( ) == control . Value ) : <EOL> text = v . get_value_text ( ) <EOL> if not isinstance ( text , ( unicode , str ) ) : <EOL> text = str ( text ) <EOL> control . Value = text <EOL> if text is not None : <EOL> lines = text . split ( "<STR_LIT:\n>" ) <EOL> if len ( lines ) > <NUM_LIT:0> : <EOL> width = max ( [ control . GetTextExtent ( line ) [ <NUM_LIT:0> ] for line in lines ] ) <EOL> height = sum ( [ control . GetTextExtent ( line ) [ <NUM_LIT:1> ] for line in lines ] ) <EOL> min_width , min_height = control . GetTextExtent ( "<STR_LIT:M>" ) <EOL> if width < min_width : <EOL> width = min_width <EOL> if height < min_height : <EOL> height = min_height <EOL> bw , bh = control . GetWindowBorderSize ( ) <EOL> control . SetMinSize ( ( bw * <NUM_LIT:2> + width , bh * <NUM_LIT:2> + height ) ) <EOL> return control <EOL> def make_range_control ( self , v , panel ) : <EOL> """<STR_LIT>""" <EOL> if not panel : <EOL> panel = wx . Panel ( self . __module_panel , - <NUM_LIT:1> , name = edit_control_name ( v ) ) <EOL> sizer = wx . BoxSizer ( wx . HORIZONTAL ) <EOL> panel . SetSizer ( sizer ) <EOL> min_ctrl = wx . TextCtrl ( <EOL> panel , - <NUM_LIT:1> , v . min_text , name = min_control_name ( v ) ) <EOL> sizer . Add ( min_ctrl , <NUM_LIT:0> , wx . EXPAND | wx . RIGHT , <NUM_LIT:1> ) <EOL> max_ctrl = wx . TextCtrl ( <EOL> panel , - <NUM_LIT:1> , v . max_text , name = max_control_name ( v ) ) <EOL> sizer . Add ( max_ctrl , <NUM_LIT:0> , wx . EXPAND ) <EOL> def on_min_change ( event , setting = v , control = min_ctrl ) : <EOL> self . __on_min_change ( event , setting , control ) <EOL> self . __module_panel . Bind ( wx . EVT_TEXT , on_min_change , min_ctrl ) <EOL> def on_max_change ( event , setting = v , control = max_ctrl ) : <EOL> self . __on_max_change ( event , setting , control ) <EOL> self . __module_panel . Bind ( wx . EVT_TEXT , on_max_change , max_ctrl ) <EOL> else : <EOL> min_ctrl = panel . FindWindowByName ( min_control_name ( v ) ) <EOL> if min_ctrl . Value != v . min_text : <EOL> min_ctrl . Value = v . min_text <EOL> max_ctrl = panel . FindWindowByName ( max_control_name ( v ) ) <EOL> if max_ctrl . Value != v . max_text : <EOL> max_ctrl . Value = v . max_text <EOL> for ctrl in ( min_ctrl , max_ctrl ) : <EOL> self . fit_ctrl ( ctrl ) <EOL> return panel <EOL> def make_unbounded_range_control ( self , v , panel ) : <EOL> """<STR_LIT>""" <EOL> if not panel : <EOL> panel = wx . Panel ( self . __module_panel , - <NUM_LIT:1> , name = edit_control_name ( v ) ) <EOL> sizer = wx . BoxSizer ( wx . HORIZONTAL ) <EOL> panel . SetSizer ( sizer ) <EOL> min_ctrl = wx . TextCtrl ( panel , - <NUM_LIT:1> , value = str ( v . min ) , <EOL> name = min_control_name ( v ) ) <EOL> best_width = min_ctrl . GetCharWidth ( ) * <NUM_LIT:5> <EOL> min_ctrl . SetInitialSize ( wx . Size ( best_width , - <NUM_LIT:1> ) ) <EOL> sizer . Add ( min_ctrl , <NUM_LIT:0> , wx . EXPAND | wx . RIGHT , <NUM_LIT:1> ) <EOL> max_ctrl = wx . TextCtrl ( panel , - <NUM_LIT:1> , value = v . display_max , <EOL> name = max_control_name ( v ) ) <EOL> max_ctrl . SetInitialSize ( wx . Size ( best_width , - <NUM_LIT:1> ) ) <EOL> sizer . Add ( max_ctrl , <NUM_LIT:0> , wx . EXPAND ) <EOL> value = ABSOLUTE if v . is_abs ( ) else FROM_EDGE <EOL> absrel_ctrl = wx . ComboBox ( panel , - <NUM_LIT:1> , value , <EOL> choices = [ ABSOLUTE , FROM_EDGE ] , <EOL> name = absrel_control_name ( v ) , <EOL> style = wx . CB_DROPDOWN | wx . CB_READONLY ) <EOL> sizer . Add ( absrel_ctrl , <NUM_LIT:0> , wx . EXPAND | wx . RIGHT , <NUM_LIT:1> ) <EOL> def on_min_change ( event , setting = v , control = min_ctrl ) : <EOL> if not self . __handle_change : <EOL> return <EOL> proposed_value = setting . compose_min_text ( control . Value ) <EOL> setting_edited_event = SettingEditedEvent ( setting , self . __module , <EOL> proposed_value , event ) <EOL> self . notify ( setting_edited_event ) <EOL> self . fit_ctrl ( control ) <EOL> self . __module_panel . Bind ( wx . EVT_TEXT , on_min_change , min_ctrl ) <EOL> def on_max_change ( event , setting = v , control = max_ctrl , <EOL> absrel_ctrl = absrel_ctrl ) : <EOL> if not self . __handle_change : <EOL> return <EOL> proposed_value = setting . compose_display_max_text ( control . Value ) <EOL> setting_edited_event = SettingEditedEvent ( setting , self . __module , <EOL> proposed_value , event ) <EOL> self . notify ( setting_edited_event ) <EOL> self . fit_ctrl ( control ) <EOL> self . __module_panel . Bind ( wx . EVT_TEXT , on_max_change , max_ctrl ) <EOL> def on_absrel_change ( event , setting = v , control = absrel_ctrl ) : <EOL> if not self . __handle_change : <EOL> return <EOL> if control . Value == ABSOLUTE : <EOL> proposed_value = setting . compose_abs ( ) <EOL> else : <EOL> proposed_value = setting . compose_rel ( ) <EOL> if proposed_value is not None : <EOL> setting_edited_event = SettingEditedEvent ( setting , self . __module , <EOL> proposed_value , event ) <EOL> self . notify ( setting_edited_event ) <EOL> self . __module_panel . Bind ( wx . EVT_COMBOBOX , <EOL> on_absrel_change , absrel_ctrl ) <EOL> else : <EOL> min_ctrl = panel . FindWindowByName ( min_control_name ( v ) ) <EOL> if min_ctrl . Value != v . display_min : <EOL> min_ctrl . Value = v . display_min <EOL> max_ctrl = panel . FindWindowByName ( max_control_name ( v ) ) <EOL> if max_ctrl . Value != v . display_max : <EOL> min_ctrl . Value = v . display_max <EOL> absrel_ctrl = panel . FindWindowByName ( absrel_control_name ( v ) ) <EOL> absrel_value = ABSOLUTE if v . is_abs ( ) else FROM_EDGE <EOL> if absrel_ctrl . Value != absrel_value : <EOL> absrel_ctrl . Value = absrel_value <EOL> return panel <EOL> def make_coordinates_control ( self , v , panel ) : <EOL> """<STR_LIT>""" <EOL> if not panel : <EOL> panel = wx . Panel ( self . __module_panel , - <NUM_LIT:1> , name = edit_control_name ( v ) ) <EOL> sizer = wx . BoxSizer ( wx . HORIZONTAL ) <EOL> panel . SetSizer ( sizer ) <EOL> sizer . Add ( wx . StaticText ( panel , - <NUM_LIT:1> , "<STR_LIT>" ) , <NUM_LIT:0> , wx . EXPAND | wx . RIGHT , <NUM_LIT:1> ) <EOL> x_ctrl = wx . TextCtrl ( <EOL> panel , - <NUM_LIT:1> , v . get_x_text ( ) , name = x_control_name ( v ) ) <EOL> best_width = x_ctrl . GetCharWidth ( ) * <NUM_LIT:5> <EOL> x_ctrl . SetInitialSize ( wx . Size ( best_width , - <NUM_LIT:1> ) ) <EOL> sizer . Add ( x_ctrl , <NUM_LIT:0> , wx . EXPAND | wx . RIGHT , <NUM_LIT:1> ) <EOL> sizer . Add ( wx . StaticText ( panel , - <NUM_LIT:1> , "<STR_LIT>" ) , <NUM_LIT:0> , wx . EXPAND | wx . RIGHT , <NUM_LIT:1> ) <EOL> y_ctrl = wx . TextCtrl ( <EOL> panel , - <NUM_LIT:1> , v . get_y_text ( ) , name = y_control_name ( v ) ) <EOL> y_ctrl . SetInitialSize ( wx . Size ( best_width , - <NUM_LIT:1> ) ) <EOL> sizer . Add ( y_ctrl , <NUM_LIT:0> , wx . EXPAND ) <EOL> def on_x_change ( event , setting = v , control = x_ctrl ) : <EOL> if not self . __handle_change : <EOL> return <EOL> old_value = str ( setting ) <EOL> proposed_value = "<STR_LIT>" % ( str ( control . Value ) , str ( setting . y ) ) <EOL> setting_edited_event = SettingEditedEvent ( setting , self . __module , <EOL> proposed_value , event ) <EOL> self . notify ( setting_edited_event ) <EOL> self . __module_panel . Bind ( wx . EVT_TEXT , on_x_change , x_ctrl ) <EOL> def on_y_change ( event , setting = v , control = y_ctrl ) : <EOL> if not self . __handle_change : <EOL> return <EOL> old_value = str ( setting ) <EOL> proposed_value = "<STR_LIT>" % ( str ( setting . x ) , str ( control . Value ) ) <EOL> setting_edited_event = SettingEditedEvent ( setting , self . __module , <EOL> proposed_value , event ) <EOL> self . notify ( setting_edited_event ) <EOL> self . __module_panel . Bind ( wx . EVT_TEXT , on_y_change , y_ctrl ) <EOL> else : <EOL> x_ctrl = panel . FindWindowByName ( x_control_name ( v ) ) <EOL> if x_ctrl . Value != v . get_x_text ( ) : <EOL> x_ctrl . Value = v . get_x_text ( ) <EOL> y_ctrl = panel . FindWindowByName ( y_control_name ( v ) ) <EOL> if y_ctrl . Value != v . get_y_text ( ) : <EOL> y_ctrl . Value = v . get_y_text ( ) <EOL> return panel <EOL> def make_measurement_control ( self , v , panel ) : <EOL> """<STR_LIT>""" <EOL> if not panel : <EOL> panel = wx . Panel ( self . __module_panel , - <NUM_LIT:1> , name = edit_control_name ( v ) ) <EOL> sizer = wx . BoxSizer ( wx . VERTICAL ) <EOL> panel . SetSizer ( sizer ) <EOL> sub_sizer = wx . BoxSizer ( wx . HORIZONTAL ) <EOL> sizer . Add ( sub_sizer , <NUM_LIT:0> , wx . ALIGN_LEFT ) <EOL> category_text_ctrl = wx . StaticText ( panel , label = '<STR_LIT>' , <EOL> name = category_text_control_name ( v ) ) <EOL> sub_sizer . Add ( category_text_ctrl , <NUM_LIT:0> , wx . EXPAND | wx . ALL , <NUM_LIT:2> ) <EOL> category_ctrl = wx . ComboBox ( panel , style = wx . CB_READONLY , <EOL> name = category_control_name ( v ) ) <EOL> sub_sizer . Add ( category_ctrl , <NUM_LIT:0> , wx . EXPAND | wx . ALL , <NUM_LIT:2> ) <EOL> sub_sizer = wx . BoxSizer ( wx . HORIZONTAL ) <EOL> sizer . Add ( sub_sizer , <NUM_LIT:0> , wx . ALIGN_LEFT ) <EOL> feature_text_ctrl = wx . StaticText ( panel , label = '<STR_LIT>' , <EOL> name = feature_text_control_name ( v ) ) <EOL> sub_sizer . Add ( feature_text_ctrl , <NUM_LIT:0> , wx . EXPAND | wx . ALL , <NUM_LIT:2> ) <EOL> feature_ctrl = wx . ComboBox ( panel , style = wx . CB_READONLY , <EOL> name = feature_control_name ( v ) ) <EOL> sub_sizer . Add ( feature_ctrl , <NUM_LIT:0> , wx . EXPAND | wx . ALL , <NUM_LIT:2> ) <EOL> sub_sizer = wx . BoxSizer ( wx . HORIZONTAL ) <EOL> sizer . Add ( sub_sizer , <NUM_LIT:0> , wx . ALIGN_LEFT ) <EOL> object_text_ctrl = wx . StaticText ( panel , label = '<STR_LIT>' , <EOL> name = object_text_control_name ( v ) ) <EOL> sub_sizer . Add ( object_text_ctrl , <NUM_LIT:0> , wx . EXPAND | wx . ALL , <NUM_LIT:2> ) <EOL> object_ctrl = wx . ComboBox ( panel , style = wx . CB_READONLY , <EOL> name = object_control_name ( v ) ) <EOL> sub_sizer . Add ( object_ctrl , <NUM_LIT:0> , wx . EXPAND | wx . ALL , <NUM_LIT:2> ) <EOL> sub_sizer = wx . BoxSizer ( wx . HORIZONTAL ) <EOL> sizer . Add ( sub_sizer , <NUM_LIT:0> , wx . ALIGN_LEFT ) <EOL> scale_text_ctrl = wx . StaticText ( panel , label = '<STR_LIT>' , <EOL> name = scale_text_ctrl_name ( v ) ) <EOL> sub_sizer . Add ( scale_text_ctrl , <NUM_LIT:0> , wx . EXPAND | wx . ALL , <NUM_LIT:2> ) <EOL> scale_ctrl = wx . ComboBox ( panel , style = wx . CB_READONLY , <EOL> name = scale_control_name ( v ) ) <EOL> sub_sizer . Add ( scale_ctrl , <NUM_LIT:0> , wx . EXPAND | wx . ALL , <NUM_LIT:2> ) <EOL> max_width = <NUM_LIT:0> <EOL> for sub_sizer_item in sizer . GetChildren ( ) : <EOL> static = sub_sizer_item . Sizer . GetChildren ( ) [ <NUM_LIT:0> ] . Window <EOL> max_width = max ( max_width , static . Size . width ) <EOL> for sub_sizer_item in sizer . GetChildren ( ) : <EOL> static = sub_sizer_item . Sizer . GetChildren ( ) [ <NUM_LIT:0> ] . Window <EOL> static . Size = wx . Size ( max_width , static . Size . height ) <EOL> static . SetSizeHints ( max_width , - <NUM_LIT:1> , max_width ) <EOL> def on_change ( event , v = v , category_ctrl = category_ctrl , <EOL> feature_ctrl = feature_ctrl , <EOL> object_ctrl = object_ctrl , <EOL> scale_ctrl = scale_ctrl ) : <EOL> """<STR_LIT>""" <EOL> if not self . __handle_change : <EOL> return <EOL> def value_of ( ctrl ) : <EOL> return ctrl . Value if ctrl . Selection != - <NUM_LIT:1> else None <EOL> value = v . construct_value ( value_of ( category_ctrl ) , <EOL> value_of ( feature_ctrl ) , <EOL> value_of ( object_ctrl ) , <EOL> value_of ( scale_ctrl ) ) <EOL> setting_edited_event = SettingEditedEvent ( v , <EOL> self . __module , <EOL> value , <EOL> event ) <EOL> self . notify ( setting_edited_event ) <EOL> self . reset_view ( ) <EOL> for ctrl in ( category_ctrl , feature_ctrl , object_ctrl , scale_ctrl ) : <EOL> panel . Bind ( wx . EVT_COMBOBOX , on_change , ctrl ) <EOL> else : <EOL> category_ctrl = panel . FindWindowByName ( category_control_name ( v ) ) <EOL> category_text_ctrl = panel . FindWindowByName ( category_text_control_name ( v ) ) <EOL> feature_ctrl = panel . FindWindowByName ( feature_control_name ( v ) ) <EOL> feature_text_ctrl = panel . FindWindowByName ( feature_text_control_name ( v ) ) <EOL> object_ctrl = panel . FindWindowByName ( object_control_name ( v ) ) <EOL> object_text_ctrl = panel . FindWindowByName ( object_text_control_name ( v ) ) <EOL> scale_ctrl = panel . FindWindowByName ( scale_control_name ( v ) ) <EOL> scale_text_ctrl = panel . FindWindowByName ( scale_text_ctrl_name ( v ) ) <EOL> category = v . get_category ( self . __pipeline ) <EOL> categories = v . get_category_choices ( self . __pipeline ) <EOL> feature_name = v . get_feature_name ( self . __pipeline ) <EOL> feature_names = v . get_feature_name_choices ( self . __pipeline ) <EOL> image_name = v . get_image_name ( self . __pipeline ) <EOL> image_names = v . get_image_name_choices ( self . __pipeline ) <EOL> object_name = v . get_object_name ( self . __pipeline ) <EOL> object_names = v . get_object_name_choices ( self . __pipeline ) <EOL> scale = v . get_scale ( self . __pipeline ) <EOL> scales = v . get_scale_choices ( self . __pipeline ) <EOL> def set_up_combobox ( ctrl , text_ctrl , choices , value , always_show = False ) : <EOL> if len ( choices ) : <EOL> if value is None : <EOL> choices = [ "<STR_LIT>" ] + choices <EOL> if not ( len ( ctrl . Strings ) == len ( choices ) and <EOL> all ( [ x == y for x , y in zip ( ctrl . Strings , choices ) ] ) ) : <EOL> ctrl . Clear ( ) <EOL> ctrl . AppendItems ( choices ) <EOL> ctrl . SetSelection ( <NUM_LIT:0> ) <EOL> if not value is None : <EOL> try : <EOL> if ctrl . Value != value : <EOL> ctrl . Value = value <EOL> except : <EOL> ctrl . Value = value <EOL> else : <EOL> if ctrl . Value != "<STR_LIT>" : <EOL> ctrl . SetSelection ( <NUM_LIT:0> ) <EOL> ctrl . Show ( ) <EOL> text_ctrl . Show ( ) <EOL> elif always_show : <EOL> ctrl . Clear ( ) <EOL> ctrl . Value = "<STR_LIT>" <EOL> else : <EOL> ctrl . Hide ( ) <EOL> ctrl . Clear ( ) <EOL> text_ctrl . Hide ( ) <EOL> set_up_combobox ( category_ctrl , category_text_ctrl , categories , <EOL> category , True ) <EOL> set_up_combobox ( feature_ctrl , feature_text_ctrl , <EOL> feature_names , feature_name ) <EOL> if len ( object_names ) > <NUM_LIT:0> : <EOL> if len ( image_names ) > <NUM_LIT:0> : <EOL> object_text_ctrl . Label = "<STR_LIT>" <EOL> object_names += image_names <EOL> else : <EOL> object_text_ctrl . Label = "<STR_LIT>" <EOL> else : <EOL> object_text_ctrl . Label = "<STR_LIT>" <EOL> object_names = image_names <EOL> if object_name is None : <EOL> object_name = image_name <EOL> set_up_combobox ( object_ctrl , object_text_ctrl , object_names , object_name ) <EOL> set_up_combobox ( scale_ctrl , scale_text_ctrl , scales , scale ) <EOL> return panel <EOL> def make_html_control ( self , v , control ) : <EOL> from cellprofiler . gui . html import HtmlClickableWindow <EOL> if control is None : <EOL> control = HtmlClickableWindow ( self . module_panel , - <NUM_LIT:1> , <EOL> name = edit_control_name ( v ) ) <EOL> if v . size is not None : <EOL> unit = float ( wx . SystemSettings . GetMetric ( wx . SYS_CAPTION_Y ) ) <EOL> if unit == - <NUM_LIT:1> : <EOL> unit = <NUM_LIT> <EOL> control . SetMinSize ( ( v . size [ <NUM_LIT:0> ] * unit , v . size [ <NUM_LIT:1> ] * unit ) ) <EOL> control . SetPage ( v . content ) <EOL> return control <EOL> def make_help_control ( self , content , title = "<STR_LIT>" , <EOL> name = wx . ButtonNameStr ) : <EOL> control = wx . Button ( self . __module_panel , - <NUM_LIT:1> , '<STR_LIT:?>' , ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:30> , - <NUM_LIT:1> ) , <EOL> name = name ) <EOL> def callback ( event ) : <EOL> dialog = htmldialog . HTMLDialog ( self . __module_panel , title , content ) <EOL> dialog . CentreOnParent ( ) <EOL> dialog . Show ( ) <EOL> control . Bind ( wx . EVT_BUTTON , callback , control ) <EOL> return control <EOL> class CornerButtonGrid ( wx . grid . Grid , cornerbuttonmixin . CornerButtonMixin ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> kwargs = kwargs . copy ( ) <EOL> if "<STR_LIT>" in kwargs : <EOL> fn_clicked = kwargs . pop ( "<STR_LIT>" ) <EOL> else : <EOL> fn_clicked = None <EOL> label = kwargs . pop ( "<STR_LIT:label>" , "<STR_LIT>" ) <EOL> tooltip = kwargs . pop ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> wx . grid . Grid . __init__ ( self , * args , ** kwargs ) <EOL> cornerbuttonmixin . CornerButtonMixin . __init__ ( self , fn_clicked , label , tooltip ) <EOL> def make_table_control ( self , v , control ) : <EOL> if control is None : <EOL> control = wx . lib . resizewidget . ResizeWidget ( <EOL> self . module_panel , <EOL> name = edit_control_name ( v ) ) <EOL> if v . corner_button is None : <EOL> grid = wx . grid . Grid ( control , name = grid_control_name ( v ) ) <EOL> else : <EOL> grid = self . CornerButtonGrid ( <EOL> control , name = grid_control_name ( v ) , ** v . corner_button ) <EOL> grid . SetTable ( TableController ( v ) ) <EOL> grid . Table . bind_to_grid ( grid ) <EOL> else : <EOL> grid = control . FindWindowByName ( grid_control_name ( v ) ) <EOL> grid . Table . update_grid ( ) <EOL> grid . ForceRefresh ( ) <EOL> grid . SetBestFittingSize ( v . min_size ) <EOL> control . AdjustToSize ( ( v . min_size [ <NUM_LIT:0> ] + wx . lib . resizewidget . RW_THICKNESS , <EOL> v . min_size [ <NUM_LIT:1> ] + wx . lib . resizewidget . RW_THICKNESS ) ) <EOL> return control <EOL> def add_listener ( self , listener ) : <EOL> self . __listeners . append ( listener ) <EOL> def remove_listener ( self , listener ) : <EOL> self . __listeners . remove ( listener ) <EOL> def notify ( self , event ) : <EOL> self . __inside_notify = True <EOL> try : <EOL> for listener in self . __listeners : <EOL> listener ( self , event ) <EOL> finally : <EOL> self . __inside_notify = False <EOL> def __on_column_sized ( self , event ) : <EOL> self . __module_panel . GetTopLevelParent ( ) . Layout ( ) <EOL> def __on_radiobox_change ( self , event , setting , control ) : <EOL> if not self . __handle_change : <EOL> return <EOL> self . on_value_change ( <EOL> setting , control , control . GetStringSelection ( ) , event ) <EOL> def __on_combobox_change ( self , event , setting , control ) : <EOL> if not self . __handle_change : <EOL> return <EOL> self . on_value_change ( setting , control , control . GetValue ( ) , event ) <EOL> def __on_multichoice_change ( self , event , setting , control ) : <EOL> if not self . __handle_change : <EOL> return <EOL> proposed_value = u'<STR_LIT:U+002C>' . join ( [ control . Items [ i ] <EOL> for i in control . Selections ] ) <EOL> self . on_value_change ( setting , control , proposed_value , event ) <EOL> def __on_cell_change ( self , event , setting , control ) : <EOL> if not self . __handle_change : <EOL> return <EOL> proposed_value = unicode ( control . GetValue ( ) ) <EOL> self . on_value_change ( setting , control , proposed_value , event , <EOL> EDIT_TIMEOUT_SEC * <NUM_LIT:1000> ) <EOL> def on_value_change ( self , setting , control , proposed_value , event , <EOL> timeout = None ) : <EOL> """<STR_LIT>""" <EOL> setting_edited_event = SettingEditedEvent ( setting , <EOL> self . __module , <EOL> proposed_value , <EOL> event ) <EOL> self . notify ( setting_edited_event ) <EOL> if timeout is None : <EOL> self . reset_view ( ) <EOL> elif timeout is not False : <EOL> self . reset_view ( timeout ) <EOL> @ staticmethod <EOL> def fit_ctrl ( ctrl ) : <EOL> """<STR_LIT>""" <EOL> width , height = ctrl . GetTextExtent ( ctrl . Value + "<STR_LIT>" ) <EOL> ctrl . SetSizeHintsSz ( wx . Size ( width , - <NUM_LIT:1> ) ) <EOL> ctrl . Parent . Fit ( ) <EOL> def __on_min_change ( self , event , setting , control ) : <EOL> if not self . __handle_change : <EOL> return <EOL> old_value = str ( setting ) <EOL> proposed_value = setting . compose_min_text ( control . Value ) <EOL> setting_edited_event = SettingEditedEvent ( <EOL> setting , self . __module , proposed_value , event ) <EOL> self . notify ( setting_edited_event ) <EOL> self . fit_ctrl ( control ) <EOL> def __on_max_change ( self , event , setting , control ) : <EOL> if not self . __handle_change : <EOL> return <EOL> old_value = str ( setting ) <EOL> proposed_value = setting . compose_max_text ( control . Value ) <EOL> setting_edited_event = SettingEditedEvent ( <EOL> setting , self . __module , proposed_value , event ) <EOL> self . notify ( setting_edited_event ) <EOL> self . fit_ctrl ( control ) <EOL> def request_validation ( self , module = None ) : <EOL> """<STR_LIT>""" <EOL> if module is None : <EOL> module = self . __module <EOL> if self . __validation_request is not None : <EOL> self . __validation_request . cancel ( ) <EOL> self . __validation_request = ValidationRequest ( <EOL> self . __pipeline , module , self . on_validation ) <EOL> request_module_validation ( self . __validation_request ) <EOL> def __on_pipeline_event ( self , pipeline , event ) : <EOL> if ( isinstance ( event , cellprofiler . pipeline . PipelineClearedEvent ) or <EOL> isinstance ( event , cellprofiler . pipeline . PipelineLoadedEvent ) ) : <EOL> if self . __module not in self . __pipeline . modules ( False ) : <EOL> self . clear_selection ( ) <EOL> elif isinstance ( event , cellprofiler . pipeline . ModuleEditedPipelineEvent ) : <EOL> if ( not self . __inside_notify and self . __module is not None <EOL> and self . __module . module_num == event . module_num ) : <EOL> self . reset_view ( ) <EOL> if ( self . __module is not None and <EOL> self . __module . module_num == event . module_num ) : <EOL> self . request_validation ( ) <EOL> elif isinstance ( event , cellprofiler . pipeline . ModuleRemovedPipelineEvent ) : <EOL> if ( self . __module is not None and <EOL> event . module_num == self . __module . module_num ) : <EOL> self . clear_selection ( ) <EOL> def __on_workspace_event ( self , event ) : <EOL> import cellprofiler . workspace as cpw <EOL> if isinstance ( event , ( cpw . Workspace . WorkspaceLoadedEvent , <EOL> cpw . Workspace . WorkspaceCreatedEvent ) ) : <EOL> if self . __module is not None : <EOL> self . __module . on_deactivated ( ) <EOL> self . __module . on_activated ( self . __workspace ) <EOL> self . do_reset ( ) <EOL> def __on_do_something ( self , event , setting ) : <EOL> setting . on_event_fired ( ) <EOL> setting_edited_event = SettingEditedEvent ( setting , self . __module , <EOL> None , event ) <EOL> self . notify ( setting_edited_event ) <EOL> self . __module . on_setting_changed ( setting , self . __pipeline ) <EOL> self . reset_view ( ) <EOL> def on_validation ( self , setting_idx , message , level ) : <EOL> default_fg_color = wx . SystemSettings . GetColour ( wx . SYS_COLOUR_WINDOWTEXT ) <EOL> default_bg_color = cellprofiler . preferences . get_background_color ( ) <EOL> if not self . __module : <EOL> return <EOL> visible_settings = self . __module . visible_settings ( ) <EOL> bad_setting = None <EOL> if setting_idx is not None : <EOL> if setting_idx >= len ( visible_settings ) : <EOL> return <EOL> try : <EOL> level = logging . ERROR <EOL> visible_settings [ setting_idx ] . test_valid ( self . __pipeline ) <EOL> self . __module . test_valid ( self . __pipeline ) <EOL> level = logging . WARNING <EOL> self . __module . test_module_warnings ( self . __pipeline ) <EOL> except cellprofiler . settings . ValidationError , instance : <EOL> message = instance . message <EOL> bad_setting = instance . get_setting ( ) <EOL> if bad_setting is None : <EOL> self . module_settings_box . Label = self . get_module_settings_label ( ) <EOL> self . module_settings_box . SetToolTip ( None ) <EOL> else : <EOL> msg = "<STR_LIT>" % ( <EOL> "<STR_LIT:error>" if level == logging . ERROR else "<STR_LIT>" ) <EOL> self . module_settings_box . Label = "<STR_LIT>" % ( <EOL> self . get_module_settings_label ( ) , msg ) <EOL> self . module_settings_box . SetToolTipString ( message ) <EOL> try : <EOL> for setting in visible_settings : <EOL> self . set_tool_tip ( setting , message if ( setting is bad_setting ) else None ) <EOL> static_text_name = text_control_name ( setting ) <EOL> static_text = self . __module_panel . FindWindowByName ( static_text_name ) <EOL> if static_text is not None : <EOL> desired_fg , desired_bg = default_fg_color , default_bg_color <EOL> if setting is bad_setting : <EOL> if level == logging . ERROR : <EOL> desired_fg = cellprofiler . preferences . get_error_color ( ) <EOL> elif level == logging . WARNING : <EOL> desired_bg = WARNING_COLOR <EOL> except Exception : <EOL> logger . debug ( "<STR_LIT>" , exc_info = True ) <EOL> pass <EOL> def set_tool_tip ( self , setting , message ) : <EOL> """<STR_LIT>""" <EOL> control_name = edit_control_name ( setting ) <EOL> control = self . __module_panel . FindWindowByName ( <EOL> control_name ) <EOL> if message is None : <EOL> def set_tool_tip ( ctrl ) : <EOL> ctrl . SetToolTip ( None ) <EOL> else : <EOL> def set_tool_tip ( ctrl , message = message ) : <EOL> ctrl . SetToolTipString ( message ) <EOL> if control is not None : <EOL> set_tool_tip ( control ) <EOL> for child in control . GetChildren ( ) : <EOL> set_tool_tip ( child ) <EOL> static_text_name = text_control_name ( setting ) <EOL> static_text = self . __module_panel . FindWindowByName ( static_text_name ) <EOL> if static_text is not None : <EOL> set_tool_tip ( static_text ) <EOL> def reset_view ( self , refresh_delay = <NUM_LIT> ) : <EOL> """<STR_LIT>""" <EOL> if self . __module is None : <EOL> return <EOL> if self . refresh_pending : <EOL> return <EOL> refresh_pending = True <EOL> wx . CallLater ( refresh_delay , self . do_reset ) <EOL> def do_reset ( self ) : <EOL> self . refresh_pending = False <EOL> focus_control = wx . Window . FindFocus ( ) <EOL> if not focus_control is None : <EOL> focus_name = focus_control . GetName ( ) <EOL> else : <EOL> focus_name = None <EOL> if self . __module is None : <EOL> return <EOL> self . set_selection ( self . __module . module_num ) <EOL> if focus_name : <EOL> focus_control = self . module_panel . FindWindowByName ( focus_name ) <EOL> if focus_control : <EOL> focus_control . SetFocus ( ) <EOL> def disable ( self ) : <EOL> self . __module_panel . Disable ( ) <EOL> def enable ( self ) : <EOL> self . __module_panel . Enable ( ) <EOL> def get_max_width ( self ) : <EOL> sizer = self . __sizer <EOL> return sizer . calc_max_text_width ( ) + sizer . calc_edit_size ( ) [ <NUM_LIT:0> ] + sizer . calc_help_size ( ) [ <NUM_LIT:0> ] <EOL> class FilterPanelController ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , module_view , v , panel ) : <EOL> assert isinstance ( module_view , ModuleView ) <EOL> assert isinstance ( v , cellprofiler . settings . Filter ) <EOL> self . module_view = module_view <EOL> self . v = v <EOL> self . panel = wx . Panel ( self . module_view . module_panel , <EOL> style = wx . TAB_TRAVERSAL , <EOL> name = edit_control_name ( self . v ) ) <EOL> self . panel . Sizer = wx . BoxSizer ( wx . VERTICAL ) <EOL> self . sizer_dict = { } <EOL> self . sizer_item_dict = { } <EOL> self . stretch_spacer_dict = { } <EOL> self . hide_show_dict = { } <EOL> self . update ( ) <EOL> def get_sizer ( self , address ) : <EOL> """<STR_LIT>""" <EOL> key = tuple ( address ) <EOL> line_name = self . line_name ( address ) <EOL> self . hide_show_dict [ line_name ] = True <EOL> if self . sizer_dict . has_key ( key ) : <EOL> if len ( address ) > <NUM_LIT:0> : <EOL> self . hide_show_dict [ self . remove_button_name ( address ) ] = True <EOL> self . hide_show_dict [ self . add_button_name ( address ) ] = True <EOL> self . hide_show_dict [ self . add_group_button_name ( address ) ] = True <EOL> return self . sizer_dict [ key ] <EOL> line_style = wx . LI_HORIZONTAL | wx . BORDER_SUNKEN <EOL> sizer = wx . BoxSizer ( wx . HORIZONTAL ) <EOL> self . indent ( sizer , address ) <EOL> self . stretch_spacer_dict [ key ] = sizer . AddStretchSpacer ( ) <EOL> line = wx . StaticLine ( self . panel , - <NUM_LIT:1> , style = line_style , <EOL> name = self . line_name ( address ) ) <EOL> if len ( address ) == <NUM_LIT:0> : <EOL> key = None <EOL> else : <EOL> sizer . Add ( self . make_delete_button ( address ) , <NUM_LIT:0> , <EOL> wx . ALIGN_RIGHT | wx . ALIGN_CENTER_VERTICAL ) <EOL> sizer . Add ( self . make_add_rule_button ( address ) , <NUM_LIT:0> , <EOL> wx . ALIGN_RIGHT | wx . ALIGN_CENTER_VERTICAL ) <EOL> sizer . Add ( self . make_add_rules_button ( address ) , <NUM_LIT:0> , <EOL> wx . ALIGN_RIGHT | wx . ALIGN_CENTER_VERTICAL ) <EOL> key = tuple ( address [ : - <NUM_LIT:1> ] + [ address [ - <NUM_LIT:1> ] + <NUM_LIT:1> ] ) <EOL> if not self . sizer_dict . has_key ( key ) : <EOL> if len ( address ) == <NUM_LIT:1> : <EOL> key = None <EOL> else : <EOL> key = tuple ( address [ : - <NUM_LIT:2> ] + [ address [ - <NUM_LIT:2> ] + <NUM_LIT:1> ] ) <EOL> if not self . sizer_dict . has_key ( key ) : <EOL> key = None <EOL> if key is not None : <EOL> next_sizer = self . sizer_dict [ key ] <EOL> idx = self . get_sizer_index ( self . panel . Sizer , next_sizer ) <EOL> self . panel . Sizer . Insert ( idx , sizer , <NUM_LIT:0> , wx . EXPAND ) <EOL> self . panel . Sizer . Insert ( idx + <NUM_LIT:1> , line , <NUM_LIT:0> , wx . EXPAND ) <EOL> else : <EOL> self . panel . Sizer . Add ( sizer , <NUM_LIT:0> , wx . EXPAND ) <EOL> self . panel . Sizer . Add ( line , <NUM_LIT:0> , wx . EXPAND ) <EOL> self . sizer_dict [ tuple ( address ) ] = sizer <EOL> return sizer <EOL> def get_tokens ( self ) : <EOL> try : <EOL> tokens = self . v . parse ( ) <EOL> except Exception , e : <EOL> logger . debug ( "<STR_LIT>" , <EOL> self . v . value_text , str ( e ) ) <EOL> tokens = self . v . default ( ) <EOL> if ( len ( tokens ) == <NUM_LIT:0> or <EOL> ( tokens [ <NUM_LIT:0> ] not in <EOL> ( cellprofiler . settings . Filter . AND_PREDICATE , cellprofiler . settings . Filter . OR_PREDICATE ) ) ) : <EOL> tokens = [ cellprofiler . settings . Filter . AND_PREDICATE , tokens ] <EOL> return tokens <EOL> def update ( self ) : <EOL> self . inside_update = True <EOL> try : <EOL> structure = self . get_tokens ( ) <EOL> for key in self . hide_show_dict : <EOL> self . hide_show_dict [ key ] = False <EOL> self . populate_subpanel ( structure , [ ] ) <EOL> for key , value in self . hide_show_dict . iteritems ( ) : <EOL> self . panel . FindWindowByName ( key ) . Show ( value ) <EOL> self . panel . Layout ( ) <EOL> except : <EOL> logger . exception ( "<STR_LIT>" ) <EOL> finally : <EOL> self . inside_update = False <EOL> ANY_ALL_PREDICATES = [ cellprofiler . settings . Filter . AND_PREDICATE , <EOL> cellprofiler . settings . Filter . OR_PREDICATE ] <EOL> def any_all_choices ( self ) : <EOL> return [ x . display_name for x in self . ANY_ALL_PREDICATES ] <EOL> @ staticmethod <EOL> def indent ( sizer , address ) : <EOL> assert isinstance ( sizer , wx . Sizer ) <EOL> if len ( address ) == <NUM_LIT:0> : <EOL> return <EOL> sizer . AddSpacer ( ( len ( address ) * <NUM_LIT:20> , <NUM_LIT:0> ) ) <EOL> def find_and_mark ( self , name ) : <EOL> """<STR_LIT>""" <EOL> ctrl = self . panel . FindWindowByName ( name ) <EOL> self . hide_show_dict [ name ] = True <EOL> return ctrl <EOL> @ staticmethod <EOL> def get_sizer_index ( sizer , item ) : <EOL> if isinstance ( item , wx . Sizer ) : <EOL> indexes = [ i for i , s in enumerate ( sizer . GetChildren ( ) ) <EOL> if s . IsSizer ( ) and s . GetSizer ( ) is item ] <EOL> elif isinstance ( item , wx . Window ) : <EOL> indexes = [ i for i , s in enumerate ( sizer . GetChildren ( ) ) <EOL> if s . IsWindow ( ) and s . GetWindow ( ) is item ] <EOL> elif isinstance ( item , wx . SizerItem ) : <EOL> return sizer . GetChildren ( ) . index ( item ) <EOL> if len ( indexes ) > <NUM_LIT:0> : <EOL> return indexes [ <NUM_LIT:0> ] <EOL> return None <EOL> def on_value_change ( self , event , new_text , timeout = None ) : <EOL> if not self . inside_update : <EOL> self . module_view . on_value_change ( <EOL> self . v , self . panel , new_text , event , timeout ) <EOL> def make_delete_button ( self , address ) : <EOL> name = self . remove_button_name ( address ) <EOL> button = self . find_and_mark ( name ) <EOL> if button is not None : <EOL> return button <EOL> button = wx . Button ( self . panel , - <NUM_LIT:1> , "<STR_LIT:->" , <EOL> name = name , <EOL> style = wx . BU_EXACTFIT ) <EOL> button . Bind ( wx . EVT_BUTTON , <EOL> lambda event : self . on_delete_rule ( event , address ) ) <EOL> return button <EOL> def on_delete_rule ( self , event , address ) : <EOL> logger . debug ( "<STR_LIT>" + str ( address ) ) <EOL> structure = self . v . parse ( ) <EOL> sequence = self . find_address ( structure , address [ : - <NUM_LIT:1> ] ) <EOL> del sequence [ address [ - <NUM_LIT:1> ] + <NUM_LIT:1> ] <EOL> new_text = self . v . build_string ( structure ) <EOL> self . on_value_change ( event , new_text ) <EOL> def make_add_rule_button ( self , address ) : <EOL> name = self . add_button_name ( address ) <EOL> button = self . find_and_mark ( name ) <EOL> if button is not None : <EOL> return button <EOL> button = wx . Button ( self . panel , - <NUM_LIT:1> , "<STR_LIT:+>" , <EOL> name = name , <EOL> style = wx . BU_EXACTFIT ) <EOL> button . Bind ( wx . EVT_BUTTON , <EOL> lambda event : self . on_add_rule ( event , address ) ) <EOL> return button <EOL> def on_add_rule ( self , event , address ) : <EOL> logger . debug ( "<STR_LIT>" + str ( address ) ) <EOL> structure = self . v . parse ( ) <EOL> sequence = self . find_address ( structure , address [ : - <NUM_LIT:1> ] ) <EOL> new_rule = self . v . default ( ) <EOL> sequence . insert ( address [ - <NUM_LIT:1> ] + <NUM_LIT:2> , new_rule ) <EOL> new_text = self . v . build_string ( structure ) <EOL> self . on_value_change ( event , new_text ) <EOL> def make_add_rules_button ( self , address ) : <EOL> name = self . add_group_button_name ( address ) <EOL> button = self . find_and_mark ( name ) <EOL> if button is not None : <EOL> return button <EOL> button = wx . Button ( self . panel , - <NUM_LIT:1> , "<STR_LIT>" , <EOL> name = name , <EOL> style = wx . BU_EXACTFIT ) <EOL> button . Bind ( wx . EVT_BUTTON , <EOL> lambda event : self . on_add_rules ( event , address ) ) <EOL> return button <EOL> def on_add_rules ( self , event , address ) : <EOL> logger . debug ( "<STR_LIT>" + str ( address ) ) <EOL> structure = self . v . parse ( ) <EOL> sequence = self . find_address ( structure , address [ : - <NUM_LIT:1> ] ) <EOL> new_rule = [ cellprofiler . settings . Filter . OR_PREDICATE , self . v . default ( ) ] <EOL> sequence . insert ( address [ - <NUM_LIT:1> ] + <NUM_LIT:2> , new_rule ) <EOL> new_text = self . v . build_string ( structure ) <EOL> self . on_value_change ( event , new_text ) <EOL> def make_predicate_choice ( self , predicates , index , address , sizer ) : <EOL> name = self . choice_name ( index , address ) <EOL> choice_ctrl = self . find_and_mark ( name ) <EOL> choices = [ x . display_name for x in predicates ] <EOL> if choice_ctrl is not None : <EOL> items = choice_ctrl . GetItems ( ) <EOL> if ( len ( items ) != len ( choices ) or <EOL> any ( [ choice not in items for choice in choices ] ) ) : <EOL> choice_ctrl . SetItems ( choices ) <EOL> return choice_ctrl <EOL> choice_ctrl = wx . Choice ( self . panel , - <NUM_LIT:1> , choices = choices , <EOL> name = name ) <EOL> choice_ctrl . Bind ( wx . EVT_CHOICE , <EOL> lambda event : self . on_predicate_changed ( event , index , address ) ) <EOL> self . add_to_sizer ( sizer , choice_ctrl , index , address ) <EOL> return choice_ctrl <EOL> def on_predicate_changed ( self , event , index , address ) : <EOL> logger . debug ( "<STR_LIT>" % <EOL> ( index , self . saddress ( address ) ) ) <EOL> structure = self . v . parse ( ) <EOL> sequence = self . find_address ( structure , address ) <EOL> while len ( sequence ) <= index : <EOL> sequence . append ( self . v . predicates [ <NUM_LIT:0> ] <EOL> if len ( sequence ) == <NUM_LIT:0> <EOL> else sequence [ - <NUM_LIT:1> ] . subpredicates [ <NUM_LIT:0> ] ) <EOL> if index == <NUM_LIT:0> : <EOL> predicates = self . v . predicates <EOL> else : <EOL> predicates = sequence [ index - <NUM_LIT:1> ] . subpredicates <EOL> new_predicate = predicates [ event . GetSelection ( ) ] <EOL> sequence [ index ] = new_predicate <EOL> predicates = new_predicate . subpredicates <EOL> for index in range ( index + <NUM_LIT:1> , len ( sequence ) ) : <EOL> if isinstance ( sequence [ index ] , basestring ) : <EOL> is_good = cellprofiler . settings . Filter . LITERAL_PREDICATE in predicates <EOL> else : <EOL> matches = [ p for p in predicates <EOL> if sequence [ index ] . symbol == p . symbol ] <EOL> is_good = len ( matches ) == <NUM_LIT:1> <EOL> if is_good : <EOL> sequence [ index ] = matches [ <NUM_LIT:0> ] <EOL> if not is_good : <EOL> del sequence [ index : ] <EOL> sequence += self . v . default ( predicates ) <EOL> break <EOL> if not isinstance ( sequence [ index ] , cellprofiler . settings . Filter . FilterPredicate ) : <EOL> break <EOL> predicates = sequence [ index ] . subpredicates <EOL> new_text = self . v . build_string ( structure ) <EOL> self . on_value_change ( event , new_text ) <EOL> def add_to_sizer ( self , sizer , item , index , address ) : <EOL> """<STR_LIT>""" <EOL> key = tuple ( address + [ index ] ) <EOL> next_key = tuple ( address + [ index + <NUM_LIT:1> ] ) <EOL> if self . sizer_item_dict . has_key ( next_key ) : <EOL> next_ctrl = self . sizer_item_dict [ next_key ] <EOL> else : <EOL> next_ctrl = self . stretch_spacer_dict [ tuple ( address ) ] <EOL> index = self . get_sizer_index ( sizer , next_ctrl ) <EOL> sizer . Insert ( index , item , <NUM_LIT:0> , wx . ALIGN_LEFT | wx . ALIGN_CENTER_HORIZONTAL ) <EOL> if not self . sizer_item_dict . has_key ( key ) : <EOL> self . sizer_item_dict [ key ] = item <EOL> def make_literal ( self , token , index , address , sizer ) : <EOL> name = self . literal_name ( index , address ) <EOL> literal_ctrl = self . find_and_mark ( name ) <EOL> if literal_ctrl is not None : <EOL> if literal_ctrl . GetValue ( ) != token : <EOL> literal_ctrl . SetValue ( token ) <EOL> return literal_ctrl <EOL> literal_ctrl = wx . TextCtrl ( self . panel , - <NUM_LIT:1> , token , name = name ) <EOL> literal_ctrl . Bind ( wx . EVT_TEXT , <EOL> lambda event : self . on_literal_changed ( event , index , address ) ) <EOL> self . add_to_sizer ( sizer , literal_ctrl , index , address ) <EOL> return literal_ctrl <EOL> def on_literal_changed ( self , event , index , address ) : <EOL> logger . debug ( "<STR_LIT>" % ( index , self . saddress ( address ) ) ) <EOL> try : <EOL> structure = self . v . parse ( ) <EOL> sequence = self . find_address ( structure , address ) <EOL> while len ( sequence ) <= index : <EOL> sequence . append ( self . v . predicates [ <NUM_LIT:0> ] <EOL> if len ( sequence ) == <NUM_LIT:0> <EOL> else sequence [ - <NUM_LIT:1> ] . subpredicates [ <NUM_LIT:0> ] ) <EOL> sequence [ index ] = event . GetString ( ) <EOL> except : <EOL> structure = self . v . default ( ) <EOL> new_text = self . v . build_string ( structure ) <EOL> self . on_value_change ( event , new_text , <EOL> timeout = None if self . v . reset_view else False ) <EOL> def make_anyall_ctrl ( self , address ) : <EOL> anyall = wx . Choice ( self . panel , - <NUM_LIT:1> , choices = self . any_all_choices ( ) , <EOL> name = self . anyall_choice_name ( address ) ) <EOL> anyall . Bind ( wx . EVT_CHOICE , <EOL> lambda event : self . on_anyall_changed ( event , address ) ) <EOL> return anyall <EOL> def on_anyall_changed ( self , event , address ) : <EOL> logger . debug ( "<STR_LIT>" % self . saddress ( address ) ) <EOL> structure = self . v . parse ( ) <EOL> sequence = self . find_address ( structure , address ) <EOL> predicate = self . ANY_ALL_PREDICATES [ event . GetSelection ( ) ] <EOL> sequence [ <NUM_LIT:0> ] = predicate <EOL> new_text = self . v . build_string ( structure ) <EOL> self . on_value_change ( event , new_text ) <EOL> def find_address ( self , sequence , address ) : <EOL> """<STR_LIT>""" <EOL> if len ( address ) == <NUM_LIT:0> : <EOL> return sequence <EOL> subsequence = sequence [ address [ <NUM_LIT:0> ] + <NUM_LIT:1> ] <EOL> return self . find_address ( subsequence , address [ <NUM_LIT:1> : ] ) <EOL> def populate_subpanel ( self , structure , address ) : <EOL> parent_sizer = self . panel . Sizer <EOL> any_all_name = self . anyall_choice_name ( address ) <EOL> anyall = self . find_and_mark ( any_all_name ) <EOL> self . hide_show_dict [ self . static_text_name ( <NUM_LIT:0> , address ) ] = True <EOL> if len ( address ) == <NUM_LIT:0> : <EOL> self . hide_show_dict [ self . static_text_name ( <NUM_LIT:1> , address ) ] = True <EOL> if anyall is None : <EOL> anyall = self . make_anyall_ctrl ( address ) <EOL> sizer = self . get_sizer ( address ) <EOL> idx = self . get_sizer_index ( sizer , <EOL> self . stretch_spacer_dict [ tuple ( address ) ] ) <EOL> if len ( address ) == <NUM_LIT:0> : <EOL> text = wx . StaticText ( self . panel , - <NUM_LIT:1> , "<STR_LIT>" , <EOL> name = self . static_text_name ( <NUM_LIT:0> , address ) ) <EOL> sizer . Insert ( idx , text , <NUM_LIT:0> , <EOL> wx . ALIGN_LEFT | wx . ALIGN_CENTER_VERTICAL ) <EOL> sizer . InsertSpacer ( idx + <NUM_LIT:1> , ( <NUM_LIT:3> , <NUM_LIT:0> ) ) <EOL> sizer . Insert ( idx + <NUM_LIT:2> , anyall , <NUM_LIT:0> , <EOL> wx . ALIGN_LEFT | wx . ALIGN_CENTER_VERTICAL ) <EOL> sizer . InsertSpacer ( idx + <NUM_LIT:3> , ( <NUM_LIT:3> , <NUM_LIT:0> ) ) <EOL> text = wx . StaticText ( self . panel , - <NUM_LIT:1> , "<STR_LIT>" , <EOL> name = self . static_text_name ( <NUM_LIT:1> , address ) ) <EOL> sizer . Insert ( idx + <NUM_LIT:4> , text , <EOL> <NUM_LIT:0> , wx . ALIGN_LEFT | wx . ALIGN_CENTER_VERTICAL ) <EOL> else : <EOL> sizer . Insert ( idx , anyall , <NUM_LIT:0> , <EOL> wx . ALIGN_LEFT | wx . ALIGN_CENTER_VERTICAL | wx . RIGHT ) <EOL> sizer . InsertSpacer ( idx + <NUM_LIT:1> , ( <NUM_LIT:3> , <NUM_LIT:0> ) ) <EOL> text = wx . StaticText ( self . panel , - <NUM_LIT:1> , "<STR_LIT>" , <EOL> name = self . static_text_name ( <NUM_LIT:0> , address ) ) <EOL> sizer . Insert ( idx + <NUM_LIT:2> , text , <EOL> <NUM_LIT:0> , wx . ALIGN_LEFT | wx . ALIGN_CENTER_VERTICAL ) <EOL> else : <EOL> self . hide_show_dict [ self . line_name ( address ) ] = True <EOL> if len ( address ) > <NUM_LIT:0> : <EOL> self . hide_show_dict [ self . remove_button_name ( address ) ] = True <EOL> self . hide_show_dict [ self . add_button_name ( address ) ] = True <EOL> self . hide_show_dict [ self . add_group_button_name ( address ) ] = True <EOL> if anyall . GetStringSelection ( ) != structure [ <NUM_LIT:0> ] . display_name : <EOL> anyall . SetStringSelection ( structure [ <NUM_LIT:0> ] . display_name ) <EOL> anyall . SetToolTipString ( structure [ <NUM_LIT:0> ] . doc ) <EOL> for subindex , substructure in enumerate ( structure [ <NUM_LIT:1> : ] ) : <EOL> subaddress = address + [ subindex ] <EOL> if substructure [ <NUM_LIT:0> ] . subpredicates is list : <EOL> self . populate_subpanel ( substructure , subaddress ) <EOL> else : <EOL> sizer = self . get_sizer ( subaddress ) <EOL> predicates = self . v . predicates <EOL> for i , token in enumerate ( substructure ) : <EOL> if isinstance ( token , basestring ) : <EOL> literal_ctrl = self . make_literal ( <EOL> token , i , subaddress , sizer ) <EOL> predicates = [ ] <EOL> else : <EOL> choice_ctrl = self . make_predicate_choice ( <EOL> predicates , i , subaddress , sizer ) <EOL> if choice_ctrl . GetStringSelection ( ) != token . display_name : <EOL> choice_ctrl . SetStringSelection ( token . display_name ) <EOL> if token . doc is not None : <EOL> choice_ctrl . SetToolTipString ( token . doc ) <EOL> predicates = token . subpredicates <EOL> i = len ( substructure ) <EOL> while len ( predicates ) > <NUM_LIT:0> : <EOL> if ( len ( predicates ) == <NUM_LIT:1> and <EOL> predicates [ <NUM_LIT:0> ] is cellprofiler . settings . Filter . LITERAL_PREDICATE ) : <EOL> self . make_literal ( "<STR_LIT>" , i , subaddress , sizer ) <EOL> else : <EOL> self . make_predicate_choice ( predicates , i , subaddress , <EOL> sizer ) <EOL> i += <NUM_LIT:1> <EOL> predicates = predicates [ <NUM_LIT:0> ] . subpredicates <EOL> name = self . remove_button_name ( address + [ <NUM_LIT:0> ] ) <EOL> delete_button = self . panel . FindWindowByName ( name ) <EOL> delete_button . Enable ( len ( structure ) > <NUM_LIT:2> ) <EOL> @ property <EOL> def key ( self ) : <EOL> return str ( self . v . key ( ) ) <EOL> @ staticmethod <EOL> def saddress ( address ) : <EOL> return "<STR_LIT:_>" . join ( [ str ( x ) for x in address ] ) <EOL> def anyall_choice_name ( self , address ) : <EOL> return "<STR_LIT>" % ( self . key , self . saddress ( address ) ) <EOL> def choice_name ( self , index , address ) : <EOL> return "<STR_LIT>" % ( self . key , index , self . saddress ( address ) ) <EOL> def literal_name ( self , index , address ) : <EOL> return "<STR_LIT>" % ( self . key , index , self . saddress ( address ) ) <EOL> def remove_button_name ( self , address ) : <EOL> return "<STR_LIT>" % ( self . key , self . saddress ( address ) ) <EOL> def add_button_name ( self , address ) : <EOL> return "<STR_LIT>" % ( self . key , self . saddress ( address ) ) <EOL> def add_group_button_name ( self , address ) : <EOL> return "<STR_LIT>" % ( self . key , self . saddress ( address ) ) <EOL> def line_name ( self , address ) : <EOL> return "<STR_LIT>" % ( self . key , self . saddress ( address ) ) <EOL> def static_text_name ( self , index , address ) : <EOL> return "<STR_LIT>" % ( self . key , index , self . saddress ( address ) ) <EOL> class FileCollectionDisplayController ( object ) : <EOL> """<STR_LIT>""" <EOL> IMAGE_LIST = wx . ImageList ( <NUM_LIT:16> , <NUM_LIT:16> , <NUM_LIT:3> ) <EOL> FOLDER_IMAGE_INDEX = IMAGE_LIST . Add ( <EOL> wx . ArtProvider . GetBitmap ( wx . ART_FOLDER , <EOL> wx . ART_OTHER , size = ( <NUM_LIT:16> , <NUM_LIT:16> ) ) ) <EOL> FOLDER_OPEN_IMAGE_INDEX = IMAGE_LIST . Add ( <EOL> wx . ArtProvider . GetBitmap ( wx . ART_FOLDER_OPEN , <EOL> wx . ART_OTHER , size = ( <NUM_LIT:16> , <NUM_LIT:16> ) ) ) <EOL> FILE_IMAGE_INDEX = IMAGE_LIST . Add ( <EOL> wx . ArtProvider . GetBitmap ( wx . ART_NORMAL_FILE , <EOL> wx . ART_OTHER , size = ( <NUM_LIT:16> , <NUM_LIT:16> ) ) ) <EOL> IMAGE_PLANE_IMAGE_INDEX = IMAGE_LIST . Add ( <EOL> cellprofiler . icons . get_builtin_image ( "<STR_LIT>" ) . ConvertToBitmap ( ) ) <EOL> IMAGE_PLANES_IMAGE_INDEX = IMAGE_LIST . Add ( <EOL> cellprofiler . icons . get_builtin_image ( "<STR_LIT>" ) . ConvertToBitmap ( ) ) <EOL> COLOR_IMAGE_INDEX = IMAGE_LIST . Add ( <EOL> cellprofiler . icons . get_builtin_image ( "<STR_LIT>" ) . ConvertToBitmap ( ) ) <EOL> MOVIE_IMAGE_INDEX = IMAGE_LIST . Add ( <EOL> cellprofiler . icons . get_builtin_image ( "<STR_LIT>" ) . ConvertToBitmap ( ) ) <EOL> ACTIVE_COLOR = wx . SystemSettings . GetColour ( wx . SYS_COLOUR_WINDOWTEXT ) <EOL> FILTERED_COLOR = wx . SystemSettings . GetColour ( wx . SYS_COLOUR_GRAYTEXT ) <EOL> class FCDCDropTarget ( wx . PyDropTarget ) : <EOL> def __init__ ( self , file_callback_fn , text_callback_fn ) : <EOL> super ( self . __class__ , self ) . __init__ ( ) <EOL> self . file_callback_fn = file_callback_fn <EOL> self . text_callback_fn = text_callback_fn <EOL> self . file_data_object = wx . FileDataObject ( ) <EOL> self . text_data_object = wx . TextDataObject ( ) <EOL> self . composite_data_object = wx . DataObjectComposite ( ) <EOL> self . composite_data_object . Add ( self . file_data_object , True ) <EOL> self . composite_data_object . Add ( self . text_data_object ) <EOL> self . SetDataObject ( self . composite_data_object ) <EOL> def OnDropFiles ( self , x , y , filenames ) : <EOL> self . file_callback_fn ( x , y , filenames ) <EOL> def OnDropText ( self , x , y , text ) : <EOL> self . text_callback_fn ( x , y , text ) <EOL> @ staticmethod <EOL> def OnEnter ( x , y , d ) : <EOL> return wx . DragCopy <EOL> @ staticmethod <EOL> def OnDragOver ( x , y , d ) : <EOL> return wx . DragCopy <EOL> def OnData ( self , x , y , d ) : <EOL> if self . GetData ( ) : <EOL> df = self . composite_data_object . GetReceivedFormat ( ) . GetType ( ) <EOL> if df in ( wx . DF_TEXT , wx . DF_UNICODETEXT ) : <EOL> self . OnDropText ( x , y , self . text_data_object . GetText ( ) ) <EOL> elif df == wx . DF_FILENAME : <EOL> self . OnDropFiles ( x , y , <EOL> self . file_data_object . GetFilenames ( ) ) <EOL> return wx . DragCopy <EOL> @ staticmethod <EOL> def OnDrop ( x , y ) : <EOL> return True <EOL> def __init__ ( self , module_view , v , pipeline ) : <EOL> assert isinstance ( v , cellprofiler . settings . FileCollectionDisplay ) <EOL> self . module_view = module_view <EOL> self . v = v <EOL> assert isinstance ( pipeline , cellprofiler . pipeline . Pipeline ) <EOL> self . pipeline = pipeline <EOL> self . panel = wx . Panel ( self . module_view . module_panel , - <NUM_LIT:1> , <EOL> name = edit_control_name ( v ) ) <EOL> self . panel . controller = self <EOL> self . panel . Sizer = wx . BoxSizer ( wx . VERTICAL ) <EOL> sizer = wx . BoxSizer ( wx . HORIZONTAL ) <EOL> self . panel . Sizer . Add ( sizer , <NUM_LIT:0> , wx . EXPAND ) <EOL> self . status_text = wx . StaticText ( self . panel , - <NUM_LIT:1> ) <EOL> sizer . Add ( self . status_text , <NUM_LIT:0> , wx . ALIGN_LEFT | wx . ALIGN_CENTER ) <EOL> sizer . AddStretchSpacer ( ) <EOL> sizer . Add ( wx . StaticText ( self . panel , - <NUM_LIT:1> , <EOL> "<STR_LIT>" ) , <EOL> <NUM_LIT:0> , wx . ALIGN_LEFT | wx . ALIGN_CENTER ) <EOL> sizer . AddSpacer ( ( <NUM_LIT:3> , <NUM_LIT:0> ) ) <EOL> browse_button = wx . Button ( self . panel , - <NUM_LIT:1> , "<STR_LIT>" ) <EOL> sizer . Add ( browse_button , <NUM_LIT:0> , wx . ALIGN_LEFT | wx . ALIGN_CENTER ) <EOL> browse_button . Bind ( wx . EVT_BUTTON , self . on_browse ) <EOL> tree_style = wx . TR_HIDE_ROOT | wx . TR_HAS_BUTTONS | wx . TR_MULTIPLE <EOL> self . tree_ctrl = wx . TreeCtrl ( self . panel , - <NUM_LIT:1> , <EOL> style = tree_style ) <EOL> self . panel . Sizer . Add ( self . tree_ctrl , <NUM_LIT:1> , wx . EXPAND ) <EOL> self . tree_ctrl . SetImageList ( self . IMAGE_LIST ) <EOL> self . tree_ctrl . Bind ( wx . EVT_TREE_ITEM_MENU , self . on_tree_item_menu ) <EOL> self . tree_ctrl . Bind ( wx . EVT_TREE_KEY_DOWN , self . on_tree_key_down ) <EOL> self . user_collapsed_a_node = False <EOL> def on_item_collapsed ( event ) : <EOL> logger . debug ( "<STR_LIT>" ) <EOL> self . user_collapsed_a_node = True <EOL> self . tree_ctrl . Bind ( wx . EVT_TREE_ITEM_COLLAPSED , on_item_collapsed ) <EOL> self . tree_ctrl . Bind ( wx . EVT_TREE_ITEM_ACTIVATED , self . on_tree_doubleclick ) <EOL> self . tree_ctrl . Bind ( wx . EVT_ERASE_BACKGROUND , self . on_erase_background ) <EOL> self . panel . Bind ( wx . EVT_WINDOW_DESTROY , self . on_destroy ) <EOL> self . root_item = self . tree_ctrl . AddRoot ( "<STR_LIT>" ) <EOL> self . tree_ctrl . SetPyData ( self . root_item , None ) <EOL> self . tree_ctrl . SetItemImage ( self . root_item , self . FOLDER_IMAGE_INDEX ) <EOL> self . tree_ctrl . SetItemImage ( self . root_item , <EOL> self . FOLDER_OPEN_IMAGE_INDEX , <EOL> wx . TreeItemIcon_Expanded ) <EOL> self . tree_ctrl . SetMinSize ( ( <NUM_LIT:100> , <NUM_LIT> ) ) <EOL> self . tree_ctrl . SetMaxSize ( ( sys . maxint , <NUM_LIT> ) ) <EOL> self . file_drop_target = self . FCDCDropTarget ( self . on_drop_files , <EOL> self . on_drop_text ) <EOL> self . tree_ctrl . SetDropTarget ( self . file_drop_target ) <EOL> sizer = wx . BoxSizer ( wx . HORIZONTAL ) <EOL> self . panel . Sizer . Add ( sizer , <NUM_LIT:0> , wx . EXPAND ) <EOL> self . hide_show_ctrl = wx . CheckBox ( self . panel , - <NUM_LIT:1> , <EOL> self . v . hide_text ) <EOL> sizer . Add ( self . hide_show_ctrl , <NUM_LIT:0> , <EOL> wx . ALIGN_LEFT | wx . ALIGN_BOTTOM ) <EOL> self . hide_show_ctrl . Bind ( wx . EVT_CHECKBOX , self . on_hide_show_checked ) <EOL> self . hide_show_ctrl . Value = not self . v . show_filtered <EOL> sizer . AddStretchSpacer ( ) <EOL> self . stop_button = wx . Button ( self . panel , - <NUM_LIT:1> , "<STR_LIT>" ) <EOL> self . stop_button . Enable ( False ) <EOL> self . stop_button . Bind ( wx . EVT_BUTTON , self . on_stop ) <EOL> sizer . Add ( self . stop_button , <NUM_LIT:0> , wx . ALIGN_LEFT | wx . ALIGN_CENTER_VERTICAL ) <EOL> self . pause_button = wx . Button ( self . panel , - <NUM_LIT:1> , "<STR_LIT>" ) <EOL> self . pause_button . Enable ( False ) <EOL> self . pause_button . Bind ( wx . EVT_BUTTON , self . on_pause_resume ) <EOL> sizer . Add ( self . pause_button , <NUM_LIT:0> , wx . ALIGN_LEFT | wx . ALIGN_CENTER_VERTICAL ) <EOL> v . set_update_function ( self . request_update ) <EOL> self . needs_update = False <EOL> self . modpath_to_item = { } <EOL> self . request_update ( ) <EOL> def __del__ ( self ) : <EOL> self . on_destroy ( None ) <EOL> def on_destroy ( self , event ) : <EOL> self . v . set_update_function ( ) <EOL> def on_erase_background ( self , event ) : <EOL> assert isinstance ( event , wx . EraseEvent ) <EOL> dc = event . DC <EOL> assert isinstance ( dc , wx . DC ) <EOL> brush = wx . Brush ( self . tree_ctrl . GetBackgroundColour ( ) ) <EOL> dc . SetBrush ( brush ) <EOL> dc . SetPen ( wx . TRANSPARENT_PEN ) <EOL> width , height = self . tree_ctrl . GetSize ( ) <EOL> dc . DrawRectangle ( <NUM_LIT:0> , <NUM_LIT:0> , width , height ) <EOL> if len ( self . modpath_to_item ) == <NUM_LIT:0> : <EOL> text = "<STR_LIT>" <EOL> font = wx . Font ( <NUM_LIT> , wx . FONTFAMILY_SWISS , wx . FONTSTYLE_NORMAL , <EOL> wx . FONTWEIGHT_BOLD ) <EOL> dc . SetTextForeground ( wx . SystemSettings . GetColour ( wx . SYS_COLOUR_GRAYTEXT ) ) <EOL> dc . SetFont ( font ) <EOL> text_width , text_height = dc . GetTextExtent ( text ) <EOL> dc . DrawText ( text , <EOL> ( width - text_width ) / <NUM_LIT:2> , <EOL> ( height - text_height ) / <NUM_LIT:2> ) <EOL> def on_browse ( self , event ) : <EOL> logger . debug ( "<STR_LIT>" ) <EOL> dlg = wx . DirDialog ( self . panel , "<STR_LIT>" ) <EOL> try : <EOL> if dlg . ShowModal ( ) == wx . ID_OK : <EOL> self . v . fn_on_drop ( [ dlg . Path ] , True ) <EOL> finally : <EOL> dlg . Destroy ( ) <EOL> def on_start_received ( self ) : <EOL> self . pause_button . Label = "<STR_LIT>" <EOL> self . pause_button . Enable ( True ) <EOL> self . stop_button . Enable ( True ) <EOL> def on_stop_received ( self ) : <EOL> self . pause_button . Enable ( False ) <EOL> self . stop_button . Enable ( False ) <EOL> def on_stop ( self , event ) : <EOL> """<STR_LIT>""" <EOL> self . v . fn_on_bkgnd_control ( self . v . BKGND_STOP ) <EOL> self . pause_button . Label = "<STR_LIT>" <EOL> self . pause_button . Enable ( False ) <EOL> self . stop_button . Enable ( False ) <EOL> def on_pause_resume ( self , event ) : <EOL> """<STR_LIT>""" <EOL> if self . pause_button . Label == "<STR_LIT>" : <EOL> action = self . v . BKGND_PAUSE <EOL> self . pause_button . Label = "<STR_LIT>" <EOL> else : <EOL> action = self . v . BKGND_RESUME <EOL> self . pause_button . Label = "<STR_LIT>" <EOL> self . v . fn_on_bkgnd_control ( action ) <EOL> def add_item ( self , modpath , text = None , sort = True ) : <EOL> """<STR_LIT>""" <EOL> parent_key = tuple ( modpath [ : - <NUM_LIT:1> ] ) <EOL> modpath = tuple ( modpath ) <EOL> if self . modpath_to_item . has_key ( modpath ) : <EOL> item = self . modpath_to_item [ modpath ] <EOL> if text is not None : <EOL> self . tree_ctrl . SetItemText ( item , text ) <EOL> return item <EOL> if text is None : <EOL> text = modpath [ - <NUM_LIT:1> ] <EOL> if len ( modpath ) == <NUM_LIT:1> : <EOL> parent_item = self . root_item <EOL> elif self . modpath_to_item . has_key ( parent_key ) : <EOL> parent_item = self . modpath_to_item [ parent_key ] <EOL> else : <EOL> parent_item = self . add_item ( parent_key , sort = sort ) <EOL> self . tree_ctrl . SetItemImage ( parent_item , self . FOLDER_IMAGE_INDEX ) <EOL> self . tree_ctrl . SetItemImage ( parent_item , <EOL> self . FOLDER_OPEN_IMAGE_INDEX , <EOL> wx . TreeItemIcon_Expanded ) <EOL> want_erase = len ( self . modpath_to_item ) == <NUM_LIT:0> <EOL> n_children = self . tree_ctrl . GetChildrenCount ( parent_item ) <EOL> if n_children == <NUM_LIT:0> or not sort : <EOL> item = self . tree_ctrl . AppendItem ( parent_item , text ) <EOL> else : <EOL> child , cookie = self . tree_ctrl . GetFirstChild ( parent_item ) <EOL> for i in range ( n_children ) : <EOL> ctext = self . tree_ctrl . GetItemText ( child ) <EOL> if ctext > text : <EOL> item = self . tree_ctrl . InsertItemBefore ( parent_item , i , text ) <EOL> break <EOL> child = self . tree_ctrl . GetNextSibling ( child ) <EOL> else : <EOL> item = self . tree_ctrl . AppendItem ( parent_item , text ) <EOL> self . tree_ctrl . SetPyData ( item , modpath [ - <NUM_LIT:1> ] ) <EOL> self . modpath_to_item [ modpath ] = item <EOL> if want_erase : <EOL> self . tree_ctrl . Refresh ( True ) <EOL> return item <EOL> def remove_item ( self , modpath ) : <EOL> modpath = tuple ( modpath ) <EOL> if self . modpath_to_item . has_key ( modpath ) : <EOL> item = self . modpath_to_item [ modpath ] <EOL> n_children = self . tree_ctrl . GetChildrenCount ( item , False ) <EOL> if n_children > <NUM_LIT:0> : <EOL> child , cookie = self . tree_ctrl . GetFirstChild ( item ) <EOL> child_tokens = [ ] <EOL> for i in range ( n_children ) : <EOL> child_tokens . append ( self . tree_ctrl . GetItemPyData ( child ) ) <EOL> child = self . tree_ctrl . GetNextSibling ( child ) <EOL> for child_token in child_tokens : <EOL> sub_modpath = list ( modpath ) + [ child_token ] <EOL> self . remove_item ( sub_modpath ) <EOL> self . tree_ctrl . Delete ( self . modpath_to_item [ modpath ] ) <EOL> del self . modpath_to_item [ modpath ] <EOL> @ classmethod <EOL> def get_modpath ( cls , path ) : <EOL> """<STR_LIT>""" <EOL> result = [ ] <EOL> while True : <EOL> new_path , part = os . path . split ( path ) <EOL> if len ( new_path ) == <NUM_LIT:0> or len ( part ) == <NUM_LIT:0> : <EOL> result . insert ( <NUM_LIT:0> , path ) <EOL> return result <EOL> result . insert ( <NUM_LIT:0> , part ) <EOL> path = new_path <EOL> def on_drop_files ( self , x , y , filenames ) : <EOL> self . v . fn_on_drop ( filenames , True ) <EOL> def on_drop_text ( self , x , y , text ) : <EOL> """<STR_LIT>""" <EOL> filenames = [ line . strip ( ) for line in text . split ( "<STR_LIT:\n>" ) <EOL> if len ( line . strip ( ) ) > <NUM_LIT:0> ] <EOL> self . v . fn_on_drop ( filenames , False ) <EOL> def get_path_from_event ( self , event ) : <EOL> """<STR_LIT>""" <EOL> item = event . GetItem ( ) <EOL> path = [ ] <EOL> while True : <EOL> item_data = self . tree_ctrl . GetItemPyData ( item ) <EOL> if item_data is None : <EOL> break <EOL> path . insert ( <NUM_LIT:0> , item_data ) <EOL> item = self . tree_ctrl . GetItemParent ( item ) <EOL> return path <EOL> def on_tree_item_menu ( self , event ) : <EOL> logger . debug ( "<STR_LIT>" ) <EOL> path = self . get_path_from_event ( event ) <EOL> if len ( path ) == <NUM_LIT:0> : <EOL> logger . warn ( "<STR_LIT>" ) <EOL> return <EOL> context_menu = self . v . get_context_menu ( path ) <EOL> if len ( context_menu ) > <NUM_LIT:0> : <EOL> menu = wx . Menu ( ) <EOL> try : <EOL> delete_menu_items = [ ] <EOL> for context_item in context_menu : <EOL> if isinstance ( context_item , <EOL> cellprofiler . settings . FileCollectionDisplay . DeleteMenuItem ) : <EOL> delete_menu_items . append ( <EOL> menu . Append ( - <NUM_LIT:1> , context_item . text ) . Id ) <EOL> else : <EOL> menu . Append ( - <NUM_LIT:1> , context_item ) <EOL> def on_menu ( event ) : <EOL> logger . debug ( "<STR_LIT>" ) <EOL> self . pipeline . start_undoable_action ( ) <EOL> try : <EOL> for menu_item in menu . GetMenuItems ( ) : <EOL> if menu_item . Id == event . Id : <EOL> logger . debug ( "<STR_LIT>" % menu_item . Text ) <EOL> if menu_item . Id in delete_menu_items : <EOL> self . on_delete_selected ( event ) <EOL> else : <EOL> self . v . fn_on_menu_command ( path , menu_item . Text ) <EOL> break <EOL> finally : <EOL> self . pipeline . stop_undoable_action ( ) <EOL> self . tree_ctrl . Bind ( wx . EVT_MENU , on_menu ) <EOL> self . tree_ctrl . PopupMenu ( menu , event . GetPoint ( ) ) <EOL> self . tree_ctrl . Unbind ( wx . EVT_MENU , handler = on_menu ) <EOL> finally : <EOL> menu . Destroy ( ) <EOL> def on_tree_doubleclick ( self , event ) : <EOL> path = self . get_path_from_event ( event ) <EOL> if self . v . fn_on_menu_command ( path , None ) : <EOL> return True <EOL> def on_tree_key_down ( self , event ) : <EOL> logger . debug ( "<STR_LIT>" ) <EOL> key = event . GetKeyCode ( ) <EOL> if key == wx . WXK_DELETE : <EOL> self . on_delete_selected ( event ) <EOL> def on_delete_selected ( self , event ) : <EOL> mods = [ self . get_item_address ( item ) <EOL> for item in self . tree_ctrl . GetSelections ( ) ] <EOL> mods = filter ( lambda x : x is not None , mods ) <EOL> self . v . on_remove ( [ self . v . get_tree_modpaths ( mod ) for mod in mods ] ) <EOL> def get_item_address ( self , item ) : <EOL> """<STR_LIT>""" <EOL> result = [ ] <EOL> while True : <EOL> name = self . tree_ctrl . GetItemPyData ( item ) <EOL> if name is None : <EOL> break <EOL> else : <EOL> result . insert ( <NUM_LIT:0> , name ) <EOL> item = self . tree_ctrl . GetItemParent ( item ) <EOL> return result <EOL> def get_item_from_modpath ( self , modpath ) : <EOL> """<STR_LIT>""" <EOL> return self . modpath_to_item . get ( tuple ( modpath ) ) <EOL> def request_update ( self , hint = None , modpath = None ) : <EOL> if hint == cellprofiler . settings . FileCollectionDisplay . BKGND_RESUME : <EOL> self . on_start_received ( ) <EOL> return <EOL> if hint == cellprofiler . settings . FileCollectionDisplay . BKGND_STOP : <EOL> self . on_stop_received ( ) <EOL> self . status_text . Label = "<STR_LIT>" <EOL> return <EOL> if modpath is not None and len ( modpath ) > <NUM_LIT:0> : <EOL> path = [ ] <EOL> mp = modpath [ <NUM_LIT:0> ] <EOL> any_others = len ( modpath ) > <NUM_LIT:1> <EOL> if hint != cellprofiler . settings . FileCollectionDisplay . REMOVE : <EOL> file_tree = self . v . file_tree <EOL> is_filtered = False <EOL> while True : <EOL> if isinstance ( mp , basestring ) or isinstance ( mp , tuple ) and len ( mp ) == <NUM_LIT:3> : <EOL> path . append ( mp ) <EOL> if hint != cellprofiler . settings . FileCollectionDisplay . REMOVE : <EOL> is_filtered = not file_tree [ mp ] <EOL> break <EOL> part , mp_list = mp <EOL> path . append ( part ) <EOL> if hint != cellprofiler . settings . FileCollectionDisplay . REMOVE : <EOL> file_tree = file_tree [ part ] <EOL> if len ( mp_list ) == <NUM_LIT:0> : <EOL> is_filtered = not file_tree [ None ] <EOL> break <EOL> any_others = any_others or len ( mp_list ) > <NUM_LIT:1> <EOL> mp = mp_list [ <NUM_LIT:0> ] <EOL> if hint != cellprofiler . settings . FileCollectionDisplay . REMOVE : <EOL> self . status_text . Label = ( "<STR_LIT>" + path [ - <NUM_LIT:1> ] if isinstance ( path [ - <NUM_LIT:1> ] , basestring ) <EOL> else path [ - <NUM_LIT:2> ] ) <EOL> self . status_text . Update ( ) <EOL> if not any_others : <EOL> if hint == cellprofiler . settings . FileCollectionDisplay . METADATA : <EOL> if ( not self . v . show_filtered ) and is_filtered : <EOL> return <EOL> item_id = self . get_item_from_modpath ( path ) <EOL> if item_id is not None : <EOL> text , node_type , tooltip = self . v . get_node_info ( path ) <EOL> image_id = self . get_image_id_from_nodetype ( node_type ) <EOL> self . tree_ctrl . SetItemText ( item_id , text ) <EOL> self . tree_ctrl . SetItemImage ( item_id , image_id ) <EOL> return <EOL> elif hint == cellprofiler . settings . FileCollectionDisplay . ADD : <EOL> if self . get_item_from_modpath ( path ) is None : <EOL> text , node_type , tooltip = self . v . get_node_info ( path ) <EOL> item_id = self . add_item ( path , text ) <EOL> image_id = self . get_image_id_from_nodetype ( node_type ) <EOL> self . tree_ctrl . SetItemImage ( item_id , image_id ) <EOL> self . manage_expansion ( ) <EOL> return <EOL> elif hint == cellprofiler . settings . FileCollectionDisplay . REMOVE : <EOL> if is_filtered : <EOL> return <EOL> self . remove_item ( path ) <EOL> if len ( path ) > <NUM_LIT:1> : <EOL> super_modpath = tuple ( path [ : - <NUM_LIT:1> ] ) <EOL> if super_modpath in self . modpath_to_item : <EOL> item = self . modpath_to_item [ super_modpath ] <EOL> n_children = self . tree_ctrl . GetChildrenCount ( <EOL> item , False ) <EOL> if n_children == <NUM_LIT:0> : <EOL> self . remove_item ( super_modpath ) <EOL> return <EOL> self . update ( ) <EOL> def update ( self ) : <EOL> operation_id = uuid . uuid4 ( ) <EOL> total = self . v . node_count ( ) <EOL> if total == <NUM_LIT:0> : <EOL> return <EOL> self . update_subtree ( self . v . file_tree , self . root_item , False , [ ] , <EOL> operation_id , <NUM_LIT:0> , total ) <EOL> self . manage_expansion ( ) <EOL> cellprofiler . preferences . report_progress ( operation_id , <NUM_LIT:1> , None ) <EOL> def manage_expansion ( self ) : <EOL> """<STR_LIT>""" <EOL> if not self . user_collapsed_a_node : <EOL> item = self . root_item <EOL> while self . tree_ctrl . GetChildrenCount ( item , False ) == <NUM_LIT:1> : <EOL> if sys . platform != "<STR_LIT>" or item != self . root_item : <EOL> self . tree_ctrl . Expand ( item ) <EOL> item , cookie = self . tree_ctrl . GetFirstChild ( item ) <EOL> if self . tree_ctrl . GetChildrenCount ( item , False ) > <NUM_LIT:0> : <EOL> self . tree_ctrl . Expand ( item ) <EOL> for i in range ( self . tree_ctrl . GetChildrenCount ( self . root_item , False ) ) : <EOL> if i == <NUM_LIT:0> : <EOL> bottom_item , thing = self . tree_ctrl . GetFirstChild ( self . root_item ) <EOL> else : <EOL> bottom_item , thing = self . tree_ctrl . GetNextChild ( self . root_item , thing ) <EOL> if not self . tree_ctrl . IsExpanded ( bottom_item ) : <EOL> self . tree_ctrl . Expand ( bottom_item ) <EOL> def update_subtree ( self , file_tree , parent_item , <EOL> is_filtered , modpath , operation_id , count , total ) : <EOL> existing_items = { } <EOL> show_filtered = self . v . show_filtered <EOL> needs_sort = False <EOL> child_count = self . tree_ctrl . GetChildrenCount ( parent_item , False ) <EOL> if child_count > <NUM_LIT:0> : <EOL> child_item_id , cookie = self . tree_ctrl . GetFirstChild ( parent_item ) <EOL> for i in range ( child_count ) : <EOL> existing_items [ self . tree_ctrl . GetItemPyData ( child_item_id ) ] = [ child_item_id , False ] <EOL> if i < child_count - <NUM_LIT:1> : <EOL> child_item_id = self . tree_ctrl . GetNextSibling ( child_item_id ) <EOL> for x in sorted ( file_tree . keys ( ) ) : <EOL> sub_modpath = modpath + [ x ] <EOL> if x is None : <EOL> continue <EOL> text , node_type , tooltip = self . v . get_node_info ( sub_modpath ) <EOL> cellprofiler . preferences . report_progress ( <EOL> operation_id , <EOL> float ( count ) / float ( total ) , <EOL> "<STR_LIT>" % text ) <EOL> count += <NUM_LIT:1> <EOL> image_id = self . get_image_id_from_nodetype ( node_type ) <EOL> if isinstance ( file_tree [ x ] , bool ) or isinstance ( x , tuple ) : <EOL> node_is_filtered = ( not file_tree [ x ] ) or is_filtered <EOL> if node_is_filtered and not show_filtered : <EOL> continue <EOL> if existing_items . has_key ( x ) : <EOL> existing_items [ x ] [ <NUM_LIT:1> ] = True <EOL> item_id = existing_items [ x ] [ <NUM_LIT:0> ] <EOL> self . tree_ctrl . SetItemText ( item_id , text ) <EOL> else : <EOL> item_id = self . add_item ( sub_modpath , text , sort = False ) <EOL> existing_items [ x ] = ( item_id , True ) <EOL> needs_sort = True <EOL> self . tree_ctrl . SetItemImage ( item_id , image_id ) <EOL> elif isinstance ( file_tree [ x ] , dict ) : <EOL> subtree = file_tree [ x ] <EOL> node_is_filtered = ( not subtree [ None ] ) or is_filtered <EOL> unfiltered_subfolders , filtered_subfolders , unfiltered_files , filtered_files = self . get_file_and_folder_counts ( subtree ) <EOL> n_subfolders = unfiltered_subfolders + filtered_subfolders <EOL> n_files = unfiltered_files + filtered_files <EOL> if node_is_filtered and not show_filtered : <EOL> continue <EOL> if node_type in ( cellprofiler . settings . FileCollectionDisplay . NODE_COMPOSITE_IMAGE , <EOL> cellprofiler . settings . FileCollectionDisplay . NODE_MOVIE ) : <EOL> expanded_image_id = image_id <EOL> else : <EOL> image_id = self . FOLDER_IMAGE_INDEX <EOL> expanded_image_id = self . FOLDER_OPEN_IMAGE_INDEX <EOL> text = "<STR_LIT>" + x <EOL> if n_subfolders > <NUM_LIT:0> or n_files > <NUM_LIT:0> : <EOL> text += "<STR_LIT>" <EOL> if n_subfolders > <NUM_LIT:0> : <EOL> if node_is_filtered : <EOL> text += "<STR_LIT>" % n_subfolders <EOL> else : <EOL> text += "<STR_LIT>" % ( <EOL> unfiltered_subfolders , n_subfolders ) <EOL> if n_files > <NUM_LIT:0> : <EOL> text += "<STR_LIT:U+002CU+0020>" <EOL> if n_files > <NUM_LIT:0> : <EOL> if node_is_filtered : <EOL> text += "<STR_LIT>" % n_files <EOL> else : <EOL> text += "<STR_LIT>" % ( <EOL> unfiltered_files , n_files ) <EOL> text += "<STR_LIT:)>" <EOL> if existing_items . has_key ( x ) : <EOL> existing_items [ x ] [ <NUM_LIT:1> ] = True <EOL> item_id = existing_items [ x ] [ <NUM_LIT:0> ] <EOL> self . tree_ctrl . SetItemText ( item_id , text ) <EOL> else : <EOL> item_id = self . add_item ( sub_modpath , text , sort = False ) <EOL> existing_items [ x ] = ( item_id , True ) <EOL> needs_sort = True <EOL> self . tree_ctrl . SetItemImage ( item_id , image_id ) <EOL> self . tree_ctrl . SetItemImage ( item_id , expanded_image_id , <EOL> wx . TreeItemIcon_Expanded ) <EOL> has_children = n_subfolders + n_files > <NUM_LIT:0> <EOL> self . tree_ctrl . SetItemHasChildren ( item_id , has_children ) <EOL> count = self . update_subtree ( <EOL> subtree , item_id , node_is_filtered , <EOL> sub_modpath , operation_id , count , total ) <EOL> color = self . FILTERED_COLOR if node_is_filtered else self . ACTIVE_COLOR <EOL> self . tree_ctrl . SetItemTextColour ( item_id , color ) <EOL> for last_part , ( item_id , keep ) in existing_items . iteritems ( ) : <EOL> if not keep : <EOL> self . remove_item ( modpath + [ last_part ] ) <EOL> if needs_sort : <EOL> self . tree_ctrl . SortChildren ( parent_item ) <EOL> return count <EOL> def get_image_id_from_nodetype ( self , node_type ) : <EOL> if node_type == cellprofiler . settings . FileCollectionDisplay . NODE_COLOR_IMAGE : <EOL> image_id = self . COLOR_IMAGE_INDEX <EOL> elif node_type == cellprofiler . settings . FileCollectionDisplay . NODE_COMPOSITE_IMAGE : <EOL> image_id = self . IMAGE_PLANES_IMAGE_INDEX <EOL> elif node_type in ( cellprofiler . settings . FileCollectionDisplay . NODE_MONOCHROME_IMAGE , <EOL> cellprofiler . settings . FileCollectionDisplay . NODE_IMAGE_PLANE ) : <EOL> image_id = self . IMAGE_PLANE_IMAGE_INDEX <EOL> elif node_type == cellprofiler . settings . FileCollectionDisplay . NODE_MOVIE : <EOL> image_id = self . MOVIE_IMAGE_INDEX <EOL> else : <EOL> image_id = self . FILE_IMAGE_INDEX <EOL> return image_id <EOL> @ classmethod <EOL> def get_file_and_folder_counts ( cls , tree ) : <EOL> """<STR_LIT>""" <EOL> unfiltered_subfolders = filtered_subfolders = <NUM_LIT:0> <EOL> unfiltered_files = filtered_files = <NUM_LIT:0> <EOL> for key in tree : <EOL> if key is None : <EOL> continue <EOL> if isinstance ( tree [ key ] , bool ) : <EOL> if tree [ key ] : <EOL> unfiltered_files += <NUM_LIT:1> <EOL> else : <EOL> filtered_files += <NUM_LIT:1> <EOL> else : <EOL> is_filtered = not tree [ key ] [ None ] <EOL> if is_filtered : <EOL> unfiltered_subfolders += <NUM_LIT:1> <EOL> else : <EOL> filtered_subfolders += <NUM_LIT:1> <EOL> ufolders , ffolders , ufiles , ffiles = cls . get_file_and_folder_counts ( tree [ key ] ) <EOL> filtered_files += ffiles <EOL> if is_filtered : <EOL> filtered_files += ufiles <EOL> else : <EOL> unfiltered_files += ufiles <EOL> return unfiltered_subfolders , filtered_subfolders , unfiltered_files , filtered_files <EOL> def on_hide_show_checked ( self , event ) : <EOL> self . v . show_filtered = not self . hide_show_ctrl . Value <EOL> self . request_update ( ) <EOL> class JoinerController ( object ) : <EOL> """<STR_LIT>""" <EOL> DISPLAY_NONE = "<STR_LIT>" <EOL> def __init__ ( self , module_view , v ) : <EOL> super ( self . __class__ , self ) . __init__ ( ) <EOL> assert isinstance ( module_view , ModuleView ) <EOL> self . module_view = module_view <EOL> self . v = v <EOL> self . panel = wx . Panel ( module_view . module_panel , - <NUM_LIT:1> , <EOL> name = edit_control_name ( v ) ) <EOL> self . panel . Sizer = wx . lib . rcsizer . RowColSizer ( ) <EOL> self . panel . joiner_controller = self <EOL> self . update ( ) <EOL> def get_header_control_name ( self , colidx ) : <EOL> return "<STR_LIT>" % ( colidx , str ( self . v . key ( ) ) ) <EOL> def get_add_button_control_name ( self , rowidx ) : <EOL> return "<STR_LIT>" % ( rowidx , str ( self . v . key ( ) ) ) <EOL> def get_delete_button_control_name ( self , rowidx ) : <EOL> return "<STR_LIT>" % ( rowidx , str ( self . v . key ( ) ) ) <EOL> def get_up_button_control_name ( self , rowidx ) : <EOL> return "<STR_LIT>" % ( rowidx , str ( self . v . key ( ) ) ) <EOL> def get_down_button_control_name ( self , rowidx ) : <EOL> return "<STR_LIT>" % ( rowidx , str ( self . v . key ( ) ) ) <EOL> def get_choice_control_name ( self , rowidx , colidx ) : <EOL> return "<STR_LIT>" % ( rowidx , colidx , str ( self . v . key ( ) ) ) <EOL> @ classmethod <EOL> def update_control ( cls , module_view , v ) : <EOL> """<STR_LIT>""" <EOL> assert isinstance ( module_view , ModuleView ) <EOL> control = module_view . module_panel . FindWindowByName ( edit_control_name ( v ) ) <EOL> if control is None : <EOL> jc = JoinerController ( module_view , v ) <EOL> return jc . panel <EOL> else : <EOL> control . joiner_controller . update ( ) <EOL> return control <EOL> @ property <EOL> def column_names ( self ) : <EOL> """<STR_LIT>""" <EOL> return sorted ( self . v . entities . keys ( ) ) <EOL> @ property <EOL> def joins ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . v . parse ( ) <EOL> def update ( self ) : <EOL> """<STR_LIT>""" <EOL> column_names = self . column_names <EOL> joins = self . joins <EOL> if len ( joins ) == <NUM_LIT:0> : <EOL> joins = [ dict ( [ ( cn , "<STR_LIT>" ) for cn in column_names ] ) ] <EOL> all_subcontrols = { } <EOL> self . panel . Sizer . Clear ( ) <EOL> for ctrl in self . panel . GetChildren ( ) : <EOL> assert isinstance ( ctrl , wx . Window ) <EOL> all_subcontrols [ ctrl . GetName ( ) ] = False <EOL> for i , column_name in enumerate ( column_names ) : <EOL> header_control_name = self . get_header_control_name ( i ) <EOL> ctrl = self . panel . FindWindowByName ( header_control_name ) <EOL> if ctrl is None : <EOL> ctrl = wx . StaticText ( self . panel , - <NUM_LIT:1> , column_name , <EOL> name = header_control_name ) <EOL> else : <EOL> ctrl . Label = column_name <EOL> self . panel . Sizer . Add ( <EOL> ctrl , row = <NUM_LIT:0> , col = i , <EOL> flag = wx . ALIGN_CENTER_HORIZONTAL | wx . ALIGN_BOTTOM ) <EOL> all_subcontrols [ header_control_name ] = True <EOL> for i , join in enumerate ( joins ) : <EOL> for j , column_name in enumerate ( column_names ) : <EOL> choice_ctrl_name = self . get_choice_control_name ( i , j ) <EOL> ctrl = self . panel . FindWindowByName ( choice_ctrl_name ) <EOL> selection = join . get ( column_name , self . DISPLAY_NONE ) <EOL> if selection is None : <EOL> selection = self . DISPLAY_NONE <EOL> choices = sorted ( self . v . entities . get ( column_name , [ ] ) ) <EOL> if self . v . allow_none : <EOL> choices += [ self . DISPLAY_NONE ] <EOL> if selection not in choices : <EOL> choices += [ selection ] <EOL> if ctrl is None : <EOL> ctrl = wx . Choice ( self . panel , - <NUM_LIT:1> , <EOL> choices = choices , <EOL> name = choice_ctrl_name ) <EOL> ctrl . Bind ( wx . EVT_CHOICE , <EOL> lambda event , row = i , col = j : <EOL> self . on_choice_changed ( event , row , col ) ) <EOL> else : <EOL> ctrl . SetItems ( choices ) <EOL> ctrl . SetStringSelection ( selection ) <EOL> self . panel . Sizer . Add ( ctrl , row = i + <NUM_LIT:1> , col = j , <EOL> flag = wx . ALIGN_BOTTOM ) <EOL> all_subcontrols [ choice_ctrl_name ] = True <EOL> add_button_name = self . get_add_button_control_name ( i ) <EOL> ctrl = self . panel . FindWindowByName ( add_button_name ) <EOL> if ctrl is None : <EOL> ctrl = wx . Button ( self . panel , - <NUM_LIT:1> , "<STR_LIT:+>" , <EOL> name = add_button_name , <EOL> style = wx . BU_EXACTFIT ) <EOL> ctrl . Bind ( wx . EVT_BUTTON , <EOL> lambda event , position = i + <NUM_LIT:1> : <EOL> self . on_insert_row ( event , position ) ) <EOL> self . panel . Sizer . Add ( ctrl , row = i + <NUM_LIT:1> , col = len ( column_names ) , <EOL> flag = wx . ALIGN_BOTTOM ) <EOL> all_subcontrols [ add_button_name ] = True <EOL> if len ( joins ) > <NUM_LIT:1> : <EOL> delete_button_name = self . get_delete_button_control_name ( i ) <EOL> ctrl = self . panel . FindWindowByName ( delete_button_name ) <EOL> if ctrl is None : <EOL> ctrl = wx . Button ( self . panel , - <NUM_LIT:1> , "<STR_LIT:->" , <EOL> name = delete_button_name , <EOL> style = wx . BU_EXACTFIT ) <EOL> ctrl . Bind ( wx . EVT_BUTTON , <EOL> lambda event , position = i : <EOL> self . on_delete_row ( event , position ) ) <EOL> self . panel . Sizer . Add ( ctrl , row = i + <NUM_LIT:1> , col = len ( column_names ) + <NUM_LIT:1> , <EOL> flag = wx . ALIGN_BOTTOM ) <EOL> all_subcontrols [ delete_button_name ] = True <EOL> if i > <NUM_LIT:0> : <EOL> move_up_button_name = self . get_up_button_control_name ( i ) <EOL> ctrl = self . panel . FindWindowByName ( move_up_button_name ) <EOL> if ctrl is None : <EOL> img = wx . ArtProvider . GetBitmap ( wx . ART_GO_UP , <EOL> wx . ART_BUTTON , <EOL> ( <NUM_LIT:16> , <NUM_LIT:16> ) ) <EOL> ctrl = wx . BitmapButton ( self . panel , - <NUM_LIT:1> , img , <EOL> name = move_up_button_name ) <EOL> ctrl . Bind ( wx . EVT_BUTTON , <EOL> lambda event , position = i : <EOL> self . on_move_row_up ( event , position ) ) <EOL> self . panel . Sizer . Add ( ctrl , row = i + <NUM_LIT:1> , col = len ( column_names ) + <NUM_LIT:2> , <EOL> flag = wx . ALIGN_BOTTOM ) <EOL> all_subcontrols [ move_up_button_name ] = True <EOL> if i < len ( joins ) - <NUM_LIT:1> : <EOL> move_down_button_name = self . get_down_button_control_name ( i ) <EOL> ctrl = self . panel . FindWindowByName ( move_down_button_name ) <EOL> if ctrl is None : <EOL> img = wx . ArtProvider . GetBitmap ( wx . ART_GO_DOWN , <EOL> wx . ART_BUTTON , <EOL> ( <NUM_LIT:16> , <NUM_LIT:16> ) ) <EOL> ctrl = wx . BitmapButton ( self . panel , - <NUM_LIT:1> , img , <EOL> name = move_down_button_name ) <EOL> ctrl . Bind ( wx . EVT_BUTTON , <EOL> lambda event , position = i : <EOL> self . on_move_row_down ( event , position ) ) <EOL> self . panel . Sizer . Add ( ctrl , row = i + <NUM_LIT:1> , col = len ( column_names ) + <NUM_LIT:3> , <EOL> flag = wx . ALIGN_BOTTOM ) <EOL> all_subcontrols [ move_down_button_name ] = True <EOL> for key , value in all_subcontrols . iteritems ( ) : <EOL> ctrl = self . panel . FindWindowByName ( key ) <EOL> ctrl . Show ( value ) <EOL> def on_choice_changed ( self , event , row , column ) : <EOL> new_value = event . EventObject . GetItems ( ) [ event . GetSelection ( ) ] <EOL> if new_value == self . DISPLAY_NONE : <EOL> new_value = None <EOL> joins = list ( self . joins ) <EOL> while len ( joins ) <= row : <EOL> joins . append ( dict ( [ ( cn , "<STR_LIT>" ) for cn in self . column_names ] ) ) <EOL> join = joins [ row ] . copy ( ) <EOL> join [ self . column_names [ column ] ] = new_value <EOL> joins [ row ] = join <EOL> self . module_view . on_value_change ( self . v , self . panel , <EOL> self . v . build_string ( joins ) , event ) <EOL> def on_insert_row ( self , event , position ) : <EOL> joins = list ( self . joins ) <EOL> new_join = dict ( [ ( column_name , None ) for column_name in self . column_names ] ) <EOL> joins . insert ( position , new_join ) <EOL> self . module_view . on_value_change ( self . v , self . panel , <EOL> self . v . build_string ( joins ) , event ) <EOL> def on_delete_row ( self , event , position ) : <EOL> joins = list ( self . joins ) <EOL> del joins [ position ] <EOL> self . module_view . on_value_change ( self . v , self . panel , <EOL> self . v . build_string ( joins ) , event ) <EOL> def on_move_row_up ( self , event , position ) : <EOL> joins = list ( self . joins ) <EOL> joins = joins [ <NUM_LIT:0> : ( position - <NUM_LIT:1> ) ] + [ joins [ position ] , joins [ position - <NUM_LIT:1> ] ] + joins [ ( position + <NUM_LIT:1> ) : ] <EOL> self . module_view . on_value_change ( self . v , self . panel , <EOL> self . v . build_string ( joins ) , event ) <EOL> def on_move_row_down ( self , event , position ) : <EOL> joins = list ( self . joins ) <EOL> joins = joins [ <NUM_LIT:0> : position ] + [ joins [ position + <NUM_LIT:1> ] , joins [ position ] ] + joins [ ( position + <NUM_LIT:2> ) : ] <EOL> self . module_view . on_value_change ( self . v , self . panel , <EOL> self . v . build_string ( joins ) , event ) <EOL> class BinaryMatrixController ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , module_view , v ) : <EOL> """<STR_LIT>""" <EOL> self . module_view = module_view <EOL> self . setting = v <EOL> self . panel = wx . Panel ( module_view . module_panel , <EOL> name = edit_control_name ( v ) ) <EOL> self . panel . controller = self <EOL> self . panel . Sizer = wx . BoxSizer ( wx . VERTICAL ) <EOL> self . matrix_ctrl = wx . Panel ( self . panel ) <EOL> self . panel . Sizer . Add ( self . matrix_ctrl , <NUM_LIT:0> , wx . EXPAND | wx . ALL , <NUM_LIT:10> ) <EOL> self . matrix_ctrl . SetMinSize ( wx . Size ( <NUM_LIT:50> , <NUM_LIT:50> ) ) <EOL> sizer = wx . BoxSizer ( wx . HORIZONTAL ) <EOL> self . panel . Sizer . Add ( sizer , <NUM_LIT:0> , wx . EXPAND | wx . ALL , <NUM_LIT:2> ) <EOL> sizer . Add ( wx . StaticText ( self . panel , label = "<STR_LIT>" ) , <EOL> <NUM_LIT:0> , wx . ALIGN_RIGHT | wx . ALIGN_CENTER ) <EOL> sizer . AddSpacer ( <NUM_LIT:1> ) <EOL> self . width_ctrl = wx . SpinCtrl ( self . panel ) <EOL> self . width_ctrl . SetRange ( <NUM_LIT:1> , <NUM_LIT:100> ) <EOL> sizer . Add ( self . width_ctrl , <NUM_LIT:1> , wx . EXPAND ) <EOL> sizer . AddSpacer ( <NUM_LIT:4> ) <EOL> sizer . Add ( wx . StaticText ( self . panel , label = "<STR_LIT>" ) , <EOL> <NUM_LIT:0> , wx . ALIGN_RIGHT | wx . ALIGN_CENTER ) <EOL> sizer . AddSpacer ( <NUM_LIT:1> ) <EOL> self . height_ctrl = wx . SpinCtrl ( self . panel ) <EOL> self . height_ctrl . SetRange ( <NUM_LIT:1> , <NUM_LIT:100> ) <EOL> sizer . Add ( self . height_ctrl , <NUM_LIT:1> , wx . EXPAND ) <EOL> self . matrix_ctrl . Bind ( wx . EVT_PAINT , self . on_matrix_ctrl_paint ) <EOL> self . matrix_ctrl . Bind ( wx . EVT_LEFT_UP , self . on_matrix_ctrl_clicked ) <EOL> self . width_ctrl . Bind ( wx . EVT_SPINCTRL , self . on_width_changed ) <EOL> self . height_ctrl . Bind ( wx . EVT_SPINCTRL , self . on_height_changed ) <EOL> self . update ( ) <EOL> def update ( self ) : <EOL> h , w = self . setting . get_size ( ) <EOL> hh , ww = [ ( x - <NUM_LIT:1> ) / <NUM_LIT:2> for x in h , w ] <EOL> if self . height_ctrl . Value != hh : <EOL> self . height_ctrl . Value = hh <EOL> if self . width_ctrl . Value != ww : <EOL> self . width_ctrl . Value = ww <EOL> r = self . get_matrix_element_rect ( h - <NUM_LIT:1> , w - <NUM_LIT:1> ) <EOL> b = wx . SystemSettings . GetMetric ( wx . SYS_EDGE_X ) <EOL> self . matrix_ctrl . SetMinSize ( wx . Size ( r . GetRight ( ) + b , r . GetBottom ( ) + b ) ) <EOL> self . matrix_ctrl . Refresh ( eraseBackground = False ) <EOL> def on_matrix_ctrl_clicked ( self , event ) : <EOL> assert isinstance ( event , wx . MouseEvent ) <EOL> i , j = self . hit_test ( event . X , event . Y ) <EOL> if i is not None : <EOL> matrix = self . setting . get_matrix ( ) <EOL> matrix [ i ] [ j ] = not matrix [ i ] [ j ] <EOL> value = cellprofiler . settings . BinaryMatrix . to_value ( matrix ) <EOL> self . module_view . on_value_change ( self . setting , self . panel , <EOL> value , event ) <EOL> def on_matrix_ctrl_paint ( self , event ) : <EOL> paint_dc = wx . BufferedPaintDC ( self . matrix_ctrl ) <EOL> paint_dc . BeginDrawing ( ) <EOL> matrix = self . setting . get_matrix ( ) <EOL> h = len ( matrix ) <EOL> w = len ( matrix [ <NUM_LIT:0> ] ) <EOL> bx , ex , dx , by , ey , dy = [ <EOL> wx . SystemSettings . GetMetric ( m ) for m in ( <EOL> wx . SYS_BORDER_X , wx . SYS_EDGE_X , wx . SYS_SMALLICON_X , <EOL> wx . SYS_BORDER_Y , wx . SYS_EDGE_Y , wx . SYS_SMALLICON_Y ) ] <EOL> paint_dc . Background = wx . Brush ( cellprofiler . preferences . get_background_color ( ) ) <EOL> paint_dc . Clear ( ) <EOL> pShadow = wx . Pen ( <EOL> wx . SystemSettings . GetColour ( wx . SYS_COLOUR_BTNSHADOW ) , <NUM_LIT:1> , wx . SOLID ) <EOL> pHighlight = wx . Pen ( <EOL> wx . SystemSettings . GetColour ( wx . SYS_COLOUR_BTNHIGHLIGHT ) , <NUM_LIT:1> , wx . SOLID ) <EOL> bBackground , bForeground = [ <EOL> wx . Brush ( color ) for color in <EOL> wx . Colour ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:255> ) , wx . WHITE ] <EOL> rw = <NUM_LIT:2> * ex + dx <EOL> rh = <NUM_LIT:2> * ey + dy <EOL> for x in range ( w ) : <EOL> for y in range ( h ) : <EOL> rx = x * rw + x * bx <EOL> ry = y * rh + y * by <EOL> value = matrix [ y ] [ x ] <EOL> paint_dc . Pen = pHighlight if value else pShadow <EOL> for k in range ( ex ) : <EOL> paint_dc . DrawLine ( rx + k , ry + k , rx + rw - k - <NUM_LIT:1> , ry + k ) <EOL> paint_dc . DrawLine ( rx + k , ry + k , rx + k , ry + rh - k - <NUM_LIT:1> ) <EOL> paint_dc . Pen = pShadow if value else pHighlight <EOL> for k in range ( ex ) : <EOL> paint_dc . DrawLine ( rx + k , ry + rh - k - <NUM_LIT:1> , rx + rw - k - <NUM_LIT:1> , ry + rh - k - <NUM_LIT:1> ) <EOL> paint_dc . DrawLine ( rx + rw - k - <NUM_LIT:1> , ry + k , rx + rw - k - <NUM_LIT:1> , ry + rh - k - <NUM_LIT:1> ) <EOL> paint_dc . Pen = wx . TRANSPARENT_PEN <EOL> paint_dc . Brush = bForeground if value else bBackground <EOL> paint_dc . DrawRectangle ( rx + ex , ry + ey , dx , dy ) <EOL> paint_dc . EndDrawing ( ) <EOL> event . Skip ( ) <EOL> @ staticmethod <EOL> def get_matrix_element_rect ( i , j ) : <EOL> bx , ex , dx , by , ey , dy = [ <EOL> wx . SystemSettings . GetMetric ( m ) for m in ( <EOL> wx . SYS_BORDER_X , wx . SYS_EDGE_X , wx . SYS_SMALLICON_X , <EOL> wx . SYS_BORDER_Y , wx . SYS_EDGE_Y , wx . SYS_SMALLICON_Y ) ] <EOL> return wx . Rect ( ex * ( <NUM_LIT:2> * j + <NUM_LIT:1> ) + dx * j + bx * j , <EOL> ey * ( <NUM_LIT:2> * i + <NUM_LIT:1> ) + dy * i + by * i , dx , dy ) <EOL> def hit_test ( self , x , y ) : <EOL> """<STR_LIT>""" <EOL> bx , ex , dx , by , ey , dy = [ <EOL> wx . SystemSettings . GetMetric ( m ) for m in ( <EOL> wx . SYS_BORDER_X , wx . SYS_EDGE_X , wx . SYS_SMALLICON_X , <EOL> wx . SYS_BORDER_Y , wx . SYS_EDGE_Y , wx . SYS_SMALLICON_Y ) ] <EOL> i = int ( ( y - ey ) / ( <NUM_LIT:2> * ey + dy + by ) ) <EOL> j = int ( ( x - ex ) / ( <NUM_LIT:2> * ex + dx + bx ) ) <EOL> h , w = self . setting . get_size ( ) <EOL> if ( i < <NUM_LIT:0> or j < <NUM_LIT:0> or i >= h or j >= w or <EOL> not self . get_matrix_element_rect ( i , j ) . ContainsXY ( x , y ) ) : <EOL> return None , None <EOL> return i , j <EOL> def on_width_changed ( self , event ) : <EOL> matrix = self . setting . get_matrix ( ) <EOL> h , w = self . setting . get_size ( ) <EOL> d = self . width_ctrl . Value * <NUM_LIT:2> + <NUM_LIT:1> - w <EOL> n = abs ( int ( d / <NUM_LIT:2> ) ) <EOL> if d < <NUM_LIT:0> : <EOL> matrix = [ row [ n : - n ] for row in matrix ] <EOL> elif d > <NUM_LIT:0> : <EOL> matrix = [ [ False ] * n + row + [ False ] * n for row in matrix ] <EOL> else : <EOL> return <EOL> value = cellprofiler . settings . BinaryMatrix . to_value ( matrix ) <EOL> self . module_view . on_value_change ( self . setting , self . panel , <EOL> value , event ) <EOL> def on_height_changed ( self , event ) : <EOL> matrix = self . setting . get_matrix ( ) <EOL> h , w = self . setting . get_size ( ) <EOL> d = self . height_ctrl . Value * <NUM_LIT:2> + <NUM_LIT:1> - h <EOL> n = abs ( int ( d / <NUM_LIT:2> ) ) <EOL> if d < <NUM_LIT:0> : <EOL> matrix = matrix [ n : - n ] <EOL> elif d > <NUM_LIT:0> : <EOL> matrix = [ [ False ] * w for _ in range ( n ) ] + matrix + [ [ False ] * w for _ in range ( n ) ] <EOL> else : <EOL> return <EOL> value = cellprofiler . settings . BinaryMatrix . to_value ( matrix ) <EOL> self . module_view . on_value_change ( self . setting , self . panel , <EOL> value , event ) <EOL> @ classmethod <EOL> def update_control ( cls , module_view , v ) : <EOL> """<STR_LIT>""" <EOL> assert isinstance ( module_view , ModuleView ) <EOL> control = module_view . module_panel . FindWindowByName ( edit_control_name ( v ) ) <EOL> if control is None : <EOL> controller = BinaryMatrixController ( module_view , v ) <EOL> return controller . panel <EOL> else : <EOL> control . controller . update ( ) <EOL> return control <EOL> class DataTypeController ( object ) : <EOL> """<STR_LIT>""" <EOL> DTC_NONE = "<STR_LIT:None>" <EOL> DTC_TEXT = "<STR_LIT>" <EOL> DTC_INTEGER = "<STR_LIT>" <EOL> DTC_FLOAT = "<STR_LIT>" <EOL> DTC_TO_DT = { <EOL> DTC_NONE : cellprofiler . settings . DataTypes . DT_NONE , <EOL> DTC_TEXT : cellprofiler . settings . DataTypes . DT_TEXT , <EOL> DTC_INTEGER : cellprofiler . settings . DataTypes . DT_INTEGER , <EOL> DTC_FLOAT : cellprofiler . settings . DataTypes . DT_FLOAT , <EOL> None : cellprofiler . settings . DataTypes . DT_TEXT } <EOL> DT_TO_DTC = { <EOL> cellprofiler . settings . DataTypes . DT_NONE : DTC_NONE , <EOL> cellprofiler . settings . DataTypes . DT_TEXT : DTC_TEXT , <EOL> cellprofiler . settings . DataTypes . DT_INTEGER : DTC_INTEGER , <EOL> cellprofiler . settings . DataTypes . DT_FLOAT : DTC_FLOAT } <EOL> def __init__ ( self , module_view , v ) : <EOL> assert isinstance ( v , cellprofiler . settings . DataTypes ) <EOL> self . module_view = module_view <EOL> self . v = v <EOL> self . panel = module_view . module_panel . FindWindowByName ( <EOL> edit_control_name ( v ) ) <EOL> if self . panel is None : <EOL> class DoesntInheritBackgroundColor ( wx . Panel ) : <EOL> def InheritsBackgroundColour ( self ) : <EOL> return False <EOL> self . panel = DoesntInheritBackgroundColor ( <EOL> module_view . module_panel , - <NUM_LIT:1> , <EOL> name = edit_control_name ( v ) ) <EOL> self . panel . Sizer = wx . lib . rcsizer . RowColSizer ( ) <EOL> self . panel . Bind ( wx . EVT_PAINT , self . on_paint ) <EOL> self . panel . controller = self <EOL> self . n_items = <NUM_LIT:0> <EOL> self . update ( ) <EOL> def on_paint ( self , event ) : <EOL> dc = wx . BufferedPaintDC ( self . panel ) <EOL> dc . BeginDrawing ( ) <EOL> dc . Background = wx . Brush ( wx . SystemSettings . GetColour ( <EOL> wx . SYS_COLOUR_WINDOW ) ) <EOL> dc . Clear ( ) <EOL> dc . Pen = wx . Pen ( wx . SystemSettings . GetColour ( <EOL> wx . SYS_COLOUR_GRAYTEXT ) ) <EOL> sizer = self . panel . Sizer <EOL> _ , panel_width = self . panel . GetClientSize ( ) <EOL> assert isinstance ( sizer , wx . lib . rcsizer . RowColSizer ) <EOL> bottom_choice_name = self . get_choice_control_name ( self . n_items ) <EOL> bottom_choice = self . panel . FindWindowByName ( bottom_choice_name ) <EOL> if bottom_choice is not None : <EOL> r = bottom_choice . GetRect ( ) <EOL> dc . DrawLine ( r . Left - <NUM_LIT:2> , <NUM_LIT:1> , r . Left - <NUM_LIT:2> , r . Bottom ) <EOL> for i in range ( <NUM_LIT:1> , self . n_items + <NUM_LIT:1> ) : <EOL> choice_name = self . get_choice_control_name ( i ) <EOL> choice = self . panel . FindWindowByName ( choice_name ) <EOL> if choice is not None : <EOL> r = choice . GetRect ( ) <EOL> dc . DrawLine ( <NUM_LIT:1> , r . Top - <NUM_LIT:2> , panel_width - <NUM_LIT:1> , r . Top - <NUM_LIT:2> ) <EOL> dc . EndDrawing ( ) <EOL> event . Skip ( ) <EOL> def get_label_control_name ( self , rowidx ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" % ( rowidx , str ( self . v . key ( ) ) ) <EOL> def get_choice_control_name ( self , rowidx ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" % ( rowidx , str ( self . v . key ( ) ) ) <EOL> def update ( self ) : <EOL> """<STR_LIT>""" <EOL> d = self . v . get_data_types ( ) <EOL> needs_bind = [ ] <EOL> sizer = self . panel . Sizer <EOL> assert isinstance ( sizer , wx . lib . rcsizer . RowColSizer ) <EOL> for child in self . panel . GetChildren ( ) : <EOL> sizer . Hide ( child ) <EOL> label_header_name = self . get_label_control_name ( <NUM_LIT:0> ) <EOL> choice_header_name = self . get_choice_control_name ( <NUM_LIT:0> ) <EOL> for header_name , column , text in ( <EOL> ( label_header_name , <NUM_LIT:0> , "<STR_LIT>" ) , <EOL> ( choice_header_name , <NUM_LIT:1> , "<STR_LIT>" ) ) : <EOL> ctrl = self . panel . FindWindowByName ( header_name ) <EOL> if ctrl is None : <EOL> ctrl = wx . StaticText ( self . panel , <EOL> label = text , <EOL> name = header_name ) <EOL> ctrl . Font = wx . Font ( <EOL> ctrl . Font . GetPointSize ( ) , <EOL> ctrl . Font . GetFamily ( ) , <EOL> ctrl . Font . GetStyle ( ) , <EOL> wx . FONTWEIGHT_BOLD , False , <EOL> ctrl . Font . GetFaceName ( ) ) <EOL> sizer . Add ( ctrl , <EOL> flag = wx . ALIGN_CENTER_HORIZONTAL | wx . ALIGN_CENTER_VERTICAL | wx . BOTTOM , <EOL> border = <NUM_LIT:1> , <EOL> row = <NUM_LIT:0> , col = column ) <EOL> else : <EOL> sizer . Show ( ctrl ) <EOL> for i , feature in enumerate ( sorted ( d . keys ( ) ) ) : <EOL> label_name = self . get_label_control_name ( i + <NUM_LIT:1> ) <EOL> choice_name = self . get_choice_control_name ( i + <NUM_LIT:1> ) <EOL> label = self . panel . FindWindowByName ( label_name ) <EOL> if label is None : <EOL> label = wx . StaticText ( <EOL> self . panel , <EOL> label = feature , <EOL> name = label_name ) <EOL> sizer . Add ( label , <EOL> flag = wx . ALIGN_LEFT | wx . BOTTOM | wx . LEFT | wx . RIGHT , <EOL> border = <NUM_LIT:3> , <EOL> row = i + <NUM_LIT:1> , col = <NUM_LIT:0> ) <EOL> else : <EOL> sizer . Show ( label ) <EOL> if label . Label != feature : <EOL> label . Label = feature <EOL> choice = self . panel . FindWindowByName ( choice_name ) <EOL> if choice is None : <EOL> choice = wx . Choice ( <EOL> self . panel , <EOL> choices = [ self . DTC_TEXT , self . DTC_INTEGER , self . DTC_FLOAT , <EOL> self . DTC_NONE ] , <EOL> name = choice_name ) <EOL> sizer . Add ( choice , <EOL> flag = wx . EXPAND | wx . BOTTOM | wx . RIGHT , <EOL> border = <NUM_LIT:3> , <EOL> row = i + <NUM_LIT:1> , col = <NUM_LIT:1> ) <EOL> needs_bind . append ( choice ) <EOL> else : <EOL> sizer . Show ( choice ) <EOL> value = self . DT_TO_DTC . get ( d [ feature ] , self . DTC_TEXT ) <EOL> if choice . GetStringSelection ( ) != value : <EOL> choice . SetStringSelection ( value ) <EOL> self . n_items = len ( d . keys ( ) ) <EOL> for choice in needs_bind : <EOL> choice . Bind ( wx . EVT_CHOICE , self . on_choice_changed ) <EOL> def on_choice_changed ( self , event ) : <EOL> result = { } <EOL> for i in range ( <NUM_LIT:1> , self . n_items + <NUM_LIT:1> ) : <EOL> label = self . panel . FindWindowByName ( self . get_label_control_name ( i ) ) <EOL> choice = self . panel . FindWindowByName ( <EOL> self . get_choice_control_name ( i ) ) <EOL> result [ label . Label ] = self . DTC_TO_DT [ choice . GetStringSelection ( ) ] <EOL> result = cellprofiler . settings . DataTypes . encode_data_types ( result ) <EOL> if self . v . value != result : <EOL> self . module_view . on_value_change ( self . v , self . panel , result , event ) <EOL> @ classmethod <EOL> def update_control ( cls , module_view , v ) : <EOL> """<STR_LIT>""" <EOL> assert isinstance ( module_view , ModuleView ) <EOL> control = module_view . module_panel . FindWindowByName ( edit_control_name ( v ) ) <EOL> if control is None : <EOL> controller = DataTypeController ( module_view , v ) <EOL> return controller . panel <EOL> else : <EOL> control . controller . update ( ) <EOL> return control <EOL> class TableController ( wx . grid . PyGridTableBase ) : <EOL> DEFAULT_ATTR = wx . grid . GridCellAttr ( ) <EOL> ERROR_ATTR = wx . grid . GridCellAttr ( ) <EOL> ERROR_ATTR . TextColour = cellprofiler . preferences . get_error_color ( ) <EOL> def __init__ ( self , v ) : <EOL> super ( self . __class__ , self ) . __init__ ( ) <EOL> assert isinstance ( v , cellprofiler . settings . Table ) <EOL> self . v = v <EOL> self . column_size = [ v . max_field_size ] * len ( v . column_names ) <EOL> def bind_to_grid ( self , grid ) : <EOL> """<STR_LIT>""" <EOL> self . grid = grid <EOL> grid . AutoSize ( ) <EOL> grid . EnableEditing ( False ) <EOL> grid . SetDefaultCellOverflow ( False ) <EOL> if self . v . corner_button is None : <EOL> grid . fn_clicked = None <EOL> else : <EOL> fn_clicked = self . v . corner_button [ "<STR_LIT>" ] <EOL> def on_corner_button_clicked ( ) : <EOL> fn_clicked ( ) <EOL> self . update_grid ( ) <EOL> grid . ForceRefresh ( ) <EOL> grid . Parent . Layout ( ) <EOL> grid . fn_clicked = on_corner_button_clicked <EOL> grid . label = self . v . corner_button . get ( "<STR_LIT:label>" , "<STR_LIT>" ) <EOL> grid . tooltip = self . v . corner_button . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . last_pos = ( None , None ) <EOL> grid . GetGridWindow ( ) . Bind ( wx . EVT_MOTION , self . on_mouse_motion ) <EOL> grid . Bind ( wx . grid . EVT_GRID_COL_SIZE , self . on_column_resize ) <EOL> def update_grid ( self ) : <EOL> """<STR_LIT>""" <EOL> need_column_layout = False <EOL> grid = self . grid <EOL> v = self . v <EOL> if len ( v . column_names ) < grid . GetNumberCols ( ) : <EOL> tm = wx . grid . GridTableMessage ( <EOL> grid . Table , <EOL> wx . grid . GRIDTABLE_NOTIFY_COLS_DELETED , <EOL> <NUM_LIT:0> , grid . GetNumberCols ( ) - len ( v . column_names ) ) <EOL> grid . ProcessTableMessage ( tm ) <EOL> need_column_layout = True <EOL> elif grid . GetNumberCols ( ) < len ( v . column_names ) : <EOL> tm = wx . grid . GridTableMessage ( <EOL> grid . Table , <EOL> wx . grid . GRIDTABLE_NOTIFY_COLS_INSERTED , <EOL> <NUM_LIT:0> , len ( v . column_names ) - grid . GetNumberCols ( ) ) <EOL> grid . ProcessTableMessage ( tm ) <EOL> need_column_layout = True <EOL> if len ( v . data ) < grid . GetNumberRows ( ) : <EOL> tm = wx . grid . GridTableMessage ( <EOL> grid . Table , <EOL> wx . grid . GRIDTABLE_NOTIFY_ROWS_DELETED , <EOL> <NUM_LIT:0> , grid . GetNumberRows ( ) - len ( v . data ) ) <EOL> grid . ProcessTableMessage ( tm ) <EOL> elif grid . GetNumberRows ( ) < len ( v . data ) : <EOL> tm = wx . grid . GridTableMessage ( <EOL> grid . Table , <EOL> wx . grid . GRIDTABLE_NOTIFY_ROWS_INSERTED , <EOL> <NUM_LIT:0> , len ( v . data ) - grid . GetNumberRows ( ) ) <EOL> grid . ProcessTableMessage ( tm ) <EOL> if need_column_layout : <EOL> grid . AutoSizeColumns ( ) <EOL> def on_mouse_motion ( self , event ) : <EOL> x , y = self . grid . CalcUnscrolledPosition ( event . GetPosition ( ) ) <EOL> row = self . grid . YToRow ( y ) <EOL> col = self . grid . XToCol ( x ) <EOL> this_pos = ( row , col ) <EOL> if ( this_pos != self . last_pos and row >= <NUM_LIT:0> and col >= <NUM_LIT:0> and <EOL> row < len ( self . v . data ) and col < len ( self . v . data [ row ] ) ) : <EOL> self . last_pos = this_pos <EOL> s = self . v . data [ row ] [ col ] <EOL> if s is None : <EOL> s = '<STR_LIT>' <EOL> elif not isinstance ( s , basestring ) : <EOL> s = str ( s ) <EOL> self . grid . GetGridWindow ( ) . SetToolTipString ( s ) <EOL> event . Skip ( ) <EOL> def on_column_resize ( self , event ) : <EOL> grid = self . grid <EOL> col = event . GetRowOrCol ( ) <EOL> width = grid . GetColSize ( col ) <EOL> table = grid . GetTable ( ) <EOL> self . column_size [ col ] = int ( width * <NUM_LIT> ) / grid . CharWidth <EOL> tm = wx . grid . GridTableMessage ( <EOL> self , <EOL> wx . grid . GRIDTABLE_REQUEST_VIEW_GET_VALUES ) <EOL> grid . ProcessTableMessage ( tm ) <EOL> grid . ForceRefresh ( ) <EOL> def GetAttr ( self , row , col , kind ) : <EOL> attrs = self . v . get_cell_attributes ( <EOL> row , self . v . column_names [ col ] ) <EOL> attr = self . DEFAULT_ATTR <EOL> if attrs is not None and self . v . ATTR_ERROR in attrs : <EOL> attr = self . ERROR_ATTR <EOL> attr . IncRef ( ) <EOL> return attr <EOL> def CanHaveAttributes ( self ) : <EOL> return True <EOL> def GetNumberRows ( self ) : <EOL> return len ( self . v . data ) <EOL> def GetNumberCols ( self ) : <EOL> return len ( self . v . column_names ) <EOL> def IsEmptyCell ( self , row , col ) : <EOL> return ( len ( self . v . data ) <= row or <EOL> len ( self . v . data [ row ] ) <= col or <EOL> self . v . data [ row ] [ col ] is None ) <EOL> def GetValue ( self , row , col ) : <EOL> if self . IsEmptyCell ( row , col ) : <EOL> return None <EOL> s = unicode ( self . v . data [ row ] [ col ] ) <EOL> if len ( self . column_size ) <= col : <EOL> self . column_size += [ self . v . max_field_size ] * ( col - len ( self . column_size ) + <NUM_LIT:1> ) <EOL> field_size = self . column_size [ col ] <EOL> if len ( s ) > field_size : <EOL> half = int ( field_size - <NUM_LIT:3> ) / <NUM_LIT:2> <EOL> s = s [ : half ] + "<STR_LIT>" + s [ - half : ] <EOL> return s <EOL> def GetRowLabelValue ( self , row ) : <EOL> attrs = self . v . get_row_attributes ( row ) <EOL> if attrs is not None and self . v . ATTR_ERROR in attrs : <EOL> return "<STR_LIT>" % ( row + <NUM_LIT:1> ) <EOL> return str ( row + <NUM_LIT:1> ) <EOL> def GetColLabelValue ( self , col ) : <EOL> return self . v . column_names [ col ] <EOL> def AppendCols ( self , numCols ) : <EOL> return True <EOL> def AppendRows ( self , numRows ) : <EOL> return True <EOL> def InsertCols ( self , index , numCols ) : <EOL> return True <EOL> def InsertRows ( self , index , numRows ) : <EOL> return True <EOL> def DeleteCols ( self , index , numCols ) : <EOL> return True <EOL> def DeleteRows ( self , index , numRows ) : <EOL> return True <EOL> class ModuleSizer ( wx . PySizer ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , rows , cols = <NUM_LIT:2> ) : <EOL> wx . PySizer . __init__ ( self ) <EOL> self . __rows = rows <EOL> self . __cols = cols <EOL> self . __min_text_width = <NUM_LIT> <EOL> self . __height_padding = <NUM_LIT:5> <EOL> self . __printed_exception = False <EOL> self . __items = [ ] <EOL> def get_item ( self , i , j ) : <EOL> if len ( self . __items ) <= j or len ( self . __items [ j ] ) <= i : <EOL> return None <EOL> return self . __items [ j ] [ i ] <EOL> def Reset ( self , rows , cols = <NUM_LIT:3> , destroy_windows = True ) : <EOL> if destroy_windows : <EOL> windows = [ ] <EOL> for j in range ( self . __rows ) : <EOL> for i in range ( self . __cols ) : <EOL> item = self . get_item ( i , j ) <EOL> if item is None : <EOL> continue <EOL> if item . IsWindow ( ) : <EOL> window = item . GetWindow ( ) <EOL> if isinstance ( window , wx . Window ) : <EOL> windows . append ( window ) <EOL> for window in windows : <EOL> window . Hide ( ) <EOL> window . Destroy ( ) <EOL> self . Clear ( False ) <EOL> self . __rows = rows <EOL> self . __cols = cols <EOL> self . __items = [ ] <EOL> def Add ( self , control , * args , ** kwargs ) : <EOL> if len ( self . __items ) == <NUM_LIT:0> or len ( self . __items [ - <NUM_LIT:1> ] ) == self . __cols : <EOL> self . __items . append ( [ ] ) <EOL> item = super ( ModuleSizer , self ) . Add ( control , * args , ** kwargs ) <EOL> self . __items [ - <NUM_LIT:1> ] . append ( item ) <EOL> return item <EOL> def CalcMin ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> if ( self . __rows * self . __cols == <NUM_LIT:0> or <EOL> self . Children is None or <EOL> len ( self . Children ) == <NUM_LIT:0> ) : <EOL> return wx . Size ( <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> height = self . __height_padding <EOL> for j in range ( <NUM_LIT:0> , self . __rows ) : <EOL> borders = [ self . get_item ( col , j ) . GetBorder ( ) <EOL> for col in range ( <NUM_LIT:2> ) <EOL> if self . get_item ( col , j ) is not None ] <EOL> if len ( borders ) == <NUM_LIT:0> : <EOL> height += <NUM_LIT:10> <EOL> else : <EOL> height_border = max ( borders ) <EOL> height += self . get_row_height ( j ) + <NUM_LIT:2> * height_border <EOL> height += self . __height_padding <EOL> self . __printed_exception = False <EOL> return wx . Size ( self . calc_edit_size ( ) [ <NUM_LIT:0> ] + self . __min_text_width + <EOL> self . calc_help_size ( ) [ <NUM_LIT:0> ] , <EOL> height ) <EOL> except : <EOL> if not self . __printed_exception : <EOL> logger . error ( "<STR_LIT>" , exc_info = True ) <EOL> self . __printed_exception = True <EOL> return wx . Size ( <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> def get_row_height ( self , j ) : <EOL> height = <NUM_LIT:0> <EOL> for i in range ( self . __cols ) : <EOL> item = self . get_item ( i , j ) <EOL> if item is None : <EOL> continue <EOL> if item . IsWindow ( ) and isinstance ( item . GetWindow ( ) , wx . StaticLine ) : <EOL> height = max ( height , item . CalcMin ( ) [ <NUM_LIT:1> ] * <NUM_LIT> ) <EOL> else : <EOL> height = max ( height , item . CalcMin ( ) [ <NUM_LIT:1> ] ) <EOL> return height <EOL> def calc_column_size ( self , j ) : <EOL> """<STR_LIT>""" <EOL> height = <NUM_LIT:0> <EOL> width = <NUM_LIT:0> <EOL> for i in range ( self . __rows ) : <EOL> item = self . get_item ( j , i ) <EOL> if item is None : <EOL> continue <EOL> size = item . CalcMin ( ) <EOL> height += size [ <NUM_LIT:1> ] <EOL> width = max ( width , size [ <NUM_LIT:0> ] ) <EOL> return wx . Size ( width , height ) <EOL> def calc_help_size ( self ) : <EOL> return self . calc_column_size ( <NUM_LIT:2> ) <EOL> def calc_edit_size ( self ) : <EOL> return self . calc_column_size ( <NUM_LIT:1> ) <EOL> def calc_max_text_width ( self ) : <EOL> width = self . __min_text_width <EOL> for i in range ( self . __rows ) : <EOL> item = self . get_item ( <NUM_LIT:0> , i ) <EOL> if item is None : <EOL> continue <EOL> control = item . GetWindow ( ) <EOL> assert isinstance ( control , wx . StaticText ) , '<STR_LIT>' '<STR_LIT>' % ( i , str ( control ) ) <EOL> text = control . GetLabel ( ) . replace ( '<STR_LIT:\n>' , '<STR_LIT:U+0020>' ) <EOL> ctrl_width = control . GetTextExtent ( text ) [ <NUM_LIT:0> ] + <NUM_LIT:2> * item . GetBorder ( ) <EOL> width = max ( width , ctrl_width ) <EOL> return width <EOL> def RecalcSizes ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . __rows * self . __cols == <NUM_LIT:0> : <EOL> return <EOL> try : <EOL> size = self . GetSize ( ) <EOL> width = size [ <NUM_LIT:0> ] - <NUM_LIT:20> <EOL> edit_width = self . calc_edit_size ( ) [ <NUM_LIT:0> ] <EOL> help_width = self . calc_help_size ( ) [ <NUM_LIT:0> ] <EOL> max_text_width = self . calc_max_text_width ( ) <EOL> if edit_width + help_width + max_text_width < width : <EOL> edit_width = width - max_text_width - help_width <EOL> elif edit_width * <NUM_LIT:4> < width : <EOL> edit_width = width / <NUM_LIT:4> <EOL> text_width = max ( [ width - edit_width - help_width , <EOL> self . __min_text_width ] ) <EOL> widths = [ text_width , edit_width , help_width ] <EOL> height = self . __height_padding <EOL> panel = self . GetContainingWindow ( ) <EOL> for i in range ( self . __rows ) : <EOL> text_item = self . get_item ( <NUM_LIT:0> , i ) <EOL> edit_item = self . get_item ( <NUM_LIT:1> , i ) <EOL> if edit_item is None : <EOL> continue <EOL> inner_text_width = text_width - <NUM_LIT:2> * text_item . GetBorder ( ) <EOL> control = text_item . GetWindow ( ) <EOL> assert isinstance ( control , wx . StaticText ) , '<STR_LIT>' % ( <EOL> i , str ( control ) ) <EOL> text = control . GetLabel ( ) <EOL> edit_control = edit_item . GetWindow ( ) <EOL> height_border = max ( [ x . GetBorder ( ) for x in ( edit_item , text_item ) ] ) <EOL> if ( isinstance ( edit_control , wx . StaticLine ) and <EOL> len ( text ) == <NUM_LIT:0> ) : <EOL> text_item . Show ( False ) <EOL> item_height = self . get_row_height ( i ) <EOL> assert isinstance ( edit_item , wx . SizerItem ) <EOL> border = edit_item . GetBorder ( ) <EOL> third_width = ( text_width + edit_width - <NUM_LIT:2> * border ) / <NUM_LIT:3> <EOL> item_location = wx . Point ( text_width - third_width / <NUM_LIT:2> , <EOL> height + border + item_height / <NUM_LIT:2> ) <EOL> item_size = wx . Size ( third_width , edit_item . Size [ <NUM_LIT:1> ] ) <EOL> item_location = panel . CalcScrolledPosition ( item_location ) <EOL> edit_item . SetDimension ( item_location , item_size ) <EOL> else : <EOL> text_item . Show ( True ) <EOL> if ( text_width > self . __min_text_width and <EOL> ( text . find ( '<STR_LIT:\n>' ) != - <NUM_LIT:1> or <EOL> control . GetTextExtent ( text ) [ <NUM_LIT:0> ] > inner_text_width ) ) : <EOL> text = text . replace ( '<STR_LIT:\n>' , '<STR_LIT:U+0020>' ) <EOL> control . SetLabel ( text ) <EOL> control . Wrap ( inner_text_width ) <EOL> row_height = self . get_row_height ( i ) <EOL> for j in range ( self . __cols ) : <EOL> item = self . get_item ( j , i ) <EOL> item_x = sum ( widths [ <NUM_LIT:0> : j ] ) <EOL> item_y = height <EOL> if ( item . Flag & wx . EXPAND ) == <NUM_LIT:0> : <EOL> item_size = item . CalcMin ( ) <EOL> if item . Flag & wx . ALIGN_CENTER_VERTICAL : <EOL> item_y = height + ( row_height - item_size [ <NUM_LIT:1> ] ) / <NUM_LIT:2> <EOL> if item . Flag & wx . ALIGN_CENTER_HORIZONTAL : <EOL> item_x += ( widths [ j ] - item_size [ <NUM_LIT:0> ] ) / <NUM_LIT:2> <EOL> elif item . Flag & wx . ALIGN_RIGHT : <EOL> item_x += widths [ j ] - item_size [ <NUM_LIT:0> ] <EOL> else : <EOL> item_size = wx . Size ( widths [ j ] , item . CalcMin ( ) [ <NUM_LIT:1> ] ) <EOL> item_location = wx . Point ( item_x , item_y ) <EOL> item_location = panel . CalcScrolledPosition ( item_location ) <EOL> item . SetDimension ( item_location , item_size ) <EOL> height += self . get_row_height ( i ) + <NUM_LIT:2> * height_border <EOL> except : <EOL> if not self . __printed_exception : <EOL> logger . warning ( "<STR_LIT>" , exc_info = True ) <EOL> self . __printed_exception = True <EOL> validation_queue = Queue . Queue ( ) <EOL> pipeline_queue_thread = None <EOL> request_pipeline_cache = threading . local ( ) <EOL> validation_queue_keep_running = True <EOL> class ValidationRequest ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , pipeline , module , callback ) : <EOL> """<STR_LIT>""" <EOL> self . pipeline = cache_pipeline ( pipeline ) <EOL> self . module_num = module . module_num <EOL> self . test_mode = pipeline . test_mode <EOL> self . callback = callback <EOL> self . cancelled = False <EOL> def cancel ( self ) : <EOL> self . cancelled = True <EOL> def cache_pipeline ( pipeline ) : <EOL> """<STR_LIT>""" <EOL> d = getattr ( request_pipeline_cache , "<STR_LIT:d>" , None ) <EOL> if d is None : <EOL> d = weakref . WeakValueDictionary ( ) <EOL> setattr ( request_pipeline_cache , "<STR_LIT:d>" , d ) <EOL> settings_hash = pipeline . settings_hash ( ) <EOL> result = d . get ( settings_hash ) <EOL> if result is None : <EOL> result = d [ settings_hash ] = pipeline . copy ( False ) <EOL> return result <EOL> def validate_module ( pipeline , module_num , test_mode , callback ) : <EOL> """<STR_LIT>""" <EOL> pipeline . test_mode = test_mode <EOL> modules = [ m for m in pipeline . modules ( ) if m . module_num == module_num ] <EOL> if len ( modules ) != <NUM_LIT:1> : <EOL> return <EOL> module = modules [ <NUM_LIT:0> ] <EOL> level = logging . INFO <EOL> setting_idx = None <EOL> message = None <EOL> try : <EOL> level = logging . ERROR <EOL> module . test_valid ( pipeline ) <EOL> level = logging . WARNING <EOL> module . test_module_warnings ( pipeline ) <EOL> level = logging . INFO <EOL> except cellprofiler . settings . ValidationError , instance : <EOL> message = instance . message <EOL> setting_idx = [ m . key ( ) for m in module . visible_settings ( ) ] . index ( instance . get_setting ( ) . key ( ) ) <EOL> wx . CallAfter ( callback , setting_idx , message , level ) <EOL> def validation_queue_handler ( ) : <EOL> from javabridge import attach , detach <EOL> attach ( ) <EOL> try : <EOL> while validation_queue_keep_running : <EOL> request = validation_queue . get ( ) <EOL> if not isinstance ( request , ValidationRequest ) or request . cancelled : <EOL> continue <EOL> start = time . clock ( ) <EOL> try : <EOL> validate_module ( request . pipeline , request . module_num , <EOL> request . test_mode , request . callback ) <EOL> except : <EOL> pass <EOL> wait_for = max ( <NUM_LIT> , time . clock ( ) - start ) <EOL> time . sleep ( wait_for ) <EOL> finally : <EOL> detach ( ) <EOL> logger . info ( "<STR_LIT>" ) <EOL> def request_module_validation ( validation_request ) : <EOL> """<STR_LIT>""" <EOL> global pipeline_queue_thread , validation_queue <EOL> if pipeline_queue_thread is None : <EOL> pipeline_queue_thread = threading . Thread ( target = validation_queue_handler ) <EOL> pipeline_queue_thread . setName ( "<STR_LIT>" ) <EOL> pipeline_queue_thread . setDaemon ( True ) <EOL> pipeline_queue_thread . start ( ) <EOL> validation_queue . put ( validation_request ) <EOL> def stop_validation_queue_thread ( ) : <EOL> """<STR_LIT>""" <EOL> global validation_queue_keep_running <EOL> if pipeline_queue_thread is not None : <EOL> validation_queue_keep_running = False <EOL> validation_queue . put ( None ) <EOL> pipeline_queue_thread . join ( ) </s>
