def make_full_filename(self,
                        file_name,
                        workspace=None,
                        image_set_number=None):
     """Convert a file name into an absolute path
     
     We do a few things here:
     * apply metadata from an image set to the file name if an 
       image set is specified
     * change the relative path into an absolute one using the "." and "&"
       convention
     * Create any directories along the path
     """
     if image_set_number is not None and workspace is not None:
         file_name = workspace.measurements.apply_metadata(
             file_name, image_set_number)
     measurements = None if workspace is None else workspace.measurements
     path_name = self.directory.get_absolute_path(measurements,
                                                  image_set_number)
     file_name = os.path.join(path_name, file_name)
     path, file = os.path.split(file_name)
     if not os.path.isdir(path):
         os.makedirs(path)
     if self.prepend_output_filename.value:
         file = os.path.splitext(get_output_file_name())[0] + '_' + file
     return os.path.join(path, file)
예제 #2
0
 def on_add(self, event):
     for i in range(self.file_chooser.ItemCount):
         if self.file_chooser.IsSelected(i):
             path = os.path.join(self.directory_picker.Path,
                                 self.file_chooser.GetItemText(i))
             index = self.pipeline_list_view.InsertStringItem(
                 sys.maxint, path)
             self.pipeline_list_view.SetStringItem(
                 index, P_INPUT_DIRECTORY_COLUMN,
                 cpprefs.get_default_image_directory())
             self.pipeline_list_view.SetStringItem(
                 index, P_OUTPUT_DIRECTORY_COLUMN,
                 cpprefs.get_default_output_directory())
             self.pipeline_list_view.SetStringItem(
                 index, P_OUTPUT_FILE_COLUMN,
                 cpprefs.get_output_file_name())
             self.pipeline_list_view.SetItemColumnImage(
                 index, P_REMOVE_BUTTON_COLUMN, self.delete_bmp_idx)
             self.file_chooser.Select(i, False)
     self.pipeline_list_view.SetColumnWidth(P_FILENAME_COLUMN,
                                            wx.LIST_AUTOSIZE)
     self.pipeline_list_view.SetColumnWidth(P_INPUT_DIRECTORY_COLUMN,
                                            wx.LIST_AUTOSIZE)
     self.pipeline_list_view.SetColumnWidth(P_OUTPUT_DIRECTORY_COLUMN,
                                            wx.LIST_AUTOSIZE)
     self.pipeline_list_view.SetColumnWidth(P_OUTPUT_FILE_COLUMN,
                                            wx.LIST_AUTOSIZE)
 def on_add(self, event):
     for i in range(self.file_chooser.ItemCount):
         if self.file_chooser.IsSelected(i):
             path = os.path.join(
                 self.directory_picker.Path,
                 self.file_chooser.GetItemText(i))
             index = self.pipeline_list_view.InsertStringItem(
                 sys.maxint, path)
             self.pipeline_list_view.SetStringItem(
                 index, P_INPUT_DIRECTORY_COLUMN,
                 cpprefs.get_default_image_directory())
             self.pipeline_list_view.SetStringItem(
                 index, P_OUTPUT_DIRECTORY_COLUMN,
                 cpprefs.get_default_output_directory())
             self.pipeline_list_view.SetStringItem(
                 index, P_OUTPUT_FILE_COLUMN, 
                 cpprefs.get_output_file_name())
             self.pipeline_list_view.SetItemColumnImage(
                 index, P_REMOVE_BUTTON_COLUMN, self.delete_bmp_idx)
             self.file_chooser.Select(i, False)
     self.pipeline_list_view.SetColumnWidth(P_FILENAME_COLUMN, wx.LIST_AUTOSIZE)
     self.pipeline_list_view.SetColumnWidth(P_INPUT_DIRECTORY_COLUMN, wx.LIST_AUTOSIZE)
     self.pipeline_list_view.SetColumnWidth(P_OUTPUT_DIRECTORY_COLUMN, wx.LIST_AUTOSIZE)
     self.pipeline_list_view.SetColumnWidth(P_OUTPUT_FILE_COLUMN, wx.LIST_AUTOSIZE)
예제 #4
0
 def make_full_filename(self, file_name, 
                        workspace = None, image_set_number = None):
     """Convert a file name into an absolute path
     
     We do a few things here:
     * apply metadata from an image set to the file name if an 
       image set is specified
     * change the relative path into an absolute one using the "." and "&"
       convention
     * Create any directories along the path
     """
     if image_set_number is not None and workspace is not None:
         file_name = workspace.measurements.apply_metadata(file_name,
                                                           image_set_number)
     measurements = None if workspace is None else workspace.measurements
     path_name = self.directory.get_absolute_path(measurements, 
                                                  image_set_number)
     file_name = os.path.join(path_name, file_name)
     path, file = os.path.split(file_name)
     if not os.path.isdir(path):
         os.makedirs(path)
     if self.prepend_output_filename.value:
         file = os.path.splitext(get_output_file_name())[0] + '_' + file 
     return os.path.join(path,file)
예제 #5
0
 def __on_preferences_output_filename_event(self, event):
     if self.__output_filename_edit_box.Value != cpprefs.get_output_file_name(
     ):
         self.__output_filename_edit_box.Value = cpprefs.get_output_file_name(
         )
예제 #6
0
    def __make_odds_and_ends_panel(self):
        panel = self.__odds_and_ends_panel
        output_filename_text = wx.StaticText(panel, -1, 'Output Filename:')
        output_filename_edit_box = wx.TextCtrl(
            panel, value=cpprefs.get_output_file_name())
        self.__output_filename_edit_box = output_filename_edit_box
        allow_output_filename_overwrite_check_box = \
            wx.CheckBox(panel, label = "Allow overwrite?")
        allow_output_filename_overwrite_check_box.Value = \
            cpprefs.get_allow_output_file_overwrite()
        write_measurements_combo_box = wx.Choice(
            panel,
            choices=[
                WRITE_HDF_FILE_TEXT, WRITE_MAT_FILE_TEXT,
                DO_NOT_WRITE_MEASUREMENTS_TEXT
            ])
        # set measurements mode, then fake an event to update output
        # filename and which controls are shown.
        measurements_mode_idx = [cpprefs.WRITE_HDF5, True,
                                 False].index(cpprefs.get_write_MAT_files())
        write_measurements_combo_box.SetSelection(measurements_mode_idx)
        output_filename_help_button = wx.Button(panel,
                                                label='?',
                                                style=wx.BU_EXACTFIT)
        output_file_format_text = wx.StaticText(panel,
                                                label="Output file format:")
        cpprefs.add_output_file_name_listener(
            self.__on_preferences_output_filename_event)
        cpprefs.add_image_directory_listener(
            self.__on_preferences_image_directory_event)
        cpprefs.add_output_directory_listener(
            self.__on_preferences_output_directory_event)
        self.__hold_a_reference_to_progress_callback = self.progress_callback
        cpprefs.add_progress_callback(
            self.__hold_a_reference_to_progress_callback)

        def on_output_filename_changed(event):
            cpprefs.set_output_file_name(output_filename_edit_box.Value)

        def on_allow_checkbox(event):
            cpprefs.set_allow_output_file_overwrite(
                allow_output_filename_overwrite_check_box.Value)

        def on_write_MAT_files_combo_box(event):
            #
            # Update the state to reflect the new measurement choice
            #
            sel = write_measurements_combo_box.GetStringSelection()
            output_filename = output_filename_edit_box.Value
            if sel == WRITE_HDF_FILE_TEXT:
                cpprefs.set_write_MAT_files(cpprefs.WRITE_HDF5)
                if output_filename.lower().endswith('.mat'):
                    output_filename = output_filename[:-4] + u".h5"
            elif sel == WRITE_MAT_FILE_TEXT:
                cpprefs.set_write_MAT_files(True)
                if output_filename.lower().endswith('.h5'):
                    output_filename = output_filename[:-3] + u".mat"
            else:
                cpprefs.set_write_MAT_files(False)

            if output_filename != output_filename_edit_box.Value:
                output_filename_edit_box.Value = output_filename
                cpprefs.set_output_file_name(output_filename_edit_box.Value)
            #
            # Reconstruct the sizers depending on whether we have one or two rows
            #
            if sel == DO_NOT_WRITE_MEASUREMENTS_TEXT:
                show = False
                output_sizer = wx.BoxSizer(wx.HORIZONTAL)
                output_sizer.Add(output_filename_help_button, 0, wx.EXPAND)
                output_sizer.Add(output_file_format_text, 0, wx.ALIGN_RIGHT)
                output_sizer.Add(write_measurements_combo_box, 0,
                                 wx.ALIGN_LEFT)
            else:
                show = True
                output_sizer = wx.FlexGridSizer(2, 3, 2, 2)
                output_sizer.SetFlexibleDirection(wx.HORIZONTAL)
                output_sizer.AddGrowableCol(2)
                output_filename_edit_box_sizer = wx.BoxSizer(wx.HORIZONTAL)
                output_filename_edit_box_sizer.Add(output_filename_edit_box, 1,
                                                   wx.EXPAND)
                output_filename_edit_box_sizer.AddSpacer(2)
                output_filename_edit_box_sizer.Add(
                    allow_output_filename_overwrite_check_box, 0,
                    wx.ALIGN_CENTER)
                output_sizer.Add(output_filename_help_button, 0, wx.EXPAND)
                output_sizer.Add(output_filename_text, 0, wx.ALIGN_RIGHT)
                output_sizer.Add(output_filename_edit_box_sizer, 1, wx.EXPAND)

                output_sizer.Add(wx.BoxSizer(), 0, wx.EXPAND)
                output_sizer.Add(output_file_format_text, 0, wx.ALIGN_RIGHT)
                output_sizer.Add(write_measurements_combo_box, 0,
                                 wx.ALIGN_LEFT)

            panel.SetSizer(output_sizer)
            for ctrl in (output_filename_text, output_filename_edit_box,
                         allow_output_filename_overwrite_check_box):
                ctrl.Show(show)

            panel.Parent.Layout()
            panel.Layout()

        write_measurements_combo_box.Bind(wx.EVT_CHOICE,
                                          on_write_MAT_files_combo_box)
        allow_output_filename_overwrite_check_box.Bind(wx.EVT_CHECKBOX,
                                                       on_allow_checkbox)
        output_filename_help_button.Bind(
            wx.EVT_BUTTON,
            lambda event: self.__on_help(event, USING_THE_OUTPUT_FILE_HELP))
        output_filename_edit_box.Bind(wx.EVT_TEXT, on_output_filename_changed)
        panel.Bind(wx.EVT_WINDOW_DESTROY, self.__on_destroy, panel)
        on_write_MAT_files_combo_box(None)
예제 #7
0
 def __on_preferences_output_filename_event(self,event):
     if self.__output_filename_edit_box.Value != cpprefs.get_output_file_name():
         self.__output_filename_edit_box.Value = cpprefs.get_output_file_name()
예제 #8
0
 def __make_odds_and_ends_panel(self):
     panel = self.__odds_and_ends_panel
     output_filename_text = wx.StaticText(panel,-1,'Output Filename:')
     output_filename_edit_box = wx.TextCtrl(
         panel,  value=cpprefs.get_output_file_name())
     self.__output_filename_edit_box = output_filename_edit_box
     allow_output_filename_overwrite_check_box = \
         wx.CheckBox(panel, label = "Allow overwrite?")
     allow_output_filename_overwrite_check_box.Value = \
         cpprefs.get_allow_output_file_overwrite()
     write_measurements_combo_box = wx.Choice(
         panel, choices = 
         [WRITE_HDF_FILE_TEXT, WRITE_MAT_FILE_TEXT,
          DO_NOT_WRITE_MEASUREMENTS_TEXT])
     # set measurements mode, then fake an event to update output
     # filename and which controls are shown.
     measurements_mode_idx = [cpprefs.WRITE_HDF5, True, False].index(
         cpprefs.get_write_MAT_files())
     write_measurements_combo_box.SetSelection(measurements_mode_idx)
     output_filename_help_button = wx.Button(
         panel, label = '?', style=wx.BU_EXACTFIT)
     output_file_format_text = wx.StaticText(
         panel, label = "Output file format:") 
     cpprefs.add_output_file_name_listener(
         self.__on_preferences_output_filename_event)
     cpprefs.add_image_directory_listener(
         self.__on_preferences_image_directory_event)
     cpprefs.add_output_directory_listener(
         self.__on_preferences_output_directory_event)
     self.__hold_a_reference_to_progress_callback = self.progress_callback
     cpprefs.add_progress_callback(
         self.__hold_a_reference_to_progress_callback)
     
     def on_output_filename_changed(event):
         cpprefs.set_output_file_name(output_filename_edit_box.Value)
 
     def on_allow_checkbox(event):
         cpprefs.set_allow_output_file_overwrite(
             allow_output_filename_overwrite_check_box.Value)
         
     def on_write_MAT_files_combo_box(event):
         #
         # Update the state to reflect the new measurement choice
         #
         sel = write_measurements_combo_box.GetStringSelection()
         output_filename = output_filename_edit_box.Value
         if sel == WRITE_HDF_FILE_TEXT:
             cpprefs.set_write_MAT_files(cpprefs.WRITE_HDF5)
             if output_filename.lower().endswith('.mat'):
                 output_filename = output_filename[:-4] + u".h5"
         elif sel == WRITE_MAT_FILE_TEXT:
             cpprefs.set_write_MAT_files(True)
             if output_filename.lower().endswith('.h5'):
                 output_filename = output_filename[:-3] + u".mat"
         else:
             cpprefs.set_write_MAT_files(False)
             
         if output_filename != output_filename_edit_box.Value:
             output_filename_edit_box.Value = output_filename
             cpprefs.set_output_file_name(
                 output_filename_edit_box.Value)
         #
         # Reconstruct the sizers depending on whether we have one or two rows
         #
         if sel == DO_NOT_WRITE_MEASUREMENTS_TEXT:
             show = False
             output_sizer = wx.BoxSizer(wx.HORIZONTAL)
             output_sizer.Add(output_filename_help_button, 0, wx.EXPAND)
             output_sizer.Add(output_file_format_text, 0, wx.ALIGN_RIGHT)
             output_sizer.Add(write_measurements_combo_box, 0, wx.ALIGN_LEFT)
         else:
             show = True
             output_sizer = wx.FlexGridSizer(2, 3, 2, 2)
             output_sizer.SetFlexibleDirection(wx.HORIZONTAL)
             output_sizer.AddGrowableCol(2)
             output_filename_edit_box_sizer = wx.BoxSizer(wx.HORIZONTAL)
             output_filename_edit_box_sizer.Add(
                 output_filename_edit_box, 1 , wx.EXPAND)
             output_filename_edit_box_sizer.AddSpacer(2)
             output_filename_edit_box_sizer.Add(
                 allow_output_filename_overwrite_check_box, 0, 
                 wx.ALIGN_CENTER)
             output_sizer.Add(output_filename_help_button, 0, wx.EXPAND)
             output_sizer.Add(output_filename_text, 0, wx.ALIGN_RIGHT)
             output_sizer.Add(output_filename_edit_box_sizer, 1, wx.EXPAND)
             
             output_sizer.Add(wx.BoxSizer(), 0, wx.EXPAND)
             output_sizer.Add(output_file_format_text, 0, wx.ALIGN_RIGHT)
             output_sizer.Add(write_measurements_combo_box, 0, wx.ALIGN_LEFT)
             
         panel.SetSizer(output_sizer)
         for ctrl in (output_filename_text,
                      output_filename_edit_box,
                      allow_output_filename_overwrite_check_box):
             ctrl.Show(show)
             
         panel.Parent.Layout()
         panel.Layout()
         
     write_measurements_combo_box.Bind(
         wx.EVT_CHOICE, on_write_MAT_files_combo_box)
     allow_output_filename_overwrite_check_box.Bind(
                 wx.EVT_CHECKBOX, on_allow_checkbox)
     output_filename_help_button.Bind(
         wx.EVT_BUTTON,
         lambda event: self.__on_help(event, USING_THE_OUTPUT_FILE_HELP))
     output_filename_edit_box.Bind(wx.EVT_TEXT, on_output_filename_changed)
     panel.Bind(wx.EVT_WINDOW_DESTROY, self.__on_destroy, panel)
     on_write_MAT_files_combo_box(None)
예제 #9
0
    def __make_odds_and_ends_panel(self):
        panel = self.__odds_and_ends_panel
        self.__output_filename_text = wx.StaticText(panel,-1,'Output Filename:')
        self.__output_filename_edit_box = wx.TextCtrl(panel, -1, cpprefs.get_output_file_name())
        self.__allow_output_filename_overwrite_check_box = \
            wx.CheckBox(panel, label = "Allow overwrite?")
        self.__allow_output_filename_overwrite_check_box.Value = \
            cpprefs.get_allow_output_file_overwrite()
        def on_allow_checkbox(event):
            cpprefs.set_allow_output_file_overwrite(
                self.__allow_output_filename_overwrite_check_box.Value)
        self.__allow_output_filename_overwrite_check_box.Bind(
            wx.EVT_CHECKBOX, on_allow_checkbox)
        self.__write_measurements_combo_box = \
            wx.Choice(panel, choices = 
                      [WRITE_HDF_FILE, WRITE_MAT_FILE, 
                       DO_NOT_WRITE_MEASUREMENTS])
        def on_write_MAT_files_combo_box(event):
            sel = self.__write_measurements_combo_box.GetStringSelection()
            output_filename = self.__output_filename_edit_box.Value
            if sel == WRITE_HDF_FILE:
                cpprefs.set_write_MAT_files(cpprefs.WRITE_HDF5)
                if output_filename.lower().endswith('.mat'):
                    output_filename = output_filename[:-4] + u".h5"
            elif sel == WRITE_MAT_FILE:
                cpprefs.set_write_MAT_files(True)
                if output_filename.lower().endswith('.h5'):
                    output_filename = output_filename[:-3] + u".mat"
            else:
                cpprefs.set_write_MAT_files(False)
            if output_filename != self.__output_filename_edit_box.Value:
                self.__output_filename_edit_box.Value = output_filename
                cpprefs.set_output_file_name(self.__output_filename_edit_box.Value)
            self.__show_output_filename(sel != DO_NOT_WRITE_MEASUREMENTS)
            panel.Layout()
            panel.Refresh()
        # set measurements mode, then fake an event to update output
        # filename and which controls are shown.
        measurements_mode_idx = [cpprefs.WRITE_HDF5, True, False].index(cpprefs.get_write_MAT_files())
        self.__write_measurements_combo_box.SetSelection(measurements_mode_idx)
        on_write_MAT_files_combo_box(None)

        self.__write_measurements_combo_box.Bind(
            wx.EVT_CHOICE, on_write_MAT_files_combo_box)
        output_filename_help_button = wx.Button(panel,-1,'?', (0,0), (30,-1))
        if not cpdistributed.run_distributed():
            self.__analyze_images_button = wx.Button(panel, -1, ANALYZE_IMAGES)
        else:
            self.__analyze_images_button = wx.Button(panel, -1, START_WORK_SERVER)
        self.__stop_analysis_button = wx.Button(panel,-1,'Stop analysis')
        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.AddMany([(output_filename_help_button,0,wx.ALIGN_CENTER|wx.ALL,1),
                       (self.__output_filename_text,0,wx.ALIGN_CENTER,1),
                       (self.__output_filename_edit_box,5,wx.ALL,1),
                       (self.__allow_output_filename_overwrite_check_box, 0, wx.ALIGN_CENTER | wx.ALL, 1),
                       ((1, 1), 1),
                       (wx.StaticText(panel, label = "Measurements file format:"), 0, wx.ALIGN_CENTER | wx.ALL, 1),
                       (self.__write_measurements_combo_box, 0, wx.ALIGN_CENTER | wx.ALL, 1),
                       (self.__analyze_images_button,0,wx.ALL,1),
                       (self.__stop_analysis_button, 0, wx.ALL,1)])
        sizer.Hide(self.__stop_analysis_button)
        panel.SetSizer(sizer)
        panel.Bind(wx.EVT_BUTTON,
                   lambda event: self.__on_help(event, OUTPUT_FILENAME_HELP),
                   output_filename_help_button)
        panel.Bind(wx.EVT_TEXT, self.__on_output_filename_changed, self.__output_filename_edit_box)
        cpprefs.add_output_file_name_listener(self.__on_preferences_output_filename_event)
        cpprefs.add_image_directory_listener(self.__on_preferences_image_directory_event)
        cpprefs.add_output_directory_listener(self.__on_preferences_output_directory_event)
        cpprefs.add_run_distributed_listener(self.__on_preferences_run_distributed_event)
        panel.Bind(wx.EVT_WINDOW_DESTROY, self.__on_destroy, panel)