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