Esempio n. 1
0
    def OnUpdate(self, event):
        """Updates the toolbar states"""

        # Gray out undo and redo id not available

        undo_toolid = self.label2id["Undo"]
        redo_toolid = self.label2id["Redo"]

        self.EnableTool(undo_toolid, undo.stack().canundo())
        self.EnableTool(redo_toolid, undo.stack().canredo())

        # Set ToolTip strings to potential next undo / redo action
        undotext = undo.stack().undotext()
        undo_tool = self.FindTool(undo_toolid)
        if undotext is None:
            undo_tool.SetShortHelp(_("No undo actions available"))
        else:
            undo_tool.SetShortHelp(undotext)

        redotext = undo.stack().redotext()
        redo_tool = self.FindTool(redo_toolid)
        if redotext is None:
            redo_tool.SetShortHelp(_("No redo actions available"))
        else:
            redo_tool.SetShortHelp(redotext)

        self.Refresh()

        event.Skip()
Esempio n. 2
0
    def OnUpdate(self, event):
        """Updates the toolbar states"""

        # Gray out undo and redo id not available

        undo_toolid = self.label2id["Undo"]
        redo_toolid = self.label2id["Redo"]

        self.EnableTool(undo_toolid, undo.stack().canundo())
        self.EnableTool(redo_toolid, undo.stack().canredo())

        # Set ToolTip strings to potential next undo / redo action
        undotext = undo.stack().undotext()
        undo_tool = self.FindTool(undo_toolid)
        if undotext is None:
            undo_tool.SetShortHelp(_("No undo actions available"))
        else:
            undo_tool.SetShortHelp(undotext)

        redotext = undo.stack().redotext()
        redo_tool = self.FindTool(redo_toolid)
        if redotext is None:
            redo_tool.SetShortHelp(_("No redo actions available"))
        else:
            redo_tool.SetShortHelp(redotext)

        self.Refresh()

        event.Skip()
Esempio n. 3
0
    def OnUpdate(self, event):
        """Menu state update"""

        if wx.ID_UNDO in self.id2menuitem:
            undo_item = self.id2menuitem[wx.ID_UNDO]
            undo_item.Enable(undo.stack().canundo())

        if wx.ID_REDO in self.id2menuitem:
            redo_item = self.id2menuitem[wx.ID_REDO]
            redo_item.Enable(undo.stack().canredo())

        event.Skip()
Esempio n. 4
0
    def OnSave(self, event):
        """File save event handler"""

        try:
            filetype = event.attr["filetype"]

        except (KeyError, AttributeError):
            filetype = None

        filepath = self.main_window.filepath
        if filepath is None:
            filetype = config["default_save_filetype"]

        if filetype is None:

            f2w = get_filetypes2wildcards(["pys", "pysu", "xls", "all"])
            __filetypes = f2w.keys()

            # Check if the file extension matches any valid save filetype
            for __filetype in __filetypes:
                if splitext(filepath)[-1][1:] == __filetype:
                    filetype = __filetype
                    break

        # If there is no filepath or no filetype is found then jump to save as

        if self.main_window.filepath is None or filetype is None:
            post_command_event(self.main_window, self.main_window.SaveAsMsg)
            return

        # Save the grid

        post_command_event(self.main_window,
                           self.main_window.GridActionSaveMsg,
                           attr={
                               "filepath": self.main_window.filepath,
                               "filetype": filetype
                           })

        # Update undo stack savepoint
        undo.stack().savepoint()

        # Display file save in status bar

        statustext = self.main_window.filepath.split("/")[-1] + " saved."
        post_command_event(self.main_window,
                           self.main_window.StatusBarMsg,
                           text=statustext)
Esempio n. 5
0
    def OnSave(self, event):
        """File save event handler"""

        try:
            filetype = event.attr["filetype"]

        except (KeyError, AttributeError):
            filetype = None

        filepath = self.main_window.filepath
        if filepath is None:
            filetype = config["default_save_filetype"]

        if filetype is None:

            f2w = get_filetypes2wildcards(["pys", "pysu", "xls", "all"])
            __filetypes = f2w.keys()

            # Check if the file extension matches any valid save filetype
            for __filetype in __filetypes:
                if splitext(filepath)[-1][1:] == __filetype:
                    filetype = __filetype
                    break

        # If there is no filepath or no filetype is found then jump to save as

        if self.main_window.filepath is None or filetype is None:
            post_command_event(self.main_window,
                               self.main_window.SaveAsMsg)
            return

        # Save the grid

        post_command_event(self.main_window,
                           self.main_window.GridActionSaveMsg,
                           attr={"filepath": self.main_window.filepath,
                                 "filetype": filetype})

        # Update undo stack savepoint
        undo.stack().savepoint()

        # Display file save in status bar

        statustext = self.main_window.filepath.split("/")[-1] + " saved."
        post_command_event(self.main_window,
                           self.main_window.StatusBarMsg,
                           text=statustext)
Esempio n. 6
0
    def OnContentChanged(self, event):
        """Titlebar star adjustment event handler"""

        self.main_window.grid.update_attribute_toolbar()

        title = self.main_window.GetTitle()

        if undo.stack().haschanged():
            # Put * in front of title
            if title[:2] != "* ":
                new_title = "* " + title
                post_command_event(self.main_window, self.main_window.TitleMsg,
                                   text=new_title)

        elif title[:2] == "* ":
            # Remove * in front of title
            new_title = title[2:]
            post_command_event(self.main_window, self.main_window.TitleMsg,
                               text=new_title)
Esempio n. 7
0
    def OnClose(self, event):
        """Program exit event handler"""

        # If changes have taken place save of old grid

        if undo.stack().haschanged():
            save_choice = self.interfaces.get_save_request_from_user()

            if save_choice is None:
                # Cancelled close operation
                return

            elif save_choice:
                # User wants to save content
                post_command_event(self.main_window, self.main_window.SaveMsg)

        # Save the AUI state

        config["window_layout"] = repr(self.main_window._mgr.SavePerspective())

        # Uninit the AUI stuff

        self.main_window._mgr.UnInit()

        # Save config
        config.save()

        # Close main_window

        self.main_window.Destroy()

        # Set file mode to 600 to protect GPG passwd a bit
        sp = wx.StandardPaths.Get()
        pyspreadrc_path = sp.GetUserConfigDir() + "/." + config.config_filename
        try:
            os.chmod(pyspreadrc_path, 0600)
        except OSError:
            dummyfile = open(pyspreadrc_path, "w")
            dummyfile.close()
            os.chmod(pyspreadrc_path, 0600)
Esempio n. 8
0
    def OnOpen(self, event):
        """File open event handler"""

        # If changes have taken place save of old grid
        if undo.stack().haschanged():
            save_choice = self.interfaces.get_save_request_from_user()

            if save_choice is None:
                # Cancelled close operation
                return

            elif save_choice:
                # User wants to save content
                post_command_event(self.main_window, self.main_window.SaveMsg)

        # Get filepath from user
        f2w = get_filetypes2wildcards(
            ["pys", "pysu", "xls", "xlsx", "ods", "all"])
        filetypes = f2w.keys()
        wildcards = f2w.values()
        wildcard = "|".join(wildcards)

        message = _("Choose file to open.")
        style = wx.OPEN

        default_filetype = config["default_open_filetype"]
        try:
            default_filterindex = filetypes.index(default_filetype)
        except ValueError:
            # Be graceful if the user has entered an unkown filetype
            default_filterindex = 0

        get_fp_fidx = self.interfaces.get_filepath_findex_from_user
        filepath, filterindex = get_fp_fidx(wildcard, message, style,
                                            filterindex=default_filterindex)

        if filepath is None:
            return

        filetype = filetypes[filterindex]

        # Change the main window filepath state

        self.main_window.filepath = filepath

        # Load file into grid
        post_command_event(self.main_window,
                           self.main_window.GridActionOpenMsg,
                           attr={"filepath": filepath, "filetype": filetype})

        # Set Window title to new filepath

        title_text = filepath.split("/")[-1] + " - pyspread"
        post_command_event(self.main_window,
                           self.main_window.TitleMsg, text=title_text)

        self.main_window.grid.ForceRefresh()

        if is_gtk():
            try:
                wx.Yield()
            except:
                pass

        # Update savepoint and clear the undo stack
        undo.stack().clear()
        undo.stack().savepoint()

        # Update content changed state
        try:
            post_command_event(self.main_window, self.ContentChangedMsg)
        except TypeError:
            # The main window does not exist any more
            pass
Esempio n. 9
0
    def __init__(self, parent, *args, **kwargs):
        try:
            S = kwargs.pop("S")

        except KeyError:
            S = None

        try:
            dimensions = kwargs.pop("dimensions")

        except KeyError:
            dimensions = (
                config["grid_rows"],
                config["grid_columns"],
                config["grid_tables"])

        wx.Frame.__init__(self, parent, *args, **kwargs)

        self.interfaces = GuiInterfaces(self)

        try:
            self._mgr = aui.AuiManager(self)

        except Exception:
            # This may fail if py.test runs under Windows
            # Therefore, we set up a basic framework for the unit tests
            self.grid = Grid(self, -1, S=S, dimensions=dimensions)
            self.clipboard = Clipboard()
            self.actions = AllMainWindowActions(self.grid)

        self.parent = parent

        self.handlers = MainWindowEventHandlers(self)

        # Program states
        # --------------

        self._states()

        # GUI elements
        # ------------

        # Menu Bar
        self.menubar = wx.MenuBar()
        self.main_menu = MainMenu(parent=self, menubar=self.menubar)
        self.SetMenuBar(self.menubar)

        # Disable menu item for leaving safe mode
        post_command_event(self, self.SafeModeExitMsg)

        # Status bar
        statusbar = StatusBar(self)
        self.SetStatusBar(statusbar)

        welcome_text = _("Welcome to pyspread.")
        post_command_event(self, self.StatusBarMsg, text=welcome_text)

        # Toolbars
        self.main_toolbar = MainToolbar(self, -1)
        self.macro_toolbar = MacroToolbar(self, -1)
        self.find_toolbar = FindToolbar(self, -1)
        self.attributes_toolbar = AttributesToolbar(self, -1)
        self.widget_toolbar = WidgetToolbar(self, -1)

        # Entry line
        self.entry_line_panel = EntryLineToolbarPanel(self, -1)

        # Main grid
        self.grid = Grid(self, -1, S=S, dimensions=dimensions)

        # TableChoiceListCtrl
        self.table_list_panel = TableChoiceListCtrl(self, self.grid)

        # Macro panel
        macros = self.grid.code_array.macros
        self.macro_panel = MacroPanel(self, macros, -1)

        # Clipboard
        self.clipboard = Clipboard()

        # Main window actions

        self.actions = AllMainWindowActions(self.grid)

        # Layout and bindings

        self._set_properties()
        self._do_layout()
        self._bind()

        if is_gtk():
            try:
                wx.Yield()
            except:
                pass

        # Update undo stack savepoint
        undo.stack().savepoint()

        # Update content changed state
        try:
            post_command_event(self.grid.main_window,
                               self.grid.ContentChangedMsg)
        except TypeError:
            # The main window does not exist any more
            pass
Esempio n. 10
0
    def OnNew(self, event):
        """New grid event handler"""

        # If changes have taken place save of old grid

        if undo.stack().haschanged():
            save_choice = self.interfaces.get_save_request_from_user()

            if save_choice is None:
                # Cancelled close operation
                return

            elif save_choice:
                # User wants to save content
                post_command_event(self.main_window, self.main_window.SaveMsg)

        # Get grid dimensions

        shape = self.interfaces.get_dimensions_from_user(no_dim=3)

        if shape is None:
            return

        # Set new filepath and post it to the title bar

        self.main_window.filepath = None
        post_command_event(self.main_window, self.main_window.TitleMsg,
                           text="pyspread")

        # Clear globals
        self.main_window.grid.actions.clear_globals_reload_modules()

        # Create new grid
        post_command_event(self.main_window, self.main_window.GridActionNewMsg,
                           shape=shape)

        # Update TableChoiceIntCtrl
        post_command_event(self.main_window, self.main_window.ResizeGridMsg,
                           shape=shape)

        if is_gtk():
            try:
                wx.Yield()
            except:
                pass

        self.main_window.grid.actions.change_grid_shape(shape)

        self.main_window.grid.GetTable().ResetView()
        self.main_window.grid.ForceRefresh()

        # Display grid creation in status bar
        msg = _("New grid with dimensions {dim} created.").format(dim=shape)
        post_command_event(self.main_window, self.main_window.StatusBarMsg,
                           text=msg)

        self.main_window.grid.ForceRefresh()

        if is_gtk():
            try:
                wx.Yield()
            except:
                pass

        # Update undo stack savepoint and clear undo stack
        undo.stack().clear()
        undo.stack().savepoint()

        # Update content changed state
        try:
            post_command_event(self.main_window, self.ContentChangedMsg)
        except TypeError:
            # The main window does not exist any more
            pass