示例#1
0
    def Init(self, name = None, appname = ""):
        """Method called after the panel has been initialized."""

        # Hide the close button on Mac
        if guiutil.IsMac():
            XRCCTRL(self, 'wxID_OK').Hide()
        # Set window icon
        else:
            self.SetIcon(guiutil.get_icon())

        # Set the dialog title
        if name:
            self.SetTitle(name)

        # Initialize controls
        self.notebook = XRCCTRL(self, 'notebook')

        # Modify the control and font size on Mac
        for child in self.GetChildren():
            guiutil.adjust_control(child)

        # Bind ui events to the proper methods
        self.Bind(wx.EVT_CLOSE, self.OnClose)
        self.Bind(wx.EVT_WINDOW_DESTROY, self.OnClose)
        wx.EVT_BUTTON(self, XRCID('wxID_OK'), self.OnClose)

        # Initialize variables
        self.preftemplate = []
        self.values = {}
        self.appname = appname
示例#2
0
    def Init(self, name=None, appname=""):
        """Method called after the panel has been initialized."""

        # Hide the close button on Mac
        if guiutil.IsMac():
            XRCCTRL(self, 'wxID_OK').Hide()
        # Set window icon
        else:
            self.SetIcon(guiutil.get_icon())

        # Set the dialog title
        if name:
            self.SetTitle(name)

        # Initialize controls
        self.notebook = XRCCTRL(self, 'notebook')

        # Modify the control and font size on Mac
        for child in self.GetChildren():
            guiutil.adjust_control(child)

        # Bind ui events to the proper methods
        self.Bind(wx.EVT_CLOSE, self.OnClose)
        self.Bind(wx.EVT_WINDOW_DESTROY, self.OnClose)
        wx.EVT_BUTTON(self, XRCID('wxID_OK'), self.OnClose)

        # Initialize variables
        self.preftemplate = []
        self.values = {}
        self.appname = appname
示例#3
0
    def CreatePreferencePanel(self, prefpaneldata):
        """Create a preference panel for the given data."""

        panel = wx.Panel(self.notebook, -1)
        border = wx.BoxSizer(wx.VERTICAL)
        show_restart = False

        for group in prefpaneldata:
            # Create a header for each group of settings
            bsizer = wx.BoxSizer(wx.VERTICAL)
            bsizer.Add((0,5))
            hsizer = wx.BoxSizer(wx.HORIZONTAL)
            hsizer.Add((12, 0))
            h = wx.StaticText(panel, -1, group.keys()[0])
            font = h.GetFont()
            font.SetWeight(wx.FONTWEIGHT_BOLD)
            h.SetFont(font)
            hsizer.Add(h)
            bsizer.Add(hsizer)
            bsizer.Add((0,7))
            # Create a FlexGridSizer to contain the group of settings
            fgsizer = wx.FlexGridSizer(len(group.values()[0]), 4, 10, 4)
            fgsizer.AddGrowableCol(2, 1)
            # Create controls for each setting
            for setting in group.values()[0]:
                fgsizer.Add((24, 0))
                # Show the restart asterisk for this setting if required
                restart = str('*' if 'restart' in setting else '')
                if ('restart' in setting):
                    if (setting['restart'] == True):
                        show_restart = True
                t = wx.StaticText(panel, -1, setting['name']+restart+':',
                    style=wx.ALIGN_RIGHT)
                fgsizer.Add(t, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
                sizer = wx.BoxSizer(wx.HORIZONTAL)

                # Get the setting value
                value = GetValue(self.values, setting)
                # Save the setting value in case it hasn't been saved previously
                SetValue(self.values, setting['callback'], value)

                # If this is a choice setting
                if (setting['type'] == 'choice'):
                    c = wx.Choice(panel, -1, choices=setting['values'])
                    c.SetStringSelection(value)
                    sizer.Add(c, 0, wx.ALIGN_CENTER)
                    # Add control to the callback dict
                    self.callbackdict[c] = setting['callback']
                    self.Bind(wx.EVT_CHOICE, self.OnUpdateChoice, c)
                # If this is a checkbox setting
                elif (setting['type'] == 'checkbox'):
                    c = wx.CheckBox(panel, -1, setting['name']+restart)
                    c.SetValue(value)
                    sizer.Add(c, 0, wx.ALIGN_CENTER)
                    # Remove the label preceding the checkbox
                    t = self.FindWindowById(c.PrevControlId(c.GetId()))
                    t.SetLabel('')
                    # Adjust the sizer preceding the label
                    fgsizer.GetItem(0).SetSpacer((20,0))
                    # Add control to the callback dict
                    self.callbackdict[c] = setting['callback']
                    self.Bind(wx.EVT_CHECKBOX, self.OnUpdateCheckbox, c)
                # If this is a range setting
                elif (setting['type'] == 'range'):
                    s = wx.Slider(panel, -1, value,
                        setting['values'][0], setting['values'][1],
                        size=(120, -1), style=wx.SL_HORIZONTAL)
                    sizer.Add(s, 0, wx.ALIGN_CENTER)
                    t = wx.StaticText(panel, -1, str(value))
                    sizer.Add((3, 0))
                    sizer.Add(t, 0, wx.ALIGN_CENTER)
                    sizer.Add((6, 0))
                    t = wx.StaticText(panel, -1, setting['units'])
                    sizer.Add(t, 0, wx.ALIGN_CENTER)
                    # Add control to the callback dict
                    self.callbackdict[s] = setting['callback']
                    self.Bind(wx.EVT_COMMAND_SCROLL_THUMBTRACK, self.OnUpdateSlider, s)
                    self.Bind(wx.EVT_COMMAND_SCROLL_CHANGED, self.OnUpdateSlider, s)
                # If this is a directory location setting
                elif (setting['type'] == 'directory'):
                    # Check if the value is a valid directory,
                    # otherwise set it to the default directory
                    if not os.path.isdir(value):
                        value = setting['default']
                        SetValue(self.values, setting['callback'], value)
                    t = wx.TextCtrl(panel, -1, value, style=wx.TE_READONLY)
                    sizer.Add(t, 1, wx.ALIGN_CENTER)
                    sizer.Add((5, 0))
                    b = wx.Button(panel, -1, "Browse...")
                    sizer.Add(b, 0, wx.ALIGN_CENTER)
                    # Add control to the callback dict
                    self.callbackdict[b] = setting['callback']
                    self.Bind(wx.EVT_BUTTON, self.OnUpdateDirectory, b)
                # Modify the control and font size on Mac
                for child in panel.GetChildren():
                    guiutil.adjust_control(child)
                fgsizer.Add(sizer, 1, wx.EXPAND|wx.ALL)
                fgsizer.Add((12, 0))
            bsizer.Add(fgsizer, 0, wx.EXPAND|wx.ALL)
            border.Add(bsizer, 0, wx.EXPAND|wx.ALL, 2)
        border.Add((60, 20), 0, wx.EXPAND|wx.ALL)
        # Show the restart text for this group if required for >= 1 setting
        if show_restart:
            r = wx.StaticText(panel, -1,
                              '* Restart ' + self.appname + \
                              ' for this setting to take effect.',
                              style=wx.ALIGN_CENTER)
            font = r.GetFont()
            font.SetWeight(wx.FONTWEIGHT_BOLD)
            r.SetFont(font)
            border.Add((0,0), 1, wx.EXPAND|wx.ALL)
            rhsizer = wx.BoxSizer(wx.HORIZONTAL)
            rhsizer.Add((0,0), 1, wx.EXPAND|wx.ALL)
            rhsizer.Add(r)
            rhsizer.Add((0,0), 1, wx.EXPAND|wx.ALL)
            border.Add(rhsizer, 0, wx.EXPAND|wx.ALL)
            border.Add((0,5))
        panel.SetSizer(border)

        return panel
示例#4
0
    def CreatePreferencePanel(self, prefpaneldata):
        """Create a preference panel for the given data."""

        panel = wx.Panel(self.notebook, -1)
        border = wx.BoxSizer(wx.VERTICAL)
        show_restart = False

        for group in prefpaneldata:
            # Create a header for each group of settings
            bsizer = wx.BoxSizer(wx.VERTICAL)
            bsizer.Add((0, 5))
            hsizer = wx.BoxSizer(wx.HORIZONTAL)
            hsizer.Add((12, 0))
            h = wx.StaticText(panel, -1, group.keys()[0])
            font = h.GetFont()
            font.SetWeight(wx.FONTWEIGHT_BOLD)
            h.SetFont(font)
            hsizer.Add(h)
            bsizer.Add(hsizer)
            bsizer.Add((0, 7))
            # Create a FlexGridSizer to contain the group of settings
            fgsizer = wx.FlexGridSizer(len(group.values()[0]), 4, 10, 4)
            fgsizer.AddGrowableCol(2, 1)
            # Create controls for each setting
            for setting in group.values()[0]:
                fgsizer.Add((24, 0))
                # Show the restart asterisk for this setting if required
                restart = str('*' if 'restart' in setting else '')
                if ('restart' in setting):
                    if (setting['restart'] == True):
                        show_restart = True
                t = wx.StaticText(panel,
                                  -1,
                                  setting['name'] + restart + ':',
                                  style=wx.ALIGN_RIGHT)
                fgsizer.Add(t, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
                sizer = wx.BoxSizer(wx.HORIZONTAL)

                # Get the setting value
                value = GetValue(self.values, setting)
                # Save the setting value in case it hasn't been saved previously
                SetValue(self.values, setting['callback'], value)

                # If this is a choice setting
                if (setting['type'] == 'choice'):
                    c = wx.Choice(panel, -1, choices=setting['values'])
                    c.SetStringSelection(value)
                    sizer.Add(c, 0, wx.ALIGN_CENTER)
                    # Add control to the callback dict
                    self.callbackdict[c] = setting['callback']
                    self.Bind(wx.EVT_CHOICE, self.OnUpdateChoice, c)
                # If this is a checkbox setting
                elif (setting['type'] == 'checkbox'):
                    c = wx.CheckBox(panel, -1, setting['name'] + restart)
                    c.SetValue(value)
                    sizer.Add(c, 0, wx.ALIGN_CENTER)
                    # Remove the label preceding the checkbox
                    t = c.GetPrevSibling()
                    t.SetLabel('')
                    # Adjust the sizer preceding the label
                    fgsizer.GetItem(0).AssignSpacer((20, 0))
                    # Add control to the callback dict
                    self.callbackdict[c] = setting['callback']
                    self.Bind(wx.EVT_CHECKBOX, self.OnUpdateCheckbox, c)
                # If this is a range setting
                elif (setting['type'] == 'range'):
                    s = wx.Slider(panel,
                                  -1,
                                  value,
                                  setting['values'][0],
                                  setting['values'][1],
                                  size=(120, -1),
                                  style=wx.SL_HORIZONTAL)
                    sizer.Add(s, 0, wx.ALIGN_CENTER)
                    t = wx.StaticText(panel, -1, str(value))
                    sizer.Add((3, 0))
                    sizer.Add(t, 0, wx.ALIGN_CENTER)
                    sizer.Add((6, 0))
                    t = wx.StaticText(panel, -1, setting['units'])
                    sizer.Add(t, 0, wx.ALIGN_CENTER)
                    # Add control to the callback dict
                    self.callbackdict[s] = setting['callback']
                    self.Bind(wx.EVT_COMMAND_SCROLL_THUMBTRACK,
                              self.OnUpdateSlider, s)
                    self.Bind(wx.EVT_COMMAND_SCROLL_CHANGED,
                              self.OnUpdateSlider, s)
                # If this is a directory location setting
                elif (setting['type'] == 'directory'):
                    # Check if the value is a valid directory,
                    # otherwise set it to the default directory
                    if not os.path.isdir(value):
                        value = setting['default']
                        SetValue(self.values, setting['callback'], value)
                    t = wx.TextCtrl(panel, -1, value, style=wx.TE_READONLY)
                    sizer.Add(t, 1, wx.ALIGN_CENTER)
                    sizer.Add((5, 0))
                    b = wx.Button(panel, -1, "Browse...")
                    sizer.Add(b, 0, wx.ALIGN_CENTER)
                    # Add control to the callback dict
                    self.callbackdict[b] = setting['callback']
                    self.Bind(wx.EVT_BUTTON, self.OnUpdateDirectory, b)
                # Modify the control and font size on Mac
                for child in panel.GetChildren():
                    guiutil.adjust_control(child)
                fgsizer.Add(sizer, 1, wx.EXPAND | wx.ALL)
                fgsizer.Add((12, 0))
            bsizer.Add(fgsizer, 0, wx.EXPAND | wx.ALL)
            border.Add(bsizer, 0, wx.EXPAND | wx.ALL, 2)
        border.Add((60, 20), 0, wx.EXPAND | wx.ALL)
        # Show the restart text for this group if required for >= 1 setting
        if show_restart:
            r = wx.StaticText(panel, -1,
                              '* Restart ' + self.appname + \
                              ' for this setting to take effect.',
                              style=wx.ALIGN_CENTER)
            font = r.GetFont()
            font.SetWeight(wx.FONTWEIGHT_BOLD)
            r.SetFont(font)
            border.Add((0, 0), 1, wx.EXPAND | wx.ALL)
            rhsizer = wx.BoxSizer(wx.HORIZONTAL)
            rhsizer.Add((0, 0), 1, wx.EXPAND | wx.ALL)
            rhsizer.Add(r)
            rhsizer.Add((0, 0), 1, wx.EXPAND | wx.ALL)
            border.Add(rhsizer, 0, wx.EXPAND | wx.ALL)
            border.Add((0, 5))
        panel.SetSizer(border)

        return panel