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 __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))
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): 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 __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
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)