Beispiel #1
0
    def test_propgridprops12(self):
        pg.PG_PROP_SHOW_FULL_FILENAME

        p1 = pg.FileProperty()
        value = '/foo/bar/value'
        p2 = pg.FileProperty('label', 'name', value)

        fn = p2.GetFileName()
        assert fn.replace(os.path.sep, '/') == value
Beispiel #2
0
    def add_file_property(self, name, key, value, status=None, enabled=True, *args, **kwargs):
        """
        Add file property.

        :param name:
        :param key:
        :param value:
        :param status: status bar string
        :param enabled:
        :param args:
        :param kwargs:
        :return:
        """
        item = propgrid.FileProperty(name, key, value=value)
        self.Append(item)
        self.SetPropertyHelpString(key, status)

        if status:
            self.SetPropertyHelpString(key, status)

        if enabled:
            self.EnableProperty(key)
        else:
            self.DisableProperty(key)

        return item
Beispiel #3
0
    def create_savefile_property(prop_name, wildcard):
        file_prop = wxpg.FileProperty(prop_name)
        # PG_DIALOG_TITLE
        file_prop.SetAttribute(wxpg.PG_FILE_DIALOG_STYLE, wx.FD_SAVE)
        file_prop.SetAttribute(wxpg.PG_FILE_WILDCARD, wildcard)

        return file_prop
Beispiel #4
0
    def create_openfile_property(prop_name, wildcard):
        file_prop = wxpg.FileProperty(prop_name)
        # PG_DIALOG_TITLE
        file_prop.SetAttribute(wxpg.PG_FILE_DIALOG_STYLE,
                               wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
        file_prop.SetAttribute(wxpg.PG_FILE_WILDCARD, wildcard)

        return file_prop
Beispiel #5
0
    def AddProperty(self, property, parent_property=None):
        self.inAddProperty += 1

        # add a cad.property, optionally to an existing wx.PGProperty
        if property.GetType() == cad.PROPERTY_TYPE_STRING:
            new_prop = wxpg.StringProperty(property.GetTitle(),
                                           value=property.GetString())
        elif property.GetType() == cad.PROPERTY_TYPE_LONG_STRING:
            #new_prop = wxpg.LongStringProperty("MultipleButtons", wxpg.PG_LABEL)
            new_prop = wxpg.StringProperty(property.GetTitle(),
                                           value=property.GetString())
        elif property.GetType() == cad.PROPERTY_TYPE_DOUBLE:
            new_prop = wxpg.FloatProperty(property.GetTitle(),
                                          value=property.GetDouble())
        elif property.GetType() == cad.PROPERTY_TYPE_LENGTH:
            new_prop = wxpg.FloatProperty(property.GetTitle(),
                                          value=property.GetDouble() /
                                          cad.GetUnits())
        elif property.GetType() == cad.PROPERTY_TYPE_INT:
            new_prop = wxpg.IntProperty(property.GetTitle(),
                                        value=property.GetInt())
        elif property.GetType() == cad.PROPERTY_TYPE_COLOR:
            col = property.GetColor()
            wcol = wx.Colour(col.red, col.green, col.blue)
            new_prop = wxpg.ColourProperty(property.GetTitle(), value=wcol)
        elif property.GetType() == cad.PROPERTY_TYPE_CHOICE:
            new_prop = wxpg.EnumProperty(property.GetTitle(),
                                         labels=property.GetChoices(),
                                         value=property.GetInt())
        elif property.GetType() == cad.PROPERTY_TYPE_CHECK:
            new_prop = wxpg.BoolProperty(property.GetTitle(),
                                         value=property.GetBool())
            new_prop.SetAttribute(wxpg.PG_BOOL_USE_CHECKBOX, True)
        elif property.GetType() == cad.PROPERTY_TYPE_LIST:
            new_prop = wxpg.StringProperty(property.GetTitle(),
                                           value='<composed>')
        elif property.GetType() == cad.PROPERTY_TYPE_FILE:
            new_prop = wxpg.FileProperty(property.GetTitle(),
                                         value=property.GetString())
        else:
            wx.MessageBox('invalid property type: ' + str(property.GetType()))
            return

        if not property.editable:
            new_prop.ChangeFlag(wxpg.PG_PROP_READONLY, True)
        self.Append(parent_property, new_prop, property)

        if property.GetType() == cad.PROPERTY_TYPE_LIST:
            plist = property.GetProperties()
            for p in plist:
                self.AddProperty(p, new_prop)
            new_prop.ChangeFlag(wxpg.PG_PROP_COLLAPSED, True)
        elif property.GetType() == cad.PROPERTY_TYPE_LONG_STRING:
            # Change property to use editor created in the previous code segment
            #self.pg.SetPropertyEditor("MultipleButtons", self.multiButtonEditor)
            self.pg.SetPropertyEditor(new_prop, "TrivialPropertyEditor")

        self.inAddProperty -= 1
    def _create_dummy_content(self):
        # some dummy content from the wxPython demo
        import wx.propgrid as wxpg
        pg = self.widget
        pg.AddPage( "Page 1 - Dummy" )

        pg.Append( wxpg.PropertyCategory("1 - Basic Properties") )
        pg.Append( wxpg.StringProperty("String",value="Some Text") )

        sp = pg.Append( wxpg.StringProperty('StringProperty w/ Password flag', value='ABadPassword') )
        sp.SetAttribute('Hint', 'This is a hint')
        sp.SetAttribute('Password', True)

        pg.Append( wxpg.IntProperty("Int",value=123) )
        pg.Append( wxpg.FloatProperty("Float",value=123.4) )
        pg.Append( wxpg.BoolProperty("Bool",value=True) )
        pg.Append( wxpg.BoolProperty("Bool_with_Checkbox",value=True) )
        pg.SetPropertyAttribute( "Bool_with_Checkbox", "UseCheckbox", True)
        pg.Append( wxpg.PropertyCategory("2 - More Properties") )
        pg.Append( wxpg.LongStringProperty("LongString", value="This is a\nmulti-line string\nwith\ttabs\nmixed\tin."))
        pg.Append( wxpg.DirProperty("Dir",value=r"C:\Windows") )
        pg.Append( wxpg.FileProperty("File",value=r"C:\Windows\system.ini") )
        pg.Append( wxpg.ArrayStringProperty("ArrayString",value=['A','B','C']) )

        pg.Append( wxpg.EnumProperty("Enum","Enum", ['wxPython Rules', 'wxPython Rocks', 'wxPython Is The Best'],
                                                    [10,11,12], 0) )
        pg.Append( wxpg.EditEnumProperty("EditEnum","EditEnumProperty", ['A','B','C'], [0,1,2], "Text Not in List") )

        pg.Append( wxpg.PropertyCategory("3 - Advanced Properties") )
        pg.Append( wxpg.DateProperty("Date",value=wx.DateTime.Now()) )
        pg.Append( wxpg.FontProperty("Font",value=self.widget.GetFont()) )
        pg.Append( wxpg.ColourProperty("Colour", value=self.widget.GetBackgroundColour()) )
        pg.Append( wxpg.SystemColourProperty("SystemColour") )
        pg.Append( wxpg.ImageFileProperty("ImageFile") )
        pg.Append( wxpg.MultiChoiceProperty("MultiChoice", choices=['wxWidgets','QT','GTK+']) )

        pg.Append( wxpg.PropertyCategory("4 - Additional Properties") )
        pg.Append( wxpg.IntProperty("IntWithSpin",value=256) )
        pg.SetPropertyEditor("IntWithSpin","SpinCtrl")

        pg.SetPropertyAttribute( "File", wxpg.PG_FILE_SHOW_FULL_PATH, 0 )
        pg.SetPropertyAttribute( "File", wxpg.PG_FILE_INITIAL_PATH, r"C:\Program Files\Internet Explorer" )
        if compat.IS_PHOENIX:
            pg.SetPropertyAttribute( "Date", wxpg.PG_DATE_PICKER_STYLE, wx.adv.DP_DROPDOWN|wx.adv.DP_SHOWCENTURY )

        pg.AddPage( "Page 2 - Almost Empty" )
        pg.Append( wxpg.PropertyCategory("1 - Basic Properties") )
        pg.Append( wxpg.StringProperty("String 2",value="Some Text") )
Beispiel #7
0
    def _create_plot_properties(self):
        pg = self.property_grid_1
        # pg.AddPage("Page 1 - Plot Settings")  # if pages are needed, use PropertyGridManger instead
        dir_path = os.path.dirname(os.path.realpath(__file__))
        pg.Append(wxpg.PropertyCategory("1 - Basic Properties"))
        pg.Append(wxpg.StringProperty(label="Title", value="Title"))
        pg.Append(wxpg.StringProperty(label="X Label", value="X Label"))
        pg.Append(wxpg.StringProperty(label="Y Label", value="Y Label"))
        pg.Append(wxpg.BoolProperty(label="Grid", value=True))
        pg.SetPropertyAttribute(id="Grid", attrName="UseCheckbox", value=True)

        pg.Append(wxpg.PropertyCategory("2 - Data"))
        # https://discuss.wxpython.org/t/wxpython-pheonix-4-0-2-question-regarding-multichoiceproperty-and-setting-the-selection-of-the-choices/30044
        # https://discuss.wxpython.org/t/how-to-set-propertygrid-values/30152/4
        pg.Append(
            wxpg.EnumProperty(
                label="Scale",
                labels=['Linear', 'SemilogX', 'SemilogY', 'LogLog']))
        pg.Append(
            wxpg.EnumProperty(label="X Data",
                              name="X Data",
                              labels=['NaN'],
                              values=[0]))
        pg.Append(
            wxpg.MultiChoiceProperty(label="Y Data",
                                     name='Y Data',
                                     choices=['NaN'],
                                     value=['NaN']))
        pg.Append(
            wxpg.EnumProperty(label="Data Labels",
                              name="Data Labels",
                              labels=['NaN'],
                              values=[0]))

        pg.Append(wxpg.PropertyCategory("3 - Optional Static Plot Overlay"))
        pg.Append(wxpg.FileProperty(label="Overlay Plot",
                                    value=rf"{dir_path}"))
        pg.Append(wxpg.EnumProperty(label="X Axis Variable", labels=['']))
        pg.Append(wxpg.EnumProperty(label="Y Axis Variable", labels=['']))

        pg.Append(wxpg.PropertyCategory("4 - Advanced Properties"))
        pg.Append(wxpg.ArrayStringProperty(label="xLim", value=['0', '100']))
        pg.Append(wxpg.ArrayStringProperty(label="yLim", value=['0', '100']))
        pg.Append(wxpg.DateProperty(label="Date", value=wx.DateTime.Now()))
        pg.Append(wxpg.ColourProperty(label="Line Colour", value='#1f77b4'))
        pg.Append(wxpg.FontProperty(label="Font", value=self.GetFont()))
        pg.Grid.FitColumns()
Beispiel #8
0
    def _init_file_props(self):
        self.propgrid.Append(wxpg.PropertyCategory("File properties", "file"))

        props = (
            wxpg.FileProperty("Location", "file.location", ""),
            wxpg.StringProperty("Last modified", "file.modified", ""),
            wxpg.StringProperty("Last accessed", "file.accessed", ""),
            # os.path.getctime just returns the modification time on Unix
            #wxpg.StringProperty("Created", "file.created", ""),
            wxpg.StringProperty("Size", "file.size", ""),
        )

        for prop in props:
            self.propgrid.Append(prop)
            prop.Enable(False)

        self.propgrid.SetPropertyAttribute("file.size", "Units", "KiB")

        self.refresh_file_properties()
Beispiel #9
0
    def __init__(self, RunForm, parent ):
        wx.Notebook.__init__(self, parent, style=wx.BK_DEFAULT, size=(500, 50) )

        # Create panels and pages for each of the three notebook tabs.
        parameterGridPanel = wx.Panel(self, -1)
        settingsPanel = wx.Panel(self, -1)
        executionPanel = wx.Panel(self, -1)

        self.AddPage(parameterGridPanel, "Parameter Grid")
        self.AddPage(settingsPanel, "Run Configuration")
        self.AddPage(executionPanel, "Resources and Execution")

        # ***** PARAMETER GRID TAB *****
        parameterGridSizer = wx.BoxSizer( wx.HORIZONTAL )
        RunForm.speciesGrid = ParameterGrid( parameterGridPanel, RunForm.run )
        parameterGridSizer.Add( RunForm.speciesGrid, 1, wx.EXPAND )
        parameterGridPanel.SetSizerAndFit( parameterGridSizer )

        # Create the parameter grid control.
        RunForm.speciesGrid.CreateGrid( RunForm.run.species.numRows, RunForm.run.species.numColumns )
        RunForm.speciesGrid.SetColLabelValue( 0, "Parameter" )
        RunForm.speciesGrid.SetColLabelValue( 1, "Type")
        RunForm.speciesGrid.SetColLabelValue( 2, "Value(s)")
        RunForm.speciesGrid.SetColLabelValue( 3, "Directory Order")
        RunForm.speciesGrid.SetColSize( 3, 100 )

        # ***** RUN SETTINGS TAB *****
        runSettingsSizer = wx.BoxSizer( wx.VERTICAL )
        RunForm.runPropertiesGrid = wx_propgrid.PropertyGrid( settingsPanel, size=(300, 300) )
        runSettingsSizer.Add( RunForm.runPropertiesGrid, 2, wx.EXPAND )
        settingsPanel.SetSizerAndFit( runSettingsSizer )

        RunForm.runPropertiesGrid.Append( wx_propgrid.PropertyCategory( "Basic Script Properties" ) )
        RunForm.runPropertiesGrid.Append( wx_propgrid.StringProperty( "Script filename", "scriptFilename", RunForm.run.runSettings.scriptFilename ) )
        RunForm.runPropertiesGrid.Append( wx_propgrid.DirProperty( "Script output location", "scriptLocation", RunForm.run.runSettings.scriptLocation ) )
        RunForm.runPropertiesGrid.Append( wx_propgrid.LongStringProperty( "Run notes", "runNotes", RunForm.run.runNotes ) )
        RunForm.runPropertiesGrid.Append( wx_propgrid.PropertyCategory( "Executable Properties" ) )
        RunForm.runPropertiesGrid.Append( wx_propgrid.FileProperty( "Executable filename", "executableFilename", RunForm.run.runSettings.executableFilename ) )
        RunForm.runPropertiesGrid.Append( wx_propgrid.FileProperty( "Output filename", "outputFilename", RunForm.run.runSettings.outputFilename ) )
        RunForm.runPropertiesGrid.Append( wx_propgrid.FileProperty( "Input filename", "inputFilename", RunForm.run.runSettings.inputFilename ) )
        RunForm.runPropertiesGrid.Append( wx_propgrid.DirProperty( "Source path", "sourcePath", RunForm.run.runSettings.sourcePath ) )
        RunForm.runPropertiesGrid.Append( wx_propgrid.PropertyCategory( "Basic Script Tasks" ) )
        RunForm.runPropertiesGrid.Append( wx_propgrid.BoolProperty("Compile executable from source", "optionCompileSource", RunForm.run.runSettings.optionCompileSource ) )
        RunForm.runPropertiesGrid.Append( wx_propgrid.BoolProperty("Build directory structure", "optionBuildDirectoryStructure", RunForm.run.runSettings.optionBuildDirectoryStructure ) )
        RunForm.runPropertiesGrid.Append( wx_propgrid.BoolProperty("Disable input redirection", "optionDisableInputRedirection", RunForm.run.runSettings.optionDisableInputRedirection ) )
        RunForm.runPropertiesGrid.Append( wx_propgrid.BoolProperty("Generate status check script", "optionGenerateCheckStatusScript", RunForm.run.runSettings.optionGenerateCheckStatusScript ) )

        # ***** RESOURCES AND EXECUTION PANEL *****
        executionSettingsSizer = wx.BoxSizer( wx.VERTICAL )
        RunForm.singleMachinePropertyGrid = wx_propgrid.PropertyGrid( executionPanel )
        RunForm.executionChoiceBook = wx.Choicebook( executionPanel, id=wx.ID_ANY )
        executionSettingsSizer.Add( RunForm.executionChoiceBook, 1, wx.EXPAND )
        executionPanel.SetSizerAndFit( executionSettingsSizer )

        panelSingleMachine = wx.Panel( RunForm.executionChoiceBook )
        panelPBS = wx.Panel( RunForm.executionChoiceBook )
        panelSingleMachineMPI = wx.Panel( RunForm.executionChoiceBook )
        panelPBSMPI = wx.Panel( RunForm.executionChoiceBook )

        RunForm.executionChoiceBook.AddPage( panelSingleMachine, "Single Machine or Interactive Job (Recovery Enabled)")
        RunForm.executionChoiceBook.AddPage( panelPBS, "PBS Scheduler on Cluster")
        #RunForm.executionChoiceBook.AddPage( panelSingleMachineMPI, "Single Machine or Interactive Job using MPI")
        #RunForm.executionChoiceBook.AddPage( panelPBSMPI, "PBS Scheduler on Cluster using MPI")

        # SINGLE MACHINE SETTINGS
        RunForm.propertyGridSingleMachine = wx_propgrid.PropertyGrid( panelSingleMachine )
        sizerGridSingleMachine = wx.BoxSizer( wx.VERTICAL )
        sizerGridSingleMachine.Add( RunForm.propertyGridSingleMachine, 1, wx.EXPAND )
        panelSingleMachine.SetSizerAndFit( sizerGridSingleMachine )
        RunForm.propertyGridSingleMachine.Append( wx_propgrid.PropertyCategory( "Resources" ) )
        RunForm.propertyGridSingleMachine.Append( wx_propgrid.IntProperty( "Number of simultaneous runs", "numSimRuns", RunForm.run.availableModules.SingleMachineResourceManager.numSimRuns ) )
        RunForm.propertyGridSingleMachine.Append( wx_propgrid.IntProperty( "Process status check delay (seconds)", "procCheckWaitTime", RunForm.run.availableModules.SingleMachineResourceManager.procCheckWaitTime ) )
        RunForm.propertyGridSingleMachine.Append( wx_propgrid.PropertyCategory( "Additional Commands" ) )
        RunForm.propertyGridSingleMachine.Append( wx_propgrid.LongStringProperty( "Additional pre-execution commands", "additionalPreExecutionCommands", RunForm.run.availableModules.SingleMachineResourceManager.additionalPreExecutionCommands ) )
        RunForm.propertyGridSingleMachine.Append( wx_propgrid.LongStringProperty( "Additional post-execution commands", "additionalPostExecutionCommands", RunForm.run.availableModules.SingleMachineResourceManager.additionalPostExecutionCommands ) )

        # PBS SETTINGS
        RunForm.propertyGridPBS = wx_propgrid.PropertyGrid( panelPBS )
        sizerGridPBS = wx.BoxSizer( wx.VERTICAL )
        sizerGridPBS.Add( RunForm.propertyGridPBS, 1, wx.EXPAND )
        panelPBS.SetSizerAndFit( sizerGridPBS )
        RunForm.propertyGridPBS.Append( wx_propgrid.PropertyCategory( "PBS Settings" ) )
        RunForm.propertyGridPBS.Append( wx_propgrid.IntProperty( "Number of nodes", "numNodes", RunForm.run.availableModules.PBSResourceManager.numNodes ) )
        RunForm.propertyGridPBS.Append( wx_propgrid.IntProperty( "Processors per node (ppn)", "processorsPerNode", RunForm.run.availableModules.PBSResourceManager.processorsPerNode ) )
        RunForm.propertyGridPBS.Append( wx_propgrid.StringProperty( "Walltime", "walltime", RunForm.run.availableModules.PBSResourceManager.walltime ) )
        RunForm.propertyGridPBS.Append( wx_propgrid.PropertyCategory( "Additional Commands" ) )
        RunForm.propertyGridPBS.Append( wx_propgrid.LongStringProperty( "Additional pre-execution commands", "additionalPreExecutionCommands", RunForm.run.availableModules.PBSResourceManager.additionalPreExecutionCommands ) )
        RunForm.propertyGridPBS.Append( wx_propgrid.LongStringProperty( "Additional post-execution commands", "additionalPostExecutionCommands", RunForm.run.availableModules.PBSResourceManager.additionalPostExecutionCommands ) )
Beispiel #10
0
    def __init__(self, parent, log):
        wx.Panel.__init__(self, parent, wx.ID_ANY)
        self.log = log

        self.panel = panel = wx.Panel(self, wx.ID_ANY)
        topsizer = wx.BoxSizer(wx.VERTICAL)

        # Difference between using PropertyGridManager vs PropertyGrid is that
        # the manager supports multiple pages and a description box.
        self.pg = pg = wxpg.PropertyGridManager(
            panel,
            style=wxpg.PG_SPLITTER_AUTO_CENTER | wxpg.PG_AUTO_SORT
            | wxpg.PG_TOOLBAR)

        # Show help as tooltips
        pg.SetExtraStyle(wxpg.PG_EX_HELP_AS_TOOLTIPS)

        pg.Bind(wxpg.EVT_PG_CHANGED, self.OnPropGridChange)
        pg.Bind(wxpg.EVT_PG_PAGE_CHANGED, self.OnPropGridPageChange)
        pg.Bind(wxpg.EVT_PG_SELECTED, self.OnPropGridSelect)
        pg.Bind(wxpg.EVT_PG_RIGHT_CLICK, self.OnPropGridRightClick)

        #
        # Let's use some simple custom editor
        #
        # NOTE: Editor must be registered *before* adding a property that
        # uses it.
        if not getattr(sys, '_PropGridEditorsRegistered', False):
            pg.RegisterEditor(TrivialPropertyEditor)
            pg.RegisterEditor(SampleMultiButtonEditor)
            pg.RegisterEditor(LargeImageEditor)
            # ensure we only do it once
            sys._PropGridEditorsRegistered = True

        #
        # Add properties
        #

        pg.AddPage("Page 1 - Testing All")

        pg.Append(wxpg.PropertyCategory("1 - Basic Properties"))
        pg.Append(wxpg.StringProperty("String", value="Some Text"))

        sp = pg.Append(
            wxpg.StringProperty('StringProperty w/ Password flag',
                                value='ABadPassword'))
        sp.SetAttribute('Hint', 'This is a hint')
        sp.SetAttribute('Password', True)

        pg.Append(wxpg.IntProperty("Int", value=100))
        pg.Append(wxpg.FloatProperty("Float", value=100.0))
        pg.Append(wxpg.BoolProperty("Bool", value=True))
        boolprop = pg.Append(
            wxpg.BoolProperty("Bool_with_Checkbox", value=True))
        pg.SetPropertyAttribute(
            "Bool_with_Checkbox",  # You can find the property by name,
            #boolprop,               # or give the property object itself.
            "UseCheckbox",
            True)  # The attribute name and value

        pg.Append(wxpg.PropertyCategory("2 - More Properties"))
        pg.Append(
            wxpg.LongStringProperty(
                "LongString",
                value="This is a\nmulti-line string\nwith\ttabs\nmixed\tin."))
        pg.Append(wxpg.DirProperty("Dir", value=r"C:\Windows"))
        pg.Append(wxpg.FileProperty("File", value=r"C:\Windows\system.ini"))
        pg.Append(
            wxpg.ArrayStringProperty("ArrayString", value=['A', 'B', 'C']))

        pg.Append(
            wxpg.EnumProperty(
                "Enum", "Enum",
                ['wxPython Rules', 'wxPython Rocks', 'wxPython Is The Best'],
                [10, 11, 12], 0))
        pg.Append(
            wxpg.EditEnumProperty("EditEnum", "EditEnumProperty",
                                  ['A', 'B', 'C'], [0, 1, 2],
                                  "Text Not in List"))

        pg.Append(wxpg.PropertyCategory("3 - Advanced Properties"))
        pg.Append(wxpg.DateProperty("Date", value=wx.DateTime.Now()))
        pg.Append(wxpg.FontProperty("Font", value=panel.GetFont()))
        pg.Append(
            wxpg.ColourProperty("Colour", value=panel.GetBackgroundColour()))
        pg.Append(wxpg.SystemColourProperty("SystemColour"))
        pg.Append(wxpg.ImageFileProperty("ImageFile"))
        pg.Append(
            wxpg.MultiChoiceProperty("MultiChoice",
                                     choices=['wxWidgets', 'QT', 'GTK+']))

        pg.Append(wxpg.PropertyCategory("4 - Additional Properties"))
        #pg.Append( wxpg.PointProperty("Point",value=panel.GetPosition()) )
        pg.Append(SizeProperty("Size", value=panel.GetSize()))
        #pg.Append( wxpg.FontDataProperty("FontData") )
        pg.Append(wxpg.IntProperty("IntWithSpin", value=256))
        pg.SetPropertyEditor("IntWithSpin", "SpinCtrl")

        pg.SetPropertyAttribute("File", wxpg.PG_FILE_SHOW_FULL_PATH, 0)
        pg.SetPropertyAttribute("File", wxpg.PG_FILE_INITIAL_PATH,
                                r"C:\Program Files\Internet Explorer")
        pg.SetPropertyAttribute("Date", wxpg.PG_DATE_PICKER_STYLE,
                                wx.adv.DP_DROPDOWN | wx.adv.DP_SHOWCENTURY)

        pg.Append(wxpg.PropertyCategory("5 - Custom Properties and Editors"))
        pg.Append(IntProperty2("IntProperty2", value=1024))

        pg.Append(PyObjectProperty("PyObjectProperty"))

        pg.Append(DirsProperty("Dirs1", value=['C:/Lib', 'C:/Bin']))
        pg.Append(DirsProperty("Dirs2", value=['/lib', '/bin']))

        # Test another type of delimiter
        pg.SetPropertyAttribute("Dirs2", "Delimiter", '"')

        # SampleMultiButtonEditor
        pg.Append(wxpg.LongStringProperty("MultipleButtons"))
        pg.SetPropertyEditor("MultipleButtons", "SampleMultiButtonEditor")
        pg.Append(SingleChoiceProperty("SingleChoiceProperty"))

        # Custom editor samples
        prop = pg.Append(
            wxpg.StringProperty("StringWithCustomEditor", value="test value"))
        pg.SetPropertyEditor(prop, "TrivialPropertyEditor")

        pg.Append(wxpg.ImageFileProperty("ImageFileWithLargeEditor"))
        pg.SetPropertyEditor("ImageFileWithLargeEditor", "LargeImageEditor")

        # When page is added, it will become the target page for AutoFill
        # calls (and for other property insertion methods as well)
        pg.AddPage("Page 2 - Results of AutoFill will appear here")

        topsizer.Add(pg, 1, wx.EXPAND)

        rowsizer = wx.BoxSizer(wx.HORIZONTAL)
        but = wx.Button(panel, -1, "SetPropertyValues")
        but.Bind(wx.EVT_BUTTON, self.OnSetPropertyValues)
        rowsizer.Add(but, 1)
        but = wx.Button(panel, -1, "GetPropertyValues")
        but.Bind(wx.EVT_BUTTON, self.OnGetPropertyValues)
        rowsizer.Add(but, 1)
        topsizer.Add(rowsizer, 0, wx.EXPAND)
        rowsizer = wx.BoxSizer(wx.HORIZONTAL)
        but = wx.Button(panel, -1, "GetPropertyValues(as_strings=True)")
        but.Bind(wx.EVT_BUTTON, self.OnGetPropertyValues2)
        rowsizer.Add(but, 1)
        but = wx.Button(panel, -1, "AutoFill")
        but.Bind(wx.EVT_BUTTON, self.OnAutoFill)
        rowsizer.Add(but, 1)
        topsizer.Add(rowsizer, 0, wx.EXPAND)
        rowsizer = wx.BoxSizer(wx.HORIZONTAL)
        but = wx.Button(panel, -1, "Delete")
        but.Bind(wx.EVT_BUTTON, self.OnDeleteProperty)
        rowsizer.Add(but, 1)
        but = wx.Button(panel, -1, "Run Tests")
        but.Bind(wx.EVT_BUTTON, self.RunTests)
        rowsizer.Add(but, 1)
        topsizer.Add(rowsizer, 0, wx.EXPAND)

        panel.SetSizer(topsizer)
        topsizer.SetSizeHints(panel)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(panel, 1, wx.EXPAND)
        self.SetSizer(sizer)
        self.SetAutoLayout(True)
Beispiel #11
0
    def __init__(self, parent, log):
        # Use the WANTS_CHARS style so the panel doesn't eat the Return key.
        wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS)

        self.log = log
        tID = wx.NewId()

        topsizer = wx.BoxSizer(wx.VERTICAL)

        # Difference between using PropertyGridManager vs PropertyGrid is that
        # the manager supports multiple pages and a description box.
        self.pg = pg = wxpg.PropertyGridManager(
            self,
            style=wxpg.PG_SPLITTER_AUTO_CENTER | wxpg.PG_AUTO_SORT
            | wxpg.PG_TOOLBAR)  # |wxpg.PG_DESCRIPTION
        #self.pg = pg = wxpg.PropertyGrid(self,
        #    style=wxpg.PG_SPLITTER_AUTO_CENTER|wxpg.PG_AUTO_SORT)

        # Show help as tooltips
        pg.SetExtraStyle(wxpg.PG_EX_HELP_AS_TOOLTIPS
                         | wxpg.PG_EX_MULTIPLE_SELECTION)

        pg.Bind(wxpg.EVT_PG_CHANGED, self.OnPropGridChange)
        pg.Bind(wxpg.EVT_PG_PAGE_CHANGED, self.OnPropGridPageChange)
        pg.Bind(wxpg.EVT_PG_SELECTED, self.OnPropGridSelect)
        pg.Bind(wxpg.EVT_PG_RIGHT_CLICK, self.OnPropGridRightClick)

        # Needed by custom image editor
        wx.InitAllImageHandlers()

        #
        # Let's use some simple custom editor
        #
        # NOTE: Editor must be registered *before* adding a property that
        # uses it.
        pg.RegisterEditor(TrivialPropertyEditor)
        pg.RegisterEditor(LargeImageEditor)

        #
        # Add properties
        #

        pg.AddPage("Page 1 - Testing All")

        pg.Append(wxpg.PropertyCategory("1 - Basic Properties"))

        pg.Append(wxpg.StringProperty("String", value="Some Text"))
        pg.Append(wxpg.IntProperty("Int", value=100))
        pg.Append(wxpg.FloatProperty("Float", value=100.0))
        pg.Append(wxpg.BoolProperty("Bool", value=True))
        pg.Append(wxpg.BoolProperty("Bool_with_Checkbox", value=True))
        pg.SetPropertyAttribute("Bool_with_Checkbox", "UseCheckbox", True)

        pg.Append(wxpg.PropertyCategory("2 - More Properties"))
        pg.Append(
            wxpg.LongStringProperty(
                "LongString",
                value=
                "This is a\\nmulti-line string\\nwith\\ttabs\\nmixed\\tin."))
        pg.Append(wxpg.DirProperty("Dir", value="C:\\Windows"))
        pg.Append(wxpg.FileProperty("File", value="C:\\Windows\\system.ini"))
        pg.Append(
            wxpg.ArrayStringProperty("ArrayString", value=['A', 'B', 'C']))

        pg.Append(
            wxpg.EnumProperty(
                "Enum", "Enum",
                ['wxPython Rules', 'wxPython Rocks', 'wxPython Is The Best'],
                [10, 11, 12], 0))
        pg.Append(
            wxpg.EditEnumProperty("EditEnum", "EditEnumProperty",
                                  ['A', 'B', 'C'], [0, 1, 2],
                                  "Text Not in List"))

        pg.Append(wxpg.PropertyCategory("3 - Advanced Properties"))
        pg.Append(wxpg.DateProperty("Date", value=wx.DateTime_Now()))
        pg.Append(wxpg.FontProperty("Font", value=self.GetFont()))
        pg.Append(
            wxpg.ColourProperty("Colour", value=self.GetBackgroundColour()))
        pg.Append(wxpg.SystemColourProperty("SystemColour"))
        pg.Append(wxpg.ImageFileProperty("ImageFile"))
        pg.Append(
            wxpg.MultiChoiceProperty("MultiChoice",
                                     choices=['wxWidgets', 'QT', 'GTK+']))

        pg.Append(wxpg.PropertyCategory("4 - Additional Properties"))
        pg.Append(wxpg.PointProperty("Point", value=self.GetPosition()))
        pg.Append(wxpg.SizeProperty("Size", value=self.GetSize()))
        pg.Append(wxpg.FontDataProperty("FontData"))
        pg.Append(wxpg.IntProperty("IntWithSpin", value=256))
        pg.SetPropertyEditor("IntWithSpin", "SpinCtrl")
        pg.Append(wxpg.DirsProperty("Dirs", value=['C:/Lib', 'C:/Bin']))
        pg.SetPropertyHelpString("String", "String Property help string!")
        pg.SetPropertyHelpString("Dirs", "Dirs Property help string!")

        pg.SetPropertyAttribute("File", wxpg.PG_FILE_SHOW_FULL_PATH, 0)
        pg.SetPropertyAttribute("File", wxpg.PG_FILE_INITIAL_PATH,
                                "C:\\Program Files\\Internet Explorer")
        pg.SetPropertyAttribute("Date", wxpg.PG_DATE_PICKER_STYLE,
                                wx.DP_DROPDOWN | wx.DP_SHOWCENTURY)

        pg.Append(wxpg.PropertyCategory("5 - Custom Properties"))
        pg.Append(IntProperty2("IntProperty2", value=1024))
        pg.Append(
            RectProperty("RectProperty", value=wx.Rect(100, 200, 300, 400)))

        pg.Append(ShapeProperty("ShapeProperty", value=0))
        pg.Append(PyObjectProperty("PyObjectProperty"))

        prop = pg.Append(
            wxpg.StringProperty("StringWithCustomEditor", value="test value"))
        pg.SetPropertyEditor(prop, "TrivialPropertyEditor")

        pg.Append(wxpg.ImageFileProperty("ImageFileWithLargeEditor"))
        pg.SetPropertyEditor("ImageFileWithLargeEditor", "LargeImageEditor")

        # When page is added, it will become the target page for AutoFill
        # calls (and for other property insertion methods as well)
        pg.AddPage("Page 2 - Results of AutoFill will appear here")

        pg.SetPropertyClientData("Point", 1234)
        if pg.GetPropertyClientData("Point") != 1234:
            raise ValueError("Set/GetPropertyClientData() failed")

        # Test setting unicode string
        pg.GetPropertyByName("String").SetValue(u"Some Unicode Text")

        #
        # Test some code that *should* fail (but not crash)
        try:
            a_ = pg.GetPropertyValue("NotARealProperty")
            pg.EnableProperty("NotAtAllRealProperty", False)
            pg.SetPropertyHelpString("AgaintNotARealProperty",
                                     "Dummy Help String")
        except:
            pass
            #raise

        topsizer.Add(pg, 1, wx.EXPAND)

        rowsizer = wx.BoxSizer(wx.HORIZONTAL)
        but = wx.Button(self, -1, "SetPropertyValues")
        but.Bind(wx.EVT_BUTTON, self.OnSetPropertyValues)
        rowsizer.Add(but, 1)
        but = wx.Button(self, -1, "GetPropertyValues")
        but.Bind(wx.EVT_BUTTON, self.OnGetPropertyValues)
        rowsizer.Add(but, 1)
        topsizer.Add(rowsizer, 0, wx.EXPAND)
        rowsizer = wx.BoxSizer(wx.HORIZONTAL)
        but = wx.Button(self, -1, "GetPropertyValues(as_strings=True)")
        but.Bind(wx.EVT_BUTTON, self.OnGetPropertyValues2)
        rowsizer.Add(but, 1)
        but = wx.Button(self, -1, "AutoFill")
        but.Bind(wx.EVT_BUTTON, self.OnAutoFill)
        rowsizer.Add(but, 1)
        topsizer.Add(rowsizer, 0, wx.EXPAND)
        rowsizer = wx.BoxSizer(wx.HORIZONTAL)
        but = wx.Button(self, -1, "Delete")
        but.Bind(wx.EVT_BUTTON, self.OnDeleteProperty)
        rowsizer.Add(but, 1)
        but = wx.Button(self, -1, "Run Tests")
        but.Bind(wx.EVT_BUTTON, self.RunTests)
        rowsizer.Add(but, 1)
        topsizer.Add(rowsizer, 0, wx.EXPAND)

        self.SetSizer(topsizer)
        topsizer.SetSizeHints(self)