def __init__(self, mainwindow, parent): global widgets_list super(TodoWidget, self).__init__(parent, -1) self._main_window=mainwindow self._data=self._data_map={} vbs=wx.BoxSizer(wx.VERTICAL) hbs=wx.BoxSizer(wx.HORIZONTAL) self._item_list=wx.ListBox(self, wx.NewId(), style=wx.LB_SINGLE|wx.LB_HSCROLL|wx.LB_NEEDED_SB) hbs.Add(self._item_list, 1, wx.EXPAND|wx.BOTTOM, border=5) scrolled_panel=scrolled.ScrolledPanel(self, -1) vbs1=wx.BoxSizer(wx.VERTICAL) self._items=( (GeneralEditor, 0, None), (cal_editor.CategoryEditor, 1, 'category'), (pb_editor.MemoEditor, 1, 'memo') ) self._w=[] for n in self._items: w=n[0](scrolled_panel, -1) vbs1.Add(w, n[1], wx.EXPAND|wx.ALL, 5) self._w.append(w) if n[2]: widgets_list.append((w.static_box, n[2])) scrolled_panel.SetSizer(vbs1) scrolled_panel.SetAutoLayout(True) vbs1.Fit(scrolled_panel) scrolled_panel.SetupScrolling() hbs.Add(scrolled_panel, 3, wx.EXPAND|wx.ALL, border=5) self._general_editor_w=self._w[0] self._cat_editor_w=self._w[1] self._memo_editor_w=self._w[2] hbs1=wx.BoxSizer(wx.HORIZONTAL) self._save_btn=wx.Button(self, wx.NewId(), "Save") self._revert_btn=wx.Button(self, wx.NewId(), "Revert") help_btn=wx.Button(self, wx.ID_HELP, "Help") hbs1.Add(self._save_btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5) hbs1.Add(help_btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5) hbs1.Add(self._revert_btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5) vbs.Add(hbs, 1, wx.EXPAND|wx.ALL, 5) vbs.Add(wx.StaticLine(self, -1), 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5) vbs.Add(hbs1, 0, wx.ALIGN_CENTRE|wx.ALL, 5) self.SetSizer(vbs) self.SetAutoLayout(True) vbs.Fit(self) wx.EVT_LISTBOX(self, self._item_list.GetId(), self._OnListBoxItem) wx.EVT_BUTTON(self, self._save_btn.GetId(), self._OnSave) wx.EVT_BUTTON(self, self._revert_btn.GetId(), self._OnRevert) wx.EVT_BUTTON(self, wx.ID_HELP, lambda _: wx.GetApp().displayhelpid(helpids.ID_TAB_TODO)) for w in self._w: pb_editor.EVT_DIRTY_UI(self, w.GetId(), self.OnMakeDirty) self._populate() self.ignoredirty=False self.setdirty(False) today.bind_notification_event(self.OnTodaySelection, today.Today_Group_Todo) today.bind_request_event(self.OnTodayRequest) field_color.reload_color_info(self, widgets_list) pubsub.subscribe(self.OnPhoneChanged, pubsub.PHONE_MODEL_CHANGED)
def OnPhoneChanged(self, _): # just reload the color info based on the new phone field_color.reload_color_info(self, widgets_list) self.Refresh()
def __init__(self, mainwindow, parent): wx.Panel.__init__(self, parent, -1) self._main_window = mainwindow self._data = {} self._data_map = {} # main box sizer vbs = wx.BoxSizer(wx.VERTICAL) # horizontal sizer for the listbox and tabs hbs = wx.BoxSizer(wx.HORIZONTAL) # the list box self._item_list = wx.ListBox(self, wx.NewId(), style=wx.LB_SINGLE | wx.LB_HSCROLL | wx.LB_NEEDED_SB) hbs.Add(self._item_list, 1, wx.EXPAND | wx.BOTTOM, border=5) # the detailed info pane vbs1 = wx.BoxSizer(wx.VERTICAL) self._items = ((GeneralEditor, 0, None), (cal_editor.CategoryEditor, 1, 'category'), (pb_editor.MemoEditor, 1, 'memo')) self._w = [] for n in self._items: w = n[0](self, -1) vbs1.Add(w, n[1], wx.EXPAND | wx.ALL, 5) self._w.append(w) if n[2]: widgets_list.append((w.static_box, n[2])) hbs.Add(vbs1, 3, wx.EXPAND | wx.ALL, border=5) self._general_editor_w = self._w[0] self._cat_editor_w = self._w[1] self._memo_editor_w = self._w[2] # the bottom buttons hbs1 = wx.BoxSizer(wx.HORIZONTAL) self._save_btn = wx.Button(self, wx.ID_SAVE) self._revert_btn = wx.Button(self, wx.ID_REVERT_TO_SAVED) help_btn = wx.Button(self, wx.ID_HELP) hbs1.Add(self._save_btn, 0, wx.ALIGN_CENTRE | wx.ALL, 5) hbs1.Add(help_btn, 0, wx.ALIGN_CENTRE | wx.ALL, 5) hbs1.Add(self._revert_btn, 0, wx.ALIGN_CENTRE | wx.ALL, 5) # all done vbs.Add(hbs, 1, wx.EXPAND | wx.ALL, 5) vbs.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.TOP | wx.BOTTOM, 5) vbs.Add(hbs1, 0, wx.ALIGN_CENTRE | wx.ALL, 5) self.SetSizer(vbs) self.SetAutoLayout(True) vbs.Fit(self) # event handlers wx.EVT_LISTBOX(self, self._item_list.GetId(), self._OnListBoxItem) wx.EVT_BUTTON(self, self._save_btn.GetId(), self._OnSave) wx.EVT_BUTTON(self, self._revert_btn.GetId(), self._OnRevert) wx.EVT_BUTTON(self, wx.ID_HELP, lambda _: wx.GetApp().displayhelpid(helpids.ID_TAB_MEMO)) # DIRTY UI Event handlers for w in self._w: pb_editor.EVT_DIRTY_UI(self, w.GetId(), self.OnMakeDirty) # populate data self._populate() # turn on dirty flag self.ignoredirty = False self.setdirty(False) # register for Today selection today.bind_notification_event(self.OnTodaySelection, today.Today_Group_Memo) # color code editable labels field_color.reload_color_info(self, widgets_list) pubsub.subscribe(self.OnPhoneChanged, pubsub.PHONE_MODEL_CHANGED)
def OnPhoneChanged(self, _): field_color.reload_color_info(self, widgets_list) self.Refresh() def _clear(self): self._item_list.Clear() self._clear_each() def _clear_each(self): for w in self._w: w.Set(None) w.Enable(False) self.Refresh() def _publish_today_events(self): now=datetime.datetime.now() _today='%04d%02d%02d'%(now.year, now.month, now.day) keys=self._data.keys() keys.sort() today_event=today.TodayTodoEvent() for k in keys: if self._data[k].is_active() and \ (not self._data[k].due_date or \ self._data[k].due_date<=_today): today_event.append(self._data[k].summary, { 'key': k, 'index': self._data_map[k] }) today_event.broadcast() def _publish_thisweek_events(self): now=datetime.datetime.now() _today='%04d%02d%02d'%(now.year, now.month, now.day) s=now+datetime.timedelta(7-now.isoweekday()%7) _sun='%04d%02d%02d'%(s.year, s.month, s.day) keys=self._data.keys() keys.sort() today_event=today.ThisWeekTodoEvent() dow_flg=[False]*7 for k in keys: due_date=self._data[k].due_date if due_date>_today and due_date<_sun: dt=datetime.datetime(int(due_date[:4]), int(due_date[4:6]), int(due_date[6:8])) _dow=dt.isoweekday()%7 if dow_flg[_dow]: _name=today.dow_initials[-1]+' '+self._data[k].summary else: dow_flg[_dow]=True _name=today.dow_initials[_dow]+' - '+self._data[k].summary today_event.append(_name, { 'key': k, 'index': self._data_map[k] }) today_event.broadcast() def OnTodayRequest(self, _): self._publish_today_events() self._publish_thisweek_events() def OnTodaySelection(self, evt): if evt.data: self._item_list.SetSelection(evt.data.get('index', wx.NOT_FOUND)) self._populate_each(evt.data.get('key', None)) def _populate(self): self._clear() self._data_map={} keys=self._data.keys() keys.sort() for k in keys: n=self._data[k] i=self._item_list.Append(n.summary) self._item_list.SetClientData(i, k) self._data_map[k]=i self._publish_today_events() self._publish_thisweek_events() def _populate_each(self, k): if k is None: self._clear_each() return self.ignoredirty=True for w in self._w: w.Enable(True) entry=self._data[k] self._general_editor_w.Set(entry) self._cat_editor_w.Set(entry.categories) self._memo_editor_w.Set({ 'memo': entry.note }) self.ignoredirty=False self.setdirty(False) def OnMakeDirty(self, _=None): """A public function you can call that will set the dirty flag""" if self.dirty or self.ignoredirty or not self.IsShown(): return self.setdirty(True) def setdirty(self, val): """Set the dirty flag""" if self.ignoredirty: return self.dirty=val self._item_list.Enable(not self.dirty) self._save_btn.Enable(self.dirty) self._revert_btn.Enable(self.dirty) def OnAdd(self, _): if self.dirty: return m=TodoEntry() m.summary='New Task' self._data[m.id]=m self._populate() self._save_to_db(self._data) self._item_list.Select(self._data_map[m.id]) self._populate_each(m.id) def OnDelete(self, _): sel_idx=self._item_list.GetSelection() if sel_idx is None or sel_idx==-1: return self.ignoredirty=True k=self._item_list.GetClientData(sel_idx) self._item_list.Delete(sel_idx) self._clear_each() del self._data[k] del self._data_map[k] self._save_to_db(self._data) self.ignoredirty=False self.setdirty(False) def getdata(self,dict,want=None): dict['todo']=copy.deepcopy(self._data) return dict def populate(self, dict): self._data=dict.get('todo', {}) self._populate() def _save_to_db(self, todo_dict): db_rr={} for k, e in todo_dict.items(): db_rr[k]=TodoDataObject(e) database.ensurerecordtype(db_rr, todoobjectfactory) self._main_window.database.savemajordict('todo', db_rr) self._publish_today_events() self._publish_thisweek_events() def populatefs(self, dict): self._save_to_db(dict.get('todo', {})) return dict def getfromfs(self, result): todo_dict=self._main_window.database.\ getmajordictvalues('todo',todoobjectfactory) r={} for k,e in todo_dict.items(): ce=TodoEntry() ce.set_db_dict(e) r[ce.id]=ce result.update({ 'todo': r }) return result def _OnListBoxItem(self, evt): self._populate_each(self._item_list.GetClientData(evt.GetInt())) self.Refresh() def _OnSave(self, evt): self.ignoredirty=True sel_idx=self._item_list.GetSelection() k=self._item_list.GetClientData(sel_idx) entry=self._data[k] self._general_editor_w.Get(entry) entry.note=self._memo_editor_w.Get().get('memo', None) entry.categories=self._cat_editor_w.Get() entry.check_completion() self._general_editor_w.Set(entry) self._item_list.SetString(sel_idx, entry.summary) self._save_to_db(self._data) self.ignoredirty=False self.setdirty(False) def _OnRevert(self, evt): self.ignoredirty=True sel_idx=self._item_list.GetSelection() k=self._item_list.GetClientData(sel_idx) self._populate_each(k) self.ignoredirty=False self.setdirty(False)
def Set(self, data): self.ignore_dirty=True if data is None: for n in self._fields: n[self._w_index].Enable(False) else: for n in self._fields: w=n[self._w_index] w.Enable(True) w.SetValue(getattr(data, n[self._dict_key_index])) self.ignore_dirty=self.dirty=False def Get(self, data): self.ignore_dirty=self.dirty=False if data is None: return for n in self._fields: w=n[self._w_index] v=w.GetValue() setattr(data, n[self._dict_key_index], v) class TodoWidget (wx.Panel) : color_field_name='todo' def __init__(self, mainwindow, parent): global widgets_list super(TodoWidget, self).__init__(parent, -1) self._main_window=mainwindow self._data=self._data_map={} vbs=wx.BoxSizer(wx.VERTICAL) hbs=wx.BoxSizer(wx.HORIZONTAL) self._item_list=wx.ListBox(self, wx.NewId(), style=wx.LB_SINGLE|wx.LB_HSCROLL|wx.LB_NEEDED_SB) hbs.Add(self._item_list, 1, wx.EXPAND|wx.BOTTOM, border=5) scrolled_panel=scrolled.ScrolledPanel(self, -1) vbs1=wx.BoxSizer(wx.VERTICAL) self._items=( (GeneralEditor, 0, None), (cal_editor.CategoryEditor, 1, 'category'), (pb_editor.MemoEditor, 1, 'memo') ) self._w=[] for n in self._items: w=n[0](scrolled_panel, -1) vbs1.Add(w, n[1], wx.EXPAND|wx.ALL, 5) self._w.append(w) if n[2]: widgets_list.append((w.static_box, n[2])) scrolled_panel.SetSizer(vbs1) scrolled_panel.SetAutoLayout(True) vbs1.Fit(scrolled_panel) scrolled_panel.SetupScrolling() hbs.Add(scrolled_panel, 3, wx.EXPAND|wx.ALL, border=5) self._general_editor_w=self._w[0] self._cat_editor_w=self._w[1] self._memo_editor_w=self._w[2] hbs1=wx.BoxSizer(wx.HORIZONTAL) self._save_btn=wx.Button(self, wx.NewId(), "Save") self._revert_btn=wx.Button(self, wx.NewId(), "Revert") help_btn=wx.Button(self, wx.ID_HELP, "Help") hbs1.Add(self._save_btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5) hbs1.Add(help_btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5) hbs1.Add(self._revert_btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5) vbs.Add(hbs, 1, wx.EXPAND|wx.ALL, 5) vbs.Add(wx.StaticLine(self, -1), 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5) vbs.Add(hbs1, 0, wx.ALIGN_CENTRE|wx.ALL, 5) self.SetSizer(vbs) self.SetAutoLayout(True) vbs.Fit(self) wx.EVT_LISTBOX(self, self._item_list.GetId(), self._OnListBoxItem) wx.EVT_BUTTON(self, self._save_btn.GetId(), self._OnSave) wx.EVT_BUTTON(self, self._revert_btn.GetId(), self._OnRevert) wx.EVT_BUTTON(self, wx.ID_HELP, lambda _: wx.GetApp().displayhelpid(helpids.ID_TAB_TODO)) for w in self._w: pb_editor.EVT_DIRTY_UI(self, w.GetId(), self.OnMakeDirty) self._populate() self.ignoredirty=False self.setdirty(False) today.bind_notification_event(self.OnTodaySelection, today.Today_Group_Todo) today.bind_request_event(self.OnTodayRequest) field_color.reload_color_info(self, widgets_list) pubsub.subscribe(self.OnPhoneChanged, pubsub.PHONE_MODEL_CHANGED) def OnPhoneChanged(self, _): field_color.reload_color_info(self, widgets_list) self.Refresh() def _clear(self): self._item_list.Clear() self._clear_each() def _clear_each(self): for w in self._w: w.Set(None) w.Enable(False) self.Refresh() def _publish_today_events(self): now=datetime.datetime.now() _today='%04d%02d%02d'%(now.year, now.month, now.day) keys=self._data.keys() keys.sort() today_event=today.TodayTodoEvent() for k in keys: if self._data[k].is_active() and \ (not self._data[k].due_date or \ self._data[k].due_date<=_today): today_event.append(self._data[k].summary, { 'key': k, 'index': self._data_map[k] }) today_event.broadcast() def _publish_thisweek_events(self): now=datetime.datetime.now() _today='%04d%02d%02d'%(now.year, now.month, now.day) s=now+datetime.timedelta(7-now.isoweekday()%7) _sun='%04d%02d%02d'%(s.year, s.month, s.day) keys=self._data.keys() keys.sort() today_event=today.ThisWeekTodoEvent() dow_flg=[False]*7 for k in keys: due_date=self._data[k].due_date if due_date>_today and due_date<_sun: dt=datetime.datetime(int(due_date[:4]), int(due_date[4:6]), int(due_date[6:8])) _dow=dt.isoweekday()%7 if dow_flg[_dow]: _name=today.dow_initials[-1]+' '+self._data[k].summary else: dow_flg[_dow]=True _name=today.dow_initials[_dow]+' - '+self._data[k].summary today_event.append(_name, { 'key': k, 'index': self._data_map[k] }) today_event.broadcast() def OnTodayRequest(self, _): self._publish_today_events() self._publish_thisweek_events() def OnTodaySelection(self, evt): if evt.data: self._item_list.SetSelection(evt.data.get('index', wx.NOT_FOUND)) self._populate_each(evt.data.get('key', None)) def _populate(self): self._clear() self._data_map={} keys=self._data.keys() keys.sort() for k in keys: n=self._data[k] i=self._item_list.Append(n.summary) self._item_list.SetClientData(i, k) self._data_map[k]=i self._publish_today_events() self._publish_thisweek_events() def _populate_each(self, k): if k is None: self._clear_each() return self.ignoredirty=True for w in self._w: w.Enable(True) entry=self._data[k] self._general_editor_w.Set(entry) self._cat_editor_w.Set(entry.categories) self._memo_editor_w.Set({ 'memo': entry.note }) self.ignoredirty=False self.setdirty(False) def OnMakeDirty(self, _=None): """A public function you can call that will set the dirty flag""" if self.dirty or self.ignoredirty or not self.IsShown(): return self.setdirty(True) def setdirty(self, val): """Set the dirty flag""" if self.ignoredirty: return self.dirty=val self._item_list.Enable(not self.dirty) self._save_btn.Enable(self.dirty) self._revert_btn.Enable(self.dirty) def OnAdd(self, _): if self.dirty: return m=TodoEntry() m.summary='New Task' self._data[m.id]=m self._populate() self._save_to_db(self._data) self._item_list.Select(self._data_map[m.id]) self._populate_each(m.id) def OnDelete(self, _): sel_idx=self._item_list.GetSelection() if sel_idx is None or sel_idx==-1: return self.ignoredirty=True k=self._item_list.GetClientData(sel_idx) self._item_list.Delete(sel_idx) self._clear_each() del self._data[k] del self._data_map[k] self._save_to_db(self._data) self.ignoredirty=False self.setdirty(False) def getdata(self,dict,want=None): dict['todo']=copy.deepcopy(self._data) return dict def populate(self, dict): self._data=dict.get('todo', {}) self._populate() def _save_to_db(self, todo_dict): db_rr={} for k, e in todo_dict.items(): db_rr[k]=TodoDataObject(e) database.ensurerecordtype(db_rr, todoobjectfactory) self._main_window.database.savemajordict('todo', db_rr) self._publish_today_events() self._publish_thisweek_events() def populatefs(self, dict): self._save_to_db(dict.get('todo', {})) return dict def getfromfs(self, result): todo_dict=self._main_window.database.\ getmajordictvalues('todo',todoobjectfactory) r={} for k,e in todo_dict.items(): ce=TodoEntry() ce.set_db_dict(e) r[ce.id]=ce result.update({ 'todo': r }) return result def _OnListBoxItem(self, evt): self._populate_each(self._item_list.GetClientData(evt.GetInt())) self.Refresh() def _OnSave(self, evt): self.ignoredirty=True sel_idx=self._item_list.GetSelection() k=self._item_list.GetClientData(sel_idx) entry=self._data[k] self._general_editor_w.Get(entry) entry.note=self._memo_editor_w.Get().get('memo', None) entry.categories=self._cat_editor_w.Get() entry.check_completion() self._general_editor_w.Set(entry) self._item_list.SetString(sel_idx, entry.summary) self._save_to_db(self._data) self.ignoredirty=False self.setdirty(False) def _OnRevert(self, evt): self.ignoredirty=True sel_idx=self._item_list.GetSelection() k=self._item_list.GetClientData(sel_idx) self._populate_each(k) self.ignoredirty=False self.setdirty(False)
def OnPhoneChanged(self, _): field_color.reload_color_info(self, widgets_list) self.Refresh()
def __init__(self, parent): global widgets_list wx.Dialog.__init__(self, parent, -1, 'Calendar Entry Editor', wx.DefaultPosition, style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER) # the parent is the BPCalenda widget, save it self.cw = parent # also the BPCalendar object # Tracking of the entries in the listbox. Each entry is a dict. Entries are just the # entries in a random order. entrymap maps from the order in the listbox to a # specific entry self.entries = [] self.entrymap = [] self._current_entry = None # Dirty tracking. We restrict what the user can do while editting an # entry to only be able to edit that entry. 'dirty' gets fired when # they make any updates. Annoyingly, controls generate change events # when they are updated programmatically as well as by user interaction. # ignoredirty is set when we are programmatically updating controls self.dirty = None self.ignoredirty = True # overall container vbs = wx.BoxSizer(wx.VERTICAL) self._prev_btn = wx.BitmapButton(self, wx.NewId(), wx.ArtProvider.GetBitmap( guihelper.ART_ARROW_LEFT), name="Previous Day") self._next_btn = wx.BitmapButton(self, wx.NewId(), wx.ArtProvider.GetBitmap( guihelper.ART_ARROW_RIGHT), name="Next Day") self.title = wx.StaticText(self, -1, "Date here", style=wx.ALIGN_CENTRE | wx.ST_NO_AUTORESIZE) # top row container hbs1 = wx.BoxSizer(wx.HORIZONTAL) hbs1.Add(self._prev_btn, 0, wx.EXPAND) hbs1.Add(self.title, 1, wx.EXPAND) hbs1.Add(self._next_btn, 0, wx.EXPAND) vbs.Add(hbs1, 0, wx.TOP | wx.EXPAND, 10) # list box and two buttons below self.listbox = wx.ListBox(self, wx.NewId(), style=wx.LB_SINGLE | wx.LB_HSCROLL | wx.LB_NEEDED_SB) self._add_btn = wx.Button(self, wx.ID_NEW) hbs2 = wx.BoxSizer(wx.HORIZONTAL) hbs2.Add(self._add_btn, 1, wx.ALIGN_CENTER | wx.LEFT | wx.RIGHT, border=5) # sizer for listbox lbs = wx.BoxSizer(wx.VERTICAL) lbs.Add(self.listbox, 1, wx.EXPAND | wx.BOTTOM, border=5) lbs.Add(hbs2, 0, wx.EXPAND) # right hand bit with all fields self._nb = wx.Notebook(self, -1) self._widgets = [] for i, (name, key, klass, color_name) in enumerate(self._items): if name in ('Ringtones', 'Wallpapers'): self._widgets.append(klass(self._nb, parent, False)) else: self._widgets.append(klass(self._nb, parent)) self._nb.AddPage(self._widgets[i], name) if color_name: widgets_list.append((self._widgets[i].static_box, color_name)) # buttons below fields self._delete_btn = wx.Button(self, wx.ID_DELETE) self._revert_btn = wx.Button(self, wx.ID_REVERT_TO_SAVED) self._save_btn = wx.Button(self, wx.ID_SAVE) hbs4 = wx.BoxSizer(wx.HORIZONTAL) hbs4.Add(self._delete_btn, 1, wx.ALIGN_CENTRE | wx.LEFT, border=10) hbs4.Add(self._revert_btn, 1, wx.ALIGN_CENTRE | wx.LEFT | wx.RIGHT, border=10) hbs4.Add(self._save_btn, 1, wx.ALIGN_CENTRE | wx.RIGHT, border=10) # fields and buttons together vbs2 = wx.BoxSizer(wx.VERTICAL) vbs2.Add(self._nb, 1, wx.EXPAND | wx.BOTTOM, border=5) vbs2.Add(hbs4, 0, wx.EXPAND | wx.ALIGN_CENTRE) # container for everything below title row hbs3 = wx.BoxSizer(wx.HORIZONTAL) hbs3.Add(lbs, 1, wx.EXPAND | wx.ALL, 5) hbs3.Add(vbs2, 2, wx.EXPAND | wx.ALL, 5) vbs.Add(hbs3, 1, wx.EXPAND) # the standard buttons vbs.Add(wx.StaticLine(self, -1, style=wx.LI_HORIZONTAL), 0, wx.EXPAND | wx.ALL, 5) vbs.Add(self.CreateButtonSizer(wx.OK | wx.CANCEL | wx.HELP), 0, wx.ALIGN_CENTRE | wx.ALL, 5) self.SetSizer(vbs) self.SetAutoLayout(True) vbs.Fit(self) # delete is disabled until an item is selected self._delete_btn.Enable(False) wx.EVT_LISTBOX(self, self.listbox.GetId(), self.OnListBoxItem) wx.EVT_LISTBOX_DCLICK(self, self.listbox.GetId(), self.OnListBoxItem) wx.EVT_BUTTON(self, wx.ID_SAVE, self.OnSaveButton) wx.EVT_BUTTON(self, wx.ID_REVERT_TO_SAVED, self.OnRevertButton) wx.EVT_BUTTON(self, wx.ID_NEW, self.OnNewButton) wx.EVT_BUTTON(self, wx.ID_DELETE, self.OnDeleteButton) wx.EVT_BUTTON(self, self._prev_btn.GetId(), self.OnPrevDayButton) wx.EVT_BUTTON(self, self._next_btn.GetId(), self.OnNextDayButton) # callbacks for the standard buttons wx.EVT_BUTTON(self, wx.ID_OK, self.OnOk) wx.EVT_BUTTON(self, wx.ID_CANCEL, self.OnCancel) wx.EVT_BUTTON( self, wx.ID_HELP, lambda _: wx.GetApp().displayhelpid( helpids.ID_EDITING_CALENDAR_EVENTS)) # DIRTY UI Event handlers for w in self._widgets: pb_editor.EVT_DIRTY_UI(self, w.GetId(), self.OnMakeDirty) self.ignoredirty = False self.setdirty(False) guiwidgets.set_size("CalendarEntryEditor", self, 52, 1.0) field_color.reload_color_info(self, widgets_list) pubsub.subscribe(self.OnPhoneChanged, pubsub.PHONE_MODEL_CHANGED)
def OnPhoneChanged(self, _): # just reload the color info based on the new phone field_color.reload_color_info(self, widgets_list) self.Refresh()
def __init__(self, parent): global widgets_list wx.Dialog.__init__(self, parent, -1, 'Calendar Entry Editor', wx.DefaultPosition, style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER) # the parent is the BPCalenda widget, save it self.cw=parent # also the BPCalendar object # Tracking of the entries in the listbox. Each entry is a dict. Entries are just the # entries in a random order. entrymap maps from the order in the listbox to a # specific entry self.entries=[] self.entrymap=[] self._current_entry=None # Dirty tracking. We restrict what the user can do while editting an # entry to only be able to edit that entry. 'dirty' gets fired when # they make any updates. Annoyingly, controls generate change events # when they are updated programmatically as well as by user interaction. # ignoredirty is set when we are programmatically updating controls self.dirty=None self.ignoredirty=True # overall container vbs=wx.BoxSizer(wx.VERTICAL) self._prev_btn=wx.BitmapButton(self, wx.NewId(), wx.ArtProvider.GetBitmap(guihelper.ART_ARROW_LEFT), name="Previous Day") self._next_btn=wx.BitmapButton(self, wx.NewId(), wx.ArtProvider.GetBitmap(guihelper.ART_ARROW_RIGHT), name="Next Day") self.title=wx.StaticText(self, -1, "Date here", style=wx.ALIGN_CENTRE|wx.ST_NO_AUTORESIZE) # top row container hbs1=wx.BoxSizer(wx.HORIZONTAL) hbs1.Add(self._prev_btn, 0, wx.EXPAND) hbs1.Add(self.title, 1, wx.EXPAND) hbs1.Add(self._next_btn, 0, wx.EXPAND) vbs.Add(hbs1, 0, wx.TOP|wx.EXPAND, 10) # list box and two buttons below self.listbox=wx.ListBox(self, wx.NewId(), style=wx.LB_SINGLE|wx.LB_HSCROLL|wx.LB_NEEDED_SB) self._add_btn=wx.Button(self, wx.ID_NEW) hbs2=wx.BoxSizer(wx.HORIZONTAL) hbs2.Add(self._add_btn, 1, wx.ALIGN_CENTER|wx.LEFT|wx.RIGHT, border=5) # sizer for listbox lbs=wx.BoxSizer(wx.VERTICAL) lbs.Add(self.listbox, 1, wx.EXPAND|wx.BOTTOM, border=5) lbs.Add(hbs2, 0, wx.EXPAND) # right hand bit with all fields self._nb=wx.Notebook(self, -1) self._widgets=[] for i, (name, key, klass, color_name) in enumerate(self._items): if name in ('Ringtones', 'Wallpapers'): self._widgets.append(klass(self._nb, parent, False)) else: self._widgets.append(klass(self._nb, parent)) self._nb.AddPage(self._widgets[i], name) if color_name: widgets_list.append((self._widgets[i].static_box, color_name)) # buttons below fields self._delete_btn=wx.Button(self, wx.ID_DELETE) self._revert_btn=wx.Button(self, wx.ID_REVERT_TO_SAVED) self._save_btn=wx.Button(self, wx.ID_SAVE) hbs4=wx.BoxSizer(wx.HORIZONTAL) hbs4.Add(self._delete_btn, 1, wx.ALIGN_CENTRE|wx.LEFT, border=10) hbs4.Add(self._revert_btn, 1, wx.ALIGN_CENTRE|wx.LEFT|wx.RIGHT, border=10) hbs4.Add(self._save_btn, 1, wx.ALIGN_CENTRE|wx.RIGHT, border=10) # fields and buttons together vbs2=wx.BoxSizer(wx.VERTICAL) vbs2.Add(self._nb, 1, wx.EXPAND|wx.BOTTOM, border=5) vbs2.Add(hbs4, 0, wx.EXPAND|wx.ALIGN_CENTRE) # container for everything below title row hbs3=wx.BoxSizer(wx.HORIZONTAL) hbs3.Add(lbs, 1, wx.EXPAND|wx.ALL, 5) hbs3.Add(vbs2, 2, wx.EXPAND|wx.ALL, 5) vbs.Add(hbs3, 1, wx.EXPAND) # the standard buttons vbs.Add(wx.StaticLine(self, -1, style=wx.LI_HORIZONTAL), 0, wx.EXPAND|wx.ALL, 5) vbs.Add(self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.HELP), 0, wx.ALIGN_CENTRE|wx.ALL, 5) self.SetSizer(vbs) self.SetAutoLayout(True) vbs.Fit(self) # delete is disabled until an item is selected self._delete_btn.Enable(False) wx.EVT_LISTBOX(self, self.listbox.GetId(), self.OnListBoxItem) wx.EVT_LISTBOX_DCLICK(self, self.listbox.GetId(), self.OnListBoxItem) wx.EVT_BUTTON(self, wx.ID_SAVE, self.OnSaveButton) wx.EVT_BUTTON(self, wx.ID_REVERT_TO_SAVED, self.OnRevertButton) wx.EVT_BUTTON(self, wx.ID_NEW, self.OnNewButton) wx.EVT_BUTTON(self, wx.ID_DELETE, self.OnDeleteButton) wx.EVT_BUTTON(self, self._prev_btn.GetId(), self.OnPrevDayButton) wx.EVT_BUTTON(self, self._next_btn.GetId(), self.OnNextDayButton) # callbacks for the standard buttons wx.EVT_BUTTON(self, wx.ID_OK, self.OnOk) wx.EVT_BUTTON(self, wx.ID_CANCEL, self.OnCancel) wx.EVT_BUTTON(self, wx.ID_HELP, lambda _: wx.GetApp().displayhelpid(helpids.ID_EDITING_CALENDAR_EVENTS)) # DIRTY UI Event handlers for w in self._widgets: pb_editor.EVT_DIRTY_UI(self, w.GetId(), self.OnMakeDirty) self.ignoredirty=False self.setdirty(False) guiwidgets.set_size("CalendarEntryEditor", self, 52, 1.0) field_color.reload_color_info(self, widgets_list) pubsub.subscribe(self.OnPhoneChanged, pubsub.PHONE_MODEL_CHANGED)
def __init__(self, parent): global widgets_list wx.Dialog.__init__(self, parent, -1, 'Calendar Entry Editor', wx.DefaultPosition, style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER) self.cw=parent # also the BPCalendar object self.entries=[] self.entrymap=[] self._current_entry=None self.dirty=None self.ignoredirty=True vbs=wx.BoxSizer(wx.VERTICAL) self._prev_btn=wx.BitmapButton(self, self.ID_PREV, wx.ArtProvider.GetBitmap(guihelper.ART_ARROW_LEFT), name="Previous Day") self._next_btn=wx.BitmapButton(self, self.ID_NEXT, wx.ArtProvider.GetBitmap(guihelper.ART_ARROW_RIGHT), name="Next Day") self.title=wx.StaticText(self, -1, "Date here", style=wx.ALIGN_CENTRE|wx.ST_NO_AUTORESIZE) hbs1=wx.BoxSizer(wx.HORIZONTAL) hbs1.Add(self._prev_btn, 0, wx.EXPAND) hbs1.Add(self.title, 1, wx.EXPAND) hbs1.Add(self._next_btn, 0, wx.EXPAND) vbs.Add(hbs1, 0, wx.TOP|wx.EXPAND, 10) self.listbox=wx.ListBox(self, self.ID_LISTBOX, style=wx.LB_SINGLE|wx.LB_HSCROLL|wx.LB_NEEDED_SB) self._add_btn=wx.Button(self, self.ID_ADD, "New") hbs2=wx.BoxSizer(wx.HORIZONTAL) hbs2.Add(self._add_btn, 1, wx.ALIGN_CENTER|wx.LEFT|wx.RIGHT, border=5) lbs=wx.BoxSizer(wx.VERTICAL) lbs.Add(self.listbox, 1, wx.EXPAND|wx.BOTTOM, border=5) lbs.Add(hbs2, 0, wx.EXPAND) self._nb=wx.Notebook(self, -1) self._widgets=[] for i, (name, key, klass, color_name) in enumerate(self._items): if name in ('Ringtones', 'Wallpapers'): self._widgets.append(klass(self._nb, parent, False)) else: self._widgets.append(klass(self._nb, parent)) self._nb.AddPage(self._widgets[i], name) if color_name: widgets_list.append((self._widgets[i].static_box, color_name)) self._delete_btn=wx.Button(self, self.ID_DELETE, "Delete") self._revert_btn=wx.Button(self, self.ID_REVERT, "Revert") self._save_btn=wx.Button(self, self.ID_SAVE, "Save") hbs4=wx.BoxSizer(wx.HORIZONTAL) hbs4.Add(self._delete_btn, 1, wx.ALIGN_CENTRE|wx.LEFT, border=10) hbs4.Add(self._revert_btn, 1, wx.ALIGN_CENTRE|wx.LEFT|wx.RIGHT, border=10) hbs4.Add(self._save_btn, 1, wx.ALIGN_CENTRE|wx.RIGHT, border=10) vbs2=wx.BoxSizer(wx.VERTICAL) vbs2.Add(self._nb, 1, wx.EXPAND|wx.BOTTOM, border=5) vbs2.Add(hbs4, 0, wx.EXPAND|wx.ALIGN_CENTRE) hbs3=wx.BoxSizer(wx.HORIZONTAL) hbs3.Add(lbs, 1, wx.EXPAND|wx.ALL, 5) hbs3.Add(vbs2, 2, wx.EXPAND|wx.ALL, 5) vbs.Add(hbs3, 1, wx.EXPAND) vbs.Add(wx.StaticLine(self, -1, style=wx.LI_HORIZONTAL), 0, wx.EXPAND|wx.ALL, 5) vbs.Add(self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.HELP), 0, wx.ALIGN_CENTRE|wx.ALL, 5) self.SetSizer(vbs) self.SetAutoLayout(True) vbs.Fit(self) self._delete_btn.Enable(False) wx.EVT_LISTBOX(self, self.ID_LISTBOX, self.OnListBoxItem) wx.EVT_LISTBOX_DCLICK(self, self.ID_LISTBOX, self.OnListBoxItem) wx.EVT_BUTTON(self, self.ID_SAVE, self.OnSaveButton) wx.EVT_BUTTON(self, self.ID_REVERT, self.OnRevertButton) wx.EVT_BUTTON(self, self.ID_ADD, self.OnNewButton) wx.EVT_BUTTON(self, self.ID_DELETE, self.OnDeleteButton) wx.EVT_BUTTON(self, self.ID_PREV, self.OnPrevDayButton) wx.EVT_BUTTON(self, self.ID_NEXT, self.OnNextDayButton) wx.EVT_BUTTON(self, wx.ID_OK, self.OnOk) wx.EVT_BUTTON(self, wx.ID_CANCEL, self.OnCancel) wx.EVT_BUTTON(self, wx.ID_HELP, lambda _: wx.GetApp().displayhelpid(helpids.ID_EDITING_CALENDAR_EVENTS)) for w in self._widgets: pb_editor.EVT_DIRTY_UI(self, w.GetId(), self.OnMakeDirty) self.ignoredirty=False self.setdirty(False) guiwidgets.set_size("CalendarEntryEditor", self, 50, 1.5) field_color.reload_color_info(self, widgets_list) pubsub.subscribe(self.OnPhoneChanged, pubsub.PHONE_MODEL_CHANGED)
def __init__(self, mainwindow, parent): global widgets_list super(TodoWidget, self).__init__(parent, -1) self._main_window=mainwindow self._data=self._data_map={} # main box sizer vbs=wx.BoxSizer(wx.VERTICAL) # horizontal sizer for the listbox and tabs hbs=wx.BoxSizer(wx.HORIZONTAL) # the list box self._item_list=wx.ListBox(self, wx.NewId(), style=wx.LB_SINGLE|wx.LB_HSCROLL|wx.LB_NEEDED_SB) hbs.Add(self._item_list, 1, wx.EXPAND|wx.BOTTOM, border=5) # the detailed info pane as a scrolled panel scrolled_panel=scrolled.ScrolledPanel(self, -1) vbs1=wx.BoxSizer(wx.VERTICAL) self._items=( (GeneralEditor, 0, None), (cal_editor.CategoryEditor, 1, 'category'), (pb_editor.MemoEditor, 1, 'memo') ) self._w=[] for n in self._items: w=n[0](scrolled_panel, -1) vbs1.Add(w, n[1], wx.EXPAND|wx.ALL, 5) self._w.append(w) if n[2]: widgets_list.append((w.static_box, n[2])) scrolled_panel.SetSizer(vbs1) scrolled_panel.SetAutoLayout(True) vbs1.Fit(scrolled_panel) scrolled_panel.SetupScrolling() hbs.Add(scrolled_panel, 3, wx.EXPAND|wx.ALL, border=5) # save references to the widgets self._general_editor_w=self._w[0] self._cat_editor_w=self._w[1] self._memo_editor_w=self._w[2] # the bottom buttons hbs1=wx.BoxSizer(wx.HORIZONTAL) self._save_btn=wx.Button(self, wx.ID_SAVE) self._revert_btn=wx.Button(self, wx.ID_REVERT_TO_SAVED) help_btn=wx.Button(self, wx.ID_HELP) hbs1.Add(self._save_btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5) hbs1.Add(help_btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5) hbs1.Add(self._revert_btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5) # all done vbs.Add(hbs, 1, wx.EXPAND|wx.ALL, 5) vbs.Add(wx.StaticLine(self, -1), 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5) vbs.Add(hbs1, 0, wx.ALIGN_CENTRE|wx.ALL, 5) self.SetSizer(vbs) self.SetAutoLayout(True) vbs.Fit(self) # event handlers wx.EVT_LISTBOX(self, self._item_list.GetId(), self._OnListBoxItem) wx.EVT_BUTTON(self, self._save_btn.GetId(), self._OnSave) wx.EVT_BUTTON(self, self._revert_btn.GetId(), self._OnRevert) wx.EVT_BUTTON(self, wx.ID_HELP, lambda _: wx.GetApp().displayhelpid(helpids.ID_TAB_TODO)) # DIRTY UI Event handlers for w in self._w: pb_editor.EVT_DIRTY_UI(self, w.GetId(), self.OnMakeDirty) # populate data self._populate() # turn on dirty flag self.ignoredirty=False self.setdirty(False) # register for Today selection today.bind_notification_event(self.OnTodaySelection, today.Today_Group_Todo) today.bind_request_event(self.OnTodayRequest) # color coded labels field_color.reload_color_info(self, widgets_list) pubsub.subscribe(self.OnPhoneChanged, pubsub.PHONE_MODEL_CHANGED)