def __init__(self, parent, skinkey='AppDefaults.PrefCombo'): EventMixin.__init__(self) UberCombo.__init__(self, parent, self.no_connections_label, False, valuecallback=self._on_account_changed, skinkey=skinkey) profile.account_manager.connected_accounts.add_observer(self._on_connaccts_changed) self._on_connaccts_changed()
def __init__(self, parent, content_callback, objects = None): UberCombo.__init__(self, parent, skinkey = 'combobox', typeable = False, valuecallback = self.OnValue, selectioncallback = lambda item: self.ChangeValue(item)) self.remove_menu = SimpleMenu(self.menu, 'simplemenu',callback = self.OnRemove) self.content_cb = content_callback if objects is not None: self.SetList(objects)
def __init__(self, parent, skinkey='AppDefaults.PrefCombo'): EventMixin.__init__(self) UberCombo.__init__(self, parent, self.no_connections_label, False, valuecallback=self._on_account_changed, skinkey=skinkey) profile.account_manager.connected_accounts.add_observer( self._on_connaccts_changed) self._on_connaccts_changed()
def combos(parent): uct = UberCombo(parent, value='test', skinkey='combobox', typeable=True, size=(100, 20)) uct.AppendItem(SimpleMenuItem('Sample Item 1')) uct.AppendItem(SimpleMenuItem('Sample Item 2')) uct.AppendItem(SimpleMenuItem(id=-1)) uct.AppendItem(SimpleMenuItem('Sample Item 3')) return [uct]
def SetCallbacks(self, selection=sentinel, value=sentinel, button=sentinel): 'Sets callbacks for this combobox.' UberCombo.SetCallbacks(self, selection, value) if button is not sentinel: self.buttoncallback = button
def __init__(self, parent, skinkey=None, contacts=None, inviteCallback=None, accountCallback=None, model=None, use_confirm_dialog=True): if skinkey is None: skinkey = skin.get('RoomListComboSkin') UberCombo.__init__(self, parent, typeable=True, skinkey=skinkey, editmethod=self.EditField, selectioncallback=self.on_selection, maxmenuheight=10, minmenuwidth=230, empty_text=_('Invite Buddy')) self.TextField.Bind(wx.EVT_KEY_DOWN, self.OnKey) self.contacts = contacts if contacts is not None else {} self.inviteCallback = inviteCallback self.accountCallback = accountCallback self.model = model self.use_confirm_dialog = use_confirm_dialog #from util import trace #from gui.uberwidgets.simplemenu import SimpleMenu #trace(SimpleMenu) def EditField(): if not self.display.txtfld.IsShown(): self.display.TypeField() self.menu.BeforeDisplay += lambda: self.update_menu(self.TextField. Value) self.menu.BeforeDisplay += EditField
def __init__(self, parent, skinkey=None, contacts=None, inviteCallback=None, accountCallback=None, model=None, use_confirm_dialog=True): if skinkey is None: skinkey = skin.get('RoomListComboSkin') UberCombo.__init__(self, parent, typeable=True, skinkey=skinkey, editmethod=self.EditField, selectioncallback=self.on_selection, maxmenuheight=10, minmenuwidth=230, empty_text=_('Invite Buddy')) self.TextField.Bind(wx.EVT_KEY_DOWN, self.OnKey) self.contacts = contacts if contacts is not None else {} self.inviteCallback = inviteCallback self.accountCallback = accountCallback self.model = model self.use_confirm_dialog = use_confirm_dialog #from util import trace #from gui.uberwidgets.simplemenu import SimpleMenu #trace(SimpleMenu) def EditField(): if not self.display.txtfld.IsShown(): self.display.TypeField() self.menu.BeforeDisplay += lambda: self.update_menu(self.TextField.Value) self.menu.BeforeDisplay += EditField
def UpdateSkin(self): key = 'statuspanel' if not skin.get(key, False) or skin.get(key + '.mode', '') == 'native': s = lambda k, d: None else: s = lambda k, default: skin.get('%s.%s' % (key, k), default) comboskinkey = s('comboboxskin', None) self.cbuttonskin = cbskinkey = s('statusbuttonskin', None) self.SetSkinKey(comboskinkey) UberCombo.UpdateSkin(self) if hasattr(self, 'cbutton'): self.cbutton.SetSkinKey(cbskinkey, True) self.SetButtonIcon(StatusMessage.icon_for(self.status_state)) if hasattr(self, 'menu') and self.menu: self.on_status_messages_changed()
def __init__(self): sc.SizedDialog.__init__(self, None, -1, _('New IM'), style = wx.DEFAULT_DIALOG_STYLE | wx.FRAME_FLOAT_ON_PARENT) self.Name = 'New IM Dialog' p = self.GetContentsPane() p.SetSizerType("form") R_CENTER= dict(halign='right', valign='center') Text = lambda t: wx.StaticText(p, -1, t) Text(_('To')).SetSizerProps(**R_CENTER) toctrl = self.toctrl = wx.TextCtrl(p,style = wx.TE_PROCESS_ENTER, validator=LengthLimit(255)) toctrl.Bind(wx.EVT_KEY_DOWN,self.OnKeyDown) toctrl.SetSizerProps(expand=True) Text(_('From')).SetSizerProps(**R_CENTER) fromcombo = self.fromcombo = UberCombo(p, None, skinkey='AppDefaults.PrefCombo') fromcombo.SetItems(self.UpdateAccountItems(),0) fromcombo.SetSizerProps(expand=True) self.SetButtonSizer(self.CreateButtonSizer(wx.OK | wx.CANCEL)) sendbutton = self.sendbutton = self.FindWindowById(wx.ID_OK, self) sendbutton.SetLabel(_('IM')) sendbutton.Enable(False) sendbutton.Bind(wx.EVT_BUTTON,self.OnAccept) profile.account_manager.connected_accounts.add_observer(self.WhenOnlineAcctsChange) Bind = self.Bind Bind(wx.EVT_CLOSE,self.OnClose) Bind(wx.EVT_KEY_DOWN,self.OnKeyDown) persist_window_pos(self, defaultPos = 'center', position_only = True) self.Fit() self.SetSize((300, self.BestSize.height))
class F(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, size=(500, 55)) events = [ (wx.EVT_COMBOBOX, self.OnSelect), # (wx.EVT_TEXT,self.OnType), # (wx.EVT_TEXT_ENTER,self.OnPressEnter) ] do(self.Bind(event, method) for (event, method) in events) self.skin = 'combobox' self.uc = UberCombo( self, skinkey=self.skin, typeable=False, size=(100, 20), maxmenuheight=3, minmenuwidth=400, ) #selectioncallback=self.defaultmethodtest) items = [ SimpleMenuItem([skincore.get("statusicons.typing"), 'Test1']), SimpleMenuItem([ skincore.get("statusicons.typing"), skincore.get("statusicons.typing"), 'Test2' ]), SimpleMenuItem([ skincore.get("statusicons.typing"), skincore.get("statusicons.typing"), skincore.get("statusicons.typing"), 'Test3 followed by a long line of thext so I can see if truncating worked well or not, maybe?' ]), SimpleMenuItem(id=-1), SimpleMenuItem([ skincore.get("statusicons.typing"), skincore.get("statusicons.typing"), skincore.get("statusicons.typing"), 'Test4 cause I can' ]) ] self.uc.SetItems(items) self.ucf = UberCombo(self, skinkey=self.skin, typeable=False, size=(100, 20), maxmenuheight=10, minmenuwidth=400) #font method self.ucf.SetItems(self.DoFonts()) self.uct = UberCombo(self, value='test', skinkey=self.skin, typeable=True, valuecallback=self.ValueTest, size=(100, 20)) self.uct.AppendItem(SimpleMenuItem('Sample Item 1')) self.uct.AppendItem(SimpleMenuItem('Sample Item 2')) self.uct.AppendItem(SimpleMenuItem(id=-1)) self.uct.AppendItem(SimpleMenuItem('Sample Item 3')) sizer = wx.BoxSizer(wx.HORIZONTAL) self.SetSizer(sizer) sizer.Add(self.uc, 1, wx.EXPAND | wx.ALL, 3) sizer.Add(self.ucf, 1, wx.EXPAND | wx.ALL, 3) sizer.Add(self.uct, 1, wx.EXPAND | wx.ALL, 3) self.Fit() def DoFonts(self): fontlist = GetFonts() fontitems = [] for font in fontlist: wxfont = wx.Font(self.Font.GetPointSize(), wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, font) if font[0] != '@': fontitems.append(SimpleMenuItem([font], font=wxfont)) return fontitems def defaultmethodtest(self, item): print item.id for i in item.content: if isinstance(i, basestring): print i break def DifferentMethodTest(self, item): print 'workage!!' def CycleTest(self, button): print 'yey!' button.Parent.display.TypeField() button.Parent.display.txtfld.SetSelection(-1, -1) def OnSelect(self, event): print 'OnSelect:', event.GetInt() def OnType(self, event): print 'OnType' def OnPressEnter(self, event): print 'OnPressEnter' def ValueTest(self, value): print 'valuecallback', value
def __init__(self): wx.Frame.__init__(self, None, size=(500, 55)) events = [ (wx.EVT_COMBOBOX, self.OnSelect), # (wx.EVT_TEXT,self.OnType), # (wx.EVT_TEXT_ENTER,self.OnPressEnter) ] do(self.Bind(event, method) for (event, method) in events) self.skin = 'combobox' self.uc = UberCombo( self, skinkey=self.skin, typeable=False, size=(100, 20), maxmenuheight=3, minmenuwidth=400, ) #selectioncallback=self.defaultmethodtest) items = [ SimpleMenuItem([skincore.get("statusicons.typing"), 'Test1']), SimpleMenuItem([ skincore.get("statusicons.typing"), skincore.get("statusicons.typing"), 'Test2' ]), SimpleMenuItem([ skincore.get("statusicons.typing"), skincore.get("statusicons.typing"), skincore.get("statusicons.typing"), 'Test3 followed by a long line of thext so I can see if truncating worked well or not, maybe?' ]), SimpleMenuItem(id=-1), SimpleMenuItem([ skincore.get("statusicons.typing"), skincore.get("statusicons.typing"), skincore.get("statusicons.typing"), 'Test4 cause I can' ]) ] self.uc.SetItems(items) self.ucf = UberCombo(self, skinkey=self.skin, typeable=False, size=(100, 20), maxmenuheight=10, minmenuwidth=400) #font method self.ucf.SetItems(self.DoFonts()) self.uct = UberCombo(self, value='test', skinkey=self.skin, typeable=True, valuecallback=self.ValueTest, size=(100, 20)) self.uct.AppendItem(SimpleMenuItem('Sample Item 1')) self.uct.AppendItem(SimpleMenuItem('Sample Item 2')) self.uct.AppendItem(SimpleMenuItem(id=-1)) self.uct.AppendItem(SimpleMenuItem('Sample Item 3')) sizer = wx.BoxSizer(wx.HORIZONTAL) self.SetSizer(sizer) sizer.Add(self.uc, 1, wx.EXPAND | wx.ALL, 3) sizer.Add(self.ucf, 1, wx.EXPAND | wx.ALL, 3) sizer.Add(self.uct, 1, wx.EXPAND | wx.ALL, 3) self.Fit()
def SetContents(self, content, destroyold=False): if destroyold: if not self.contents: self.content.Destroy() for content in self.contents.values(): content.Destroy() # the currently showing pane in a multiple pane pref panel if self.content: self.content.Show(False) self.content = None self.bodysizer.Clear() contents = self.contents = {} titlemaker = self.titlemaker if self.combo is None: if not wxMac: self.combo = UberCombo(self, value='', skinkey='AppDefaults.PrefCombo', valuecallback=self.ChangeShownContent) else: # use a native ComboBox on mac self.combo = wx.ComboBox(self, style=wx.CB_DROPDOWN | wx.CB_READONLY) self.combo.Bind(wx.EVT_COMBOBOX, self.ChangeShownContent) newcombo = True else: self.combo.RemoveAllItems() newcombo = False for object in content: if isinstance(object, tuple): window, label = object elif isinstance(object, wx.WindowClass): window = object label = titlemaker(window) if titlemaker else object.Label window.Show(False) window.Reparent(self) assert window.Parent is self self.bodysizer.Add(window, 1, pref_sizer_style, 7) menuitem = SimpleMenuItem(label) contents[menuitem] = window if wxMac: itemname = menuitem.GetContentAsString() self.combo.Append(itemname) self.menuitems[itemname] = menuitem else: self.combo.AppendItem(menuitem) if self.combo: if wxMac: self.combo.SetSelection(0) self.ChangeShownContent() else: self.combo.Value = self.combo[0] if self.combo is not None and newcombo: self.headersizer.Add(self.combo, 1, *combo_sizer_flags)
def __init__(self, parent, buddy_callback, showCapabilities=True, infoboxmode=False): SimplePanel.__init__(self, parent) self.buddy_callback = buddy_callback self.Bind(wx.EVT_PAINT, lambda e: wx.PaintDC(self)) self.infoboxmode = infoboxmode self._lastcaps = None self.UpdateSkin() self.Sizer = wx.BoxSizer(wx.VERTICAL) # create delegates for callbacks for action in ('OnSendFiles', 'OnSendFolder', 'OnViewPastChats', 'OnAlert', 'OnBlock', 'OnAddContact'): setattr(self, action, Delegate()) # Create the uberbar for the capabilities. self.cbar = bar = UberBar(self, skinkey=self.capabilitiesskin, overflowmode=True) # FIXME: we should simply not allow the capabilities bar to be created for native mode if not showCapabilities or nativeIMWindow: self.cbar.Hide() if not infoboxmode: self.cbar.Bind(wx.EVT_CONTEXT_MENU, lambda e: self.ActionsBarMenu.PopupMenu(event=e)) # Create all the buttons for the capabilities bar. iconsize = skin.get('ActionsBar.IconSize') icons = skin.get('ActionsBar.Icons') for attr, title, tooltip in buttons: icon = getattr(icons, attr).Resized(iconsize) if attr == 'files': # "files" has a dropdown menu button = UberButton(bar, -1, title, icon=icon, type='menu', menu=self.FileMenu) # Change the label and action of the files button when it's overflowed into # the menu on the right. button.overflow_label = _('Send File') button.overflow_callback = self.OnSendFiles else: # hack until I fix this :[ -kevin if attr == 'video' and infoboxmode: continue button = UberButton(bar, -1, title, icon=icon) button.overflow_label = title button.SetToolTipString(tooltip) setattr(self, 'b' + attr, button) bar.Add(button, calcSize=False) bar.OnUBSize() #TODO Add button logics # if not self.infoboxmode: # self.badd = UberButton(bar,-1,'',icon = getattr(icons, 'add').Resized(iconsize)) # bar.AddStatic(self.badd) # self.badd.Bind(wx.EVT_BUTTON,lambda e: self.OnAddContact()) # Create multichat icon for the roomlist if pref('messaging.groupchat.enabled', False) and not self.infoboxmode: self.bmultichat = UberButton( bar, -1, icon=skin.get('actionsbar.icons.roomlist').Resized(16), type='toggle') self.bmultichat.SetToolTipString(_('Group Chat')) bar.AddStatic(self.bmultichat) self.ihistory = SimpleMenuItem(_('View Past Chats'), method=self.OnViewPastChats) def show_prefs_notifications(a): import gui.pref.prefsdialog as prefsdialog prefsdialog.show('notifications') self.ialert = SimpleMenuItem(_("Alert Me When..."), method=show_prefs_notifications) self.iblock = SimpleMenuItem(_("Block"), method=self.OnBlock) if not self.infoboxmode: self.iadd = SimpleMenuItem(_("Add Contact"), method=self.OnAddContact) bar.AddMenuItem(self.iadd) bar.AddMenuItem(self.ihistory) bar.AddMenuItem(self.ialert) if not self.infoboxmode: bar.AddMenuItem(SimpleMenuItem(id=-1)) bar.AddMenuItem(self.iblock) self.Sizer.Add(bar, 0, wx.EXPAND) # create the To/From bar self.tfbar = tfbar = UberBar(self, skinkey=self.tofromskin) self.tfbar.Hide() tofrom_font = skin.get('tofrombar.font', default_font) tofrom_color = skin.get('tofrombar.fontcolor', wx.BLACK) talign = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT self.to_label = ClearText(tfbar, _('To:'), alignment=talign) self.to_label.Font = tofrom_font self.to_label.FontColor = tofrom_color self.from_label = ClearText(tfbar, _('From:'), alignment=talign) self.from_label.Font = tofrom_font self.from_label.FontColor = tofrom_color self.cto = UberCombo(tfbar, skinkey=self.tofromcomboskin, typeable=False, size=(100, 20), minmenuwidth=200) self.cfrom = UberCombo(tfbar, skinkey=self.tofromcomboskin, typeable=False, size=(100, 20), minmenuwidth=200) tfbar.Add(self.to_label, calcSize=False) tfbar.Add(self.cto, True, calcSize=False) tfbar.Add(self.from_label, calcSize=False) tfbar.Add(self.cfrom, True) self.Sizer.Add(tfbar, 0, wx.EXPAND) profile.prefs.link(action_icons_key, self.UpdateIcons) self.cbar.overflowmenu.BeforeDisplay += self.ApplyCaps
class CapabilitiesBar(SimplePanel): ''' A specialized UberBar used used in the infobox and the IM window has a subbar with to/from combos. ''' def __init__(self, parent, buddy_callback, showCapabilities=True, infoboxmode=False): SimplePanel.__init__(self, parent) self.buddy_callback = buddy_callback self.Bind(wx.EVT_PAINT, lambda e: wx.PaintDC(self)) self.infoboxmode = infoboxmode self._lastcaps = None self.UpdateSkin() self.Sizer = wx.BoxSizer(wx.VERTICAL) # create delegates for callbacks for action in ('OnSendFiles', 'OnSendFolder', 'OnViewPastChats', 'OnAlert', 'OnBlock', 'OnAddContact'): setattr(self, action, Delegate()) # Create the uberbar for the capabilities. self.cbar = bar = UberBar(self, skinkey=self.capabilitiesskin, overflowmode=True) # FIXME: we should simply not allow the capabilities bar to be created for native mode if not showCapabilities or nativeIMWindow: self.cbar.Hide() if not infoboxmode: self.cbar.Bind(wx.EVT_CONTEXT_MENU, lambda e: self.ActionsBarMenu.PopupMenu(event=e)) # Create all the buttons for the capabilities bar. iconsize = skin.get('ActionsBar.IconSize') icons = skin.get('ActionsBar.Icons') for attr, title, tooltip in buttons: icon = getattr(icons, attr).Resized(iconsize) if attr == 'files': # "files" has a dropdown menu button = UberButton(bar, -1, title, icon=icon, type='menu', menu=self.FileMenu) # Change the label and action of the files button when it's overflowed into # the menu on the right. button.overflow_label = _('Send File') button.overflow_callback = self.OnSendFiles else: # hack until I fix this :[ -kevin if attr == 'video' and infoboxmode: continue button = UberButton(bar, -1, title, icon=icon) button.overflow_label = title button.SetToolTipString(tooltip) setattr(self, 'b' + attr, button) bar.Add(button, calcSize=False) bar.OnUBSize() #TODO Add button logics # if not self.infoboxmode: # self.badd = UberButton(bar,-1,'',icon = getattr(icons, 'add').Resized(iconsize)) # bar.AddStatic(self.badd) # self.badd.Bind(wx.EVT_BUTTON,lambda e: self.OnAddContact()) # Create multichat icon for the roomlist if pref('messaging.groupchat.enabled', False) and not self.infoboxmode: self.bmultichat = UberButton( bar, -1, icon=skin.get('actionsbar.icons.roomlist').Resized(16), type='toggle') self.bmultichat.SetToolTipString(_('Group Chat')) bar.AddStatic(self.bmultichat) self.ihistory = SimpleMenuItem(_('View Past Chats'), method=self.OnViewPastChats) def show_prefs_notifications(a): import gui.pref.prefsdialog as prefsdialog prefsdialog.show('notifications') self.ialert = SimpleMenuItem(_("Alert Me When..."), method=show_prefs_notifications) self.iblock = SimpleMenuItem(_("Block"), method=self.OnBlock) if not self.infoboxmode: self.iadd = SimpleMenuItem(_("Add Contact"), method=self.OnAddContact) bar.AddMenuItem(self.iadd) bar.AddMenuItem(self.ihistory) bar.AddMenuItem(self.ialert) if not self.infoboxmode: bar.AddMenuItem(SimpleMenuItem(id=-1)) bar.AddMenuItem(self.iblock) self.Sizer.Add(bar, 0, wx.EXPAND) # create the To/From bar self.tfbar = tfbar = UberBar(self, skinkey=self.tofromskin) self.tfbar.Hide() tofrom_font = skin.get('tofrombar.font', default_font) tofrom_color = skin.get('tofrombar.fontcolor', wx.BLACK) talign = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT self.to_label = ClearText(tfbar, _('To:'), alignment=talign) self.to_label.Font = tofrom_font self.to_label.FontColor = tofrom_color self.from_label = ClearText(tfbar, _('From:'), alignment=talign) self.from_label.Font = tofrom_font self.from_label.FontColor = tofrom_color self.cto = UberCombo(tfbar, skinkey=self.tofromcomboskin, typeable=False, size=(100, 20), minmenuwidth=200) self.cfrom = UberCombo(tfbar, skinkey=self.tofromcomboskin, typeable=False, size=(100, 20), minmenuwidth=200) tfbar.Add(self.to_label, calcSize=False) tfbar.Add(self.cto, True, calcSize=False) tfbar.Add(self.from_label, calcSize=False) tfbar.Add(self.cfrom, True) self.Sizer.Add(tfbar, 0, wx.EXPAND) profile.prefs.link(action_icons_key, self.UpdateIcons) self.cbar.overflowmenu.BeforeDisplay += self.ApplyCaps ToCombo = property(lambda self: self.cto) FromCombo = property(lambda self: self.cfrom) def UpdateSkin(self): 'Tells the subbars what skins they should load.' sget = skin.get self.capabilitiesskin = sget('actionsbar.toolbarskin', None) self.tofromskin = sget('tofrombar.toolbarskin', None) self.menuskin = sget('%s.menuskin' % self.capabilitiesskin, None) self.tofromcomboskin = sget("tofrombar.comboboxskin", None) self.iconsize = sget('ActionsBar.IconSize') self.icons = sget('ActionsBar.Icons') if hasattr(self, 'to_label'): tofrom_font = sget('tofrombar.font', lambda: default_font()) tofrom_color = sget('tofrombar.fontcolor', lambda: wx.BLACK) self.to_label.Font = self.from_label.Font = tofrom_font self.to_label.FontColor = self.from_label.FontColor = tofrom_color if hasattr(self, 'cbar'): self.cbar.SetSkinKey(self.capabilitiesskin) if hasattr(self, 'tfbar'): self.tfbar.SetSkinKey(self.tofromskin) if hasattr(self, 'cto'): self.cto.SetSkinKey(self.tofromcomboskin) if hasattr(self, 'cfrom'): self.cfrom.SetSkinKey(self.tofromcomboskin) self.UpdateIcons() def UpdateIcons(self, *a): 'Updates icon sizes for buttons.' icons_pref = pref(action_icons_key) textonly = icons_pref == 'text' icons = self.icons size = self.iconsize #TODO: Add Button logics # allbuttons = list(buttons) # allbuttons.append(('add','')) with self.Frozen(): for attr, title, tooltip in buttons: icon = None if textonly else getattr(icons, attr).Resized(size) button = getattr(self, 'b' + attr, None) if button is not None: button.SetIcon(icon) button.SetAlignment(wx.VERTICAL if icons_pref == 'above' else wx.HORIZONTAL) button.SetLabel('' if icons_pref == 'icons' else title) self.Parent.Layout() self.Refresh() def ShowToFrom(self, show=True): 'Show or hide the to/from bar.' return self.tfbar.Show(show) @property def RoomListButtonShown(self): bmultichat = getattr(self, 'bmultichat', None) return bmultichat is not None and bmultichat.IsShown() @property def ToFromShown(self): 'Returns True if the To/From bar is shown.' return self.tfbar.IsShown() def ShowCapabilities(self, show=True): 'Show/Hide the capabilities bar.' return self.cbar.Show(show) #self.Layout() def CapabilitiesIsShown(self): 'Returns True if the capabilities bar is shown.' return self.cbar.IsShown() def GetButton(self, button): 'Returns one of the butons by name.' return getattr(self, 'b' + button, None) def ApplyCaps(self, contact=None, convo=None): 'Those shows and hides options depending on the capabilities the Contact reports.' if contact is None and convo is None: convo = self.buddy_callback() from common.Conversation import Conversation if not isinstance(convo, Conversation): contact = convo convo = None c = None if convo is not None: if convo.ischat: c = set([caps.IM]) elif contact is None: contact = convo.buddy if c is None: c = set(contact.caps) if contact is not None: c.add(('blocked', contact.blocked)) # early exit if capabilities are the same. if c == self._lastcaps: return buttons_caps = [('binfo', contact is not None and not any( (contact.sms and contact.mobile, self.infoboxmode))), ('bim', caps.IM in c), ('bfiles', caps.FILES in c), ('bemail', caps.EMAIL in c), ('bsms', caps.SMS in c), ('bvideo', caps.VIDEO in c)] for name, val in buttons_caps: ctrl = getattr(self, name, None) if ctrl is not None: ctrl.Show(ctrl, val, False) cbar = self.cbar menu = cbar.overflowmenu count = menu.spine.items.count iblock = self.iblock if caps.BLOCKABLE in c and not count(iblock): cbar.AddMenuItem(SimpleMenuItem(id=-1)) cbar.AddMenuItem(iblock) elif not caps.BLOCKABLE in c and count(iblock): cbar.overflowmenu.RemoveItem(iblock) if contact is not None: if contact.blocked: content = _('Unblock {name}') else: content = _('Block {name}') iblock.content = [content.format(name=contact.name)] self.set_groupchat_visibility(contact, convo) i = len(menu.spine.items) - 1 if menu.GetItem(i).id == -1: menu.RemoveItem(i) # don't show the dropdown on the right for widgets. self.cbar.overflowbutton.Show(not getattr(contact, 'iswidget', False)) self._lastcaps = c cbar.GenWidthRestriction(True) self.update_add_contact_shown(convo) self.Parent.Layout() def update_add_contact_shown(self, convo): if not hasattr(self, 'iadd'): return ischat = convo is not None and convo.ischat overflow = self.cbar.overflowmenu if ischat: if overflow.GetIndex(self.iadd) != -1: overflow.RemoveItem(self.iadd) else: if overflow.GetIndex(self.iadd) == -1: overflow.InsertItem(overflow.GetIndex(self.ihistory), self.iadd) def set_groupchat_visibility(self, contact, convo): if not hasattr(self, 'bmultichat'): return proto = getattr(contact, 'protocol', getattr(convo, 'protocol', None)) groupchat = False if proto is not None: groupchat = getattr(proto, 'supports_group_chat', False) and getattr( contact, 'supports_group_chat', False) self.bmultichat.Show(groupchat) @property def FileMenu(self): self._filemenu = SimpleMenu(self, self.menuskin) self.send_file_item = SimpleMenuItem(_('Send File'), lambda *a: self.OnSendFiles()) # if b and b.online: self._filemenu.AppendItem(self.send_file_item) self._filemenu.AppendItem( SimpleMenuItem(_('Transfer History'), lambda *a: FileTransferDialog.Display())) return self._filemenu # try: # return self._filemenu # except AttributeError: # self._filemenu = self.build_file_menu() # return self._filemenu @property def ActionsBarMenu(self): try: return self._actionsbarmenu except AttributeError: self._actionsbarmenu = self.build_actionsbar_menu() return self._actionsbarmenu def build_actionsbar_menu(self): m = UMenu(self, onshow=self.update_actionsbar_menu) c = self._actionsbar_checks = {} for name, label in [('icons', _('Icons Only')), ('text', _('Text Only')), ('next', _('Icons Next to Text')), ('above', _('Icons Above Text'))]: def cb(name=name): with self.Frozen(): setpref(action_icons_key, name) c[name] = m.AddCheckItem(label, callback=cb) m.AddSep() m.AddItem( _('Hide Actions Bar'), callback=lambda: setpref('messaging.show_actions_bar', False)) return m def update_actionsbar_menu(self, menu): p = pref(action_icons_key) for name, item in self._actionsbar_checks.iteritems(): item.Check(p == name)
class PrefPanel(SimplePanel): def __init__(self, parent, content=None, title='', buttonlabel='', buttoncb=None, titlemaker=None, prefix=''): SimplePanel.__init__(self, parent, wx.FULL_REPAINT_ON_RESIZE) sizer = self.Sizer = BoxSizer(VERTICAL) self.headersizer = BoxSizer(HORIZONTAL) self.bodysizer = BoxSizer(VERTICAL) sizer.Add(self.headersizer, 0, EXPAND | TOP, space_over_header) sizer.Add(self.bodysizer, 1, EXPAND | TOP, space_under_header) self.title = None self.combo = None self.button = None self.content = None self.contents = {} self.titlemaker = titlemaker if wxMac: self.menuitems = {} if title and isinstance(title, basestring): self.title = wx.StaticText(self, -1, ' ' + title + ' ', style=wx.ALIGN_CENTER_VERTICAL) #need grey backgound behind label on mac to hide the line if wxMac: self.title.BackgroundColour = wx.Color(232, 232, 232) self.title.Font = self.HeaderFont self.headersizer.Add(self.title, 0, *header_sizer_flags) if callable(content): content = self.content = content(self, prefix) self.bodysizer.Add(self.content, 1, pref_sizer_style, 7) elif isinstance(content, wx.WindowClass): content.Reparent(self) self.content = content self.bodysizer.Add(self.content, 1, pref_sizer_style, 7) elif isinstance(content, list): self.SetContents(content) if buttoncb: self.SetButton(buttonlabel, buttoncb) Bind = self.Bind Bind(wx.EVT_PAINT, self.OnPaint) #darker border if mac so it is visible for now if not wxMac: self.pen = wx.Pen(wx.Colour(213, 213, 213)) else: self.pen = wx.Pen(wx.Colour(155, 155, 155)) def SetTitle(self, title): self.title.SetLabel(title) @property def HeaderFont(self): try: return self._headerfont except AttributeError: if not wxMac: PrefPanel._headerfont = makeFont('arial 8 bold') else: PrefPanel._headerfont = makeFont('9 bold') return self._headerfont _fg_brush = \ _bg_brush = \ _fg_pen = \ _bg_pen = lambda self: None def get_bg_brush(self): return self._bg_brush() or wx.WHITE_BRUSH def get_fg_brush(self): return self._fg_brush() or wx.TRANSPARENT_BRUSH def get_bg_pen(self): return self._bg_pen() or wx.TRANSPARENT_PEN def get_fg_pen(self): return self._fg_pen() or self.pen bg_brush = property(get_bg_brush) fg_brush = property(get_fg_brush) bg_pen = property(get_bg_pen) fg_pen = property(get_fg_pen) def OnPaint(self, event): size = self.Size dc = AutoDC(self) if not wxMac: # Non mac: white background, rounded rectangle around controls rect = wx.RectS(size) dc.Brush = self.bg_brush #background dc.Pen = self.bg_pen #background border dc.DrawRectangleRect(rect) ypos = self.headersizer.Size.height // 2 + space_over_header gc = wx.GraphicsContext.Create(dc) gc.SetBrush(self.fg_brush) #foreground gc.SetPen(self.fg_pen) #foreground gc.DrawRoundedRectangle(0, ypos, size.width - 1, size.height - ypos - 1, 5) else: # Mac: normal grey background, horizontal line above controls ypos = self.headersizer.Size.height // 2 + space_over_header + 2 dc.Pen = self.fg_pen button_width = 0 if self.button is None else ( self.button.Size.width) dc.DrawLine(10, ypos, self.headersizer.Size.width - 10 - button_width, ypos) content = self.content if isinstance(content, AnyList): # TODO: don't special case crect = wx.Rect(*content.Rect) crect = crect.Inflate(1, 1) dc.SetBrush(wx.TRANSPARENT_BRUSH) dc.SetPen(self.pen) dc.DrawRectangleRect(crect) def ChangeShownContent(self, *a): if self.content: self.content.Show(False) if wxMac: menu_item = self.menuitems[self.combo.GetStringSelection()] else: menu_item = self.combo.Value self.content = self.contents[menu_item] self.content.Show(True) self.Layout() def SetButton(self, label, callback): if self.button: self.headersizer.Detach(self.button) self.button.Destroy() # native button on mac instead of the vista clone button if not wxMac: self.button = UberButton(self, -1, label, skin='AppDefaults.PrefButton') else: self.button = wx.Button(self, -1, label) self.button.SetWindowVariant(wx.WINDOW_VARIANT_SMALL) self.button.Bind(wx.EVT_BUTTON, lambda e: callback(self.button)) self.headersizer.AddStretchSpacer(1) self.headersizer.Add(self.button, 0, wx.ALIGN_CENTER_VERTICAL | RIGHT, 7) @property def MenuItems(self): combo = self.combo if wxMac: return [combo.GetClientData(i) for i in xrange(combo.Count)] else: return combo.menu.spine.items def SetContents(self, content, destroyold=False): if destroyold: if not self.contents: self.content.Destroy() for content in self.contents.values(): content.Destroy() # the currently showing pane in a multiple pane pref panel if self.content: self.content.Show(False) self.content = None self.bodysizer.Clear() contents = self.contents = {} titlemaker = self.titlemaker if self.combo is None: if not wxMac: self.combo = UberCombo(self, value='', skinkey='AppDefaults.PrefCombo', valuecallback=self.ChangeShownContent) else: # use a native ComboBox on mac self.combo = wx.ComboBox(self, style=wx.CB_DROPDOWN | wx.CB_READONLY) self.combo.Bind(wx.EVT_COMBOBOX, self.ChangeShownContent) newcombo = True else: self.combo.RemoveAllItems() newcombo = False for object in content: if isinstance(object, tuple): window, label = object elif isinstance(object, wx.WindowClass): window = object label = titlemaker(window) if titlemaker else object.Label window.Show(False) window.Reparent(self) assert window.Parent is self self.bodysizer.Add(window, 1, pref_sizer_style, 7) menuitem = SimpleMenuItem(label) contents[menuitem] = window if wxMac: itemname = menuitem.GetContentAsString() self.combo.Append(itemname) self.menuitems[itemname] = menuitem else: self.combo.AppendItem(menuitem) if self.combo: if wxMac: self.combo.SetSelection(0) self.ChangeShownContent() else: self.combo.Value = self.combo[0] if self.combo is not None and newcombo: self.headersizer.Add(self.combo, 1, *combo_sizer_flags)
def __init__(self,parent): SimplePanel.__init__(self, parent, wx.FULL_REPAINT_ON_RESIZE) self.BackgroundColour = wx.WHITE self.Sizer = wx.BoxSizer(HORIZONTAL) sz = wx.BoxSizer(HORIZONTAL) self.Sizer.Add(sz,1,EXPAND|ALL,3) leftcol = wx.BoxSizer(VERTICAL) acctcombo = self.acctcombo = UberCombo(self, value='',skinkey='AppDefaults.PrefCombo') acctcont = PrefPanel(self,acctcombo,_('Account')) leftcol.Add(acctcont,0,EXPAND|ALL,3) buddylist = self.buddylist = ListOBuddies(self) self.buddies_panel = buddycont = PrefPanel(self, buddylist, _('Buddy')) leftcol.Add(buddycont, 1, EXPAND | TOPLESS, 3) style = wx.NO_BORDER | CAL_SUNDAY_FIRST | CAL_SEQUENTIAL_MONTH_SELECTION | CAL_SHOW_HOLIDAYS cal = self.cal = CalendarCtrl(self, -1, wx.DateTime.Now(), wx.DefaultPosition, wx.DefaultSize, style) cal.SetForegroundColour(wx.Color(160, 160, 160)) cal.SetHolidayColours(wx.BLACK, wx.WHITE) cal.SetHeaderColours(Color(160, 160, 160), Color(239, 239, 239)) calcont = PrefPanel(self,cal,_('Date')) leftcol.Add(calcont, 0, EXPAND | TOPLESS, 3) sz.Add(leftcol, 0, EXPAND) viewpanel = wx.Panel(self) viewer = self.viewer = PastBrowserWebkitWindow(viewpanel) # viewer.SetMouseWheelZooms(True) finder = self.finder = FindBar(viewpanel,viewer) menu = UMenu(viewer) menu.AddItem(_('Copy'), id = wx.ID_COPY, callback = lambda *a: viewer.Copy()) viewer.BindWheel(self) viewer.BindScrollWin(self) viewer.Bind(wx.EVT_CONTEXT_MENU, lambda e: (menu.GetItemById(wx.ID_COPY).Enable(viewer.CanCopy()), menu.PopupMenu(event = e))) viewer.Bind(wx.EVT_KEY_DOWN,self.OnKeyDown) finder.TextControl.Bind(wx.EVT_KEY_DOWN,self.OnKeyDown) nav = BoxSizer(wx.HORIZONTAL) prev = self.prev = UberButton(viewpanel, label = '<-', skin = BUTTON_SKIN) next = self.next = UberButton(viewpanel, label = '->', skin = BUTTON_SKIN) datelabel = wx.StaticText(viewpanel, -1, style = wx.ALIGN_CENTER| wx.ST_NO_AUTORESIZE) datelabel.SetMinSize((140, -1)) prev.Bind(wx.EVT_BUTTON, lambda e: self.Flip(-1)) next.Bind(wx.EVT_BUTTON, lambda e: self.Flip( 1)) nav.AddStretchSpacer(1) nav.AddMany([(prev, 0, wx.EXPAND | wx.ALIGN_CENTER), (datelabel, 0, wx.EXPAND | wx.ALIGN_CENTER), (next, 0, wx.EXPAND | wx.ALIGN_CENTER)]) nav.AddStretchSpacer(1) viewpanel.Sizer = wx.BoxSizer(wx.VERTICAL) viewpanel.Sizer.AddMany([ (nav, 0, EXPAND), (viewer, 1, EXPAND), (finder, 0, EXPAND) ]) sz.Add(PrefPanel(self, viewpanel, _('Conversation Log')), 1, EXPAND | ALL, 3) Bind = self.Bind Bind(wx.EVT_PAINT, self.OnPaint) def OnAcct(*a): ''' Handle selection of a new account from the Account drop down ''' if self.GroupChatsSelected(): from collections import defaultdict self.groupchats = defaultdict(list) for g in GetGroupChats(): d = g['time'] key = DateTimeFromDMY(d.day, d.month-1, d.year) self.groupchats[key].append(g) #dates = sorted((g['date'], g) for g in self.dates = sorted(self.groupchats.keys()) UpdateCal() self.buddies_panel.SetTitle(_('Chats')) else: buddylist.SetList(GetBuddies(acctcombo.Value.id), BuddyRenderer()) OnBuddy() self.buddies_panel.SetTitle(_('Buddy')) def OnBuddy(*a): ''' Handels selection of a buddy from the buddy pannel ''' if not self.GroupChatsSelected(): self.dates = GetDates(buddylist.SelectedBuddy.dir) UpdateCal() else: ViewLogForFile(buddylist.SelectedItem['file'], do_aliases=False) def UpdateCal(): ''' Switches the date to the last date conversed with the selected budy ''' self.next.Enable(True) self.prev.Enable(True) if self.dates: self.cal.Date = self.dates[-1] self.cal.Enable(True) OnCalChange() def OnCalChange(*a): ''' Update the Calendar UI to a new date ''' caldate = cal.Date currentyear = caldate.GetYear() currentmonth = caldate.GetMonth() relevantdates = frozenset(date.GetDay() for date in self.dates if date.GetYear() == currentyear and date.GetMonth() == currentmonth and date.GetDay()) SetHoliday, SetAttr = cal.SetHoliday, cal.SetAttr for i in xrange(1, 32): if i in relevantdates: SetHoliday(i) else: SetAttr(i, CalendarDateAttr(Color(160,160,160))) OnDayChange() self.OnCalChange = OnCalChange def ViewLogForDay(date): ''' Load the log file for the specified date for the currently selected buddy ''' logpath = logpath_for_date(buddylist.SelectedBuddy, date) ViewLogForFile(logpath) def ViewLogForFile(logpath, do_aliases=True): ''' Update the log viewer with the file specified ''' with viewer.Frozen(): viewer.SetPageSource(logpath.text('utf-8', 'replace'), logpath.url()) viewer.RunScript('window.scroll(0, 0);') if do_aliases: substitue_aliases() import hooks hooks.notify('digsby.statistics.logviewer.log_viewed') def substitue_aliases(): ''' Swap out buddy names with their allies ''' import gui with open(gui.skin.resourcedir() / 'html' / 'jquery-1.3.2.js', 'rb') as f: viewer.RunScript(f.read()) buddy = buddylist.SelectedBuddy aliases = IAliasProvider(profile()) import simplejson as json names = set(json.loads(viewer.RunScript("var foo = []; $('.buddy').each(function(){foo.push($(this).html())}); JSON.stringify(foo);"))) for name in names: alias = aliases.get_alias(name, buddy.service, buddy.protocol) or name viewer.RunScript(SUBHTML % (json.dumps(name), json.dumps(alias))) def OnDayChange(*a): ''' Show the log for the day selected in the clander ''' date = cal.Date self.date = date datelabel.SetLabel(date.FormatDate()) if cal.GetAttr(date.GetDay()).IsHoliday(): if self.GroupChatsSelected(): chats = sorted(self.groupchats[date], key=lambda g: g['time'], reverse=True) buddylist.SetList(chats, GroupChatRenderer()) if chats: ViewLogForFile(chats[0]['file'], do_aliases=False) else: ViewLogForDay(date) else: year = str(date.GetYear()) month = date.GetMonth() month = wx.DateTime.GetMonthName(int(month)) day = str(date.GetDay()) specific_day_string = _('{month}, {day}, {year}').format(month=month, day=day, year=year) if self.GroupChatsSelected(): msg = _("There are no chat logs for {specific_day_string}.").format(specific_day_string=specific_day_string) else: msg = _("There are no chat logs for {specific_day_string} with {name}.").format(specific_day_string=specific_day_string, name=buddylist.SelectedBuddy.name) viewer.SetPageSource(msg, 'file:///C:/') viewer.SetFocus() wx.CallAfter(cal.Refresh) self.OnDayChange = OnDayChange acctcombo.SetCallbacks(value = OnAcct) buddylist.Bind(wx.EVT_LISTBOX, OnBuddy) cBind = cal.Bind cBind(EVT_CALENDAR_YEAR, OnCalChange) cBind(EVT_CALENDAR_MONTH, OnCalChange) cBind(EVT_CALENDAR_SEL_CHANGED, OnDayChange) acctcombo.SetItems(MakeAccountItems(), 0)
def __init__(self, parent, buddylist, statuses, get_status_method=get_profile_status, set_status_method=set_profile_status): ''' StatusCombo constructor. parent - a wx.Window parent window statuses - an observable list of StatusMessage objects ''' self.buddylist = buddylist self.buddylist.Bind(wx.EVT_KEY_DOWN, self.on_buddylist_key) self.searching = False self.searchHintShown = False if not getattr(StatusCombo, 'searchThresholdRegistered', False) and pref('search.buddylist.show_hint', True): def SearchThresholdReached(*a, **k): if pref('search.buddylist.show_hint', True): setpref('search.buddylist.show_hint', False) Hook('digsby.achievements.threshold', 'buddylist.search').register(SearchThresholdReached) StatusCombo.searchThresholdRegistered = True self.offline_item = None self.get_profile_status = get_status_method self.set_profile_status = set_status_method status = self.get_profile_status() UberCombo.__init__(self, parent, skinkey='combobox', typeable=True, valuecallback=self.on_text_lose_focus, empty_text=getattr(status, 'hint', status.title.title()), maxmenuheight=15) self.buttoncallback = self.on_status_button self.cbutton = UberButton(self, -1, skin=self.cbuttonskin) self.cbutton.Bind(wx.EVT_BUTTON, self._on_left_button) self.content.Insert(0, self.cbutton, 0, wx.EXPAND) self.cbutton.BBind(RIGHT_UP=self.on_status_button_right_click, LEFT_DOWN=self.on_status_button_left_click, LEFT_UP=self.on_status_button_left_up) self.display.Bind( wx.EVT_LEFT_DOWN, lambda e: (e.Skip(), setattr(self, 'oldValue', self.Value))) # the on_allow_status_changes method is called when the list of connected # im accounts changes size. if all accounts are offline this control # becomes disabled.. #profile.account_manager.connected_accounts.add_observer(self.on_allow_status_changes) profile.account_manager.connected_accounts.add_observer( self.on_offline_allowed, obj=self) # Listen on status messages (changes, additions, deletes). _obs_link = statuses.add_list_observer(self.on_status_messages_changed, self.on_status_messages_changed) self.Bind( wx.EVT_WINDOW_DESTROY, lambda e: (log.info('status combo removing observers'), e.Skip(), _obs_link.disconnect())) self.on_status_messages_changed(statuses) # when the profile's status changes, update to reflect it profile.add_observer(self.on_profile_status_changed, 'status') # Display the current status. self.show_status(self.get_profile_status()) # Timer for committing status messages after a delay. self.timer = wx.PyTimer(self.SetFocus) self.Bind(wx.EVT_TEXT, self.on_typing) self.button_timer = wx.PyTimer(self.on_status_button_right_click) textbind = self.TextField.Bind textbind(wx.EVT_SET_FOCUS, lambda e: setattr(self, 'skipenter', False)) textbind(wx.EVT_KEY_DOWN, self._on_key_down) textbind(wx.EVT_TEXT_ENTER, self._on_enter) self.DropDownButton.Bind(wx.EVT_LEFT_DOWN, self._dbutton_left) self.OnActivateSearch = Delegate() self.OnDeactivateSearch = Delegate()
def __init__(self, parent=None, group='', onservice='', newname='', onaccount=None): sc.SizedDialog.__init__(self, parent, -1, _('Add Contact'), size=(314, 250), style=wx.DEFAULT_DIALOG_STYLE | wx.FRAME_FLOAT_ON_PARENT | wx.RESIZE_BORDER) #S = self.Sizer = wx.BoxSizer(VERTICAL) p = self.panel = self.GetContentsPane() #wx.Panel(self) p.SetSizerType("form") self.SetButtonSizer(self.CreateButtonSizer(wx.OK | wx.CANCEL)) okbutton = self.okbutton = self.FindWindowById( wx.ID_OK, self) #wx.Button(p, wx.ID_OK, _('Add')) okbutton.SetLabel(_('Add')) okbutton.SetDefault() okbutton.Enabled = False cancelbutton = self.FindWindowById( wx.ID_CANCEL, self) #wx.Button(p,wx.ID_CANCEL, _('Cancel')) #================================================================= protoitems = self.MakeProtocolItems() groupitems = self.MakeGroupItems() Text = lambda s: wx.StaticText(p, -1, s) #========================================================================================================= R_CENTER = dict(halign='right', valign='center') Text(_('Contact Type:')).SetSizerProps(**R_CENTER) protocombo = self.protocombo = UberCombo( p, no_connections_label, False, None, skinkey='AppDefaults.PrefCombo') protocombo.SetSizerProps(expand=True) namelabel = self.namelabel = Text(_('Screen Name:')) namelabel.SetSizerProps(**R_CENTER) name = self.namefield = wx.TextCtrl(p, validator=LengthLimit(255), value=newname) name.SetFocus() name.Bind(wx.EVT_TEXT, self.OnNameChange) name.SetSizerProps(expand=True) Text(_('Alias:')).SetSizerProps(**R_CENTER) alias = self.aliasfield = wx.TextCtrl(p, validator=LengthLimit(255)) alias.SetSizerProps(expand=True) Text(_('In Group:')).SetSizerProps(**R_CENTER) groupcombo = self.groupcombo = UberCombo( p, group, True, None, skinkey='AppDefaults.PrefCombo') groupcombo.display.txtfld.Bind(wx.EVT_TEXT, self.OnNameChange) groupcombo.SetSizerProps(expand=True) Text(_('On Accounts:')).SetSizerProps(halign='right', valign='top') checklist = self.accountchecks = CheckableList( p, setchangedcallback=self.OnCheckedSetChange) checklist.MinSize = (-1, 66) checklist.SetSizerProps(expand=True, proportion=1) #========================================================================================================== defserv = 0 if onservice: for item in protoitems: if item.id == onservice: defserv = protoitems.index(item) break protocombo.SetItems(protoitems, defserv) groupcombo.SetItems(groupitems, 0 if group == '' else None) #=========================================================================================================== def onproto(*a): self.UpdateAccounts() name.SetFocus() protocombo.SetCallbacks(value=onproto) self.UpdateAccounts() if onaccount is not None: checklist.SelectAccount(onaccount) def NoEmptyGroup(*a): if groupcombo.Value == '': groupcombo.SetSelection(0) if groupcombo.Value == '': groupcombo.Value = pref('buddylist.fakeroot_name', default='Contacts') groupcombo.SetCallbacks(value=NoEmptyGroup) self.Fit() self.Size = (314, self.Size.y) self.MinSize = self.Size okbutton.Bind(wx.EVT_BUTTON, self.OnOk) cancelbutton.Bind(wx.EVT_BUTTON, lambda e: self.Close()) Bind = self.Bind Bind(wx.EVT_CLOSE, self.OnClose) profile.account_manager.connected_accounts.add_observer( self.WhenOnlineAcctsChange) profile.blist.add_observer(self.WhenGroupsChange, 'view') import hooks hooks.notify('digsby.statistics.ui.dialogs.add_contact.created')
def __init__(self, parent, buddylist, statuses, get_status_method = get_profile_status, set_status_method = set_profile_status): ''' StatusCombo constructor. parent - a wx.Window parent window statuses - an observable list of StatusMessage objects ''' self.buddylist = buddylist self.buddylist.Bind(wx.EVT_KEY_DOWN, self.on_buddylist_key) self.searching = False self.searchHintShown = False if not getattr(StatusCombo, 'searchThresholdRegistered', False) and pref('search.buddylist.show_hint', True): def SearchThresholdReached(*a, **k): if pref('search.buddylist.show_hint', True): setpref('search.buddylist.show_hint', False) Hook('digsby.achievements.threshold', 'buddylist.search').register(SearchThresholdReached) StatusCombo.searchThresholdRegistered = True self.offline_item = None self.get_profile_status = get_status_method self.set_profile_status = set_status_method status = self.get_profile_status() UberCombo.__init__(self, parent, skinkey = 'combobox', typeable = True, valuecallback = self.on_text_lose_focus, empty_text=getattr(status, 'hint', status.title.title()), maxmenuheight = 15) self.buttoncallback = self.on_status_button self.cbutton = UberButton(self, -1, skin=self.cbuttonskin) self.cbutton.Bind(wx.EVT_BUTTON, self._on_left_button) self.content.Insert(0,self.cbutton, 0, wx.EXPAND) self.cbutton.BBind(RIGHT_UP = self.on_status_button_right_click, LEFT_DOWN = self.on_status_button_left_click, LEFT_UP = self.on_status_button_left_up) self.display.Bind(wx.EVT_LEFT_DOWN, lambda e: (e.Skip(), setattr(self, 'oldValue', self.Value))) # the on_allow_status_changes method is called when the list of connected # im accounts changes size. if all accounts are offline this control # becomes disabled.. #profile.account_manager.connected_accounts.add_observer(self.on_allow_status_changes) profile.account_manager.connected_accounts.add_observer(self.on_offline_allowed, obj = self) # Listen on status messages (changes, additions, deletes). _obs_link = statuses.add_list_observer(self.on_status_messages_changed, self.on_status_messages_changed) self.Bind(wx.EVT_WINDOW_DESTROY, lambda e: (log.info('status combo removing observers'), e.Skip(), _obs_link.disconnect())) self.on_status_messages_changed(statuses) # when the profile's status changes, update to reflect it profile.add_observer(self.on_profile_status_changed, 'status') # Display the current status. self.show_status(self.get_profile_status()) # Timer for committing status messages after a delay. self.timer = wx.PyTimer(self.SetFocus) self.Bind(wx.EVT_TEXT, self.on_typing) self.button_timer = wx.PyTimer(self.on_status_button_right_click) textbind = self.TextField.Bind textbind(wx.EVT_SET_FOCUS, lambda e: setattr(self, 'skipenter', False)) textbind(wx.EVT_KEY_DOWN, self._on_key_down) textbind(wx.EVT_TEXT_ENTER, self._on_enter) self.DropDownButton.Bind(wx.EVT_LEFT_DOWN, self._dbutton_left) self.OnActivateSearch = Delegate() self.OnDeactivateSearch = Delegate()