def __init__(self, parent, id=wx.ID_ANY, skinkey=None, name='ToolBar', alignment=None): SimplePanel.__init__(self, parent, wx.FULL_REPAINT_ON_RESIZE) self.children = [] self.content = wx.BoxSizer(wx.HORIZONTAL) self.Sizer = Margins().Sizer(self.content) self.SetSkinKey(skinkey, ToolBarSkinDefaults) self.Bind(wx.EVT_PAINT, self.OnPaint)
def UpdateSkin(self): Renderer.UpdateSkin(self) self.drawseqs = {} self._lastcalc = [] s, g = self.skin, skin.get self.statusicons = g('statusicons') s.margins = g('BuddiesPanel.BuddyMargins') s.icon_frame = g('BuddiesPanel.BuddyIcons.Frame', None) s.icon_frame_size = Margins(g('BuddiesPanel.BuddyIcons.FrameSize', (0, 0, 0, 0))) s.round_corners = try_this(lambda: int(g('BuddiesPanel.BuddyIcons.Rounded', 1)), 1) f, g = s.fontcolors, lambda k, default: skin.get('BuddiesPanel.FontColors.' + k, default) f.buddy = g('Buddy', lambda: syscol(wx.SYS_COLOUR_WINDOWTEXT)) f.buddyoffline = g('BuddyOffline', lambda: syscol(wx.SYS_COLOUR_GRAYTEXT)) f.buddyselected = g('BuddySelected', lambda: syscol(wx.SYS_COLOUR_HIGHLIGHTTEXT)) f.buddyhover = g('BuddyHover', lambda: f.buddy) f.status = g('Status', lambda: f.buddy) f.statushover = g('StatusHover', lambda: f.buddyhover) f.statusselected = g('StatusSelected', lambda: f.buddyselected) f.idletime = g('IdleTime', lambda: syscol(wx.SYS_COLOUR_GRAYTEXT)) f.idletimehover = g('IdleTimeHover', lambda: syscol(wx.SYS_COLOUR_GRAYTEXT)) f.idletimeselected = g('IdleTimeSelected', lambda: syscol(wx.SYS_COLOUR_HIGHLIGHTTEXT)) # icons to be drawn self.calcsizes()
def InitDefaults(self): self.IconSize = 32 self.margins = Margins((3, 3)) self.padding = Point(5, 5) self.CheckBoxSize = 16 self.SetNotificationInfo({}) self.SetUserNotifications({}) self.UpdateSkin()
def _constructSkinElements(self): 'Creates the buttons that launch menu dropdowns in the bar.' s, p = self.skin, self.panel p.bg = s.get("background", SkinColor(wx.WHITE)) pad = p.padding = s.get("padding", wx.Point(0, 0)) for child in list(p.Children): child.Hide() child.Destroy() v = wx.BoxSizer(wx.VERTICAL) h = wx.BoxSizer(wx.HORIZONTAL) v.Add(h, 1, wx.EXPAND | wx.TOP | wx.BOTTOM, pad.y) p.Sizer = s.get('margins', Margins()).Sizer(v) # create a button for each item in the menubar self.buttons = [] addb = self.buttons.append menus, nummenus = self.Menus, len(self.Menus) for i, (menu, label) in enumerate(menus): del menu.OnDismiss[:] # the API sucks for getting Titles with mnemonic characters label = self.toptitles.get(menu, label) # (self, parent, id = -1, label='', skin='Button', icon=None, # pos=wx.DefaultPosition, size=None, style=wx.HORIZONTAL, # type=None, menu=None, menubarmode=False, onclick = None): button = UberButton(p, -1, skin=s.itemskin, label=label, type="menu", menu=menu, menubarmode=True) addb(button) # store some special attributes in the menu, which it will use for # keyboard/mouse navigation of the menubar menu._next = menus[(i + 1) % nummenus][0] menu._prev = menus[i - 1][0] menu._button = button # add buttons to the size h.AddMany((b, 0, wx.EXPAND | wx.LEFT, pad.x) for b in self.buttons) # bind keyboard accelerators self._bindAccelerators()
def UpdateSkin(self): key = self.skinkey s = lambda k, default: skin.get('%s.%s' % (key, k), default) self.framebg = s('frame', SkinColor(wx.BLACK)) self.framesize = s('framesize', Margins([0, 0, 0, 0])) sz = self.Sizer if sz: sz.Detach(1) sz.Detach(1) sz.Add(wx.Size(self.framesize.left, self.framesize.top), (0, 0)) sz.Add(wx.Size(self.framesize.right, self.framesize.bottom), (2, 2)) wx.CallAfter(self.Layout) wx.CallAfter(self.Refresh)
def UpdateSkin(self): """ The usual. """ key = self.skinkey s = lambda k, d=None: skin.get('%s.%s' % (key, k), d) self.framebg = s('Frame', lambda: SkinColor(wx.BLACK)) self.framesize = s('FrameSize', lambda: Margins([0, 0, 0, 0])) self.iconup = s('icons.show', None) self.icondown = s( 'icons.hide', lambda: wx.BitmapFromImage( wx.ImageFromBitmap(self.iconup).Mirror(False))) self.buttonskin = s('buttonskin', None) self.WhenOrderChanges() if self.Sizer: self.Sizer.SetMargins(self.framesize)
def __init__(self, parent, skinkey, id = -1, label = '', pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.NO_BORDER): self.Padding = wx.Size() wx.PyControl.__init__(self, parent, id = id, style = style) self.skinkey = skinkey self.margins = Margins((0, 0, 0, 0)) self._native = False self.Font = default_font() self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM) self.Bind(wx.EVT_ERASE_BACKGROUND, lambda e: None) self.Bind(wx.EVT_PAINT, self.__paint) self.SetLabel(label) self.SetInitialSize(size) self.InheritAttributes()
class ToolBar(SimplePanel, NewSkinModule): def __init__(self, parent, id=wx.ID_ANY, skinkey=None, name='ToolBar', alignment=None): SimplePanel.__init__(self, parent, wx.FULL_REPAINT_ON_RESIZE) self.children = [] self.content = wx.BoxSizer(wx.HORIZONTAL) self.Sizer = Margins().Sizer(self.content) self.SetSkinKey(skinkey, ToolBarSkinDefaults) self.Bind(wx.EVT_PAINT, self.OnPaint) def Insert(self, pos, object, expand=False): skin = self.skinTB #TODO: This is stupid, should be done some other way if isinstance(object, UberButton): object.SetSkinKey(skin['buttonskin'], True) if object.menu is not None: object.menu.SetSkinKey(skin["menuskin"]) elif isinstance(object, FontDropDown): object.SetSkinKey(skin['buttonskin']) object.SetMenuSkinKey(skin["menuskin"]) self.content.Insert(pos, object, expand, wx.RIGHT | wx.EXPAND, self.skinTB['padding'].x) self.children.insert(pos, object) def Add(self, object, expand=False): skin = self.skinTB #TODO: Still stupid, see Insert if isinstance(object, UberButton): object.SetSkinKey(skin['buttonskin'], True) if object.menu is not None: object.menu.SetSkinKey(skin["menuskin"]) elif isinstance(object, FontDropDown): object.SetSkinKey(skin['buttonskin']) object.SetMenuSkinKey(skin["menuskin"]) self.content.Add(object, expand, wx.RIGHT | wx.EXPAND, self.skinTB['padding'].x) self.children.append(object) def Detach(self, object): return self.content.Detach(object) def AddMany(self, objects, expand=False): for object in objects: self.Add(object, expand) def DoUpdateSkin(self, skin): self.skinTB = skin self.Sizer.SetMargins(skin['margins']) #Even stupider; see Add and Insert do( item.SetSkinKey(skin["buttonskin"]) for item in self.children if isinstance(item, (UberButton, FontDropDown))) for item in self.children: if isinstance(item, UberButton) and item.menu is not None: item.menu.SetSkinKey(skin["menuskin"]) elif isinstance(item, FontDropDown): item.SetMenuSkinKey(skin["menuskin"]) for child in self.content.Children: child.SetBorder(skin["padding"].x) def GetSkinProxy(self): return self.skinTB if hasattr(self, 'skinTB') else None def OnPaint(self, event): dc = wx.AutoBufferedPaintDC(self) rect = wx.RectS(self.Size) self.skinTB['background'].Draw(dc, rect) self.OnPaintMore(dc) def OnPaintMore(self, dc): pass
from gui.prototypes.newskinmodule import NewSkinModule, SkinProxy from gui.uberwidgets.UberButton import UberButton from gui.skin.skinobjects import Margins, SkinColor from gui.prototypes.fontdropdown import FontDropDown import wx from cgui import SimplePanel from util.primitives.funcs import do ToolBarSkinDefaults = { 'padding': lambda: wx.Point(2, 2), 'margins': lambda: Margins([2, 2, 2, 2]), 'background': lambda: SkinColor(wx.SystemSettings_GetColour(wx.SYS_COLOUR_3DFACE)), 'buttonskin': lambda: None, 'menuskin': lambda: None, } class ToolBar(SimplePanel, NewSkinModule): def __init__(self, parent, id=wx.ID_ANY, skinkey=None, name='ToolBar', alignment=None):
def UpdateSkin(self): 'Simply gets a skin and sets it all up.' key = self.skinkey native = not key if native and self.uxthemeable: self.rendernative = True self.destroy_native() self.OpenNativeTheme() skinget = skin.get self.menuicon = skinget('appdefaults.dropdownicon') self.padding = (5, 5) self.margins = Margins([0, 0, 0, 0]) self.Font = default_font() self.fontcolors = [wx.BLACK] * 7 self.backgrounds = NATIVE_BACKGROUNDS self.Cut() elif native: if not self.native: self.native = wx.Button(self, style=wx.BU_EXACTFIT) self.native.SetLabel(self.label) self.Sizer.Add(self.native, 1, wx.EXPAND) self.Layout() self.Cut() else: self.rendernative = False self.destroy_native() skinget = skin.get skinroot = skin.get(key) #s = lambda k, default = sentinel: skinget('%s.%s' % (key, k), default) s = skinroot.get self.menuicon = s('menuicon', skinget('appdefaults.dropdownicon')) self.padding = s('padding', (5, 5)) self.margins = s('margins', Margins([0, 0, 0, 0])) self.Font = s('font', default_font()) fc = skinroot.get('fontcolors', {}) s = fc.get self.fontcolors = [ s('disabled', Color(125, 125, 125)), s('normal', wx.BLACK), s('active', wx.BLACK), s('hover', wx.BLACK), s('activehover', wx.BLACK), s('down', wx.BLACK), s('notify', wx.WHITE) ] bgs = skinroot.get('backgrounds', {}) def s(key, default): try: return bgs[key] except: return default() disabled = s( 'disabled', lambda: SkinGradient( 'vertical', [Color(125, 125, 125), Color(237, 237, 237)])) normal = s( 'normal', lambda: SkinGradient( 'vertical', [Color(200, 255, 200), Color(85, 255, 85)])) active = s( 'active', lambda: SkinGradient( 'vertical', [Color(200, 255, 238), Color(85, 255, 238)])) hover = s('hover', lambda: normal) activehover = s('activehover', lambda: active) down = s( 'down', lambda: SkinGradient('vertical', [ Color(0, 125, 0), Color(00, 204, 00) ])) notify = s( 'notify', lambda: SkinGradient( 'vertical', [Color(255, 255, 200), Color(255, 255, 85)])) self.backgrounds = [ disabled, normal, active, hover, activehover, down, notify ] self.Calcumalate() self.Refresh()
try: urllib2.urlopen('') # ensure an opener is present except Exception, e: pass class SkinHandler(urllib2.BaseHandler): def skin_open(self, req): from util import Storage val = get(req.get_host()) return Storage(read=lambda:val) urllib2._opener.add_handler(SkinHandler()) from gui.skin.skinobjects import Margins ZeroMargins = Margins() from gui.skin.skinparse import \ makeBrush as brush, \ makeFont as font font_multiply_factor = 1.0 def build_font_css(): import wx from gui.textutil import default_font from util import Point2HTMLSize h = Storage()
from ctypes import windll ReleaseCapture_win32 = windll.user32.ReleaseCapture def ClearMouseCapture(): if wxMSW: ReleaseCapture_win32() #=============================================================================== wxEVT_ENTER_WINDOW = 10032 wxEVT_LEAVE_WINDOW = 10033 MenuSkinDefaults = { 'framesize': lambda: Margins([0, 0, 0, 0]), 'frame': lambda: SkinColor(wx.BLACK), #@UndefinedVariable 'padding': lambda: wx.Point(2, 2), 'backgrounds.menu': lambda: SkinColor(wx.WHITE), #@UndefinedVariable 'backgrounds.item': lambda: None, 'backgrounds.selection': lambda: SkinColor(wx.BLACK), #@UndefinedVariable 'font': lambda: default_font(), 'fontcolors.normal': lambda: wx.BLACK, #@UndefinedVariable 'fontcolors.selection': lambda: wx.WHITE, #@UndefinedVariable 'separatorimage': lambda: None } class CustomMenuFrame(wx.PopupTransientWindow, NewSkinModule): def __init__(self, parent): wx.PopupTransientWindow.__init__(self, parent)
def r_framesize(s): return Margins(s)
def UpdateSkin(self): """ This updates the skin elements from the skin provided can be used to update skins if the window changes, change the skin, or revert to native mode if called with None or no arguments """ key = self.skinkey native = self.native = not key if native: self.padding = Point(2, 2) self.margins = Margins([0, 0, 0, 0]) self.framesize = Margins([0, 0, 0, 0]) bgc = wx.SystemSettings_GetColour(wx.SYS_COLOUR_LISTBOX) self.framebg = SkinColor(wx.BLACK) self.normalbg = SkinColor(bgc, border=wx.Pen(wx.BLACK, 1)) self.activebg = SkinColor(bgc, border=wx.Pen(wx.BLACK, 1)) self.hoverbg = SkinColor(bgc, border=wx.Pen(wx.BLACK, 1)) fc = wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOWTEXT) self.normalfc = fc self.activefc = fc self.hoverfc = fc self.Font = default_font() self.menuskin = None self.ddbuttonskin = None self.dropdownicon = None else: s = lambda k, default: skin.get('%s.%s' % (key, k), default) self.padding = s('padding', Point(2, 2)) self.margins = s('margins', Margins([0, 0, 0, 0])) self.framesize = s('framesize', Margins([0, 0, 0, 0])) self.framebg = s('frame', lambda: SkinColor(wx.BLACK)) self.normalbg = s('backgrounds.normal', lambda: SkinColor(wx.WHITE)) self.activebg = s('backgrounds.active', lambda: SkinColor(wx.WHITE)) self.hoverbg = s('backgrounds.hover', lambda: SkinColor(wx.WHITE)) self.normalfc = s('fontcolors.normal', wx.BLACK) self.activefc = s('fontcolors.active', wx.BLACK) self.hoverfc = s('fontcolors.hover', wx.BLACK) self.hintfc = s('fontcolors.hint', lambda: wx.Colour(128, 128, 128)) self.Font = s('font', lambda: default_font) self.menuskin = s('menuskin', '') self.ddbuttonskin = s('dropdownbuttonskin', '') self.dropdownicon = s('dropdownbuttonicon', '') if getattr(self, 'dbutton', None): self.dbutton.SetSkinKey(self.ddbuttonskin) self.dbutton.SetIcon(self.dropdownicon) if getattr(self, 'menu', None): self.menu.SetSkinKey(self.menuskin) if self.Sizer: self.Sizer.SetMargins(self.framesize)
def UpdateSkin(self): key = self.skinkey self.native = native = not key if native: self.OpenNativeTheme() self.padding = wx.Point(2, 2) self.framesize = Margins([1, 1, 1, 1]) #[0,0,0,0] if uxthemed else sz = self.Parent.Sizer if sz: sz.Detach(1) sz.Detach(1) sz.Add(wx.Size(self.framesize.left, self.framesize.top), (0, 0)) sz.Add(wx.Size(self.framesize.right, self.framesize.bottom), (2, 2)) self.framebg = None self.menubg = None self.itembg = None self.selbg = None self.Font = default_font() self.normalfc = wx.SystemSettings_GetColour( wx.SYS_COLOUR_WINDOWTEXT) self.selfc = wx.SystemSettings_GetColour( wx.SYS_COLOUR_HIGHLIGHTTEXT) self.MakeNativeSubmenuIcons() self.separator = None else: self.CloseNativeTheme() s = lambda k, default: skin.get('%s.%s' % (key, k), default) self.padding = s('padding', wx.Point(2, 2)) self.framesize = s('framesize', Margins([0, 0, 0, 0])) sz = self.Parent.Sizer if sz: sz.Detach(1) sz.Detach(1) sz.Add(wx.Size(self.framesize.left, self.framesize.top), (0, 0)) sz.Add(wx.Size(self.framesize.right, self.framesize.bottom), (2, 2)) self.framebg = s('frame', lambda: SkinColor(wx.BLACK)) self.menubg = s('backgrounds.menu', None) self.itembg = s('backgrounds.item', None) self.selbg = s('backgrounds.selection', None) self.Font = s('font', default_font()) self.normalfc = s('fontcolors.normal', lambda: wx.BLACK) self.selfc = s('fontcolors.selection', lambda: wx.BLACK) #TODO: Default? submenuicon = self.submenuicon = s('submenuicon', None) if submenuicon is None: self.MakeNativeSubmenuIcons() else: self.submenuiconhot = s('submenuiconhover', submenuicon) #TODO: Default? self.separator = s('separatorimage', None) for item in self.items: if item.menu: item.menu.spine.SetSkinKey(key)
def er_margins(s): return Margins(s)
def makeImage(imagedesc): 'Parses an image description, returning a SolidImage or SplitImage4.' imagedesc = imagedesc.strip() if not imagedesc: return None # use the image extension as the "split" point between the filename # and the options, so that spaces in image filenames are possible # without quotes. i = max(imagedesc.find('.' + ext) for ext in imageExts) if i == -1: raise SkinException('images end in %r' % (imageExts, )) i = imagedesc.find(' ', i) if i == -1: # just "image.png" -- return a SolidImage. return solid_si4(imagedesc) filename, options = imagedesc[:i], imagedesc[i + 1:] imgdict = S(source=filename) options = options.split() if options: # one-liner: image with cuts if isint(options[0]): # numbers...must be a splitimage n = len(options) for i, opt in enumerate(options): if not isint(opt): n = i break splits, options = options[:n], options[n:] if not splits: solid_si4(imgdict['source']) # parsing rules for splits are same as framesizes imgdict.update(izip(('x1', 'y1', 'x2', 'y2'), Margins(splits))) hstyle = vstyle = regionTypes.stretch align = None posSpecified = False offset = [] for option in options: if option.startswith('h_'): if option in ('h_right', 'h_center', 'h_left'): hstyle = regionTypes.static if align is None: align = regionAlignments[option] else: align |= regionAlignments[option] else: hstyle = regionTypes[option[2:]] elif option.startswith('v_'): if option in ('v_top', 'v_center', 'v_bottom'): vstyle = regionTypes.static if align is None: align = regionAlignments[option] else: align |= regionAlignments[option] else: vstyle = regionTypes[option[2:]] elif option == 'tile': hstyle = vstyle = regionTypes.tile elif isint(option): offset += [int(option)] else: log.warning('unknown skin option "%s"') if len(offset) == 0: # no offsets given: use (0, 0) offset = [0, 0] elif len(offset) == 1: # one offset: means it is used for both X and Y offset = offset * 2 else: # more than two: use the last two numbers found offset = offset[-2:] if align is None: align = wx.ALIGN_CENTER for a in SIREGIONS: imgdict[a] = S(extend=[], hstyle=hstyle, vstyle=vstyle, align=align, offset=wx.Point(*offset)) return si4(imgdict) else: return solid_si4(imgdict['source'])
def UpdateSkin(self): """ Update local skin references and updates skins for buttons """ key = self.skinkey self.native = not key if self.native: if self.uxthemeable: self.OpenNativeTheme() self.bg = None else: self.bg = SkinColor( wx.SystemSettings_GetColour(wx.SYS_COLOUR_3DFACE)) self.padding = Point(2, 2) self.margins = Margins([0, 0, 0, 0]) self.buttonskin = None self.menuskin = None else: self.CloseNativeTheme() self.padding = skin.get(key + '.padding', Point(2, 2)) self.margins = skin.get(key + '.margins', Margins([0, 0, 0, 0])) self.bg = skin.get( key + '.background', lambda: SkinColor( wx.SystemSettings_GetColour(wx.SYS_COLOUR_3DFACE))) self.buttonskin = skin.get(key + '.buttonskin', None) self.menuskin = skin.get(key + '.menuskin', None) s = self.Sizer if s: s.Detach(1) s.Detach(1) s.Add(Size(self.margins.left, self.margins.top), (0, 0)) s.Add(Size(self.margins.right, self.margins.bottom), (2, 2)) s.Children[0].SetBorder(self.padding.y) for child in self.content.Children: child.SetBorder(self.padding.x) for object in self.children + self.staticchildren: if isinstance(object, UberButton): object.SetSkinKey(self.buttonskin, True) if object.menu: object.menu.SetSkinKey(self.buttonskin) elif isinstance(object, FontDropDown): object.SetSkinKey(self.buttonskin) object.SetMenuSkinKey(self.menuskin) if hasattr(self, 'overflowbutton'): self.overflowbutton.SetSkinKey(self.buttonskin) self.overflowmenu.SetSkinKey(self.menuskin) if not self.overflowmode and hasattr(self, 'content'): spacersizer = self.spacersizer spacersizer.Detach(0) spacersizer.Add((self.padding.x, 1), 0, EXPAND) wx.CallAfter(self.Layout)
def UpdateSkin(self): self.skin = skinget(self.skinkey) self.Padding = wx.Size(*skinget(self.skinkey + '.Padding', (0, 0))) self.SetMargins(skinget(self.skinkey + '.Margins', lambda: Margins((0, 0, 0, 0))))