def __init__(self): config = AppConfig() splash_img = wx.Image(config.get_data_file('splash.png')) wx.SplashScreen.__init__(self, splash_img.ConvertToBitmap(), wx.SPLASH_CENTRE_ON_SCREEN | wx.SPLASH_TIMEOUT, 2000, None, -1) wnd = self.GetSplashWindow() ver = wx.StaticText(wnd, -1, version.VERSION, pos=(330, 170)) ver.SetBackgroundColour(wx.WHITE)
def new_task(cls, parent_wnd, task_type, task_parent=None): session = OBJ.Session() parent = None if task_parent is not None: parent = OBJ.Task.get(session, uuid=task_parent) task = OBJ.Task(type=task_type, parent=parent) appconfig = AppConfig() if task_type == enums.TYPE_CHECKLIST_ITEM: task.priority = -1 else: task.priority = appconfig.get('task', 'default_priority', 0) task.status = appconfig.get('task', 'default_status', None) task.alarm_pattern = appconfig.get('task', 'default_remind', None) task.hide_pattern = appconfig.get('task', 'default_hide', None) task_logic.update_task_from_parent(task, task_parent, session, appconfig) contr = TaskController(parent_wnd, session, task) contr.open_dialog()
def __init__(self, parent, dialog_name='dialog', resource='wxgtd.xrc', icon=None, save_pos=True): self._dialog_name = dialog_name self.obj_key = None self._save_pos = save_pos # setup self._wnd = self._create_window(dialog_name, resource, parent) self._appconfig = AppConfig() self._load_controls(self._wnd) self._create_bindings(self._wnd) self._setup_wnd(self._wnd, icon)
def _get_hotlist_settings(params): conf = AppConfig() now = datetime.datetime.utcnow() params['filter_operator'] = 'or' if conf.get('hotlist', 'cond', True) \ else 'and' params['max_due_date'] = now + datetime.timedelta(days=conf.get('hotlist', 'due', 0)) params['min_priority'] = conf.get('hotlist', 'priority', 3) params['starred'] = conf.get('hotlist', 'starred', False) params['next_action'] = conf.get('hotlist', 'next_action', False) params['started'] = conf.get('hotlist', 'started', False)
class BaseDialog: """ Base class for dialogs defined in xrc files. Steps: 1. _create_window 2. _load_controls 3. _create_bindings 4. _setup_wnd Args: parent: parent window dialog_name: name dialog in resource file resource: name of resource file icon: optional icon name save_pos: is position of this dialog should be saved & restored. """ # dict holding opened dialogs _windows = {} def __init__(self, parent, dialog_name='dialog', resource='wxgtd.xrc', icon=None, save_pos=True): self._dialog_name = dialog_name self.obj_key = None self._save_pos = save_pos # setup self._wnd = self._create_window(dialog_name, resource, parent) self._appconfig = AppConfig() self._load_controls(self._wnd) self._create_bindings(self._wnd) self._setup_wnd(self._wnd, icon) @property def wnd(self): return self._wnd @classmethod def create(cls, key, *args, **kwargs): """ Create or return existing window associate to given key. Args: key: identifier used to distinguish windows and object args, kwargs: argument for constructor given subclass. Returns: Dialog. """ if not key: return cls(*args, **kwargs) dlg = cls._windows.get(key) if dlg: wx.CallAfter(dlg.wnd.Raise) else: cls._windows[key] = dlg = cls(*args, **kwargs) dlg.obj_key = key return dlg def run(self, modal=False): """ Run (show) dialog. Args: modal: show dialog as modal window. """ if modal: res = self._wnd.ShowModal() in (wx.ID_OK, wx.ID_SAVE) self._wnd.Destroy() return res self._wnd.Show() self._wnd.Raise() def __getitem__(self, key): """ Get dialog element (widget). Args: key: name or id widget Returns: widget. """ if isinstance(key, (str, unicode)): ctrl = xrc.XRCCTRL(self._wnd, key) else: ctrl = self._wnd.FindWindowById(key) assert ctrl is not None, 'ctrl %s not found' % key return ctrl def __setitem__(self, _key, _val): pass def __delitem__(self, _key): pass def __len__(self): return len(self._wnd.GetChildren()) if self.wnd else 0 def _create_window(self, dialog_name, resource, # pylint: disable=R0201 parent): """ Load resources & create window """ # load resource & create wind res = wxresources.load_xrc_resource(resource) assert res is not None, 'resource %s not found' % resource wnd = res.LoadDialog(parent, dialog_name) assert wnd is not None, 'wnd %s not found in %s' % (dialog_name, resource) wnd.SetExtraStyle(wx.WS_EX_VALIDATE_RECURSIVELY) return wnd def _setup_wnd(self, wnd, icon): """ Setup window. Args: icon: name of icon; if empty try to use icon from parent window. """ if not icon: parent = wnd.GetParent() if parent and hasattr(parent, 'GetIcon'): wnd.SetIcon(parent.GetIcon()) else: wnd.SetIcon(iconprovider.get_icon(icon)) _fix_panels(wnd) if wx.Platform == '__WXMSW__': wnd.SetBackgroundColour(wx.SystemSettings.GetColour( wx.SYS_COLOUR_ACTIVEBORDER)) if self._save_pos: size = self._appconfig.get(self._dialog_name, 'size', (400, 300)) if size: wnd.SetSize(size) position = self._appconfig.get(self._dialog_name, 'position') if position: wnd.Move(position) else: wnd.Centre() wnd.SetFocus() wnd.SetEscapeId(wx.ID_CLOSE) def _load_controls(self, wnd): """ Load/create additional controls. """ pass def _create_bindings(self, wnd): """ Create default bindings.""" wnd.Bind(wx.EVT_CLOSE, self._on_close) wnd.Bind(wx.EVT_BUTTON, self._on_cancel, id=wx.ID_CLOSE) wnd.Bind(wx.EVT_BUTTON, self._on_save, id=wx.ID_SAVE) wnd.Bind(wx.EVT_BUTTON, self._on_ok, id=wx.ID_OK) wnd.Bind(wx.EVT_BUTTON, self._on_cancel, id=wx.ID_CANCEL) def _data_changed(self): # pylint: disable=R0201 """ Before close check is changed. """ return False def _on_close(self, _evt): """ Action launched on close event. """ if self._save_pos: # save size & posiotion self._appconfig.set(self._dialog_name, 'size', self._wnd.GetSizeTuple()) self._appconfig.set(self._dialog_name, 'position', self._wnd.GetPositionTuple()) # remove from cache. if self.obj_key and self.obj_key in self._windows: del self._windows[self.obj_key] self._wnd.Destroy() def _on_cancel(self, _evt): """ Action for cancel - close window. """ if self._data_changed() and not self._confirm_close(): return if self._wnd.IsModal(): self._wnd.EndModal(wx.ID_CLOSE) else: self._wnd.Close() def _on_ok(self, _evt): """ Action for ok/yes - close window. """ if self._wnd.IsModal(): self._wnd.EndModal(wx.ID_OK) else: self._wnd.Close() def _on_save(self, evt): """ Action for save action. Default - use _on_ok action. """ self._on_ok(evt) def _confirm_close(self): res = mbox.message_box_not_save_confirm(self._wnd, None) if res == wx.ID_NO: return True if res == wx.ID_YES: self._on_save(None) return False