Exemple #1
0
 def OnAdd(self, e):
     """The 'add' button is pressed."""
     index = self.choices.GetFirstSelected()
     try:
         function = self.functions[index]
     except IndexError:
         wx.MessageBox(t("ui.message.sharp.missing"),
                 t("ui.message.error"), wx.OK | wx.ICON_ERROR)
     else:
         dialog = AddEditFunctionDialog(self.engine, self.sharp_engine,
                 function, self.object, self.attribute, escape=self.escape)
         dialog.ShowModal()
         self.populate_existing()
         self.existing.SetFocus()
 def OnAdd(self, e):
     """The 'add' button is pressed."""
     index = self.choices.GetFirstSelected()
     try:
         function = self.functions[index]
     except IndexError:
         wx.MessageBox(t("ui.message.sharp.missing"),
                 t("ui.message.error"), wx.OK | wx.ICON_ERROR)
     else:
         dialog = AddEditFunctionDialog(self.engine, self.sharp_engine,
                 function, self.object, self.attribute, escape=self.escape)
         dialog.ShowModal()
         self.populate_existing()
         self.existing.SetFocus()
Exemple #3
0
    def OnInput(self, message):
        """Some text has been sent from the input."""
        # Either send the buffer to the SharpScript engine or wait for a new line
        self.lines.append(message)
        execute = True
        if len(self.lines) == 1:
            if any(message.endswith(block) for block in ("{", "{+", "(")):
                # An opening block has been detected
                execute = False
        else:
            if message not in (")", "}"):
                execute = False

        if execute:
            buffer = "\n".join(self.lines)
            if self.session and self.session.engine:
                engine = self.session.engine
                sharp_engine = self.session.sharp_engine
                self.Send("+ " + "+ ".join(self.lines))

                # Save the TTS_on and TTS_outside, turn them on temporarily
                engine.TTS_on = True
                engine.TTS_outside = True
                engine.redirect_message = self.Send
                try:
                    sharp_engine.execute(buffer)
                except Exception:
                    error = t("ui.dialog.sharp_script_console.error") + "\n"
                    error += traceback.format_exc().strip()
                    self.Send(error)
                finally:
                    self.lines[:] = []
    def __init__(self, engine, sharp_engine, function, object, attribute,
            index=-1, escape=False):
        super(AddEditFunctionDialog, self).__init__(None,
                title=t("common.action"))
        self.engine = engine
        self.sharp_engine = sharp_engine
        self.world = sharp_engine.world
        self.function = function
        self.object = object
        self.attribute = attribute
        self.index = index
        self.escape = escape
        arguments = []
        flags = {}
        if index >= 0:
            script = getattr(self.object, self.attribute)
            lines = self.sharp_engine.format(script, return_str=False)
            line = lines[index]
            function, arguments, flags = self.sharp_engine.extract_arguments(line)

        # Dialog
        sizer = wx.BoxSizer(wx.VERTICAL)
        self.top = wx.BoxSizer(wx.VERTICAL)
        buttons = self.CreateButtonSizer(wx.OK | wx.CANCEL)
        self.SetSizer(sizer)

        # Add the function-specific configuration
        sizer.Add(self.top)
        self.function.display(self, *arguments, **flags)
        sizer.Add(buttons)

        # Event binding
        self.Bind(wx.EVT_BUTTON, self.OnOk, id=wx.ID_OK)
        self.Bind(wx.EVT_BUTTON, self.OnCancel, id=wx.ID_CANCEL)
Exemple #5
0
    def __init__(self, engine, sharp_engine, function, object, attribute,
            index=-1, escape=False):
        super(AddEditFunctionDialog, self).__init__(None,
                title=t("common.action"))
        self.engine = engine
        self.sharp_engine = sharp_engine
        self.world = sharp_engine.world
        self.function = function
        self.object = object
        self.attribute = attribute
        self.index = index
        self.escape = escape
        arguments = []
        flags = {}
        if index >= 0:
            script = getattr(self.object, self.attribute)
            lines = self.sharp_engine.format(script, return_str=False)
            line = lines[index]
            function, arguments, flags = self.sharp_engine.extract_arguments(line)

        # Dialog
        sizer = wx.BoxSizer(wx.VERTICAL)
        self.top = wx.BoxSizer(wx.VERTICAL)
        buttons = self.CreateButtonSizer(wx.OK | wx.CANCEL)
        self.SetSizer(sizer)

        # Add the function-specific configuration
        sizer.Add(self.top)
        self.function.display(self, *arguments, **flags)
        sizer.Add(buttons)

        # Event binding
        self.Bind(wx.EVT_BUTTON, self.OnOk, id=wx.ID_OK)
        self.Bind(wx.EVT_BUTTON, self.OnCancel, id=wx.ID_CANCEL)
Exemple #6
0
    def OnResponseUpdate(self, build=None):
        """The check for updates has returned."""
        if self.loading:
            self.loading.Destroy()
            if build is None:
                message = t("ui.message.update.noupdate")
                wx.MessageBox(message, t("ui.message.information"),
                        wx.OK | wx.ICON_INFORMATION)

        if build is not None:
            message = t("ui.message.update.available", build=build)
            value = wx.MessageBox(message, t("ui.message.update.title"),
                    wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)

            if value == wx.YES:
                self.CloseAll()
                os.startfile("updater.exe")
Exemple #7
0
 def OnEdit(self, e):
     """The 'edit' button is pressed."""
     index = self.existing.GetFirstSelected()
     script = getattr(self.object, self.attribute)
     lines = self.sharp_engine.format(script, return_str=False)
     try:
         line = lines[index]
     except IndexError:
         wx.MessageBox(t("ui.message.sharp.missing"),
                 t("ui.message.error"), wx.OK | wx.ICON_ERROR)
     else:
         name, arguments, flags = self.sharp_engine.extract_arguments(line)
         function = self.sharp_engine.functions[name[1:]]
         dialog = AddEditFunctionDialog(self.engine, self.sharp_engine,
                 function, self.object, self.attribute, index,
                 escape=self.escape)
         dialog.ShowModal()
         self.populate_existing()
         self.existing.SetFocus()
 def OnEdit(self, e):
     """The 'edit' button is pressed."""
     index = self.existing.GetFirstSelected()
     script = getattr(self.object, self.attribute)
     lines = self.sharp_engine.format(script, return_str=False)
     try:
         line = lines[index]
     except IndexError:
         wx.MessageBox(t("ui.message.sharp.missing"),
                 t("ui.message.error"), wx.OK | wx.ICON_ERROR)
     else:
         name, arguments, flags = self.sharp_engine.extract_arguments(line)
         function = self.sharp_engine.functions[name[1:]]
         dialog = AddEditFunctionDialog(self.engine, self.sharp_engine,
                 function, self.object, self.attribute, index,
                 escape=self.escape)
         dialog.ShowModal()
         self.populate_existing()
         self.existing.SetFocus()
Exemple #9
0
    def __init__(self, parent, session):
        AccessPanel.__init__(self, parent, history=True, lock_input=True)
        self.output.SetDefaultStyle(wx.TextAttr(wx.WHITE, wx.BLACK))
        self.session = session
        self.lines = []

        # Event binding
        self.output.Bind(wx.EVT_TEXT_PASTE, self.OnPaste)

        # Launch the console
        logger.debug("Starting the SharpScript console")
        self.Send(t("ui.dialog.sharp_script_console.banner"))
    def OnRemove(self, e):
        """The 'remove' button is pressed."""
        index = self.existing.GetFirstSelected()
        script = getattr(self.object, self.attribute)
        lines = self.sharp_engine.format(script, return_str=False)
        try:
            line = lines[index]
        except IndexError:
            wx.MessageBox(t("ui.message.sharp.missing"),
                    t("ui.message.error"), wx.OK | wx.ICON_ERROR)
        else:
            value = wx.MessageBox(t("ui.message.sharp.remove",
                    line=line), t("ui.alert.confirm"),
                    wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)

            if value == wx.YES:
                del lines[index]
                content = "\n".join(lines)
                setattr(self.object, self.attribute, content)
                self.populate_existing()
                self.existing.SetFocus()
Exemple #11
0
    def OnRemove(self, e):
        """The 'remove' button is pressed."""
        index = self.existing.GetFirstSelected()
        script = getattr(self.object, self.attribute)
        lines = self.sharp_engine.format(script, return_str=False)
        try:
            line = lines[index]
        except IndexError:
            wx.MessageBox(t("ui.message.sharp.missing"),
                    t("ui.message.error"), wx.OK | wx.ICON_ERROR)
        else:
            value = wx.MessageBox(t("ui.message.sharp.remove",
                    line=line), t("ui.alert.confirm"),
                    wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)

            if value == wx.YES:
                del lines[index]
                content = "\n".join(lines)
                setattr(self.object, self.attribute, content)
                self.populate_existing()
                self.existing.SetFocus()
Exemple #12
0
    def populate_list(self):
        """Populate the list with function names."""
        self.choices.DeleteAllItems()
        for function in self.functions:
            try:
                description = t("sharp.{name}.description".format(
                        name=function.name))
            except ValueError:
                description = function.description

            self.choices.Append((description, ))

        self.choices.Select(0)
        self.choices.Focus(0)
    def populate_list(self):
        """Populate the list with function names."""
        self.choices.DeleteAllItems()
        for function in self.functions:
            try:
                description = t("sharp.{name}.description".format(
                        name=function.name))
            except ValueError:
                description = function.description

            self.choices.Append((description, ))

        self.choices.Select(0)
        self.choices.Focus(0)
Exemple #14
0
    def OnImportOndisk(self, e):
        """Import a world on disk."""
        choose_file = t("ui.button.choose_file")
        extensions = "Zip archive (*.zip)|*.zip"
        dialog = wx.FileDialog(None, choose_file,
                "", "", extensions, wx.OPEN)
        result = dialog.ShowModal()
        if result == wx.ID_OK:
            filename = dialog.GetPath()

            # Try to install the world from the archive
            archive = ZipFile(filename)
            files = {name: archive.read(name) for name in archive.namelist()}
            options = files.get("world/options.conf")
            if options:
                infos = World.get_infos(options)
                name = infos.get("connection", {}).get("name")
                wizard = InstallWorld(self.engine, name, files)
                wizard.start()
Exemple #15
0
    def __init__(self, engine, world=None, panel=None):
        wx.Dialog.__init__(self, None, title=t("ui.dialog.console.title"))
        self.engine = engine
        self.world = world

        # Build the dialog
        sizer = wx.BoxSizer(wx.VERTICAL)
        self.SetSizer(sizer)

        # Add in the panel
        logger.debug("Creating the Python console")
        self.panel = ConsolePanel(self, engine, world, panel)

        # Finish designing the window
        sizer.Add(self.panel)
        sizer.Fit(self)

        # Event binding
        self.Bind(wx.EVT_CLOSE, self.OnClose)
Exemple #16
0
    def __init__(self, session):
        wx.Dialog.__init__(self,
                           None,
                           title=t("ui.dialog.sharp_script_console.title"))
        self.session = session

        # Build the dialog
        sizer = wx.BoxSizer(wx.VERTICAL)
        self.SetSizer(sizer)

        # Add in the panel
        self.panel = SharpScriptConsolePanel(self, session)
        self.TTS_on = session.engine.TTS_on
        self.TTS_outside = session.engine.TTS_outside

        # Finish designing the window
        sizer.Add(self.panel)
        sizer.Fit(self)

        # Event binding
        self.Bind(wx.EVT_CLOSE, self.OnClose)
Exemple #17
0
    def CreateMenuBar(self):
        """Create the GUI menu bar and hierarchy of menus."""
        menubar = wx.MenuBar()

        # Differemtn menus
        fileMenu = wx.Menu()
        gameMenu = wx.Menu()
        connectionMenu = wx.Menu()
        helpMenu = wx.Menu()

        ## File menu
        # New
        create = wx.MenuItem(fileMenu, -1, t("ui.menu.create"))
        self.Bind(wx.EVT_MENU, self.OnCreate, create)
        fileMenu.AppendItem(create)

        # Open
        open = wx.MenuItem(fileMenu, -1, t("ui.menu.open"))
        self.Bind(wx.EVT_MENU, self.OnOpen, open)
        fileMenu.AppendItem(open)

        # Close
        close_tab = wx.MenuItem(fileMenu, -1, t("ui.menu.close_tab"))
        self.Bind(wx.EVT_MENU, self.OnCloseTab, close_tab)
        fileMenu.AppendItem(close_tab)

        # Import
        import_world = wx.Menu()
        import_ondisk = import_world.Append(wx.ID_ANY,
                t("ui.menu.import_on_disk"))
        import_online = import_world.Append(wx.ID_ANY,
                t("ui.menu.import_online"))
        wx.MenuItem(fileMenu, -1, t("ui.menu.import"))
        self.Bind(wx.EVT_MENU, self.OnImportOndisk, import_ondisk)
        self.Bind(wx.EVT_MENU, self.OnImportOnline, import_online)
        fileMenu.AppendMenu(wx.ID_ANY, t("ui.menu.import"), import_world)

        # Preferences
        preferences = wx.MenuItem(fileMenu, -1, t("ui.menu.preferences"))
        self.Bind(wx.EVT_MENU, self.OnPreferences, preferences)
        fileMenu.AppendItem(preferences)

        # Quit
        quit = wx.MenuItem(fileMenu, -1, t("ui.menu.quit"))
        self.Bind(wx.EVT_MENU, self.OnQuit, quit)
        fileMenu.AppendItem(quit)

        ## Game menu
        # Aliases
        alias = wx.MenuItem(gameMenu, -1, t("ui.menu.aliases"))
        self.Bind(wx.EVT_MENU, self.OnAlias, alias)
        gameMenu.AppendItem(alias)

        # Macros
        macro = wx.MenuItem(gameMenu, -1, t("ui.menu.macro"))
        self.Bind(wx.EVT_MENU, self.OnMacro, macro)
        gameMenu.AppendItem(macro)

        # Triggers
        triggers = wx.MenuItem(gameMenu, -1, t("ui.menu.triggers"))
        self.Bind(wx.EVT_MENU, self.OnTriggers, triggers)
        gameMenu.AppendItem(triggers)

        ## Connection menu
        # Disconnect
        disconnect = wx.MenuItem(connectionMenu, -1, t("ui.menu.disconnect"))
        self.Bind(wx.EVT_MENU, self.OnDisconnect, disconnect)
        connectionMenu.AppendItem(disconnect)

        # Reconnect
        reconnect = wx.MenuItem(connectionMenu, -1, t("ui.menu.reconnect"))
        self.Bind(wx.EVT_MENU, self.OnReconnect, reconnect)
        connectionMenu.AppendItem(reconnect)

        ## Help menu
        # Basics
        basics = wx.MenuItem(helpMenu, -1, t("ui.menu.help_index"))
        self.Bind(wx.EVT_MENU, self.OnBasics, basics)
        helpMenu.AppendItem(basics)

        # News
        new = wx.MenuItem(helpMenu, -1, t("ui.menu.new"))
        self.Bind(wx.EVT_MENU, self.OnNew, new)
        helpMenu.AppendItem(new)

        # Check for updates
        updates = wx.MenuItem(helpMenu, -1, t("ui.menu.updates"))
        self.Bind(wx.EVT_MENU, self.OnCheckForUpdates, updates)
        helpMenu.AppendItem(updates)

        menubar.Append(fileMenu, t("ui.menu.file"))
        menubar.Append(gameMenu, t("ui.menu.game"))
        menubar.Append(connectionMenu, t("ui.menu.connection"))
        menubar.Append(helpMenu, t("ui.menu.help"))

        self.SetMenuBar(menubar)
Exemple #18
0
 def run(self):
     self.panel.Send(t("ui.dialog.console.warning"))
     self.console.interact()
     logger.debug("Begin interacting with the Python console")
Exemple #19
0
    def __init__(self, dialog, engine, sharp, object, attribute,
            text=False, escape=False):
        """Creates the frame.

        Arguments:
            dialog: the parent dialog.
            engine: the game engine.
            sharp: the SharpScript engine.
            object: the object containing the field to be edited.
            attribute: the attribute's name of the object to edit.
            text (default to False): should a text field be added?
            escape (default to false): the #send calls are removed.

        If the SharpEditor is to modify a trigger, for instance,
        particularly its "action" attribute, the trigger is the object
        and "action" is the attribute's name.

        """
        wx.Panel.__init__(self, dialog)
        self.engine = engine
        self.sharp_engine = sharp
        self.object = object
        self.attribute = attribute
        self.text = None
        self.escape = escape

        script = getattr(self.object, self.attribute)
        self.functions = sorted(sharp.functions.values(),
                key=lambda function: function.name)
        self.functions = [f for f in self.functions if f.description]

        # Shape
        sizer = wx.BoxSizer(wx.VERTICAL)
        top = wx.BoxSizer(wx.HORIZONTAL)
        bottom = wx.BoxSizer(wx.HORIZONTAL)
        self.SetSizer(sizer)

        # Insert a text field
        if text:
            s_text = wx.BoxSizer(wx.VERTICAL)
            l_text = wx.StaticText(self, label=t("common.action"))
            t_text = wx.TextCtrl(self, value=script, style=wx.TE_MULTILINE)
            self.text = t_text
            s_text.Add(l_text)
            s_text.Add(t_text)
            top.Add(s_text)

        # List of current functions
        self.existing = wx.ListCtrl(self,
                style=wx.LC_REPORT | wx.LC_SINGLE_SEL)
        self.existing.InsertColumn(0, t("common.action"))

        # Buttons
        self.edit = wx.Button(self, label=t("ui.button.edit"))
        self.remove = wx.Button(self, label=t("ui.button.remove"))
        top.Add(self.existing)
        top.Add(self.edit)
        top.Add(self.remove)
        self.populate_existing()

        # List of functions
        self.choices = wx.ListCtrl(self, style=wx.LC_REPORT | wx.LC_SINGLE_SEL)
        self.choices.InsertColumn(0, t("common.description"))
        self.populate_list()
        bottom.Add(self.choices)

        # Add button
        self.add = wx.Button(self, label=t("ui.button.add_action"))
        bottom.Add(self.add)

        # Event binding
        self.add.Bind(wx.EVT_BUTTON, self.OnAdd)
        self.edit.Bind(wx.EVT_BUTTON, self.OnEdit)
        self.remove.Bind(wx.EVT_BUTTON, self.OnRemove)
Exemple #20
0
 def OnCheckForUpdates(self, e):
     """Open the 'check for updates' dialog box."""
     self.create_updater(just_checking=True)
     dialog = LoadingDialog(t("ui.message.update.loading"))
     self.loading = dialog
     dialog.ShowModal()
Exemple #21
0
 def handle_disconnection(self):
     """The client has been disconnected for any reason."""
     message = u"--- {} ---".format(t("ui.client.disconnected"))
     self.Send(message)
     ScreenReader.talk(message, interrupt=False)
    def __init__(self, dialog, engine, sharp, object, attribute,
            text=False, escape=False):
        """Creates the frame.

        Arguments:
            dialog: the parent dialog.
            engine: the game engine.
            sharp: the SharpScript engine.
            object: the object containing the field to be edited.
            attribute: the attribute's name of the object to edit.
            text (default to False): should a text field be added?
            escape (default to false): the #send calls are removed.

        If the SharpEditor is to modify a trigger, for instance,
        particularly its "action" attribute, the trigger is the object
        and "action" is the attribute's name.

        """
        wx.Panel.__init__(self, dialog)
        self.engine = engine
        self.sharp_engine = sharp
        self.object = object
        self.attribute = attribute
        self.text = None
        self.escape = escape

        script = getattr(self.object, self.attribute)
        self.functions = sorted(sharp.functions.values(),
                key=lambda function: function.name)
        self.functions = [f for f in self.functions if f.description]

        # Shape
        sizer = wx.BoxSizer(wx.VERTICAL)
        top = wx.BoxSizer(wx.HORIZONTAL)
        bottom = wx.BoxSizer(wx.HORIZONTAL)
        self.SetSizer(sizer)

        # Insert a text field
        if text:
            s_text = wx.BoxSizer(wx.VERTICAL)
            l_text = wx.StaticText(self, label=t("common.action"))
            t_text = wx.TextCtrl(self, value=script, style=wx.TE_MULTILINE)
            self.text = t_text
            s_text.Add(l_text)
            s_text.Add(t_text)
            top.Add(s_text)

        # List of current functions
        self.existing = wx.ListCtrl(self,
                style=wx.LC_REPORT | wx.LC_SINGLE_SEL)
        self.existing.InsertColumn(0, t("common.action"))

        # Buttons
        self.edit = wx.Button(self, label=t("ui.button.edit"))
        self.remove = wx.Button(self, label=t("ui.button.remove"))
        top.Add(self.existing)
        top.Add(self.edit)
        top.Add(self.remove)
        self.populate_existing()

        # List of functions
        self.choices = wx.ListCtrl(self, style=wx.LC_REPORT | wx.LC_SINGLE_SEL)
        self.choices.InsertColumn(0, t("common.description"))
        self.populate_list()
        bottom.Add(self.choices)

        # Add button
        self.add = wx.Button(self, label=t("ui.button.add_action"))
        bottom.Add(self.add)

        # Event binding
        self.add.Bind(wx.EVT_BUTTON, self.OnAdd)
        self.edit.Bind(wx.EVT_BUTTON, self.OnEdit)
        self.remove.Bind(wx.EVT_BUTTON, self.OnRemove)