Beispiel #1
0
    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)
Beispiel #2
0
    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)
Beispiel #3
0
 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()
Beispiel #4
0
    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)
Beispiel #5
0
    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)
Beispiel #6
0
    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)
Beispiel #7
0
    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()
Beispiel #8
0
    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)
Beispiel #9
0
    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()
Beispiel #10
0
 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)
Beispiel #11
0
    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)
Beispiel #12
0
 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()
Beispiel #13
0
 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()
Beispiel #14
0
    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()
Beispiel #15
0
 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()
Beispiel #16
0
    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()
Beispiel #17
0
 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()
Beispiel #18
0
 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()
Beispiel #19
0
    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()
Beispiel #20
0
    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()
Beispiel #21
0
    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()
Beispiel #22
0
    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
Beispiel #23
0
    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, )
Beispiel #24
0
    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
Beispiel #25
0
    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, )
Beispiel #26
0
    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)
Beispiel #27
0
    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)
Beispiel #28
0
 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()
Beispiel #29
0
 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()
Beispiel #30
0
    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()
Beispiel #31
0
    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()
Beispiel #32
0
    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)
Beispiel #33
0
 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()
Beispiel #34
0
 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()
Beispiel #35
0
 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()
Beispiel #36
0
    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()
Beispiel #37
0
    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()
Beispiel #38
0
    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()
Beispiel #39
0
    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()
Beispiel #40
0
    def __init__(self, engine, session):
        super(ConnectionDialog, self).__init__(None,
                                               title=t("common.connection"))
        self.engine = engine
        self.session = session

        self.InitUI()
        self.Center()
Beispiel #41
0
    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()
Beispiel #42
0
    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()
Beispiel #43
0
    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)
Beispiel #44
0
    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()
Beispiel #45
0
    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()
Beispiel #46
0
 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()
Beispiel #47
0
    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()
Beispiel #48
0
 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()
Beispiel #49
0
    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
Beispiel #50
0
    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()
Beispiel #51
0
 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()
Beispiel #52
0
    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")
Beispiel #53
0
    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))
Beispiel #54
0
 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()
Beispiel #55
0
    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()
Beispiel #56
0
    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()
Beispiel #57
0
    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, )
Beispiel #58
0
    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)
Beispiel #59
0
    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")
Beispiel #60
0
 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