Esempio n. 1
0
    def ApplyFrom(self):
        frm = self.fromcombo
        accts = [a for a in profile.emailaccounts if a.enabled]

        #TODO: UberCombo doesn't store items :(

        def sel(item, acct):
            frm.ChangeValue(item)
            self.OnEmailAccountChanged(acct)
            self.acct = acct

        # Create menu items for each enabled email account.
        fitems = self.from_menu_items = []
        for a in accts:
            item = SimpleMenuItem(emailacct_menu_content(a),
                                  method=lambda item, a=a: sel(item, a))
            item.acct = a
            fitems.append(item)

        # Add extra account managment items.
        items = list(fitems)

        if len(fitems):
            items.append(SimpleMenuItem(id=-1))  # separator

        items.append(SimpleMenuItem(_('Add Email Account'), menu=self.addList))
        items.append(self.accounts_item)

        self.fromcombo.SetCallbacks(None, None)
        self.fromcombo.SetItems(items)

        if accts:
            try:
                i = accts.index(getattr(self, 'acct', None))
            except ValueError:
                i = 0

            sel(fitems[i], accts[i])
        else:
            self.fromcombo.ChangeValue('')
            self.OnEmailAccountChanged(None)
Esempio n. 2
0
    def __init__(self):
        wx.Frame.__init__(self, None, wx.NewId(), "UberBar Overflow sampler",
                          (0, 0), (600, 150))

        content = wx.BoxSizer(wx.VERTICAL)

        self.skin = 'buttonbar'  #None#

        self.ubar = UberBar(self,
                            skinkey=self.skin,
                            overflowmode=True,
                            alignment=wx.ALIGN_LEFT)
        self.b1 = UberButton(self.ubar, -1, 'Button 1')
        self.b2 = UberButton(self.ubar, -1, 'Button 2')
        self.bi = UberButton(self.ubar, -1, 'Button i')
        self.b3 = UberButton(self.ubar, -1, 'Button 3')
        self.b4 = UberButton(self.ubar, -1, 'Button 4')
        self.ubar.Add(self.b1)
        self.ubar.Add(self.b2)
        self.ubar.Add(self.bi)
        self.ubar.Add(self.b3)
        self.ubar.Add(self.b4)

        #        self.b1.Show(self.b1,False)
        self.bi.Show(self.bi, False)

        self.ubar.AddMenuItem(SimpleMenuItem('Menu Item 1'))
        self.ubar.AddMenuItem(SimpleMenuItem('Menu Item 2'))
        self.ubar.AddMenuItem(SimpleMenuItem('Menu Item 3'))

        self.b4 = UberButton(self.ubar,
                             -1,
                             icon=wx.Bitmap(
                                 resdir / 'skins/default/digsbybig.png',
                                 wx.BITMAP_TYPE_PNG))
        self.ubar.AddStatic(self.b4)

        content.Add(self.ubar, 0, wx.EXPAND, 0)
        self.SetSizer(content)
Esempio n. 3
0
    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()))
        ]
Esempio n. 4
0
    def OnValueLater(self, val):

        # This method is called when the editable part of the combo loses focus.
        # - if the combo is on screen, the user hit enter or otherwise caused this to happen.
        #   in this case, perform validation and display an error dialog if the validation fails
        # - otherwise, maybe another app stole focus--some external event cause this to happen
        #   popping up a modal dialog would be bad, so just return the value to what it was before

        if val == '' or not self.combo.IsShown(
        ) or not self.combo.Top.IsActive():

            LOG(
                "Val: %s\nCombo is ShownOnScreen: %s\nTop level parent is Active: %s",
                val, self.combo.IsShownOnScreen(),
                not self.combo.Top.IsActive())

            if val == '': LOG('empty string, selection is %s', self.selection)
            else:
                LOG('combo not on screen, falling back to %s', self.selection)

            # Restore the combo's value.
            if self.combo.Top.IsActive():
                self.OnLoseFocus()
            return self.combo.ChangeValue(self.menu_items[
                self.selection] if self.selection != -1 else self.default)

        val = self.add_cb(val)

        if val is None:
            self.combo.EditValue()
        else:
            LOG('add_cb returned True')

            self.seq.append(val)
            self.menu_items.append(SimpleMenuItem(self.content_cb(val)))
            self.remove_menu.AppendItem(SimpleMenuItem(self.content_cb(val)))
            self.selection = len(self.menu_items) - 1
            self.Apply()
Esempio n. 5
0
    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)
Esempio n. 6
0
    def update_items(self):
        # get list of SMS numbers for our contact
        sms = self.get_contact_sms()

        if self.contact_sms:
            self.sms_item = SimpleMenuItem([self.contact_sms])
        else:

            # obtain a "best choice" SMS number
            best_sms, best_acct = self.blist.get_tofrom_sms(self.info_key)

            self.to_editor.EditList(sms,
                                    best_sms,
                                    add_cb=self.OnAddSMS,
                                    remove_cb=self.OnRemoveSMS)
Esempio n. 7
0
    def Apply(self):
        items = list(self.menu_items)  # Normal Items

        if len(self.menu_items):
            items.append(SimpleMenuItem(id=-1)),  # ---- a separator

        items.append(self.add_item)  # Add

        if len(self.menu_items):
            items.append(
                self.remove_item)  # Remove (if there are items to remove)

        combo = self.combo
        combo.SetCallbacks(selection=self.OnComboSelection, value=self.OnValue)
        combo.menu.SetItems(items)

        newval = self.menu_items[self.selection] if len(
            self.menu_items) and self.selection != -1 else self.default
        combo.ChangeValue(newval)
Esempio n. 8
0
    def show_extended_status_menu(self):
        from gui.status import get_state_choices

        m = SimpleMenu(self, skinkey=skin.get('%s.MenuSkin' % self.skinkey))

        for status in get_state_choices():
            statusname, statuslabel = status

            def onclick(item, state=statusname):
                self.change_state(
                    state
                )  #, change_text = self.status_state == self.GetValue())

            m.AppendItem(
                SimpleMenuItem(
                    [StatusMessage.icon_for(statusname), statuslabel],
                    method=onclick))

        if m.GetCount() > 0:
            m.Display(self.cbutton)
Esempio n. 9
0
    def EditList(self,
                 seq,
                 selected_item=None,
                 add_cb=None,
                 remove_cb=None,
                 default=''):

        self.default = default

        if add_cb is not None: self.add_cb = add_cb
        if remove_cb is not None: self.remove_cb = remove_cb

        assert isinstance(seq, list), repr(list)
        self.seq = list(seq)
        self.menu_items = [SimpleMenuItem(self.content_cb(i)) for i in seq]
        self.remove_menu.SetItems(list(self.menu_items))

        if selected_item is not None:
            self.selection = seq.index(selected_item)
        else:
            self.selection = -1 if len(seq) == 0 else 0
Esempio n. 10
0
    def UpdateAccountItems(self):

        if not hasattr(self,'acctitems'):
            self.acctitems = oset()

        acctitems = self.acctitems

        accounts = oset(profile.account_manager.connected_accounts)
        accts    = set(item.id for item in acctitems)

        newaccts = accounts - accts
        oldaccts = accts - accounts

        for item in set(acctitems):
            if item.id in oldaccts:
                acctitems.remove(item)

        for account in newaccts:
            if account.allow_contact_add:
                acctitems.add(SimpleMenuItem([account.serviceicon.Resized(16),account.username],id = account))


        return list(acctitems)
Esempio n. 11
0
 def GenSizeItems(self, sizes = DEFAULT_SIZES):
     """
         Sets the list of selectable sizes
         If not set sizes default to ['8', '10', '12', '14', '18', '24', '36']
     """
     return [SimpleMenuItem([str(size)], id=size, method = self.OnSizeSelected) for size in sizes]
Esempio n. 12
0
def buddy_menu_item(buddy):
    'Return a menu item object for a "To" buddy.'

    return SimpleMenuItem(buddy_menucontent(buddy))
Esempio n. 13
0
    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()
Esempio n. 14
0
def account_menu_item(acct):
    'Return a menu item object for a "From" account.'

    return SimpleMenuItem(account_menucontent(acct))
Esempio n. 15
0
    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
Esempio n. 16
0
    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()
Esempio n. 17
0
 def additem(self, *a, **k):
     i = SimpleMenuItem(*a, **k)
     self.AppendItem(i)
     return i
Esempio n. 18
0
    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)
Esempio n. 19
0
    def __init__(self):
        wx.Frame.__init__(self,None,title='Extended Simple Menu Test')
        self.panel=wx.Panel(self)

        self.panel.Sizer=wx.BoxSizer(wx.VERTICAL)


        menu=SimpleMenu(self, 'simplemenu',width=100)
        submenu=SimpleMenu(menu, 'simplemenu',width=100)
        submenu2=SimpleMenu(submenu, 'simplemenu',width=100)

        subitems=[
            SimpleMenuItem('Test5'),
            SimpleMenuItem(id=-1),
            SimpleMenuItem('Test6'),
            SimpleMenuItem('Test7',menu=submenu2),
            SimpleMenuItem('Test8')
        ]

        submenu.SetItems(subitems)

        items=[
            SimpleMenuItem('Test1'),
            SimpleMenuItem('Test2'),
            SimpleMenuItem("Test3 is a submenu m'kay",menu=submenu),
            SimpleMenuItem(id=-1),
            SimpleMenuItem('Test4'),
        ]

        items3=[
            SimpleMenuItem('Test9'),
            SimpleMenuItem('Test10'),
            SimpleMenuItem('Test11'),
            SimpleMenuItem('Test12'),
            SimpleMenuItem('Test13'),
            SimpleMenuItem('Test14'),
            SimpleMenuItem('Test15'),
            SimpleMenuItem('Test16'),
            SimpleMenuItem('Test17')
        ]

        submenu2.SetItems(items3)


        menu.SetItems(items)

        skin='button'
        size=None#(100,100)#
        type='menu'#None#'toggle'#
        #menu=None#self.menu#
        icon=wx.Bitmap('../../../res/skins/default/statusicons/mobile.png',wx.BITMAP_TYPE_PNG)#wx.Bitmap('../../res/skins/default/tinydigsby.png',wx.BITMAP_TYPE_PNG)

        self.smb1=UberButton(self.panel,wx.NewId(),"SMB",skin,icon=icon,style=wx.HORIZONTAL,size=size,type=type,menu=menu)

        self.panel.Sizer.Add(self.smb1)

        self.Bind(wx.EVT_MENU,self.OnMenu)