def __init__(self): wx.Frame.__init__(self,None,title='Add Remove Combo') self.panel=wx.Panel(self) self.panel.Sizer=wx.BoxSizer(wx.VERTICAL) self.uc=UberCombo(self.panel, skinkey = 'combobox', typeable = False, size=(200,20), minmenuwidth=200, valuecallback = self.ValCB, selectioncallback = self.SelCB) self.remmenu=SimpleMenu(self.uc.menu,'simplemenu',width=200,callback=self.RemCB) items=[ SimpleMenuItem('*****@*****.**'), SimpleMenuItem('*****@*****.**'), SimpleMenuItem('*****@*****.**'), SimpleMenuItem('*****@*****.**') ] self.panel.Sizer.Add(self.uc,0,wx.EXPAND) do(self.remmenu.AppendItem(item) for item in items) do(self.uc.AppendItem(item) for item in items) self.sep=SimpleMenuItem(id=-1) self.uc.AppendItem(self.sep) self.remitem=SimpleMenuItem('Remove', menu = self.remmenu) self.uc.AppendItem(SimpleMenuItem('Add', method = self.AddCB)) self.uc.AppendItem(self.remitem)
def update_mailclient(self, mc = None): if mc is None: mc = self.account.mailclient or '' ch = self.mailclient_choice with ch.Frozen(): ch.Clear() choices = [MAIL_CLIENT_SYSDEFAULT] file_entry = 0 if mc.startswith('file:'): import os.path if not os.path.exists(mc[5:]): mc == 'sysdefault' else: choices += [_('Custom ({mailclient_name})').format(mailclient_name=mc[5:])] file_entry = len(choices) - 1 choices += [MAIL_CLIENT_OTHER, MAIL_CLIENT_URL] do(ch.Append(s) for s in choices) if mc == 'sysdefault': selection = 0 elif mc == '__urls__': selection = ch.Count - 1 else: selection = file_entry ch.SetSelection(selection) ch.Layout()
def __init__(cls, name, bases, dict): global _actioncalls super(ActionMeta, cls).__init__(name, bases, dict) # Inherit actions from base classes. superactions = mapping.odict() if 'inherited_actions' in dict: bases = bases + tuple(dict['inherited_actions']) funcs.do(superactions.update(c._actions) for c in bases if hasattr(c, '_actions')) setattr(cls, ActionMeta.class_action_attr, superactions) actions = getattr(cls, ActionMeta.class_action_attr) prefix = ActionMeta.action_prefix for v in dict.itervalues(): # for each method in the classdict: # if it's a function and it starts with our magic action prefix, # remove the prefix and add it to our list of actions, along with # the callable "predicate" determining the action's validity at any # point in time if isinstance(v, function) and v.__name__.startswith(prefix): v.__name__ = v.__name__[len(prefix):] val = _actioncalls.pop(v) actions[v.__name__] = val
def __init__(self, parent, skin): 'Generic constructor' wx.VListBox.__init__(self, parent) UberWidget.__init__(self, 'LISTBOX') self.MinSize = wx.Size(1, 1) #fix for small menus events = [(wx.EVT_PAINT, self.OnPaint), (wx.EVT_MOUSEWHEEL, self.OnMouseWheel), (wx.EVT_MOTION, self.OnMouseMove), (wx.EVT_LEFT_UP, self.OnLUp), (wx.EVT_LEFT_DOWN, self.OnLDown), (wx.EVT_RIGHT_DOWN, self.OnLDown), (wx.EVT_MIDDLE_DOWN, self.OnLDown), (wx.EVT_LEFT_DCLICK, lambda e: None), (wx.EVT_SCROLLWIN, self.OnScroll), (wx.EVT_MOUSE_CAPTURE_LOST, self.OnMouseCaptureLost)] do(self.Bind(event, method) for (event, method) in events) #TODO: soft code this self.itemheight = 20 self.items = [] self.ItemCount = len(self.items) self.SetSkinKey(skin, True)
def __init__(self, parent, skin): 'Generic constructor' wx.VListBox.__init__(self,parent) UberWidget.__init__(self,'LISTBOX') self.MinSize = wx.Size(1, 1) #fix for small menus events = [ (wx.EVT_PAINT, self.OnPaint), (wx.EVT_MOUSEWHEEL, self.OnMouseWheel), (wx.EVT_MOTION, self.OnMouseMove), (wx.EVT_LEFT_UP, self.OnLUp), (wx.EVT_LEFT_DOWN, self.OnLDown), (wx.EVT_RIGHT_DOWN, self.OnLDown), (wx.EVT_MIDDLE_DOWN, self.OnLDown), (wx.EVT_LEFT_DCLICK, lambda e:None), (wx.EVT_SCROLLWIN, self.OnScroll), (wx.EVT_MOUSE_CAPTURE_LOST, self.OnMouseCaptureLost) ] do(self.Bind(event, method) for (event, method) in events) #TODO: soft code this self.itemheight = 20 self.items = [] self.ItemCount = len(self.items) self.SetSkinKey(skin,True)
def OnMouseMove(self, event): 'Mouse over event handling.' mp = self.ScreenToClient(GetMousePosition()) items = self.items if self.ClientRect.Contains(mp): n = self.HitTest(mp) if self.Selection != n: do( item.menu.Show(False) for item in self.items if item.menu and item.menu.IsShown()) if items[n].id != -1: self.SetSelection(n) if items[n].menu: items[n].menu.DelayedDisplay(self.GetItemRect(n), self) else: self.SetSelection(-1) elif self.Rect.Contains(mp): self.Parent.CascadeRelease() self.recaptimer = RecapTimer(self) else: self.SetSelection(-1) gp = self.GrandParent if isinstance(gp, SimpleMenu) and gp.CheckParentalContact( GetMousePosition()): gp.spine.AddPendingEvent(event)
def __init__(self, parent, panel, size = wx.DefaultSize): # wx.Panel.__init__(self, parent, size=size) SimplePanel.__init__(self, parent) self.Show(False) do(self.Bind(event, method) for (event,method) in ( (wx.EVT_CLOSE, self.OnClose), )) panel.Reparent(self) self.Sizer=wx.BoxSizer(wx.VERTICAL) self.Sizer.Add(panel, 1, wx.EXPAND) #panel.Show(True) self.panel=panel self.name = getattr(panel, 'name', getattr(panel, 'Title', u'')) from gui import skin self.icon = skin.get('BuddiesPanel.BuddyIcons.NoIcon').WXB self.nicon = None self.notified = False self.tab = None panel.update_icon() panel.update_title()
def init_gui(self): name = 'vCard Editor' if self.protocol is not None else 'vCard Viewer' title = (_('vCard Editor for {username}').format( username=self.protocol.username) ) if self.protocol is not None else _('vCard Viewer') self.frame = f = wx.Frame(None, -1, title=title, name=name) self.notebook = wx.Notebook(f, -1) if self.protocol is not None: #add retrieve/set buttons f.Sizer = s = wx.BoxSizer(wx.VERTICAL) s.Add(self.notebook, 1, wx.EXPAND) p = wx.Panel(f) save = wx.Button(p, wx.ID_SAVE, 'Save') retrieve = Button(p, _('Retreive'), self.on_retrieve) cancel = wx.Button(p, wx.ID_CANCEL, 'Cancel') save.Bind(wx.EVT_BUTTON, lambda e: self.on_save()) p.Sizer = h = wx.BoxSizer(wx.HORIZONTAL) h.AddStretchSpacer(1) do( h.Add(b, 0, wx.EXPAND | wx.ALL, 3) for b in [save, retrieve, cancel]) s.Add(p, 0, wx.EXPAND) else: assert False #no buttons pass
def _rebuild_panels(self): trayaccts = [] if pref('buddylist.show_email_as', 'panel') in ('systray', 'both'): trayaccts += [a for a in profile.emailaccounts] if pref('buddylist.show_social_as', 'panel') in ('systray', 'both'): trayaccts += [a for a in profile.socialaccounts] with self.Frozen(): if trayaccts: shown = [a for (a, icon) in self.tray_icons] enabled = [a for a in trayaccts if a.enabled] icons = dict(self.tray_icons) e, s = set(enabled), set(shown) # remove tray icons no longer needed do(icons.pop(acct).Destroy() for acct in s - e) # add new ones, indexed by their positions in the accounts list for acct in sorted(e - s, key = lambda a: enabled.index(a), reverse = True): try: icons[acct] = AccountTrayIcon.create(acct, self.infobox) except Exception: print_exc() self.tray_icons = icons.items() else: # destroy all tray icons do(icon.Destroy() for acct, icon in self.tray_icons) self.tray_icons = {} wx.CallAfter(self.gui_layout)
def __init__(self, name, protocol): Observable.__init__(self) self.add_observer(self.store_remote_alias, 'remote_alias') self.name = name self.protocol = protocol self._notify_dirty = True self.entering = self.leaving = False # all Buddy slots default to None! do(setattr(self, s, None) for s in [ 'icon_bitmap']) self.icon_hash = self.get_icon_hash() self._getting_image = False self._cached_hash = None self.icon_disabled = False # register with the BuddyWatcher try: register = profile.account_manager.buddywatcher.register except AttributeError: log.debug('No buddy watcher to register with') return else: register(self)
def set_screen_button_mode(self): b = self.buttonfor('screen') if self._screen_button_mode == 'capture': self._set_screen_button_mode('screen') f = b.Font; f.SetWeight(wx.FONTWEIGHT_NORMAL); b.Font = f do(self.buttonfor(b).Enable(True) for b in self.capture_related) ApplySmokeAndMirrors(wx.GetTopLevelParent(self))
def _rebuild_panels(self): trayaccts = [] if pref('buddylist.show_email_as', 'panel') in ('systray', 'both'): trayaccts += [a for a in profile.emailaccounts] if pref('buddylist.show_social_as', 'panel') in ('systray', 'both'): trayaccts += [a for a in profile.socialaccounts] with self.Frozen(): if trayaccts: shown = [a for (a, icon) in self.tray_icons] enabled = [a for a in trayaccts if a.enabled] icons = dict(self.tray_icons) e, s = set(enabled), set(shown) # remove tray icons no longer needed do(icons.pop(acct).Destroy() for acct in s - e) # add new ones, indexed by their positions in the accounts list for acct in sorted(e - s, key=lambda a: enabled.index(a), reverse=True): try: icons[acct] = AccountTrayIcon.create( acct, self.infobox) except Exception: print_exc() self.tray_icons = icons.items() else: # destroy all tray icons do(icon.Destroy() for acct, icon in self.tray_icons) self.tray_icons = {} wx.CallAfter(self.gui_layout)
def __init__(self, name, protocol): Observable.__init__(self) self.add_observer(self.store_remote_alias, 'remote_alias') self.name = name self.protocol = protocol self._notify_dirty = True self.entering = self.leaving = False # all Buddy slots default to None! do(setattr(self, s, None) for s in ['icon_bitmap']) self.icon_hash = self.get_icon_hash() self._getting_image = False self._cached_hash = None self.icon_disabled = False # register with the BuddyWatcher try: register = profile.account_manager.buddywatcher.register except AttributeError: log.debug('No buddy watcher to register with') return else: register(self)
def Enable(self, switch=True): """ Enables or disables the button Enables by default (maybe change to toggle?) """ if not self.native: wx.PyControl.Enable(self, switch) if switch: events = [(wx.EVT_LEFT_DOWN, self.OnLeftDown), (wx.EVT_LEFT_DCLICK, self.OnLeftDown), (wx.EVT_LEFT_UP, self.OnLeftUp), (wx.EVT_ENTER_WINDOW, self.OnMouseIn), (wx.EVT_LEAVE_WINDOW, self.OnMouseOut)] do(self.Bind(event, method) for (event, method) in events) else: events = [ wx.EVT_LEFT_DOWN, wx.EVT_LEFT_DCLICK, wx.EVT_LEFT_UP, wx.EVT_ENTER_WINDOW, wx.EVT_LEAVE_WINDOW ] do(self.Unbind(event) for event in events) self.state = (1 if switch else 0) if self.ScreenRect.Contains(wx.GetMousePosition()): self.GetHover() else: self.ReleaseHover() else: self.native.Enable(switch) self.Refresh()
def __init__(cls, name, bases, dict): global _actioncalls super(ActionMeta, cls).__init__(name, bases, dict) # Inherit actions from base classes. superactions = mapping.odict() if 'inherited_actions' in dict: bases = bases + tuple(dict['inherited_actions']) funcs.do( superactions.update(c._actions) for c in bases if hasattr(c, '_actions')) setattr(cls, ActionMeta.class_action_attr, superactions) actions = getattr(cls, ActionMeta.class_action_attr) prefix = ActionMeta.action_prefix for v in dict.itervalues(): # for each method in the classdict: # if it's a function and it starts with our magic action prefix, # remove the prefix and add it to our list of actions, along with # the callable "predicate" determining the action's validity at any # point in time if isinstance(v, function) and v.__name__.startswith(prefix): v.__name__ = v.__name__[len(prefix):] val = _actioncalls.pop(v) actions[v.__name__] = val
def update_mailclient(self, mc=None): if mc is None: mc = self.account.mailclient or "" ch = self.mailclient_choice with ch.Frozen(): ch.Clear() choices = [MAIL_CLIENT_SYSDEFAULT] file_entry = 0 if mc.startswith("file:"): import os.path if not os.path.exists(mc[5:]): mc == "sysdefault" else: choices += [_("Custom ({mailclient_name})").format(mailclient_name=mc[5:])] file_entry = len(choices) - 1 choices += [MAIL_CLIENT_OTHER, MAIL_CLIENT_URL] do(ch.Append(s) for s in choices) if mc == "sysdefault": selection = 0 elif mc == "__urls__": selection = ch.Count - 1 else: selection = file_entry ch.SetSelection(selection) ch.Layout()
def init_gui(self): name = 'vCard Editor' if self.protocol is not None else 'vCard Viewer' title = (_('vCard Editor for {username}').format(username=self.protocol.username)) if self.protocol is not None else _('vCard Viewer') self.frame = f = wx.Frame( None, -1, title = title, name = name) self.notebook = wx.Notebook(f, -1) if self.protocol is not None: #add retrieve/set buttons f.Sizer = s = wx.BoxSizer(wx.VERTICAL) s.Add(self.notebook, 1, wx.EXPAND) p = wx.Panel(f) save = wx.Button(p, wx.ID_SAVE, 'Save') retrieve = Button(p, _('Retreive'), self.on_retrieve) cancel = wx.Button(p, wx.ID_CANCEL, 'Cancel') save.Bind(wx.EVT_BUTTON, lambda e: self.on_save()) p.Sizer = h = wx.BoxSizer(wx.HORIZONTAL) h.AddStretchSpacer(1) do(h.Add(b, 0, wx.EXPAND | wx.ALL, 3) for b in [save, retrieve, cancel]) s.Add(p, 0, wx.EXPAND) else: assert False #no buttons pass
def MakeGroupItems(self): accounts = profile.account_manager.connected_accounts groups = set() groups.add(pref('buddylist.fakeroot_name', default='Contacts')) do(groups.update(account.connection.get_groups()) for account in accounts if getattr(account, 'connection', None) is not None) return [SimpleMenuItem(group) for group in list(sorted(groups,key = lambda g: g.lower()))]
def merge_groups(root, grouphash=group_hash, depth=0): ''' if hash(group1) == hash(group2) the contents of both are put into a new group. ''' from contacts.metacontacts import MetaContact assert callable(grouphash) group_contents = collections.defaultdict(list) is_group = {True: [], False: []} do(is_group[isinstance(x, GroupTypes)].append(x) for x in root) ordered_names = [] for g in is_group[True]: group_contents[grouphash(g)].append(g) if grouphash(g) not in ordered_names: ordered_names.append(grouphash(g)) del root[:] newlist = [] for _, groups in ((name, group_contents[name]) for name in ordered_names): # Create a DGroup which preserves information from the original # protocol groups. def plural(objects, attr): ret = [] for g in objects: if hasattr(g, attr + 's'): ret.extend(getattr(g, attr + 's')) else: ret.append(getattr(g, attr)) return ret protos = plural(groups, 'protocol') ids = plural(groups, 'id') newgroup = DGroup( groups[0].name, # Choose a name protos, ids, # All the protocols and ids sum(groups, [])) # and all the contents. merged = merge_groups(newgroup, depth=depth + 1) newlist.append(merged) root.extend(newlist) # remove "duplicate" contacts--that is, contacts with the same on the same # protocol that appear under different accounts. If functionality in the # right click menu is required, we'll have to make some kind of "DContact" # with multiple protocols. unique = set() for con in is_group[False]: chash = con.info_key if chash not in unique: unique.add(chash) root.append(con) return root
def set_screen_button_mode(self): b = self.buttonfor('screen') if self._screen_button_mode == 'capture': self._set_screen_button_mode('screen') f = b.Font f.SetWeight(wx.FONTWEIGHT_NORMAL) b.Font = f do(self.buttonfor(b).Enable(True) for b in self.capture_related) ApplySmokeAndMirrors(wx.GetTopLevelParent(self))
def __init__(self, parent, color="red"): wx.Panel.__init__(self, parent, style=0) self.name=color events=[ (wx.EVT_PAINT, self.OnPaint), (wx.EVT_ERASE_BACKGROUND, lambda e:None) ] do(self.Bind(event, method) for (event, method) in events)
def on_success(self, sock): if self.success: sock.do_disconnect() else: sock.cancel_timeout() do(sock_.do_disconnect() for sock_ in self.socks if sock_ is not sock) self.success = True self.connected_sock = sock self.on_connect(sock)
def merge_groups(root, grouphash=group_hash, depth=0): ''' if hash(group1) == hash(group2) the contents of both are put into a new group. ''' from contacts.metacontacts import MetaContact assert callable(grouphash) group_contents = collections.defaultdict(list) is_group = {True: [], False: []} do(is_group[isinstance(x, GroupTypes)].append(x) for x in root) ordered_names = [] for g in is_group[True]: group_contents[grouphash(g)].append(g) if grouphash(g) not in ordered_names: ordered_names.append(grouphash(g)) del root[:] newlist = [] for _, groups in ((name, group_contents[name]) for name in ordered_names): # Create a DGroup which preserves information from the original # protocol groups. def plural(objects, attr): ret = [] for g in objects: if hasattr(g, attr + 's'): ret.extend(getattr(g, attr + 's')) else: ret.append(getattr(g, attr)) return ret protos = plural(groups, 'protocol') ids = plural(groups, 'id') newgroup = DGroup(groups[0].name, # Choose a name protos, ids, # All the protocols and ids sum(groups, [])) # and all the contents. merged = merge_groups(newgroup, depth = depth+1) newlist.append(merged) root.extend(newlist) # remove "duplicate" contacts--that is, contacts with the same on the same # protocol that appear under different accounts. If functionality in the # right click menu is required, we'll have to make some kind of "DContact" # with multiple protocols. unique = set() for con in is_group[False]: chash = con.info_key if chash not in unique: unique.add(chash) root.append(con) return root
def x03_x0a(o, sock, data): ''' SNAC (x3, xa): Notification rejected! reference: U{http://iserverd.khstu.ru/oscar/snac_03_0a.html} ''' fmt = (('bnames', 'list', 'pstring'), ) bnames, data = oscar.unpack(fmt, data) assert not data #TODO: notify user? do(log.info('Notification failed for %s', name) for name in bnames)
def x03_x0a(o, sock, data): ''' SNAC (x3, xa): Notification rejected! reference: U{http://iserverd.khstu.ru/oscar/snac_03_0a.html} ''' fmt = (('bnames', 'list', 'pstring'),) bnames, data = oscar.unpack(fmt, data) assert not data #TODO: notify user? do(log.info('Notification failed for %s', name) for name in bnames)
def __init__(self): wx.Frame.__init__(self,None,size=(75,100)) events=[ (wx.EVT_BUTTON,self.OnButton) ] do(self.Bind(event,method) for (event,method) in events) emotihandler=EmotiHandler() self.cp=UberEmotiBox(self,emotihandler) self.b1=wx.Button(self,label='^_^')
def __init__( self, parent ): Renderer.__init__(self, parent) layout_attrs = ''' name_font_face name_font_size padding '''.strip().split() do(self.attrlink(attr) for attr in layout_attrs) self.UpdateSkin()
def __init__(self, parent, host): """ Usses the OnPaint function of host to draw and region itself host.OnPaint(otherdc,otherwindow) """ wx.PopupWindow.__init__(self, parent) events = [(wx.EVT_PAINT, self.OnPaint)] do(self.Bind(event, method) for (event, method) in events) self.host = host self.Size = host.Size
def MakeGroupItems(self): accounts = profile.account_manager.connected_accounts groups = set() groups.add(pref('buddylist.fakeroot_name', default='Contacts')) do( groups.update(account.connection.get_groups()) for account in accounts if getattr(account, 'connection', None) is not None) return [ SimpleMenuItem(group) for group in list(sorted(groups, key=lambda g: g.lower())) ]
def __init__(self,parent,host): """ Usses the OnPaint function of host to draw and region itself host.OnPaint(otherdc,otherwindow) """ wx.PopupWindow.__init__(self,parent) events=[ (wx.EVT_PAINT, self.OnPaint) ] do(self.Bind(event, method) for (event,method) in events) self.host=host self.Size=host.Size
def scrape_profile(s): # fixup HTML s = s.replace(u' ', u' ').replace(u'Hobbies:</dd>', u'Hobbies:</dt>') soup = BeautifulStoneSoup(s, convertEntities=BeautifulStoneSoup.ALL_ENTITIES, fromEncoding = 'utf-8') profile = odict() # grab info for section in ('basics', 'more'): div = soup('div', id='ypfl-' + section)[0].dl if div is not None: info = [elem.renderContents(None) for elem in div if elem != u'\n'] profile.update(dictfrompairs(info)) # grab links links = dictfrompairs([e.renderContents(None).replace('<em>','').replace('</em>','') for e in soup('dl', attrs = {'class':'mylinks'})[0].contents if e != u'\n']) # construct [list of] tuples for links if 'Home Page:' in links: links['Home Page:'] = anchor2tuple(links['Home Page:']) linktuples = [anchor2tuple(v) for k, v in sorted(links.items()) if k.startswith('Cool Link')] # insert newlines between the link tuples. finallinks = [] for i, tuple in enumerate(linktuples): finallinks.append(tuple) if i != len(linktuples) - 1: finallinks.append(u'\n') links['Links:'] = finallinks do(links.pop(k) for k in links.keys() if k.startswith('Cool Link')) profile.update(links) # pull "member since" and "last update" for p in soup.findAll('p', attrs = {'class':'footnote'}): c = p.renderContents(None) for hdr in ('Member Since ', 'Last Update: '): if c.startswith(hdr): profile[hdr] = c[len(hdr):] # remove empty entries for k, v in dict(profile).iteritems(): if isinstance(v, basestring): dict.__setitem__(profile, k, None if v.strip() in ('', 'No Answer') else scrape_clean(v)) profile.pop('Yahoo! ID:', None) return profile
def MakeProtocolItems(self): set = oset if not hasattr(self,'protoitems'): self.protoitems = set() protoitems = self.protoitems oldprotocols = set(p.id for p in protoitems) #============================================================================== accounts = profile.account_manager.connected_accounts protocols = set() protocols2 = set() do(protocols.add(account.protocol) for account in accounts) for proto in protocols: try: protocols2.update(protocolmeta.SERVICE_MAP[proto]) except: pass protocols = protocols2 #============================================================================== for account in accounts: if not account.allow_contact_add: protocols.discard(account.protocol) removeprotos = oldprotocols - protocols addprotos = protocols - oldprotocols #============================================================================== for item in set(protoitems): if item.id in removeprotos: protoitems.remove(item) for protocol in addprotos: skinval = skin.get('serviceicons.%s'%protocol, None) if skinval is not None: skinval = skinval.Resized(16) protoval = protocolmeta.protocols.get(protocol, None) protoval = protoval.name if protoval is not None else protocol protoitems.add(SimpleMenuItem([skinval, protoval],id = protocol)) return list(protoitems)
def __init__(self, parent, item, sizer=None): """ item - the object on the left or top """ wx.Panel.__init__(self, parent, style=0) events = [(wx.EVT_PAINT, self.OnPaint), (wx.EVT_ERASE_BACKGROUND, lambda e: None), (wx.EVT_LEFT_DOWN, self.OnLDown), (wx.EVT_LEFT_UP, self.OnLUp), (wx.EVT_MOTION, self.OnDrag), (wx.EVT_SIZE, self.OnSize), (wx.EVT_IDLE, self.OnIdle), (wx.EVT_LEAVE_WINDOW, lambda e: self.Refresh()), (wx.EVT_ENTER_WINDOW, lambda e: self.Refresh())] do(self.Bind(event, method) for (event, method) in events) self.dpoint = 0 self.delta = None self.item = item self.itemminsize = wx.Size(max(item.MinSize.width, 0), max(item.MinSize.height, 0)) def NewSetMinSize(size): self.itemminsize = wx.Size( self.itemminsize.width if size[0] == -1 else size[0], self.itemminsize.height if size[1] == -1 else size[1]) if self.item.OldMinSize < self.itemminsize: self.item.OldMinSize = self.itemminsize def NewGetMinSize(): return self.itemminsize item.OldSetMinSize = item.SetMinSize item.OldGetMinSize = item.GetMinSize item.OldMinSize = item.MinSize item.SetMinSize = NewSetMinSize item.GetMinSize = NewGetMinSize item.__dict__['MinSize'] = property(item.GetMinSize, item.SetMinSize) self.sizer = sizer or self.Parent.Sizer self.orientation = self.sizer.Orientation self.SetSkinKey( 'VerticalSizerBar' if self.orientation == wx.VERTICAL else 'HorizontalSizerBar', True) self.OnSize() self.sizer.Layout()
def MakeProtocolItems(self): set = oset if not hasattr(self, 'protoitems'): self.protoitems = set() protoitems = self.protoitems oldprotocols = set(p.id for p in protoitems) #============================================================================== accounts = profile.account_manager.connected_accounts protocols = set() protocols2 = set() do(protocols.add(account.protocol) for account in accounts) for proto in protocols: try: protocols2.update(protocolmeta.SERVICE_MAP[proto]) except: pass protocols = protocols2 #============================================================================== for account in accounts: if not account.allow_contact_add: protocols.discard(account.protocol) removeprotos = oldprotocols - protocols addprotos = protocols - oldprotocols #============================================================================== for item in set(protoitems): if item.id in removeprotos: protoitems.remove(item) for protocol in addprotos: skinval = skin.get('serviceicons.%s' % protocol, None) if skinval is not None: skinval = skinval.Resized(16) protoval = protocolmeta.protocols.get(protocol, None) protoval = protoval.name if protoval is not None else protocol protoitems.add(SimpleMenuItem([skinval, protoval], id=protocol)) return list(protoitems)
def build_button_sizer(save, cancel = None, border=5): 'Builds a standard platform specific button sizer.' # Only because wxStdDialogButtonSizer.Realize crashed the Mac sz = wx.BoxSizer(wx.HORIZONTAL) sz.AddStretchSpacer(1) addbutton = lambda b: sz.Add(b, 0, (wx.ALL & ~wx.TOP) | wx.ALIGN_RIGHT, border) mac = 'wxMac' in wx.PlatformInfo import util.primitives.funcs as funcs if save and cancel: funcs.do(addbutton(b) for b in ([cancel, save] if mac else [save, cancel])) else: addbutton(save) return sz
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 __init__(self, parent, item, sizer = None): """ item - the object on the left or top """ wx.Panel.__init__(self, parent, style=0) events=[(wx.EVT_PAINT, self.OnPaint), (wx.EVT_ERASE_BACKGROUND, lambda e:None), (wx.EVT_LEFT_DOWN, self.OnLDown), (wx.EVT_LEFT_UP,self.OnLUp), (wx.EVT_MOTION,self.OnDrag), (wx.EVT_SIZE,self.OnSize), (wx.EVT_IDLE,self.OnIdle), (wx.EVT_LEAVE_WINDOW,lambda e: self.Refresh()), (wx.EVT_ENTER_WINDOW,lambda e: self.Refresh())] do(self.Bind(event, method) for (event,method) in events) self.dpoint = 0 self.delta = None self.item = item self.itemminsize = wx.Size(max(item.MinSize.width, 0), max(item.MinSize.height, 0)) def NewSetMinSize(size): self.itemminsize=wx.Size(self.itemminsize.width if size[0]==-1 else size[0],self.itemminsize.height if size[1]==-1 else size[1]) if self.item.OldMinSize<self.itemminsize: self.item.OldMinSize=self.itemminsize def NewGetMinSize(): return self.itemminsize item.OldSetMinSize=item.SetMinSize item.OldGetMinSize=item.GetMinSize item.OldMinSize=item.MinSize item.SetMinSize=NewSetMinSize item.GetMinSize=NewGetMinSize item.__dict__['MinSize']=property(item.GetMinSize,item.SetMinSize) self.sizer = sizer or self.Parent.Sizer self.orientation = self.sizer.Orientation self.SetSkinKey('VerticalSizerBar' if self.orientation == wx.VERTICAL else 'HorizontalSizerBar', True) self.OnSize() self.sizer.Layout()
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 protocol_changed(e = None): '''Invoked when the choice box with "Global Settings" and all the other protocols changes.''' i = proto_choice.Selection checkstr = _('&Use Proxy Server') if i == 0 else _('&Use Global Settings') checkbox.Label = checkstr enabled = bool(get_pref(getcheckpref(i))) checkbox.SetValue(enabled) proxy_proto_choice.SetStringSelection(get_pref(getprotopref(i))) for i, (name, trans) in enumerate(proxy_info): proxy_info_fields[name].Value = get_pref(gettextpref(i, name)) print i, enabled do(c.Window.Enable(enabled if i == 0 else not enabled) for c in grid.Children)
def __init__(self, name, protocol): # Yahoo buddy names are case insensitive. self._nice_name = name name = name.lower() self.status = 'unknown' self.status_message = '' self.idle = None self._service = 'yahoo' common.buddy.__init__(self, name, protocol) self.icon_hash = None #force yahoo buddies to find out what the current checksum is do(setattr(self, slot, None) for slot in YahooBuddy.__slots__) self._service = 'yahoo' self.contact_info = {} self.stealth_perm = False self.stealth_session = True
def draw(self, dc, rect): ''' draws this image into the specified rectangle of the drawing context given, per the dictionary given to the constructor @param dc: a wx.DC to draw into @param rect: a wx.Rect as a description of where/how big to draw ''' self.dc = dc self.rect = rect self.rs = [] do(func(args) for (func,args) in self.draw_commands) self.region = wx.Region(0, 0, 0, 0) for region in self.rs: if not region.IsEmpty(): self.region.UnionRegion(region) self.dc = None self.rect = None
def draw(self, dc, rect): ''' draws this image into the specified rectangle of the drawing context given, per the dictionary given to the constructor @param dc: a wx.DC to draw into @param rect: a wx.Rect as a description of where/how big to draw ''' self.dc = dc self.rect = rect self.rs = [] do(func(args) for (func, args) in self.draw_commands) self.region = wx.Region(0, 0, 0, 0) for region in self.rs: if not region.IsEmpty(): self.region.UnionRegion(region) self.dc = None self.rect = None
def calcsizes(self): p, s = self.getpref, self.skin padding = p('padding', 4) do(setattr(self, k.replace('.', '_'), p(k)) for k in self.layout_attrs) # Main Font: contact's name sz = int(p('name_font_size', 10)) self.mainfont = safefont(p('name_font_face', None), sz) self.mainfont.Style = FONTSTYLE_NORMAL self.mainfont_height = mainfont_height = self.mainfont.LineHeight # Extra font: idle time, status message self.extrafont = safefont(p('extra_font_face', None), int(p('extra_font_size', 10))) self.extrafont_height = extrafont_height = self.extrafont.LineHeight # depth indent self.depth_indent = p('indent', 5) # decide on a maximum height icon_size = p('buddy_icon_size', 0) if s.icon_frame_size: # add overlay size if necessary icon_size += s.icon_frame_size.top + s.icon_frame_size.bottom show_icon = p('show_buddy_icon', False) # item_height method will use this extraheight = extrafont_height if (p('show_extra', True) \ and p('extra_info', 'status') in ('status','both'))\ else 0 margins = self.skin.margins self.cell_height = padding * 2 + \ max(icon_size if show_icon else 0, mainfont_height + extraheight) + \ margins.top + margins.bottom if self.cell_height < mainfont_height * 1.2: self.cell_height = mainfont_height * 1.2 self.drawseqs.clear() self._serviceiconcache = {} self._lastcalc = None return self.cell_height
def OnClose(self,event): """ Handels hiding of submenus and deactivating caller if aplicable when the menu is closed """ if not self.IsShown(): do(item.menu.Show(False) for item in self.spine.items if item.menu and item.menu.IsShown()) while self.spine.HasCapture():self.spine.ReleaseMouse() if self.caller:# and hasattr(self.caller,'Active'): event=wx.MenuEvent(wx.wxEVT_MENU_CLOSE,self.Id) self.caller.AddPendingEvent(event) self.caller = None if self.connected: window, id = self.connected window.Disconnect(id, id, wx.wxEVT_ACTIVATE) self.connected = None
def __init__(self, parent, id = -1, range = 100, skinkey = None, showlabel = False, style = wx.GA_SMOOTH, pos = wx.DefaultPosition, size = wx.DefaultSize): wx.Gauge.__init__(self,parent,-1,range, pos, size, style) self.style = style self.range = range self.value = 0 self.showlabel = showlabel events=[(wx.EVT_PAINT, self.OnPaint), (wx.EVT_ERASE_BACKGROUND, self.OnBGPaint), (wx.EVT_SIZE, self.OnSize)] do(self.Bind(event, method) for (event, method) in events) self.SetSkinKey(skinkey,True) self.Calcumalate()
def __init__(self, parent, image, size=wx.Size(-1, -1), rot=0): """ image - wx.Image of the item """ wx.PopupWindow.__init__(self, parent) events = [(wx.EVT_PAINT, self.onPaint), (wx.EVT_MOVE, self.OnMove)] do(self.Bind(event, method) for (event, method) in events) self.parent = parent self.rot = rot if size != wx.Size(-1, -1): self.SetSize(size) if isinstance(image, wx.Bitmap): self.bitmap = image else: self.SetImage(image, size)
def __init__(self): wx.Frame.__init__(self, None, wx.NewId(), "UberBar sampler 2",(0,0),(600,150)) events=[ #(wx.EVT_BUTTON,self.onButton) ] do(self.Bind(event, method) for (event,method) in events) content=wx.BoxSizer(wx.VERTICAL) self.skin = 'buttonbar'#None# self.ubar=UberBar(self,skinkey=self.skin,alignment=wx.ALIGN_CENTER) self.b1=UberButton(self.ubar,-1,'Button 1',icon=wx.Bitmap(resdir / 'skins/default/digsbybig.png',wx.BITMAP_TYPE_PNG)) self.b2=UberButton(self.ubar,-1,'Button 2',style=wx.VERTICAL,icon=wx.Bitmap(resdir / 'skins/default/digsbybig.png',wx.BITMAP_TYPE_PNG)) self.b3=UberButton(self.ubar,-1,'Button 3',icon=wx.Bitmap(resdir / 'skins/default/digsbybig.png',wx.BITMAP_TYPE_PNG)) self.ubar.Add(self.b1) self.ubar.Add(self.b2) self.ubar.Add(self.b3) content.Add(self.ubar,0,wx.EXPAND,0) self.SetSizer(content)
def __init__(self, parent): """ standard fair """ wx.Panel.__init__(self, parent, style=0) events=[ (wx.EVT_PAINT,self.OnPaint), (wx.EVT_ERASE_BACKGROUND, lambda e:None), (wx.EVT_BUTTON, self.OnButton) ] do(self.Bind(event, method) for (event, method) in events) #make sizers self.Sizer=wx.BoxSizer(wx.HORIZONTAL) self.hsizer=wx.BoxSizer(wx.HORIZONTAL) self.vsizer=wx.BoxSizer(wx.VERTICAL) #make Buttons self.closebutton=UberButton(self, CLOSEID, skin=self.Parent.closebuttonskin, icon=self.Parent.closeicon) self.prevb=UberButton(self, PREVID, skin=self.Parent.scrollbuttonskin, icon=self.Parent.lefticon) self.nextb=UberButton(self, NEXTID, skin=self.Parent.scrollbuttonskin, icon=self.Parent.righticon) self.upb=UberButton(self, UPID, skin=self.Parent.scrollbuttonskin, icon=self.Parent.upicon) self.downb=UberButton(self, DOWNID, skin=self.Parent.scrollbuttonskin, icon=self.Parent.downicon) #add butons to sizers self.hsizer.Add(self.prevb, 0, wx.EXPAND) self.hsizer.Add(self.nextb, 0, wx.EXPAND) self.vsizer.Add(self.upb, 1, wx.EXPAND) self.vsizer.Add(self.downb, 1, wx.EXPAND) self.Sizer.Add(self.hsizer, 0, wx.EXPAND) self.Sizer.Add(self.closebutton, 0, wx.CENTER|wx.ALL, 5) #Hide all buttons self.prevb.Show(False) self.nextb.Show(False) self.upb.Show(False) self.downb.Show(False) self.closebutton.Show(pref('tabs.tabbar_x', False)) self.type=None
def __init__(self,winman,tabman,pos=wx.DefaultPosition): wx.Frame.__init__(self, None, wx.NewId(), "UberBook Sampler", pos, (600, 150)) events=[(wx.EVT_MOVE, self.OnMove), (wx.EVT_SIZE, self.OnSize)] do(self.Bind(event,method) for (event,method) in events) self.skin = 'Tabs' self.content = wx.BoxSizer(wx.VERTICAL) self.winman = winman self.tabman = tabman self.notebook = NoteBook(self, self, self.tabman, self.skin) self.content.Add(self.notebook, 1, wx.EXPAND) self.SetSizer(self.content) self.focus = False self.mergstuff = None
def protocol_changed(e=None): '''Invoked when the choice box with "Global Settings" and all the other protocols changes.''' i = proto_choice.Selection checkstr = _('&Use Proxy Server') if i == 0 else _( '&Use Global Settings') checkbox.Label = checkstr enabled = bool(get_pref(getcheckpref(i))) checkbox.SetValue(enabled) proxy_proto_choice.SetStringSelection(get_pref(getprotopref(i))) for i, (name, trans) in enumerate(proxy_info): proxy_info_fields[name].Value = get_pref(gettextpref(i, name)) print i, enabled do( c.Window.Enable(enabled if i == 0 else not enabled) for c in grid.Children)
def OnClose(self, event): """ Handels hiding of submenus and deactivating caller if aplicable when the menu is closed """ if not self.IsShown(): do( item.menu.Show(False) for item in self.spine.items if item.menu and item.menu.IsShown()) while self.spine.HasCapture(): self.spine.ReleaseMouse() if self.caller: # and hasattr(self.caller,'Active'): event = wx.MenuEvent(wx.wxEVT_MENU_CLOSE, self.Id) self.caller.AddPendingEvent(event) self.caller = None if self.connected: window, id = self.connected window.Disconnect(id, id, wx.wxEVT_ACTIVATE) self.connected = None
def __init__(self): wx.Frame.__init__(self, None, wx.NewId(), "UberBar sampler", (0, 0), (600, 150)) events = [ #(wx.EVT_BUTTON,self.onButton) ] do(self.Bind(event, method) for (event, method) in events) content = wx.BoxSizer(wx.VERTICAL) self.skin = 'buttonbar' #None# self.ubar = UberBar(self, skinkey=self.skin, alignment=wx.ALIGN_LEFT) self.b1 = UberButton(self.ubar, -1, 'Button 1', icon=wx.Bitmap( resdir / 'skins/default/digsbybig.png', wx.BITMAP_TYPE_PNG)) self.b2 = UberButton(self.ubar, -1, 'Button 2', style=wx.VERTICAL, icon=wx.Bitmap( resdir / 'skins/default/digsbybig.png', wx.BITMAP_TYPE_PNG)) self.b3 = UberButton(self.ubar, -1, 'Button 3', icon=wx.Bitmap( resdir / 'skins/default/digsbybig.png', wx.BITMAP_TYPE_PNG)) self.ubar.Add(self.b1) self.ubar.Add(self.b2) self.ubar.AddSpacer() self.ubar.Add(self.b3) content.Add(self.ubar, 0, wx.EXPAND, 0) self.SetSizer(content)