def Populate(self): panel = wx.Panel(self, wx.ID_ANY) vsz = wx.BoxSizer(wx.VERTICAL) hsz = wx.BoxSizer(wx.HORIZONTAL) if self.icon is not None: hsz.Add(wx.StaticBitmap(panel, wx.ID_ANY, self.icon), 0, wx.ALL | wx.ALIGN_CENTRE, 2) # Seems that font copy-on-write does not work sometimes... font = wx.FontFromNativeInfoString( wx.NORMAL_FONT.GetNativeFontInfoDesc()) font.SetPointSize(8) font.SetWeight(wx.FONTWEIGHT_BOLD) titleCtrl = wx.StaticText(panel, wx.ID_ANY, self.title) titleCtrl.SetFont(font) hsz.Add(titleCtrl, 1, wx.ALL | wx.ALIGN_CENTRE, 2) btn = self.CloseButton(panel) if btn is not None: hsz.Add(btn, 0, wx.ALL, 2) wx.EVT_BUTTON(btn, wx.ID_ANY, self.DoClose) vsz.Add(hsz, 0, wx.ALL | wx.EXPAND, 2) self.AddInnerContent(vsz, panel) panel.SetSizer(vsz) sz = wx.BoxSizer() sz.Add(panel, 1, wx.EXPAND) self.SetSizer(sz) self.Fit()
def Draw( self, dc, testText, textColour, backgroundColour, fontStr, offsetLines, ): dc.SetBackground(wx.Brush(backgroundColour)) dc.Clear() dc.SetTextForeground(textColour) dc.SetFont(wx.FontFromNativeInfoString(fontStr)) tw, th, descent, externalLeading = dc.GetFullTextExtent(testText) if offsetLines: offset = -(tw / 2) else: offset = 0 w, h = dc.GetSizeTuple() lineNum = 0 y = 0 while y < h: if (lineNum % 2): x = offset else: x = 0 while x < w: dc.DrawText(testText, x, y) x += tw y += th lineNum += 1
def __parse_font_description(self, text, default_value=None): ''' Parse a font from the text. In case of failure, return the default value. ''' if text: font = wx.FontFromNativeInfoString(text) if font and font.IsOk(): if font.GetPointSize() < 4: font.SetPointSize(self.__default_font_size) return font return default_value
def _parseFontDesc(self, fontDesc, defaultValue=None): if fontDesc: try: font = wx.FontFromNativeInfoString(fontDesc) except wx.PyAssertionError: return defaultValue if font.IsOk(): if font.GetPointSize() < 4: font.SetPointSize(self.__defaultFontSize) return font return defaultValue
def OnChoosePlainTextFont(evt): fontdata = wx.FontData() if panel.fontDesc: font = wx.FontFromNativeInfoString(panel.fontDesc) fontdata.SetInitialFont(font) dlg = wx.FontDialog(panel, fontdata) try: if dlg.ShowModal() == wx.ID_OK: # fontdata = dlg.GetFontData() font = dlg.GetFontData().GetChosenFont() panel.fontDesc = font.GetNativeFontInfoDesc() finally: dlg.Destroy()
def addAppearanceSetting(self, fgColorSection, fgColorSetting, bgColorSection, bgColorSetting, fontSection, fontSetting, iconSection, iconSetting, text): currentFgColor = self.getvalue(fgColorSection, fgColorSetting) fgColorButton = wx.ColourPickerCtrl(self, col=currentFgColor) currentBgColor = self.getvalue(bgColorSection, bgColorSetting) bgColorButton = wx.ColourPickerCtrl(self, col=currentBgColor) defaultFont = wx.SystemSettings_GetFont(wx.SYS_DEFAULT_GUI_FONT) nativeInfoString = self.gettext(fontSection, fontSetting) currentFont = wx.FontFromNativeInfoString( nativeInfoString) if nativeInfoString else None fontButton = widgets.FontPickerCtrl(self, font=currentFont or defaultFont, colour=currentFgColor) fontButton.SetBackgroundColour(currentBgColor) iconEntry = wx.combo.BitmapComboBox(self, style=wx.CB_READONLY) imageNames = sorted(artprovider.chooseableItemImages.keys()) for imageName in imageNames: label = artprovider.chooseableItemImages[imageName] bitmap = wx.ArtProvider_GetBitmap(imageName, wx.ART_MENU, (16, 16)) item = iconEntry.Append(label, bitmap) iconEntry.SetClientData(item, imageName) currentIcon = self.gettext(iconSection, iconSetting) currentSelectionIndex = imageNames.index(currentIcon) iconEntry.SetSelection(currentSelectionIndex) # pylint: disable=E1101 self.addEntry( text, fgColorButton, bgColorButton, fontButton, iconEntry, flags=( wx.ALL | wx.ALIGN_CENTER_VERTICAL, wx.ALL | wx.EXPAND | wx.ALIGN_CENTER_VERTICAL, wx.ALL | wx.EXPAND | wx.ALIGN_CENTER_VERTICAL, wx.ALL | wx. ALIGN_CENTER_VERTICAL, # wx.EXPAND causes the button to be top aligned on Mac OS X wx.ALL | wx.EXPAND | wx.ALIGN_CENTER_VERTICAL)) self._colorSettings.append( (fgColorSection, fgColorSetting, fgColorButton)) self._colorSettings.append( (bgColorSection, bgColorSetting, bgColorButton)) self._iconSettings.append((iconSection, iconSetting, iconEntry)) self._fontSettings.append((fontSection, fontSetting, fontButton)) self._syncers.append( FontColorSyncer(fgColorButton, bgColorButton, fontButton))
def addFontSetting(self, section, setting, text): default_font = wx.SystemSettings_GetFont(wx.SYS_DEFAULT_GUI_FONT) native_info_string = self.gettext(section, setting) current_font = wx.FontFromNativeInfoString(native_info_string) \ if native_info_string else None font_button = widgets.FontPickerCtrl(self, font=current_font or default_font, colour=(0, 0, 0, 255)) font_button.SetBackgroundColour((255, 255, 255, 255)) self.addEntry( text, font_button, flags=( wx.ALL | wx.ALIGN_CENTER_VERTICAL, wx.ALL | wx. ALIGN_CENTER_VERTICAL # wx.EXPAND causes the button to be top aligned on Mac OS X )) self._fontSettings.append((section, setting, font_button))
def OnButton(self, event): fontData = wx.FontData() fontData.EnableEffects(False) if self.value is not None: font = wx.FontFromNativeInfoString(self.value) fontData.SetInitialFont(font) else: fontData.SetInitialFont( wx.SystemSettings_GetFont(wx.SYS_ANSI_VAR_FONT)) dialog = wx.FontDialog(self.GetParent(), fontData) if dialog.ShowModal() == wx.ID_OK: fontData = dialog.GetFontData() font = fontData.GetChosenFont() self.value = font.GetNativeFontInfo().ToString() event.Skip() dialog.Destroy() evt = eg.ValueChangedEvent(self.GetId(), value=self.value) wx.PostEvent(self, evt)
def ShowOSD( self, osdText="", fontInfo=None, textColour=(255, 255, 255), outlineColour=(0, 0, 0), alignment=0, offset=(0, 0), displayNumber=0, timeout=3.0, event=None, skin=None, ): self.timer.cancel() if osdText.strip() == "": self.bitmap = wx.EmptyBitmap(0, 0) SetWindowPos(self.hwnd, 0, 0, 0, 0, 0, HWND_FLAGS | SWP_HIDEWINDOW) SetEvent(event) return #self.Freeze() memoryDC = wx.MemoryDC() # make sure the mask colour is not used by foreground or # background colour forbiddenColours = (textColour, outlineColour) maskColour = (255, 0, 255) if maskColour in forbiddenColours: maskColour = (0, 0, 2) if maskColour in forbiddenColours: maskColour = (0, 0, 3) maskBrush = wx.Brush(maskColour, wx.SOLID) memoryDC.SetBackground(maskBrush) if fontInfo is None: fontInfo = DEFAULT_FONT_INFO font = wx.FontFromNativeInfoString(fontInfo) memoryDC.SetFont(font) textLines = osdText.splitlines() sizes = [memoryDC.GetTextExtent(line or " ") for line in textLines] textWidths, textHeights = zip(*sizes) textWidth = max(textWidths) textHeight = sum(textHeights) if skin: bitmap = self.GetSkinnedBitmap(textLines, textWidths, textHeights, textWidth, textHeight, memoryDC, textColour, "Default") width, height = bitmap.GetSize() elif outlineColour is None: width, height = textWidth, textHeight bitmap = wx.EmptyBitmap(width, height) memoryDC.SelectObject(bitmap) # fill the DC background with the maskColour memoryDC.Clear() # draw the text with the foreground colour memoryDC.SetTextForeground(textColour) DrawTextLines(memoryDC, textLines, textHeights) # mask the bitmap, so we can use it to get the needed # region of the window memoryDC.SelectObject(wx.NullBitmap) bitmap.SetMask(wx.Mask(bitmap, maskColour)) # fill the anti-aliased pixels of the text with the foreground # colour, because the region of the window will add these # half filled pixels also. Otherwise we would get an ugly # border with mask-coloured pixels. memoryDC.SetBackground(wx.Brush(textColour, wx.SOLID)) memoryDC.SelectObject(bitmap) memoryDC.Clear() memoryDC.SelectObject(wx.NullBitmap) else: width, height = textWidth + 5, textHeight + 5 outlineBitmap = wx.EmptyBitmap(width, height, 1) outlineDC = wx.MemoryDC() outlineDC.SetFont(font) outlineDC.SelectObject(outlineBitmap) outlineDC.Clear() outlineDC.SetBackgroundMode(wx.SOLID) DrawTextLines(outlineDC, textLines, textHeights) outlineDC.SelectObject(wx.NullBitmap) outlineBitmap.SetMask(wx.Mask(outlineBitmap)) outlineDC.SelectObject(outlineBitmap) bitmap = wx.EmptyBitmap(width, height) memoryDC.SetTextForeground(outlineColour) memoryDC.SelectObject(bitmap) memoryDC.Clear() Blit = memoryDC.Blit logicalFunc = wx.COPY for x in xrange(5): for y in xrange(5): Blit(x, y, width, height, outlineDC, 0, 0, logicalFunc, True) outlineDC.SelectObject(wx.NullBitmap) memoryDC.SetTextForeground(textColour) DrawTextLines(memoryDC, textLines, textHeights, 2, 2) memoryDC.SelectObject(wx.NullBitmap) bitmap.SetMask(wx.Mask(bitmap, maskColour)) region = wx.RegionFromBitmap(bitmap) self.SetShape(region) self.bitmap = bitmap monitorDimensions = GetMonitorDimensions() try: displayRect = monitorDimensions[displayNumber] except IndexError: displayRect = monitorDimensions[0] xOffset, yOffset = offset xFunc, yFunc = ALIGNMENT_FUNCS[alignment] x = displayRect.x + xFunc((displayRect.width - width), xOffset) y = displayRect.y + yFunc((displayRect.height - height), yOffset) deviceContext = wx.ClientDC(self) deviceContext.DrawBitmap(self.bitmap, 0, 0, False) SetWindowPos(self.hwnd, 0, x, y, width, height, HWND_FLAGS | SWP_SHOWWINDOW) if timeout > 0.0: self.timer = threading.Timer(timeout, self.OnTimeout) self.timer.start() eg.app.Yield(True) SetEvent(event)
def Draw( self, dc, firstColour=(0,0,0), lastColour=(255,255,255), barCount=16, orientation=0, makeDoubleBars=False, showNumbers=True, fontStr=u'0;-19;0;0;0;400;0;0;0;0;3;2;1;34;Arial', ): dc.SetBackground(wx.Brush(firstColour)) dc.Clear() w, h = dc.GetSizeTuple() if orientation == 0: barSize = int(w * 1.0 / barCount) else: barSize = int(h * 1.0 / barCount) r1, g1, b1 = firstColour r2, g2, b2 = lastColour dc.SetFont(wx.FontFromNativeInfoString(fontStr)) if makeDoubleBars: w1 = w / 2 h1 = h / 2 else: w1 = w h1 = h for n1 in range(barCount): n2 = (barCount - n1 - 1) r = r1 + (1.0 * (r2 - r1) / (barCount - 1)) * n1 g = g1 + (1.0 * (g2 - g1) / (barCount - 1)) * n1 b = b1 + (1.0 * (b2 - b1) / (barCount - 1)) * n1 dc.SetPen(wx.Pen((r, g, b), 1)) dc.SetBrush(wx.Brush((r, g, b))) numberStr = str(n1 + 1) tw, th = dc.GetTextExtent(numberStr) if orientation == 0: dc.DrawRectangle(n1 * barSize, 0, barSize, h1) if makeDoubleBars: dc.DrawRectangle(n2 * barSize, h1, barSize, h) ty1 = h / 2 * 0.95 - th ty2 = h / 2 * 1.05 else: ty1 = (h * 0.66 - th) tx1 = n1 * barSize + ((barSize - tw) / 2) tx2 = n2 * barSize + ((barSize - tw) / 2) else: dc.DrawRectangle(0, n1 * barSize, w1, barSize) if makeDoubleBars: dc.DrawRectangle(w1, n2 * barSize, w1, barSize) tx1 = w / 2 * 0.95 - tw tx2 = w / 2 * 1.05 else: tx1 = w * 0.66 - tw ty1 = n1 * barSize + ((barSize - th) / 2) ty2 = n2 * barSize + ((barSize - th) / 2) if showNumbers: v = colorsys.rgb_to_hsv(r / 255.0, g / 255.0, b / 255.0)[2] if v < 0.5: dc.SetTextBackground((0, 0, 0)) dc.SetTextForeground((255, 255, 255)) else: dc.SetTextBackground((255, 255, 255)) dc.SetTextForeground((0, 0, 0)) dc.DrawText(numberStr, tx1, ty1) if makeDoubleBars: dc.DrawText(numberStr, tx2, ty2)
def _printAndIndex(self, pageNum=-1): """ Combined function to either fill the self.pageCharStartIndex if pageNum == -1 or print page pageNum if it is >= 1 """ dc = self.GetDC() if self.mm2logUnitsFactor is None: self._calcMmScaling(dc) if pageNum == -1: self.pageCharStartIndex = [0, 0] # Calculate print rectangle tlMarg = self.psddata.GetMarginTopLeft() brMarg = self.psddata.GetMarginBottomRight() leftLu, topLu = self.mmlenToLogUnits((tlMarg.x, tlMarg.y)) rMargLu, bMargLu = self.mmlenToLogUnits((brMarg.x, brMarg.y)) sizeLu = dc.GetSize() sizeLu.x = dc.DeviceToLogicalXRel(sizeLu.x) sizeLu.y = dc.DeviceToLogicalYRel(sizeLu.y) printRectLu = (leftLu, topLu, sizeLu.x - rMargLu, sizeLu.y - bMargLu) fontDesc = self.fontDesc if not fontDesc: font = wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.NORMAL, False, "Courier New") else: font = wx.FontFromNativeInfoString(fontDesc) dc.SetFont(font) if pageNum != -1: pagepos = pageNum else: pagepos = 1 textpos = self.pageCharStartIndex[pagepos] text = self.text if pageNum == -1: # Build a list of cuttedText. Each item is either a newline, # a new page command '\f', one or more spaces or one or more # other characters cuttedText = _CUT_RE.findall(text[textpos:]) else: if pageNum + 1 >= len(self.pageCharStartIndex): lastCharPos = len(text) else: lastCharPos = self.pageCharStartIndex[pageNum + 1] cuttedText = _CUT_RE.findall( text[self.pageCharStartIndex[pageNum]:lastCharPos]) currLine = u"" currLineWidth = 0 w, stepY, d, e = dc.GetFullTextExtent("aaaaaaaa") posxLu, posyLu = printRectLu[0:2] prAreaWidth = printRectLu[2] - printRectLu[0] i = 0 while i < len(cuttedText): # _CUT_RE.finditer(text[textpos:]): part = cuttedText[i] flushLine = False flushPage = False if part[0] == u" ": # One or more spaces -> Append to current line if possible, # throw away and start new print line if not partWidth = dc.GetTextExtent(part)[0] linewidth = currLineWidth + partWidth # linewidth = dc.GetTextExtent(currLine + part)[0] if linewidth > prAreaWidth: flushLine = True else: currLine += part currLineWidth = linewidth textpos += len(part) elif part[0] == u"\n": flushLine = True textpos += 1 elif part[0] == u"\f": # New page flushPage = True textpos += 1 else: partWidth = dc.GetTextExtent(part)[0] linewidth = currLineWidth + partWidth # linewidth = dc.GetTextExtent(currLine + part)[0] if linewidth > prAreaWidth: # Part doesn't fit into current print line if currLine != u"": # Current print line already contains text -> # Make new print line and reread part flushLine = True i -= 1 else: # A single "word" which doesn't fit into a line # TODO Use bisect algorithm? for partPos in xrange(1, len(part)): partWidth = dc.GetTextExtent(part[:partPos])[0] if partWidth > prAreaWidth: break partPos -= 1 currLine = part[:partPos] textpos += partPos cuttedText[i] = part[partPos:] flushLine = True i -= 1 else: currLine += part textpos += len(part) currLineWidth = linewidth i += 1 if i == len(cuttedText) or flushPage: flushLine = True if flushLine: # Draw current row, start new one if pageNum != -1: dc.DrawText(currLine, posxLu, posyLu) currLine = u"" currLineWidth = 0 posyLu += stepY if posyLu + stepY > printRectLu[3]: # End of page reached flushPage = True if flushPage: if pageNum != -1 or textpos == len(text): break pagepos += 1 # print "PagePos", pagepos # if pagepos > 100: break posyLu = printRectLu[1] self.pageCharStartIndex.append(textpos) dc.SetFont(wx.NullFont) return True
def set_theme(self, theme): self.theme = theme self.tree_colour = wx.Colour(*theme.Colours.COLOUR_TREE) self.tree_text_colour = wx.Colour(*theme.Colours.COLOUR_TREETEXT) self.log_colour = wx.Colour(*theme.Colours.COLOUR_LOG) self.log_text_colour = wx.Colour(*theme.Colours.COLOUR_LOGTEXT) self.log_error_colour = wx.Colour(*theme.Colours.COLOUR_LOGERROR) self.log_error_text_colour = wx.Colour( *theme.Colours.COLOUR_LOGERRORTEXT) self.log_warning_colour = wx.Colour(*theme.Colours.COLOUR_LOGWARNING) self.log_warning_text_colour = wx.Colour( *theme.Colours.COLOUR_LOGWARNINGTEXT) self.log_debug_colour = wx.Colour(*theme.Colours.COLOUR_LOGDEBUG) self.log_debug_text_colour = wx.Colour( *theme.Colours.COLOUR_LOGDEBUGTEXT) self.window_colour = wx.Colour(*theme.Colours.COLOUR_WINDOW) self.window_text_colour = wx.Colour(*theme.Colours.COLOUR_WINDOWTEXT) self.button_colour = wx.Colour(*theme.Colours.COLOUR_BUTTON) self.button_text_colour = wx.Colour(*theme.Colours.COLOUR_BUTTONTEXT) self.listbox_colour = wx.Colour(*theme.Colours.COLOUR_LISTBOX) self.listbox_text_colour = wx.Colour(*theme.Colours.COLOUR_LISTBOXTEXT) self.menu_colour = wx.Colour(*theme.Colours.COLOUR_MENU) self.menu_text_colour = wx.Colour(*theme.Colours.COLOUR_MENUTEXT) self.menubar_colour = wx.Colour(*theme.Colours.COLOUR_MENUBAR) self.menubar_text_colour = wx.Colour(*theme.Colours.COLOUR_MENUBARTEXT) self.tooltip_colour = wx.Colour(*theme.Colours.COLOUR_TOOLTIP) self.tooltip_text_colour = wx.Colour(*theme.Colours.COLOUR_TOOLTIPTEXT) self.active_caption_colour = wx.Colour( *theme.Colours.COLOUR_ACTIVECAPTION) self.active_caption_gradient_colour = wx.Colour( *theme.Colours.COLOUR_GRADIENTACTIVECAPTION) self.active_caption_text_colour = wx.Colour( *theme.Colours.COLOUR_ACTIVECAPTIONTEXT) self.inactive_caption_text_colour = wx.Colour( *theme.Colours.COLOUR_INACTIVECAPTIONTEXT) self.inactive_caption_colour = wx.Colour( *theme.Colours.COLOUR_INACTIVECAPTION) self.inactive_caption_gradient_colour = wx.Colour( *theme.Colours.COLOUR_GRADIENTINACTIVECAPTION) self.tree_font = wx.FontFromNativeInfoString(theme.Fonts.FONT_TREE) self.log_font = wx.FontFromNativeInfoString(theme.Fonts.FONT_LOG) self.window_font = wx.FontFromNativeInfoString(theme.Fonts.FONT_WINDOW) self.button_font = wx.FontFromNativeInfoString(theme.Fonts.FONT_BUTTON) self.listbox_font = wx.FontFromNativeInfoString( theme.Fonts.FONT_LISTBOX) self.caption_font = wx.FontFromNativeInfoString( theme.Fonts.FONT_CAPTION) self.menu_font = wx.FontFromNativeInfoString(theme.Fonts.FONT_MENU) self.menubar_font = wx.FontFromNativeInfoString( theme.Fonts.FONT_MENUBAR) self.tooltip_font = wx.FontFromNativeInfoString( theme.Fonts.FONT_TOOLTIP) for item in self.active_widgets: self.handle_item(item)
def handle_item(self, item): try: if isinstance(item, eg.HeaderBox): text = item.text text = text.replace( 'bgcolor="' + item.GetBackgroundColour().GetAsString(wx.C2S_HTML_SYNTAX), 'bgcolor="' + self.window_colour.GetAsString(wx.C2S_HTML_SYNTAX)) text = text.replace( 'text="' + item.GetForegroundColour().GetAsString(wx.C2S_HTML_SYNTAX), 'text="' + self.window_text_colour.GetAsString(wx.C2S_HTML_SYNTAX)) item.text = text if eg.mainFrame is not None and item == eg.mainFrame.logCtrl: from .MainFrame.LogCtrl import _create_colour_attributes item.SetFont(self.log_font) item.SetBackgroundColour(self.log_colour) eg.mainFrame.logCtrl.logColours = _create_colour_attributes( self.log_text_colour, self.log_colour) eg.mainFrame.logCtrl.errorColours = _create_colour_attributes( self.log_error_text_colour, self.log_error_colour) eg.mainFrame.logCtrl.warningColours = _create_colour_attributes( self.log_warning_text_colour, self.log_warning_colour) eg.mainFrame.logCtrl.debugColours = _create_colour_attributes( self.log_debug_text_colour, self.log_debug_colour) elif isinstance(item, (wx.CheckListBox, wx.ComboBox, wx.Choice, wx.ListBox, wx.VListBox, wx.ListCtrl)): item.SetFont(self.listbox_font) item.SetBackgroundColour(self.listbox_colour) item.SetForegroundColour(self.listbox_text_colour) elif isinstance(item, wx.MenuItem): item.SetBackgroundColour(self.menu_colour) item.SetFont(self.menu_font) elif isinstance(item, wx.MenuBar): item.SetBackgroundColour(self.menubar_colour) item.SetForegroundColour(self.menubar_text_colour) item.SetFont(self.menubar_font) elif isinstance(item, (wx.lib.agw.supertooltip.SuperToolTip, wx.TipWindow, wx.ToolTip)): item.SetBackgroundColour(self.tooltip_colour) item.SetForegroundColour(self.tooltip_text_colour) item.SetFont(self.tooltip_font) elif isinstance(item, wx.lib.agw.balloontip.BalloonTip): tooltip_bold_font = wx.FontFromNativeInfoString( self.theme.Fonts.FONT_TOOLTIP) tooltip_bold_font.SetWeight(wx.FONTFLAG_BOLD) item.SetBalloonColour(self.tooltip_colour) item.SetTitleFont(tooltip_bold_font) item.SetMessageFont(self.tooltip_font) item.SetTitleColour(self.tooltip_text_colour) item.SetMessageColour(self.tooltip_text_colour) elif isinstance( item, (wx.TreeCtrl, wx.lib.agw.customtreectrl.CustomTreeCtrl)): item.SetBackgroundColour(self.tree_colour) item.SetForegroundColour(self.tree_text_colour) item.SetFont(self.tree_font) elif isinstance(item, ( wx.Button, wx.ToggleButton, wx.lib.agw.aquabutton.AquaButton, wx.lib.agw.aquabutton.AquaToggleButton, wx.lib.agw.gradientbutton.GradientButton, wx.lib.agw.shapedbutton.SBitmapTextButton, wx.lib.agw.shapedbutton.SBitmapTextToggleButton, wx.lib.buttons.GenBitmapTextButton, wx.lib.buttons.GenBitmapTextToggleButton, )): item.SetBackgroundColour(self.button_colour) item.SetForegroundColour(self.button_text_colour) item.SetFont(self.button_font) elif isinstance(item, (wx.lib.agw.shapedbutton.SBitmapButton, wx.lib.agw.shapedbutton.SBitmapToggleButton, wx.lib.buttons.GenBitmapButton, wx.lib.buttons.GenToggleButton, wx.lib.buttons.GenBitmapToggleButton)): item.SetBackgroundColour(self.button_colour) elif isinstance(item, (wx.lib.agw.aui.AuiManager, wx.aui.AuiManager)): ap = item.GetArtProvider() ap.SetColor(wx.aui.AUI_DOCKART_BACKGROUND_COLOUR, self.window_colour) ap.SetColor(wx.aui.AUI_DOCKART_ACTIVE_CAPTION_COLOUR, self.active_caption_colour) ap.SetColor(wx.aui.AUI_DOCKART_ACTIVE_CAPTION_GRADIENT_COLOUR, self.active_caption_gradient_colour) ap.SetColor(wx.aui.AUI_DOCKART_ACTIVE_CAPTION_TEXT_COLOUR, self.active_caption_text_colour) ap.SetColor(wx.aui.AUI_DOCKART_INACTIVE_CAPTION_COLOUR, self.inactive_caption_colour) ap.SetColor( wx.aui.AUI_DOCKART_INACTIVE_CAPTION_GRADIENT_COLOUR, self.inactive_caption_gradient_colour) ap.SetColor(wx.aui.AUI_DOCKART_INACTIVE_CAPTION_TEXT_COLOUR, self.inactive_caption_text_colour) ap.SetFont(wx.aui.AUI_DOCKART_CAPTION_FONT, self.caption_font) else: try: item.SetFont(self.window_font) except AttributeError: pass try: item.SetBackgroundColour(self.window_colour) except AttributeError: pass try: item.SetForegroundColour(self.window_text_colour) except AttributeError: pass try: item.Refresh() item.Update() except AttributeError: pass except wx.PyDeadObjectError: self.active_widgets.remove(item)
def CreateRemote(plugin, xPos, yPos, alwaysOnTop): data = plugin.data borderSize = plugin.borderSize if plugin.frame: plugin.frame.Destroy() plugin.frame = frame = RemoteFrame(plugin, (xPos, yPos), alwaysOnTop) panel = RemotePanel(frame, plugin) mainSizer = wx.BoxSizer(wx.VERTICAL) mainSizer.Add((0, borderSize)) lineSizer = wx.BoxSizer(wx.HORIZONTAL) x = 0 y = 0 def MakeButtonDownFunc(eventstring): if not eventstring: return def OnButtonDown(event): event.Skip() plugin.lastEvent = plugin.TriggerEnduringEvent(eventstring) return OnButtonDown for itemType, args in data: if itemType is ButtonType: kwargs = args def GetOption(name): return kwargs.get(name, plugin.defaults.get(name)) label = kwargs.get("label") event = kwargs.get("event") image = kwargs.get("image", None) invisible = kwargs.get("invisible", False) size = (GetOption("width"), GetOption("height")) if invisible: # create a spacer button = size else: if image: stream = StringIO(b64decode(image)) bmp = wx.BitmapFromImage(wx.ImageFromStream(stream)) stream.close() button = GenBitmapButton(panel, -1, bmp, size=size) button.SetLabel(label) else: button = GenButton(panel, -1, label, size=size) button.SetFont( wx.FontFromNativeInfoString(GetOption("fontInfo"))) button.SetBezelWidth(3) button.SetBackgroundColour(GetOption("backgroundColour")) button.SetForegroundColour(GetOption("foregroundColour")) OnButtonDown = MakeButtonDownFunc(event) if OnButtonDown: button.Bind(wx.EVT_LEFT_DOWN, OnButtonDown) button.Bind(wx.EVT_LEFT_DCLICK, OnButtonDown) button.Bind(wx.EVT_LEFT_UP, plugin.OnButtonUp) if x == 0: lineSizer.Add(button) else: lineSizer.Add(button, 0, wx.LEFT, plugin.rowGap) x += 1 elif itemType is LineType: height = args[0] mainSizer.Add(lineSizer, 0, wx.BOTTOM | wx.ALIGN_CENTER_HORIZONTAL, height + plugin.columnGap) lineSizer = wx.BoxSizer(wx.HORIZONTAL) y += 1 x = 0 mainSizer.Add(lineSizer, 0, wx.LEFT | wx.RIGHT, borderSize) mainSizer.Add((0, borderSize)) panel.SetSizerAndFit(mainSizer) frame.SetClientSize(panel.GetSize()) frame.Show(True) frame.Update()
def SetTickFont(self, font, target): fs = font.GetNativeFontInfoDesc() for i, attr in enumerate(["TicksH", "TicksM"]): if _targets[i] & target: tick = getattr(self, attr) tick.SetFont(wx.FontFromNativeInfoString(fs))