def GetBackgroundBrush(self, dc): """ Returns the current :class:`wx.Brush` to be used to draw the button background. :param wx.DC `dc`: the device context used to draw the button background. """ if self.up: colBg = self.GetBackgroundColour() brush = wx.Brush(colBg) if self.style & wx.BORDER_NONE: myAttr = self.GetDefaultAttributes() parAttr = self.GetParent().GetDefaultAttributes() myDef = colBg == myAttr.colBg parDef = self.GetParent().GetBackgroundColour() == parAttr.colBg if myDef and parDef: if wx.Platform == "__WXMAC__": c = wx.MacThemeColour(1) # 1 == kThemeBrushDialogBackgroundActive brush = wx.Brush(c) elif wx.Platform == "__WXMSW__": if hasattr(self, 'DoEraseBackground') and self.DoEraseBackground(dc): brush = None elif myDef and not parDef: colBg = self.GetParent().GetBackgroundColour() brush = wx.Brush(colBg) else: # this line assumes that a pressed button should be highlighted with # a solid colour even if the background is supposed to be transparent brush = wx.Brush(self.faceDnClr) return brush
def GetBaseColour(): """ Returns the face shading colour on push buttons/backgrounds, mimicking as closely as possible the platform UI colours. """ if wx.Platform == "__WXMAC__": if hasattr(wx, 'MacThemeColour'): base_colour = wx.MacThemeColour(Carbon.Appearance.kThemeBrushToolbarBackground) else: brush = wx.Brush(wx.BLACK) brush.MacSetTheme(Carbon.Appearance.kThemeBrushToolbarBackground) base_colour = brush.GetColour() else: base_colour = wx.SystemSettings.GetColour(wx.SYS_COLOUR_3DFACE) # the base_colour is too pale to use as our base colour, # so darken it a bit if ((255-base_colour.Red()) + (255-base_colour.Green()) + (255-base_colour.Blue()) < 60): base_colour = StepColour(base_colour, 92) return base_colour
def GetBackgroundBrush(self, dc): if self.up: colBg = self.GetBackgroundColour() brush = wx.Brush(colBg, wx.SOLID) if self.style & wx.BORDER_NONE: myAttr = self.GetDefaultAttributes() parAttr = self.GetParent().GetDefaultAttributes() myDef = colBg == myAttr.colBg parDef = self.GetParent().GetBackgroundColour( ) == parAttr.colBg if myDef and parDef: if wx.Platform == "__WXMAC__": c = wx.MacThemeColour( 1) # 1 == kThemeBrushDialogBackgroundActive brush = wx.Brush(c) elif wx.Platform == "__WXMSW__": if self.DoEraseBackground(dc): brush = None elif myDef and not parDef: colBg = self.GetParent().GetBackgroundColour() brush = wx.Brush(colBg, wx.SOLID) else: # this line assumes that a pressed button should be hilighted with # a solid colour even if the background is supposed to be transparent brush = wx.Brush(self.faceDnClr, wx.SOLID) return brush
def __init__(self): RibbonMSWArtProvider.__init__(self) if wx.Platform == "__WXMAC__": if hasattr(wx, 'MacThemeColour'): base_colour = wx.MacThemeColour( Carbon.Appearance.kThemeBrushToolbarBackground) else: brush = wx.Brush(wx.BLACK) brush.MacSetTheme( Carbon.Appearance.kThemeBrushToolbarBackground) base_colour = brush.GetColour() else: base_colour = wx.SystemSettings.GetColour(wx.SYS_COLOUR_3DFACE) self.SetColourScheme( base_colour, wx.SystemSettings.GetColour(wx.SYS_COLOUR_HIGHLIGHT), wx.SystemSettings.GetColour(wx.SYS_COLOUR_HIGHLIGHTTEXT)) self._tab_active_label_font = FontFromFont(self._tab_label_font) self._tab_active_label_font.SetWeight(wx.FONTWEIGHT_BOLD) self._page_border_left = 1 self._page_border_right = 1 self._page_border_top = 1 self._page_border_bottom = 2 self._tab_separation_size = 0 self._gallery_bitmap_padding_left_size = 3 self._gallery_bitmap_padding_right_size = 3 self._gallery_bitmap_padding_top_size = 3 self._gallery_bitmap_padding_bottom_size = 3
def GetHighlightColour(): """Get the default highlight color @return: wx.Color """ if wx.Platform == '__WXMAC__': brush = wx.Brush(wx.BLACK) # kThemeBrushButtonPressedLightHighlight return wx.MacThemeColour(Carbon.Appearance.kThemeBrushFocusHighlight) else: return wx.SystemSettings.GetColour(wx.SYS_COLOUR_HIGHLIGHT)
def OnPaint(self, event): """ Handles the ``wx.EVT_PAINT`` for :class:`GenStaticText`. :param `event`: a :class:`wx.PaintEvent` event to be processed. """ if BUFFERED: dc = wx.BufferedPaintDC(self) else: dc = wx.PaintDC(self) width, height = self.GetClientSize() if not width or not height: return if BUFFERED: clr = self.GetBackgroundColour() if wx.Platform == "__WXMAC__" and clr == self.defBackClr: # if colour is still the default then use the theme's background on Mac themeColour = wx.MacThemeColour( kThemeBrushDialogBackgroundActive) backBrush = wx.Brush(themeColour) else: backBrush = wx.Brush(clr, wx.BRUSHSTYLE_SOLID) dc.SetBackground(backBrush) dc.Clear() if self.IsEnabled(): dc.SetTextForeground(self.GetForegroundColour()) else: dc.SetTextForeground( wx.SystemSettings.GetColour(wx.SYS_COLOUR_GRAYTEXT)) dc.SetFont(self.GetFont()) label = self.GetLabel() style = self.GetWindowStyleFlag() x = y = 0 for line in label.split('\n'): if line == '': w, h = self.GetTextExtent('W') # empty lines have height too else: w, h = self.GetTextExtent(line) if style & wx.ALIGN_RIGHT: x = width - w if style & wx.ALIGN_CENTER: x = (width - w) / 2 dc.DrawText(line, x + self.delta_point[0], y + self.delta_point[1]) # 加入额外的位置调节参数 y = y + h + self.delta_linespace # 下次的起点y 上一次的y 加上 上一行的h+额外的linespace调节
def GetHighlightColour(): """Get the default highlight color @return: wx.Colour """ if wx.Platform == '__WXMAC__': if CARBON: if hasattr(wx, 'MacThemeColour'): color = wx.MacThemeColour(Carbon.Appearance.kThemeBrushFocusHighlight) return color else: # kThemeBrushButtonPressedLightHighlight brush = wx.Brush(wx.BLACK) brush.MacSetTheme(Carbon.Appearance.kThemeBrushFocusHighlight) return brush.GetColour() # Fallback to text highlight color return wx.SystemSettings.GetColour(wx.SYS_COLOUR_HIGHLIGHT)
def GetHighlightColour(): """Get the default highlight color @return: wx.Colour """ if wx.Platform == '__WXMAC__': if CARBON: if wx.VERSION < (2, 9, 0, 0, ''): # kThemeBrushButtonPressedLightHighlight color = wx.MacThemeColour( Carbon.Appearance.kThemeBrushFocusHighlight) return color else: color = wx.Colour(Carbon.Appearance.kThemeBrushFocusHighlight) return color # Fallback to text highlight color return wx.SystemSettings.GetColour(wx.SYS_COLOUR_HIGHLIGHT)
def OnPaint(self, event): if BUFFERED: dc = wx.BufferedPaintDC(self) else: dc = wx.PaintDC(self) width, height = self.GetClientSize() if not width or not height: return if BUFFERED: clr = self.GetBackgroundColour() if wx.Platform == "__WXMAC__" and clr == self.defBackClr: # if colour is still the default then use the theme's background on Mac themeColour = wx.MacThemeColour( kThemeBrushDialogBackgroundActive) backBrush = wx.Brush(themeColour) else: backBrush = wx.Brush(clr, wx.SOLID) dc.SetBackground(backBrush) dc.Clear() if self.IsEnabled(): dc.SetTextForeground(self.GetForegroundColour()) else: dc.SetTextForeground( wx.SystemSettings.GetColour(wx.SYS_COLOUR_GRAYTEXT)) dc.SetFont(self.GetFont()) label = self.GetLabel() style = self.GetWindowStyleFlag() x = y = 0 for line in label.split('\n'): if line == '': w, h = self.GetTextExtent('W') # empty lines have height too else: w, h = self.GetTextExtent(line) if style & wx.ALIGN_RIGHT: x = width - w if style & wx.ALIGN_CENTER: x = (width - w) / 2 dc.DrawText(line, x, y) y += h
def GetHighlightColour(): """ Gets the default highlight color. :rtype: :class:`wx.Colour` """ if wx.Platform == '__WXMAC__': if CARBON: if wx.VERSION < (2, 9, 0, 0, ''): # kThemeBrushButtonPressedLightHighlight brush = wx.Brush(wx.BLACK) brush.MacSetTheme(Carbon.Appearance.kThemeBrushFocusHighlight) return brush.GetColour() else: color = wx.MacThemeColour(Carbon.Appearance.kThemeBrushFocusHighlight) return color # Fallback to text highlight color return wx.SystemSettings.GetColour(wx.SYS_COLOUR_HIGHLIGHT)
def modify_check(self): new_pass_word = self.PassWord.GetValue() check_new_pass_word = self.CheckPassWord.GetValue() if '#' in self.user_name or '#' in self.pass_word: wx.MessageBox('不可含#') elif self.user_name == '' or self.pass_word == '': wx.MacThemeColour('不可为空') else: out_string = '01#' + self.user_name + '#' + self.pass_word + '#' + new_pass_word + '#' + check_new_pass_word + '#' client_socket.sendto(out_string.encode(), server) in_string = client_socket.recv(1024).decode() print(in_string) if in_string == '01:01': wx.MessageBox('用户初始密码错误') elif in_string == '01:02': wx.MessageBox('两次密码不一致') if in_string == '01:03': wx.MessageBox('用户密码修改成功') self.Close() if in_string == '01:04': wx.MessageBox('用户不存在')
def OnPaint(self, evt): # repaint full area self.SetClientRect(self.full_rect) BUFFERED = 1 if BUFFERED: dc = wx.BufferedPaintDC(self) else: dc = wx.PaintDC(self) width = self.full_rect.width height = self.full_rect.height if not width or not height: return if BUFFERED: clr = self.GetBackgroundColour() self.defBackClr = clr if wx.Platform == "__WXMAC__" and clr == self.defBackClr: # if colour is still the default then use the theme's # background on Mac themeColour = wx.MacThemeColour(1) backBrush = wx.Brush(themeColour) else: backBrush = wx.Brush(clr, wx.SOLID) dc.SetBackground(backBrush) dc.Clear() if self.IsEnabled(): dc.SetTextForeground(self.GetForegroundColour()) else: dc.SetTextForeground( wx.SystemSettings.GetColour(wx.SYS_COLOUR_GRAYTEXT)) dc.SetFont(self.GetFont()) label = self.GetLabel() style = self.GetWindowStyleFlag() x = y = 0 # TODO: figure out a platform agnostic way to do this if wx.Platform == "__WXMAC__": y -= 3 for line in label.split('\n'): if line == '': w, h = self.GetTextExtent('W') # empty lines have height too else: w, h = self.GetTextExtent(line) if style & wx.ALIGN_RIGHT: x = width - w if style & wx.ALIGN_CENTER: x = (width - w) / 2 dc.DrawText(line, x, y) y += h # draw arrow (either using native methods or by using a bitmap) if 0: # draw native rendered arrow renderer = wx.RendererNative.Get() w = 16 h = height x = width - 1 - w y = (height - h) / 2 renderer.DrawDropArrow(self, dc, (x, y, w, y), wx.CONTROL_CURRENT) else: # draw bitmap arrow width = self.full_rect.width height = self.full_rect.height w, h = self.up_down_bitmap.GetSize() x = width - 1 - w y = (height - h) / 2 dc.DrawBitmap(self.up_down_bitmap, x, y, useMask=False)
def __DrawButton(self): """Draw the button""" # TODO using a buffered paintdc on windows with the nobg style # causes lots of weird drawing. So currently the use of a # buffered dc is dissabled for this style. if PB_STYLE_NOBG & self._style: dc = wx.PaintDC(self) else: dc = wx.AutoBufferedPaintDCFactory(self) gc = wx.GCDC(dc) # Setup dc.SetBrush(wx.TRANSPARENT_BRUSH) gc.SetBrush(wx.TRANSPARENT_BRUSH) gc.SetFont(self.GetFont()) gc.SetBackgroundMode(wx.TRANSPARENT) # The background needs some help to look transparent on # on Gtk and Windows if wx.Platform in ['__WXGTK__', '__WXMSW__']: gc.SetBackground(self.GetBackgroundBrush(gc)) gc.Clear() # Calc Object Positions width, height = self.GetSize() tw, th = gc.GetTextExtent(self.GetLabel()) txt_y = max((height - th) / 2, 1) if self._state['cur'] == PLATE_HIGHLIGHT: gc.SetTextForeground(self._color['htxt']) gc.SetPen(wx.TRANSPARENT_PEN) self.__DrawHighlight(gc, width, height) elif self._state['cur'] == PLATE_PRESSED: gc.SetTextForeground(self._color['ptxt']) if wx.Platform == '__WXMAC__': c = wx.MacThemeColour( Carbon.Appearance.kThemeBrushFocusHighlight) brush = wx.Brush(c) pen = wx.Pen(c, 1, wx.SOLID) else: pen = wx.Pen(AdjustColour(self._color['press'], -80, 220), 1) gc.SetPen(pen) txt_x = self.__DrawBitmap(gc) gc.DrawText(self.GetLabel(), txt_x + 2, txt_y) self.__DrawDropArrow(gc, txt_x + tw + 6, (height / 2) - 2) self.__DrawHighlight(gc, width, height) else: if self.IsEnabled(): gc.SetTextForeground(self.GetForegroundColour()) else: txt_c = wx.SystemSettings.GetColour(wx.SYS_COLOUR_GRAYTEXT) gc.SetTextForeground(txt_c) # Draw bitmap and text if self._state['cur'] != PLATE_PRESSED: txt_x = self.__DrawBitmap(gc) gc.DrawText(self.GetLabel(), txt_x + 2, txt_y) self.__DrawDropArrow(gc, txt_x + tw + 6, (height / 2) - 2)