def __init__(self, parent, title, bitmap='edit', direction=None, *args, **kwargs): # On wxGTK, calling Raise() on the dialog causes it to be shown, which # is rather undesirable during testing, so provide a way to instruct # the dialog to not call self.Raise(): raiseDialog = kwargs.pop('raiseDialog', True) super(Dialog, self).__init__(parent, -1, title, style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER) self.SetIcon( wx.ArtProvider_GetIcon(bitmap, wx.ART_FRAME_ICON, (16, 16))) self._verticalSizer = wx.BoxSizer(wx.VERTICAL) self._panel = wx.Panel(self) self._panelSizer = wx.GridSizer(1, 1) self._panelSizer.Add(self._panel, flag=wx.EXPAND) self._direction = direction self._interior = self.createInterior() self.fillInterior() self._verticalSizer.Add(self._interior, 1, flag=wx.EXPAND) self._buttonBox = self.createButtonBox() self._verticalSizer.Add(self._buttonBox, 0, wx.ALIGN_CENTER) self._panel.SetSizerAndFit(self._verticalSizer) self.SetSizerAndFit(self._panelSizer) if raiseDialog: wx.CallAfter(self.Raise) wx.CallAfter(self._panel.SetFocus)
def getIconFromArtProvider(self, iconTitle, iconSize=None): size = iconSize or self.__iconSizeOnCurrentPlatform # I just spent two hours trying to get rid of garbage in the icon # background on KDE. I give up. if operating_system.isGTK(): return wx.ArtProvider_GetIcon(iconTitle, wx.ART_FRAME_ICON, (size, size)) # wx.ArtProvider_GetIcon doesn't convert alpha to mask, so we do it # ourselves: bitmap = wx.ArtProvider_GetBitmap(iconTitle, wx.ART_FRAME_ICON, (size, size)) bitmap = ArtProvider.convertAlphaToMask(bitmap) return wx.IconFromBitmap(bitmap)
def __init__(self): self.config = ConfigParser.SafeConfigParser() self.config.read(CONFIG_FILENAME) wx.ArtProvider.Push(MedArtProvider()) wx.Frame.__init__(self, None, title='Mangalore Level Editor', size=(800, 600)) self.SetIcon(wx.ArtProvider_GetIcon('MED', wx.ART_OTHER, (16, 16))) self.createMenuBar() self.createToolBar() self.CreateStatusBar() self.splitter = MedSplitter(self) sizer = wx.BoxSizer() sizer.Add(self.splitter, 1, wx.EXPAND) self.SetSizer(sizer) self.Bind(wx.EVT_WINDOW_DESTROY, self.onDestroy, self)
def __init__(self, task, taskList, settings, *args, **kwargs): kwargs['title'] = kwargs.get('title', meta.name + ' ' + _('Reminder')) super(ReminderDialog, self).__init__(*args, **kwargs) self.SetIcon( wx.ArtProvider_GetIcon('taskcoach', wx.ART_FRAME_ICON, (16, 16))) self.task = task self.taskList = taskList self.settings = settings patterns.Publisher().registerObserver( self.onTaskRemoved, eventType=self.taskList.removeItemEventType(), eventSource=self.taskList) patterns.Publisher().registerObserver( self.onTaskCompletionDateChanged, eventType='task.completionDateTime', eventSource=self.task) self.openTaskAfterClose = self.ignoreSnoozeOption = False pane = self.GetContentsPane() pane.SetSizerType("form") wx.StaticText(pane, label=_('Task') + ':') self.openTask = wx.Button(pane, label=self.task.subject(recursive=True)) self.openTask.Bind(wx.EVT_BUTTON, self.onOpenTask) for label in _('Reminder date/time') + ':', \ render.dateTime(self.task.reminder()), _('Snooze') + ':': wx.StaticText(pane, label=label) self.snoozeOptions = wx.ComboBox(pane) snoozeTimesUserWantsToSee = [0] + eval( self.settings.get('view', 'snoozetimes')) for minutes, label in date.snoozeChoices: if minutes in snoozeTimesUserWantsToSee: self.snoozeOptions.Append(label, date.TimeDelta(minutes=minutes)) self.snoozeOptions.SetSelection(0) buttonSizer = self.CreateStdDialogButtonSizer(wx.OK) self.markCompleted = wx.Button(self, label=_('Mark task completed')) self.markCompleted.Bind(wx.EVT_BUTTON, self.onMarkTaskCompleted) if self.task.completed(): self.markCompleted.Disable() buttonSizer.Add(self.markCompleted) self.SetButtonSizer(buttonSizer) self.Bind(wx.EVT_CLOSE, self.onClose) self.Bind(wx.EVT_BUTTON, self.onOK, id=self.GetAffirmativeId()) self.Fit() self.RequestUserAttention()
def __init__(self, parent, title, bitmap='edit', direction=None, *args, **kwargs): self._buttonTypes = kwargs.get('buttonTypes', wx.OK | wx.CANCEL) super(Dialog, self).__init__(parent, -1, title, style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER | wx.MAXIMIZE_BOX | wx.MINIMIZE_BOX) self.SetIcon( wx.ArtProvider_GetIcon(bitmap, wx.ART_FRAME_ICON, (16, 16))) if operating_system.isWindows7_OrNewer(): # Without this the window has no taskbar icon on Windows, and the focus comes back to the main # window instead of this one when returning to Task Coach through Alt+Tab. Which is probably not # what we want. import win32gui, win32con exStyle = win32gui.GetWindowLong(self.GetHandle(), win32con.GWL_EXSTYLE) win32gui.SetWindowLong(self.GetHandle(), win32con.GWL_EXSTYLE, exStyle | win32con.WS_EX_APPWINDOW) self._panel = self.GetContentsPane() self._panel.SetSizerType('vertical') self._panel.SetSizerProps(expand=True, proportion=1) self._direction = direction self._interior = self.createInterior() self._interior.SetSizerProps(expand=True, proportion=1) self.fillInterior() self._buttons = self.createButtons() self._panel.Fit() self.Fit() self.CentreOnParent() if not operating_system.isGTK(): wx.CallAfter(self.Raise) wx.CallAfter(self._panel.SetFocus)
def __init__(self, task, taskList, effortList, settings, *args, **kwargs): kwargs['title'] = _('%(name)s reminder - %(task)s') % \ dict(name=meta.name, task=task.subject(recursive=True)) super(ReminderDialog, self).__init__(*args, **kwargs) self.SetIcon(wx.ArtProvider_GetIcon('taskcoach', wx.ART_FRAME_ICON, (16, 16))) self.task = task self.taskList = taskList self.effortList = effortList self.settings = settings self.registerObserver(self.onTaskRemoved, eventType=self.taskList.removeItemEventType(), eventSource=self.taskList) pub.subscribe(self.onTaskCompletionDateChanged, task.completionDateTimeChangedEventType()) pub.subscribe(self.onTrackingChanged, task.trackingChangedEventType()) self.openTaskAfterClose = self.ignoreSnoozeOption = False pane = self.GetContentsPane() pane.SetSizerType("form") wx.StaticText(pane, label=_('Task') + ':') panel = wx.Panel(pane) sizer = wx.BoxSizer(wx.HORIZONTAL) self.openTask = wx.Button(panel, label=self.task.subject(recursive=True)) self.openTask.Bind(wx.EVT_BUTTON, self.onOpenTask) sizer.Add(self.openTask, flag=wx.ALIGN_CENTER_VERTICAL) if self.settings.getboolean('feature', 'effort'): self.startTracking = wx.BitmapButton(panel) self.setTrackingIcon() self.startTracking.Bind(wx.EVT_BUTTON, self.onStartOrStopTracking) sizer.Add((3, -1), flag=wx.ALIGN_CENTER_VERTICAL) sizer.Add(self.startTracking, flag=wx.ALIGN_CENTER_VERTICAL) panel.SetSizerAndFit(sizer) for label in _('Reminder date/time') + ':', \ render.dateTime(self.task.reminder()), _('Snooze') + ':': wx.StaticText(pane, label=label) self.snoozeOptions = wx.ComboBox(pane, style=wx.CB_READONLY) sizer.Add(self.snoozeOptions, flag=wx.ALIGN_CENTER_VERTICAL) snoozeTimesUserWantsToSee = [0] + self.settings.getlist('view', 'snoozetimes') defaultSnoozeTime = self.settings.getint('view', 'defaultsnoozetime') # Use the 1st non-zero option if we don't find the last snooze time: selectionIndex = 1 # pylint: disable=E1101 for minutes, label in date.snoozeChoices: if minutes in snoozeTimesUserWantsToSee: self.snoozeOptions.Append(label, date.TimeDelta(minutes=minutes)) if minutes == defaultSnoozeTime: selectionIndex = self.snoozeOptions.Count - 1 self.snoozeOptions.SetSelection(min(selectionIndex, self.snoozeOptions.Count - 1)) wx.StaticText(pane, label='') self.replaceDefaultSnoozeTime = wx.CheckBox(pane, label=_('Also make this the default snooze time for future ' 'reminders')) self.replaceDefaultSnoozeTime.SetValue(self.settings.getboolean('view', 'replacedefaultsnoozetime')) buttonSizer = self.CreateStdDialogButtonSizer(wx.OK) self.markCompleted = wx.Button(self, label=_('Mark task completed')) self.markCompleted.Bind(wx.EVT_BUTTON, self.onMarkTaskCompleted) if self.task.completed(): self.markCompleted.Disable() buttonSizer.Add(self.markCompleted, flag=wx.ALIGN_CENTER_VERTICAL) self.SetButtonSizer(buttonSizer) self.Bind(wx.EVT_CLOSE, self.onClose) self.Bind(wx.EVT_BUTTON, self.onOK, id=self.GetAffirmativeId()) self.Fit() self.RequestUserAttention() if self.settings.getboolean('feature', 'sayreminder'): speak.Speaker().say('"%s: %s"' % (_('Reminder'), task.subject()))
def GetIconHelp(): return wx.ArtProvider_GetIcon(wx.ART_HELP, wx.ART_FRAME_ICON, (16, 16))
def GetIcon(self, name, client='other', size=None): wx_image, wx_client = self._GetWxArtIds(name, client) if size == None: size = self.size return wx.ArtProvider_GetIcon(wx_image, wx_client, size)
def __init__(self): wx.Frame.__init__(self, parent=None, title=conf.Title, size=conf.WindowSize) self.data = {} self.text = None self.text_id = None # ID of currently selected text self.panels_history = [] # In Windows 7 and Vista the wx.media.MediaCtrl fires state change # events unreliably, so cannot use sequential play. self.mc_hack = hasattr(sys, "getwindowsversion") \ and sys.getwindowsversion()[0] > 5 icons = wx.IconBundle() for s in [-1, 32]: icons.AddIcon(wx.ArtProvider_GetIcon( wx.ART_TICK_MARK, wx.ART_FRAME_ICON, (s, s))) self.SetIcons(icons) panel_frame = wx.lib.sized_controls.SizedPanel(self) panel_frame.SetSizerType("vertical") splitter = self.splitter_main = \ wx.SplitterWindow(parent=panel_frame, style=wx.BORDER_NONE) splitter.SetSizerProps(expand=True, proportion=1) splitter.SetMinimumPaneSize(1) # Create main panel with text box, buttons, and media control. panel_main = wx.lib.sized_controls.SizedPanel(splitter) panel_main.SetSizerType("vertical") panel_labels = wx.lib.sized_controls.SizedPanel(panel_main) panel_labels.SetSizerProps(expand=True, border=(["top"], 5)) panel_labels.SetSizerType("horizontal") label_text = wx.StaticText(panel_labels, label="&Enter text to speak:") panel_labels.Sizer.AddStretchSpacer() label_help = wx.StaticText( panel_labels, label="Use commas and line breaks to create pauses ") label_help.ForegroundColour = "GRAY" label_help.SetSizerProps(halign="right") text = self.edit_text = wx.TextCtrl( panel_main, size=(-1, 50), style=wx.TE_MULTILINE | wx.TE_RICH2) text.SetSizerProps(expand=True, proportion=1, border=(["left", "right", "bottom"], 3)) gauge = self.gauge = wx.Gauge(panel_main) gauge.SetSizerProps(expand=True) panel_buttons = wx.lib.sized_controls.SizedPanel(panel_main) panel_buttons.SetSizerType("horizontal") panel_buttons.SetSizerProps(expand=True) self.button_go = wx.Button(panel_buttons, label="&Text to speech") panel_buttons.Sizer.AddSpacer(10) label_lang = wx.StaticText(panel_buttons, label="&Language:") label_lang.SetSizerProps(border=(["all"], 0), valign="center") self.list_lang = wx.ComboBox(parent=panel_buttons, choices=[i[1] for i in conf.Languages], style=wx.CB_READONLY) self.list_lang.SetSizerProps(border=(["all"], 0), valign="center") panel_buttons.Sizer.AddStretchSpacer() self.cb_allatonce = wx.CheckBox(parent=panel_buttons, label="Complete audio before playing") self.cb_allatonce.SetSizerProps(halign="right", valign="center") self.cb_allatonce.Show(not self.mc_hack) self.button_save = wx.Button(panel_buttons, label="&Save MP3") gauge.ToolTipString = "Audio data chunks" self.button_save.Enabled = False self.list_lang.Selection = conf.Languages.index(("en", "English")) self.list_lang.ToolTipString = "Choose the speech language" self.cb_allatonce.Value = True self.cb_allatonce.ToolTipString = \ "Download all audio chunks and merge them before playing anything" mc = self.mediactrl = wx.media.MediaCtrl(panel_main, size=(-1, 70)) mc.ShowPlayerControls(wx.media.MEDIACTRLPLAYERCONTROLS_DEFAULT) mc.SetSizerProps(expand=True) self.text_info = wx.StaticText(panel_main, label=conf.InfoText, style=wx.ALIGN_CENTER) # Create side panel with list of texts, and program information. panel_side = wx.lib.sized_controls.SizedPanel(splitter) panel_side.SetSizerType("vertical") panel_list = self.panel_list = \ wx.lib.scrolledpanel.ScrolledPanel(panel_side) panel_list.BackgroundColour = "WHITE" panel_list.SetSizerProps(expand=True, proportion=100) panel_list.Sizer = wx.BoxSizer(wx.VERTICAL) panel_side.Sizer.AddStretchSpacer() panel_btm = wx.lib.sized_controls.SizedPanel(panel_side) panel_btm.SetSizerProps(halign="right") panel_btm.SetSizerType("horizontal") panel_btm.Sizer.AddStretchSpacer() self.text_version = wx.StaticText(panel_btm, label=conf.VersionText, style=wx.ALIGN_RIGHT) self.text_version.ForegroundColour = "GRAY" self.text_version.ToolTipString = "Ctrl-shift-doubleclick " \ "opens Python console." panel_btm.Sizer.Add((10, 5)) self.text_version.SetSizerProps(halign="right") self.link_www = wx.HyperlinkCtrl(panel_btm, id=-1, label="github", url=conf.URLHomepage) self.link_www.ToolTipString = "Go to source code repository " \ "at %s" % conf.URLHomepage self.link_www.SetSizerProps(halign="right") self.out_queue = Queue.Queue() self.mp3_loader = TextToMP3Loader(self, self.out_queue) self.dialog_save = wx.FileDialog( parent=self, defaultDir=os.getcwd(), style=wx.FD_OVERWRITE_PROMPT | wx.FD_SAVE | wx.RESIZE_BORDER) self.frame_console = wx.py.shell.ShellFrame( parent=self, title="%s Console" % conf.Title) self.frame_console.SetIcons(icons) self.frame_console.Enabled = False # Flag for first toggle if not self.mc_hack: mc.Bind(wx.media.EVT_MEDIA_LOADED, self.on_media_loaded) mc.Bind(wx.media.EVT_MEDIA_FINISHED, self.on_media_finished) self.Bind(EVT_RESULT, self.on_result_event) self.Bind(wx.EVT_BUTTON, self.on_text_to_speech, self.button_go) self.Bind(wx.EVT_BUTTON, self.on_save_mp3, self.button_save) self.Bind(wx.EVT_CLOSE, lambda evt: self.cleanup()) idfocus = wx.NewId() self.Bind(wx.EVT_MENU, lambda e: self.edit_text.SetFocus(), id=idfocus) ac = wx.AcceleratorTable([(wx.ACCEL_ALT, ord("T"), self.button_go.Id), (wx.ACCEL_ALT, ord("S"), self.button_save.Id), (wx.ACCEL_ALT, ord("E"), idfocus), ]) self.SetAcceleratorTable(ac) self.Bind(wx.EVT_CLOSE, self.on_exit) self.Bind(wx.EVT_SIZE, self.on_size) self.Bind(wx.EVT_SPLITTER_SASH_POS_CHANGED, self.on_size, splitter) self.frame_console.Bind(wx.EVT_CLOSE, self.on_toggle_console) self.text_version.Bind(wx.EVT_LEFT_DCLICK, self.on_toggle_console) conf.load() if conf.LastText and isinstance(conf.LastText, basestring): self.edit_text.Value = conf.LastText if conf.LastLanguage: index = next((i for i, x in enumerate(conf.Languages) if x[0] == conf.LastLanguage), None) if index is not None: self.list_lang.Selection = index if not 0 <= conf.LastVolume <= 1: conf.LastVolume = 0.5 if conf.WindowPosition and conf.WindowSize: if [-1, -1] != conf.WindowSize: self.Position, self.Size = conf.WindowPosition, conf.WindowSize else: self.Maximize() else: self.Center(wx.HORIZONTAL) self.Position.top = 50 sashPos = 3 * self.Size.width / 4 splitter.SplitVertically(panel_main, panel_side, sashPosition=sashPos) self.Show(True) self.edit_text.SetFocus() self.edit_text.SetInsertionPoint(-1)