def InitUI(self): sizer = wx.BoxSizer(wx.VERTICAL) self.SetSizer(sizer) # Create the dialog worlds = wx.ListCtrl(self, style=wx.LC_REPORT | wx.LC_SINGLE_SEL) worlds.InsertColumn(0, t("common.name")) worlds.InsertColumn(1, t("ui.dialog.worlds.author")) worlds.InsertColumn(2, t("ui.dialog.worlds.last_updated")) self.worlds = worlds # Description field l_description = wx.StaticText(self, label=t("common.description")) self.description = wx.TextCtrl(self, size=(600, 400), style=wx.TE_MULTILINE | wx.TE_READONLY) # Buttons install = wx.Button(self, label=t("ui.dialog.worlds.install")) # Main sizer sizer.Add(worlds, proportion=4) sizer.Add(l_description) sizer.Add(self.description, proportion=2) sizer.Add(install) sizer.Fit(self) # Populate the list self.populate_list() self.worlds.SetFocus() # Event binding self.worlds.Bind(wx.EVT_LIST_ITEM_FOCUSED, self.OnSelect) install.Bind(wx.EVT_BUTTON, self.OnInstall)
def OnOK(self, e): """Export the world.""" filename = self.t_name.GetValue() aliases = self.aliases.GetValue() channels = self.channels.GetValue() macros = self.macros.GetValue() triggers = self.triggers.GetValue() # Check that we can export into the file filename = "export/" + os.path.split(filename)[1] if not filename.lower().endswith(".zip"): filename += ".zip" if not os.path.exists("export"): os.mkdir("export") if os.path.exists(filename) and not os.access(filename, os.W_OK): wx.MessageBox(t("ui.dialog.export_world.cant_write"), t("ui.alert.error"), wx.OK | wx.ICON_ERROR) else: # Ready the configuration lines = [] # Aliases if aliases: for alias in self.world.aliases: lines.append(alias.sharp_script) # Channels if channels: for channel in self.world.channels: lines.append("#channel {{{}}}".format(channel.name)) # Macros if macros: for macro in self.world.macros: lines.append(macro.sharp_script) # Triggers if triggers: for trigger in self.world.triggers: lines.append(trigger.sharp_script) configuration = "\n".join(lines) + "\n" # Ready files to copy to_copy = [] if os.path.exists(os.path.join(self.world.path, "sounds")): sounds = os.listdir(os.path.join(self.world.path, "sounds")) to_copy += ["sounds/" + sound for sound in sounds] # Create the task task = Export(self.world, filename, configuration, to_copy) task.start() wx.MessageBox( t("ui.dialog.export_world.success", filename=filename), t("ui.alert.success"), wx.OK | wx.ICON_INFORMATION) os.startfile("export") self.EndModal(wx.ID_OK)
def OnOK(self, e): """Save the preferences.""" settings = self.engine.settings general = self.tabs.general display = self.tabs.display input = self.tabs.input accessibility = self.tabs.accessibility new_language = general.get_selected_language() encoding = display.get_selected_encoding() command_stacking = input.command_stacking.GetValue() old_language = settings["options.general.language"] interrupt = accessibility.TTS_interrupt.GetValue() settings["options.general.language"] = new_language settings["options.general.encoding"] = encoding settings["options.input.command_stacking"] = command_stacking settings["options.TTS.on"] = accessibility.TTS_on.GetValue() settings["options.TTS.outside"] = accessibility.TTS_outside.GetValue() settings["options.TTS.interrupt"] = interrupt settings["options"].write() self.engine.TTS_on = accessibility.TTS_on.GetValue() self.engine.TTS_outside = accessibility.TTS_outside.GetValue() if old_language != new_language: wx.MessageBox(t("ui.dialog.preferences.update_language"), t("ui.button.restart"), wx.OK | wx.ICON_INFORMATION) self.Destroy()
def display(self, dialog, filename=""): """Display the function's argument.""" self.dialog = dialog directory = os.path.join(self.world.path, "sounds") if not os.path.isdir(directory): directory = self.world.path dialog.default_directory = directory dialog.default_file = filename l_file = self.t("file", "Audio file to be played") # Dialog l_file = wx.StaticText(dialog, label=l_file) t_file = wx.TextCtrl(dialog, value=filename) browse = wx.Button(dialog, label=t("ui.button.browse")) test = wx.Button(dialog, label=t("ui.button.test")) dialog.file = t_file dialog.top.Add(l_file) dialog.top.Add(t_file) dialog.top.Add(browse) dialog.top.Add(test) # Event binding browse.Bind(wx.EVT_BUTTON, self.browse_file) test.Bind(wx.EVT_BUTTON, self.test_file)
def InitUI(self): sizer = wx.BoxSizer(wx.VERTICAL) self.SetSizer(sizer) # Create the dialog worlds = wx.ListCtrl(self, style=wx.LC_REPORT | wx.LC_SINGLE_SEL) worlds.InsertColumn(0, t("common.name")) worlds.InsertColumn(1, t("ui.dialog.worlds.author")) worlds.InsertColumn(2, t("ui.dialog.worlds.last_updated")) self.worlds = worlds # Description field l_description = wx.StaticText(self, label=t("common.description")) self.description = wx.TextCtrl(self, size=(600, 400), style=wx.TE_MULTILINE | wx.TE_READONLY) # Buttons install = wx.Button(self, label=t("ui.dialog.worlds.install")) # Main sizer sizer.Add(worlds, proportion=4) sizer.Add(l_description) sizer.Add(self.description, proportion=2) sizer.Add(install) sizer.Fit(self) # Populate the list self.populate_list() self.worlds.SetFocus() # Event binding install.Bind(wx.EVT_BUTTON, self.OnInstall)
def OnCancel(self, e): """The user clicks on 'cancel'.""" value = wx.MessageBox(t("ui.message.update.confirm_cancel"), t("ui.dialog.confirm"), wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION) if value == wx.YES: self.Destroy()
def InitUI(self): settings = self.engine.settings sizer = wx.GridBagSizer(15, 15) self.SetSizer(sizer) # Command stacking l_stacking = wx.StaticText(self, label=t("ui.dialog.preferences.command_stacking")) t_stacking = wx.TextCtrl(self, value=settings["options.input.command_stacking"]) self.command_stacking = t_stacking # Help on command stacking h_stacking = wx.Button(self, label=t("ui.button.what.command_stacking")) # Auto-send self.auto_send_paste = wx.CheckBox(self, label=t("ui.dialog.preferences.auto_send_paste")) self.auto_send_paste.SetValue(settings["options.input.auto_send_paste"]) # Append to the sizer sizer.Add(l_stacking, pos=(0, 0)) sizer.Add(t_stacking, pos=(1, 0)) sizer.Add(h_stacking, pos=(0, 1)) sizer.Add(self.auto_send_paste, pos=(2, 0)) # Event binding h_stacking.Bind(wx.EVT_BUTTON, self.OnHelpStacking)
def OnSelect(self, e): """When the selection changes.""" index = self.worlds.GetFirstSelected() try: world = self.online[index] except IndexError: wx.MessageBox(t("ui.dialog.worlds.unknown_world"), t("ui.alert.error"), wx.OK | wx.ICON_ERROR) else: self.description.SetValue(world.description)
def __init__(self, parent): wx.Menu.__init__(self) self.parent = parent # Create the sub-menu on_disk = wx.MenuItem(self, wx.NewId(), t("ui.menu.import_on_disk")) self.AppendItem(on_disk) self.Bind(wx.EVT_MENU, self.OnDisk, on_disk) online = wx.MenuItem(self, wx.NewId(), t("ui.menu.import_online")) self.AppendItem(online) self.Bind(wx.EVT_MENU, self.Online, online)
def __init__(self, engine, name, worlds): wx.Dialog.__init__(self, None, title="Preparing to install the world {}".format(name)) self.engine = engine self.name = name self.worlds = worlds self.merging = [ t("wizard.install_world.merging.ignore"), t("wizard.install_world.merging.replace"), ] self.results = {} self.InitUI() self.Center()
def __init__(self, engine, world=None): if world.name: title = t("ui.message.world.edit") else: title = t("ui.message.world.add") super(EditWorldDialog, self).__init__(None, title=title) self.engine = engine self.worlds = engine.worlds self.world = world self.InitUI() self.Center()
def OnEdit(self, e): """The 'edit' button is pressed.""" index = self.worlds.GetFirstSelected() worlds = sorted(self.engine.worlds.values(), key=lambda w: w.name) try: world = worlds[index] except IndexError: wx.MessageBox(t("ui.message.world.unknown"), t("ui.alert.error"), wx.OK | wx.ICON_ERROR) else: dialog = EditWorldDialog(self.engine, world) dialog.ShowModal() self.populate_list(index) self.worlds.SetFocus()
def __init__(self, engine, world, aliases, alias=None): if alias.alias: title = t("ui.message.alias.edit") else: title = t("ui.message.alias.add") super(EditAliasDialog, self).__init__(None, title=title) self.engine = engine self.world = world self.aliases = aliases self.alias = alias self.InitUI() self.Center()
def OnEdit(self, e): """The 'edit' button is pressed.""" index = self.aliases.GetFirstSelected() try: alias = self.alias_list[index] except IndexError: wx.MessageBox(t("ui.message.alias.unknown"), t("ui.alert.error"), wx.OK | wx.ICON_ERROR) else: dialog = EditAliasDialog(self.engine, self.world, self.alias_list, alias) dialog.ShowModal() self.populate_list(index) self.aliases.SetFocus()
def OnEdit(self, e): """The 'edit' button is pressed.""" index = self.triggers.GetFirstSelected() try: trigger = self.trigger_list[index] except IndexError: wx.MessageBox(t("ui.message.trigger.unknown"), t("ui.alert.error"), wx.OK | wx.ICON_ERROR) else: dialog = EditTriggerDialog(self.engine, self.world, self.trigger_list, trigger) dialog.ShowModal() self.populate_list(index) self.triggers.SetFocus()
def __init__(self, engine, macros, macro, world): if macro.shortcut: title = t("ui.message.macro.edit") else: title = t("ui.message.macro.add") super(EditMacroDialog, self).__init__(None, title=title) self.engine = engine self.macros = macros self.macro = macro self.world = world self.InitUI() self.Center()
def __init__(self, engine, world, triggers, trigger=None): if trigger.reaction: title = t("ui.message.trigger.edit") else: title = t("ui.message.trigger.add") super(EditTriggerDialog, self).__init__(None, title=title) self.engine = engine self.world = world self.triggers = triggers self.trigger = trigger self.InitUI() self.Center()
def __init__(self, parent, engine): wx.Notebook.__init__(self, parent) general_tab = GeneralTab(self, engine) display_tab = DisplayTab(self, engine) input_tab = InputTab(self, engine) accessibility_tab = AccessibilityTab(self, engine) self.AddPage(general_tab, t("ui.dialog.preferences.general")) self.AddPage(display_tab, t("ui.dialog.preferences.display")) self.AddPage(input_tab, t("ui.dialog.preferences.input")) self.AddPage(accessibility_tab, t("ui.dialog.preferences.accessibility")) self.general = general_tab self.display = display_tab self.input = input_tab self.accessibility = accessibility_tab
def complete(self, dialog): """The user pressed 'ok' in the dialog.""" commands = dialog.commands.GetValue().encode("utf-8", "replace") try: empty_commands = t("sharp.send.empty_commands") except ValueError: empty_commands = "The commands field is empty." if not commands: wx.MessageBox(empty_commands, t("ui.message.error"), wx.OK | wx.ICON_ERROR) dialog.commands.SetFocus() return None return (commands, )
def complete(self, dialog): """The user pressed 'ok' in the dialog.""" commands = dialog.commands.GetValue() try: empty_commands = t("sharp.send.empty_commands") except ValueError: empty_commands = "The commands field is empty." if not commands: wx.MessageBox(empty_commands, t("ui.alert.error"), wx.OK | wx.ICON_ERROR) dialog.commands.SetFocus() return None return (commands, )
def InitUI(self): sizer = wx.BoxSizer(wx.VERTICAL) top = wx.BoxSizer(wx.HORIZONTAL) buttons = self.CreateButtonSizer(wx.OK | wx.CANCEL) self.SetSizer(sizer) # Create the alias field s_alias = wx.BoxSizer(wx.VERTICAL) l_alias = wx.StaticText(self, label=t("common.alias", 1)) t_alias = wx.TextCtrl(self, value=self.alias.alias) self.t_alias = t_alias s_alias.Add(l_alias) s_alias.Add(t_alias) top.Add(s_alias) top.Add((15, -1)) # Main sizer sizer.Add(top, proportion=4) # SharpScript editor self.editor = SharpEditor(self, self.engine, self.world.sharp_engine, self.alias, "action") sizer.Add(self.editor) sizer.Add(buttons) sizer.Fit(self) self.t_alias.SetFocus() # Event binding self.Bind(wx.EVT_BUTTON, self.OnOK, id=wx.ID_OK) self.Bind(wx.EVT_BUTTON, self.OnCancel, id=wx.ID_CANCEL)
def populate_list(self, selection=0): """Populate the list with existing worlds.""" self.worlds.DeleteAllItems() worlds = sorted(self.engine.worlds.values(), key=lambda w: w.name) for world in worlds: self.worlds.Append((world.name, world.hostname, str(world.port))) if worlds: self.worlds.Select(selection) self.worlds.Focus(selection) worlds = sorted(self.engine.worlds.values(), key=lambda w: w.name) try: world = worlds[selection] except IndexError: pass else: self.session.world = world # Change the world's characters self.characters.DeleteAllItems() self.characters.Append((t("ui.client.any_character"), )) self.characters.Select(0) self.characters.Focus(0) characters = sorted(world.characters.values(), key=lambda c: c.location) for i, character in enumerate(characters): self.characters.Append((character.name, )) if character.default: self.characters.Select(i + 1) self.characters.Focus(i + 1)
def __init__(self, parent, just_checking=False): DummyUpdater.__init__(self, parent) self.create_updater(just_checking) self.InitUI() self.SetTitle(t("ui.message.update.updating")) self.Show() self.Center()
def __init__(self, engine, worlds): wx.Dialog.__init__(self, None, title=t("ui.dialog.worlds.title")) self.engine = engine self.online = worlds self.online.sort() self.InitUI() self.Center()
def __init__(self, engine, world): super(MacroDialog, self).__init__(None, title=t("common.macro", 2)) self.engine = engine self.world = world self.InitUI() self.Center()
def __init__(self, engine, world): super(AliasDialog, self).__init__(None, title=t("common.alias", 2)) self.engine = engine self.world = world self.InitUI() self.Center()
def __init__(self, parent, engine, world): super(ExportWorldDialog, self).__init__(parent, title=t("ui.dialog.export_world.title")) self.engine = engine self.world = world self.InitUI() self.Center()
def __init__(self, engine, world): super(TriggerDialog, self).__init__(None, title=t("common.trigger", 2)) self.engine = engine self.world = world self.InitUI() self.Center()
def OnRemove(self, e): """The 'remove' button is pressed.""" index = self.triggers.GetFirstSelected() try: trigger = self.trigger_list[index] except IndexError: wx.MessageBox(t("ui.message.trigger.unknown"), t("ui.alert.error"), wx.OK | wx.ICON_ERROR) else: value = wx.MessageBox(t("ui.message.trigger.remove", trigger=trigger.reaction), t("ui.alert.confirm"), wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION) if value == wx.YES: self.trigger_list.remove(trigger) self.populate_list(0) self.triggers.SetFocus()
def OnCancel(self, e): """The user clicks on 'cancel'.""" value = wx.MessageBox(self.confirmation, t("ui.alert.confirm"), wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION) if value == wx.YES: self.task.cancelled = True self.Destroy()
def __init__(self, engine, session): super(CharacterDialog, self).__init__(None, title=t("common.character", 1)) self.engine = engine self.session = session self.InitUI() self.Center()
def __init__(self, engine, session): super(ConnectionDialog, self).__init__(None, title=t("common.connection")) self.engine = engine self.session = session self.InitUI() self.Center()
def OnAdd(self, e): """Add a new channel.""" dialog = wx.TextEntryDialog(self, t("ui.message.channels.name"), t("ui.message.channels.title")) dialog.ShowModal() name = dialog.GetValue() dialog.Destroy() # If the name is already used if name in [ch.name for ch in self.world.channels]: wx.MessageBox(t("ui.message.channels.already"), t("ui.alert.error"), wx.OK | wx.ICON_ERROR) else: channel = Channel(self.world, name) self.world.add_channel(channel) self.world.save_config() self.Destroy()
def InitUI(self): sizer = wx.BoxSizer(wx.VERTICAL) top = wx.BoxSizer(wx.HORIZONTAL) buttons = wx.BoxSizer(wx.HORIZONTAL) self.SetSizer(sizer) # Create the dialog worlds = wx.ListCtrl(self, style=wx.LC_REPORT | wx.LC_SINGLE_SEL) worlds.InsertColumn(0, t("common.name")) worlds.InsertColumn(1, t("common.hostname")) worlds.InsertColumn(2, t("common.port")) self.worlds = worlds # Characters characters = wx.ListCtrl(self, style=wx.LC_REPORT | wx.LC_SINGLE_SEL) characters.InsertColumn(0, t("common.name")) self.characters = characters # Buttons connect = wx.Button(self, label=t("ui.button.connect")) add = wx.Button(self, label=t("ui.button.add")) edit = wx.Button(self, label=t("ui.button.edit")) remove = wx.Button(self, label=t("ui.button.remove")) b_import = wx.Button(self, label=t("ui.menu.import")) buttons.Add(connect) buttons.Add(add) buttons.Add(edit) buttons.Add(remove) buttons.Add(b_import) # Main sizer top.Add(worlds) top.Add(characters) sizer.Add(top) sizer.Add(buttons) sizer.Fit(self) # Populate the list self.populate_list() self.worlds.SetFocus() # Event binding worlds.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown) worlds.Bind(wx.EVT_LIST_ITEM_FOCUSED, self.OnSelectWorld) characters.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown) connect.Bind(wx.EVT_BUTTON, self.OnConnect) edit.Bind(wx.EVT_BUTTON, self.OnEdit) remove.Bind(wx.EVT_BUTTON, self.OnRemove) add.Bind(wx.EVT_BUTTON, self.OnAdd) b_import.Bind(wx.EVT_BUTTON, self.OnImport)
def execute(self): """Download the file at the URL.""" logger.debug("Task {}: preparing to download {}".format(self, self.url)) response = urlopen(self.url) meta = response.info() encoding = response.headers['content-type'].split('charset=')[-1] size = int(meta.getheaders("Content-Length")[0]) logger.debug("Task {}: size={}, encoding={}".format(self, size, encoding)) chunk_size = 4096 if self.filename is None: file = self.file else: file = open(self.filename, "wb") try: keep = True progress = 0.0 percent = 0 self.update(title=t("task.download.title", url=self.url, progress=0), text=t("task.download.downloading", url=self.url, percent=0)) while keep: old_percent = percent progress += chunk_size percent = round((progress / size) * 100, 1) if int(percent) != int(old_percent): self.update(title=t("task.download.title", url=self.url, percent=int(percent)), text=t("task.download.downloading", url=self.url, percent=int(percent)), progress=int(percent)) chunk = response.read(chunk_size) if not chunk: keep = False file.write(chunk) file.seek(0) finally: if self.filename is not None: file.close()
def OnRemove(self, e): """The 'remove' button is pressed.""" index = self.aliases.GetFirstSelected() try: alias = self.alias_list[index] except IndexError: wx.MessageBox(t("ui.message.alias.unknown"), t("ui.alert.error"), wx.OK | wx.ICON_ERROR) else: value = wx.MessageBox( t("ui.message.alias.remove", alias=alias.alias), t("ui.alert.confirm"), wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION) if value == wx.YES: self.alias_list.remove(alias) self.populate_list(0) self.aliases.SetFocus()
def __init__(self, engine, world, channels, name=None): super(ChannelsDialog, self).__init__(None, title=t("common.channel", 2)) self.engine = engine self.world = world self.channels = channels self.name = name self.messages = {} self.InitUI() self.Center()
def OnInstall(self, e): """The user clicked on 'install'>""" index = self.worlds.GetFirstSelected() try: world = self.online[index] except IndexError: wx.MessageBox(t("ui.dialog.worlds.unknown_world"), t("ui.alert.error"), wx.OK | wx.ICON_ERROR) else: attachment = world.attachments[0] url = attachment.content_url download = Download(None, url) download.start() # Extract the world in memory archive = ZipFile(download.file) files = {name: archive.read(name) for name in archive.namelist()} wizard = InstallWorld(self.engine, "VanciaMUD", files) wizard.start()
def OnOK(self, e): """Save the alias.""" alias = self.t_alias.GetValue() action = self.alias.action if not alias: wx.MessageBox(t("ui.message.alias.missing_alias"), t("ui.alert.missing"), wx.OK | wx.ICON_ERROR) self.t_alias.SetFocus() elif not action: wx.MessageBox(t("ui.message.alias.missing_action"), t("ui.alert.missing"), wx.OK | wx.ICON_ERROR) else: alias = alias self.alias.alias = alias self.alias.action = action self.alias.re_alias = self.alias.find_regex(self.alias.alias) if self.alias not in self.aliases: self.aliases.append(self.alias) self.Destroy()
def open_notepad(self): """Open and return the notepad associated to this character.""" if self.notepad: return self.notepad self.notepad = Notepad(self) empty_string = t("ui.message.notepad.character_empty", character=self.name, world=self.world.name) self.notepad.open(empty_string) return self.notepad
def OnRemove(self, e): """The 'remove' button is pressed.""" index = self.macros.GetFirstSelected() try: macro = self.macro_list[index] except IndexError: wx.MessageBox(t("ui.message.macro.unknown"), t("ui.alert.error"), wx.OK | wx.ICON_ERROR) else: value = wx.MessageBox( t("ui.message.macro.remove", shortcut=macro.shortcut, action=macro.action), t("ui.alert.confirm"), wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION) if value == wx.YES: self.macro_list.remove(macro) self.populate_list(0) self.macros.SetFocus()
def __init__(self, engine, wizard): wx.Dialog.__init__(self, None, title=t("wizard.install_world.installing", world=wizard.name)) self.engine = engine self.wizard = wizard self.data = {} self.widgets = OrderedDict() self.choices = {} self.InitUI() self.Center()
def __init__(self, parent): wx.Frame.__init__(self, parent) self.autoupdater = None self.default_text = t("ui.message.update.loading") self.progress = 0 # Event binding pub.subscribe(self.OnGauge, "gauge") pub.subscribe(self.OnText, "text") pub.subscribe(self.OnForceDestroy, "forceDestroy") pub.subscribe(self.OnResponseUpdate, "responseUpdate")
def InitUI(self): settings = self.engine.settings sizer = wx.GridBagSizer(15, 15) self.SetSizer(sizer) # TTS preferendces self.TTS_on = wx.CheckBox(self, label=t("ui.dialog.preferences.TTS.on")) self.TTS_on.SetValue(settings["options.TTS.on"]) self.TTS_outside = wx.CheckBox(self, label=t("ui.dialog.preferences.TTS.outside")) self.TTS_outside.SetValue(settings["options.TTS.outside"]) self.TTS_interrupt = wx.CheckBox(self, label=t("ui.dialog.preferences.TTS.interrupt")) self.TTS_interrupt.SetValue(settings["options.TTS.interrupt"]) # Append to the sizer sizer.Add(self.TTS_on, pos=(0, 0)) sizer.Add(self.TTS_outside, pos=(0, 1)) sizer.Add(self.TTS_interrupt, pos=(1, 1))
def OnOK(self, e): """Save the trigger.""" reaction = self.t_trigger.GetValue() action = self.trigger.action mute = self.mute.GetValue() if not reaction: wx.MessageBox(t("ui.message.trigger.missing_reaction"), t("ui.alert.missing"), wx.OK | wx.ICON_ERROR) self.t_trigger.SetFocus() elif not action: wx.MessageBox(t("ui.message.trigger.missing_action"), t("ui.alert.missing"), wx.OK | wx.ICON_ERROR) else: self.trigger.reaction = reaction self.trigger.action = action self.trigger.re_reaction = self.trigger.find_regex(reaction) self.trigger.mute = mute if self.trigger not in self.triggers: self.triggers.append(self.trigger) self.Destroy()
def OnClose(self, e): """Simply exit the dialog.""" # First, check that there hasn't been any modification dlg_triggers = {} for trigger in self.trigger_list: dlg_triggers[trigger.reaction] = trigger.action # Active triggers act_triggers = {} for trigger in self.world.triggers: act_triggers[trigger.reaction] = trigger.action if dlg_triggers == act_triggers: self.Destroy() else: value = wx.MessageBox(t("ui.message.trigger.unsaved"), t("ui.alert.confirm"), wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION) if value == wx.YES: self.Destroy()
def OnClose(self, e): """Simply exit the dialog.""" # First, check that there hasn't been any modification dlg_aliases = {} for alias in self.alias_list: dlg_aliases[alias.alias] = alias.action # Active aliases act_aliases = {} for alias in self.world.aliases: act_aliases[alias.alias] = alias.action if dlg_aliases == act_aliases: self.Destroy() else: value = wx.MessageBox(t("ui.message.alias.unsaved"), t("ui.alert.confirm"), wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION) if value == wx.YES: self.Destroy()
def complete(self, dialog): """The user pressed 'ok' in the dialog.""" file = dialog.default_file empty_path = self.t("empty_path", "The path hasn't been set. What file should I play?") if not file: wx.MessageBox(empty_path, t("ui.message.error"), wx.OK | wx.ICON_ERROR) dialog.file.SetFocus() return None return (file, )
def display(self, dialog, commands=""): """Display the function's argument.""" try: label = t("sharp.send.command") except ValueError: label = "Commands to be sent" l_commands = wx.StaticText(dialog, label=label) t_commands = wx.TextCtrl(dialog, value=commands, style=wx.TE_MULTILINE) dialog.commands = t_commands dialog.top.Add(l_commands) dialog.top.Add(t_commands)
def __init__(self, filename, url, background=False): """Initialize the task. Parameters: filename: the name of file to be created (or None). url: the url of the file to be downloaded. background (default False): should the task run in the background? If the filename is None, then download in memory. The file attribute will contain a StringIO pointing to this object. """ BaseTask.__init__(self) self.filename = filename self.file = StringIO() if filename is None else None self.url = url if background: self.dialog = None else: self.dialog = TaskDialog(self, t("task.download.title", url=url, progress=0)) self.dialog.confirmation = t("task.download.confirmation")
def browse_file(self, e): """Browse for a file.""" choose_file = t("ui.button.choose_file") parent = self.dialog extensions = "Audio file (*.wav)|*.wav" dialog = wx.FileDialog(parent, choose_file, parent.default_directory, "", extensions, wx.OPEN) result = dialog.ShowModal() if result == wx.ID_OK: filename = self.find_rel_filename(dialog.GetPath()) parent.file.SetValue(filename) parent.default_file = filename