def setup_gui(self): self.buttons = [] self.grid = wx.GridSizer(cols=3, hgap=2, vgap=2) translated = [i[1] for i in meta.languages] translated.sort() self.lang = wx.ComboBox(self, choices=translated, style=wx.CB_READONLY, size=(240, 30)) self.lang.Layout() self.lang.SetValue(_(self.config.language())) colours = [] for x in range(1, 10): col = self.config.colour(x) colours.append([int(c) for c in col]) for x, colour in enumerate(colours): method = lambda evt, _id = x: self.on_colour(evt, _id) b = wx.BitmapButton(self, bitmap=create_colour_bitmap(colour)) self.buttons.append(b) self.grid.Add(b, 0) b.Bind(wx.EVT_BUTTON, method) self.fontBtn = button(self, wx.NewId(), _("Select Font"), self.on_font) font = wx.SystemSettings.GetFont(wx.SYS_SYSTEM_FONT) self.font = font # the correct font, w/ right size self.size = font.GetPointSize() # size to use regardless of font if self.config.default_font(): f = wx.FFont(1, wx.FONTFAMILY_DEFAULT) f.SetNativeFontInfoFromString(self.config.default_font()) self.font = f self.fontBtn.SetFont(f) self.fontBtn.SetLabel(self.config.default_font()) if os.name == "nt": self.font_label(f) f = wx.FFont(1, wx.FONTFAMILY_DEFAULT) f.SetNativeFontInfoFromString(self.config.default_font()) f.SetPointSize(self.size) self.fontBtn.SetFont(f) else: if os.name == "nt": self.font_label(self.font) else: self.fontBtn.SetLabel(self.fontBtn.GetFont().GetNativeFontInfoDesc()) self.sizer.Add(label(self, _("Choose Your Language:")), 0, wx.ALL, 15) self.sizer.Add(self.lang, 0, wx.LEFT, 30) self.sizer.Add((10, 15)) self.sizer.Add(label(self, _("Choose Your Custom Colors:")), 0, wx.ALL, 15) self.sizer.Add(self.grid, 0, wx.LEFT | wx.BOTTOM, 30) self.sizer.Add(label(self, _("Default Font:")), 0, wx.LEFT, 15) self.sizer.Add((10, 15)) self.sizer.Add(self.fontBtn, 0, wx.LEFT, 30) self.lang.Bind(wx.EVT_COMBOBOX, self.on_lang)
def make_colour_grid(self): """Builds a colour grid from the user's preferred colours""" colours = [] for x in range(1, 10): col = Config().colour(x) colours.append([int(c) for c in col]) for colour in colours: left_click = lambda evt, col = colour: self.change_colour(evt, col) right_click = lambda evt, col = colour: self.change_background(evt, col) b = wx.BitmapButton(self.pane, bitmap=create_colour_bitmap(colour)) self.grid.Add(b, 0) b.Bind(wx.EVT_BUTTON, left_click) b.Bind(wx.EVT_RIGHT_UP, right_click)
def on_colour(self, event, _id): """ Change the colour of the selected button. We need to remove the current button's button, recreate it with the new colour and re-layout the sizer """ colour = self.config.colour(_id + 1) colour = ([int(c) for c in colour]) data = wx.ColourData() data.SetColour(colour) dlg = wx.ColourDialog(self, data) if dlg.ShowModal() == wx.ID_OK: self.config.colour(_id + 1, list(dlg.GetColourData().Colour.Get())) col = create_colour_bitmap(dlg.GetColourData().Colour) self.buttons[_id].SetBitmapLabel(col) self.grid.Layout() dlg.Destroy()