コード例 #1
0
class WorksheetEditor(Editor):
    DISCARD_FORMAT = 'Discard unsaved changes to worksheet "%s"?'
    DISCARD_FORMAT_BEFORE_QUIT = 'Save the changes to worksheet "%s" before quitting?'

    def __init__(self, notebook):
        Editor.__init__(self, notebook)

        self.buf = ShellBuffer(self.notebook)
        self.view = ShellView(self.buf)

        self.__font_is_custom_connection = global_settings.connect('notify::editor-font-is-custom', self.__update_font)
        self.__font_name_connection = global_settings.connect('notify::editor-font-name', self.__update_font)
        self.__update_font()

        self.widget = gtk.ScrolledWindow()
        self.widget.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)

        self.widget.add(self.view)

        self.widget.show_all()

        self.buf.worksheet.connect('notify::filename', lambda *args: self._update_filename())
        self.buf.worksheet.connect('notify::file', lambda *args: self._update_file())
        self.buf.worksheet.connect('notify::code-modified', lambda *args: self._update_modified())
        self.buf.worksheet.connect('notify::state', lambda *args: self._update_state())

    #######################################################
    # Callbacks
    #######################################################

    def __update_font(self, *arg):
        font_name = "monospace"
        if global_settings.editor_font_is_custom:
            font_name = global_settings.editor_font_name

        self.view.modify_font(pango.FontDescription(font_name))

    #######################################################
    # Overrides
    #######################################################

    def _get_display_name(self):
        if self.buf.worksheet.filename == None:
            return "Unsaved Worksheet %d" % self._unsaved_index
        else:
            return os.path.basename(self.buf.worksheet.filename)

    def _get_filename(self):
        return self.buf.worksheet.filename

    def _get_file(self):
        return self.buf.worksheet.file

    def _get_modified(self):
        return self.buf.worksheet.code_modified

    def _get_state(self):
        return self.buf.worksheet.state

    def _get_extension(self):
        return "rws"

    def _save(self, filename):
        self.buf.worksheet.save(filename)

    #######################################################
    # Public API
    #######################################################

    def close(self):
        Editor.close(self)
        self.buf.worksheet.close()
        global_settings.disconnect(self.__font_is_custom_connection)
        global_settings.disconnect(self.__font_name_connection)

    def load(self, filename):
        self.buf.worksheet.load(filename)
        self.buf.place_cursor(self.buf.get_start_iter())
        self.calculate()

    def calculate(self):
        self.view.calculate()

    def undo(self):
        self.buf.worksheet.undo()

    def redo(self):
        self.buf.worksheet.redo()
コード例 #2
0
class LibraryEditor(Editor):
    DISCARD_FORMAT = 'Discard unsaved changes to library "%s"?'
    DISCARD_FORMAT_BEFORE_QUIT = 'Save the changes to library "%s" before quitting?'

    def __init__(self, notebook):
        Editor.__init__(self, notebook)

        self.buf = ShellBuffer(self.notebook, edit_only=True)
        self.view = ShellView(self.buf)

        self.__font_is_custom_connection = global_settings.watch('editor-font-is-custom', self.__update_font)
        self.__font_name_connection = global_settings.watch('editor-font-name', self.__update_font)
        self.__update_font()

        self.widget = gtk.ScrolledWindow()
        self.widget.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)

        self.widget.add(self.view)

        self.widget.show_all()

        self.buf.worksheet.sig_filename_changed.connect( lambda *args: self._update_filename() )
        self.buf.worksheet.sig_file.connect(lambda *args: self._update_file())
        self.buf.worksheet.sig_code_modified.connect(lambda *args: self._update_modified())

    def do_destroy(self):
        self.buf.destroy()
        Editor.do_destroy(self)

    #######################################################
    # Callbacks
    #######################################################

    def __update_font(self):
        font_name = "monospace"
        if global_settings.editor_font_is_custom:
            font_name = global_settings.editor_font_name

        self.view.modify_font(pango.FontDescription(font_name))

    #######################################################
    # Overrides
    #######################################################

    def _get_display_name(self):
        if self.buf.worksheet.filename is None:
            return "Unsaved Library %d" % self._unsaved_index
        else:
            return os.path.basename(self.buf.worksheet.filename)

    def _get_filename(self):
        return self.buf.worksheet.filename

    def _get_file(self):
        return self.buf.worksheet.file

    def _get_modified(self):
        return self.buf.worksheet.code_modified

    def _get_extension(self):
        return "py"

    def _save(self, filename):
        self.buf.worksheet.save(filename)
        self.notebook.reset_module_by_filename(filename)

    def _create_print_operation(self):
        return WorksheetPrintOperation(self.buf.worksheet)

    def _export_to_pdf(self, filename, page_setup):
        export_to_pdf(self.buf.worksheet, filename, page_setup)

    @classmethod
    def _validate_name(cls, name):
        # Remove surrounding whitespace
        name = name.strip()
        if name == "":
            raise ValueError("Name cannot be empty")

        # Remove .py extension if present.
        name = re.sub(r".py$", "", name)

        # Apply identifier rules from
        # http://docs.python.org/reference/lexical_analysis.html
        if not _LETTER_OR_UNDERSCORE.match(name[0]):
            raise ValueError("Library name must start with a Latin letter or "
                             "an underscore")

        for c in name[1:]:
            if not _LETTER_DIGIT_OR_UNDERSCORE.match(c):
                raise ValueError("Library names can only contain Latin "
                                 "letters, numbers and underscores")

        return name

    #######################################################
    # Public API
    #######################################################

    def load(self, filename, escape=False):
        self.buf.worksheet.load(filename, escape=escape)
        self.buf.place_cursor(self.buf.get_start_iter())

    def undo(self):
        self.buf.worksheet.undo()

    def redo(self):
        self.buf.worksheet.redo()
コード例 #3
0
class LibraryEditor(Editor):
    DISCARD_FORMAT = 'Discard unsaved changes to library "%s"?'
    DISCARD_FORMAT_BEFORE_QUIT = 'Save the changes to library "%s" before quitting?'

    def __init__(self, notebook):
        Editor.__init__(self, notebook)

        self.buf = ShellBuffer(self.notebook, edit_only=True)
        self.view = ShellView(self.buf)

        self.__font_is_custom_connection = global_settings.watch(
            'editor-font-is-custom', self.__update_font)
        self.__font_name_connection = global_settings.watch(
            'editor-font-name', self.__update_font)
        self.__update_font()

        self.widget = gtk.ScrolledWindow()
        self.widget.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)

        self.widget.add(self.view)

        self.widget.show_all()

        self.buf.worksheet.sig_filename_changed.connect(
            lambda *args: self._update_filename())
        self.buf.worksheet.sig_file.connect(lambda *args: self._update_file())
        self.buf.worksheet.sig_code_modified.connect(
            lambda *args: self._update_modified())

    def do_destroy(self):
        self.buf.destroy()
        Editor.do_destroy(self)

    #######################################################
    # Callbacks
    #######################################################

    def __update_font(self):
        font_name = "monospace"
        if global_settings.editor_font_is_custom:
            font_name = global_settings.editor_font_name

        self.view.modify_font(pango.FontDescription(font_name))

    #######################################################
    # Overrides
    #######################################################

    def _get_display_name(self):
        if self.buf.worksheet.filename is None:
            return "Unsaved Library %d" % self._unsaved_index
        else:
            return os.path.basename(self.buf.worksheet.filename)

    def _get_filename(self):
        return self.buf.worksheet.filename

    def _get_file(self):
        return self.buf.worksheet.file

    def _get_modified(self):
        return self.buf.worksheet.code_modified

    def _get_extension(self):
        return "py"

    def _save(self, filename):
        self.buf.worksheet.save(filename)
        self.notebook.reset_module_by_filename(filename)

    def _create_print_operation(self):
        return WorksheetPrintOperation(self.buf.worksheet)

    def _export_to_pdf(self, filename, page_setup):
        export_to_pdf(self.buf.worksheet, filename, page_setup)

    @classmethod
    def _validate_name(cls, name):
        # Remove surrounding whitespace
        name = name.strip()
        if name == "":
            raise ValueError("Name cannot be empty")

        # Remove .py extension if present.
        name = re.sub(r".py$", "", name)

        # Apply identifier rules from
        # http://docs.python.org/reference/lexical_analysis.html
        if not _LETTER_OR_UNDERSCORE.match(name[0]):
            raise ValueError("Library name must start with a Latin letter or "
                             "an underscore")

        for c in name[1:]:
            if not _LETTER_DIGIT_OR_UNDERSCORE.match(c):
                raise ValueError("Library names can only contain Latin "
                                 "letters, numbers and underscores")

        return name

    #######################################################
    # Public API
    #######################################################

    def load(self, filename, escape=False):
        self.buf.worksheet.load(filename, escape=escape)
        self.buf.place_cursor(self.buf.get_start_iter())

    def undo(self):
        self.buf.worksheet.undo()

    def redo(self):
        self.buf.worksheet.redo()
コード例 #4
0
class WorksheetEditor(Editor):
    DISCARD_FORMAT = 'Discard unsaved changes to worksheet "%s"?'
    DISCARD_FORMAT_BEFORE_QUIT = 'Save the changes to worksheet "%s" before quitting?'

    def __init__(self, notebook):
        Editor.__init__(self, notebook)

        self.buf = ShellBuffer(self.notebook)
        self.view = ShellView(self.buf)
        self.config_state = None

        self.view.connect('notify::sidebar-open', self.on_notify_sidebar_open)

        global_settings.watch('editor-font-is-custom', self.__update_font)
        global_settings.watch('editor-font-name', self.__update_font)
        self.__update_font()

        self.widget = ViewSidebarLayout()
        self.widget.set_view(self.view)
        self.widget.set_sidebar(self.view.sidebar)
        self.widget.set_sidebar_open(self.view.sidebar_open)
        self.widget.connect('notify::sidebar-width', self.on_notify_sidebar_width)

        self.widget.show_all()

        self.buf.worksheet.sig_filename_changed.connect( lambda *args: self._update_filename() )
        self.buf.worksheet.sig_file.connect( lambda *args: self._update_file() )
        self.buf.worksheet.sig_code_modified.connect( lambda *args: self._update_modified() )
        self.buf.worksheet.sig_state.connect( lambda *args: self._update_state() )

    def do_destroy(self):
        self.buf.destroy()
        Editor.do_destroy(self)

    #######################################################
    # Callbacks
    #######################################################

    def __update_font(self):
        font_name = "monospace"
        if global_settings.editor_font_is_custom:
            font_name = global_settings.editor_font_name

        self.view.modify_font(pango.FontDescription(font_name))

    def on_notify_sidebar_open(self, *args):
        self.widget.set_sidebar_open(self.view.sidebar_open)

    def on_notify_sidebar_width(self, *args):
        if self.config_state is not None:
            self.config_state.set_sidebar_width(self.widget.sidebar_width)

    #######################################################
    # Overrides
    #######################################################

    def _get_display_name(self):
        if self.buf.worksheet.filename is None:
            return "Unsaved Worksheet %d" % self._unsaved_index
        else:
            return os.path.basename(self.buf.worksheet.filename)

    def _get_filename(self):
        return self.buf.worksheet.filename

    def _get_file(self):
        return self.buf.worksheet.file

    def _get_modified(self):
        return self.buf.worksheet.code_modified

    def _get_state(self):
        return self.buf.worksheet.state

    def _get_extension(self):
        return "rws"

    def _save(self, filename):
        old_config_state = self.config_state
        self.buf.worksheet.save(filename)
        self.config_state = application.state.get_worksheet_state(filename)
        if old_config_state:
            old_sidebar_width = old_config_state.get_sidebar_width()
            if old_sidebar_width >= 0:
                self.config_state.set_sidebar_width(old_sidebar_width)

    def _create_print_operation(self):
        return WorksheetPrintOperation(self.buf.worksheet)

    def _export_to_pdf(self, filename, page_setup):
        export_to_pdf(self.buf.worksheet, filename, page_setup)

    @classmethod
    def _validate_name(cls, name):
        return reunicode.validate_name(name)

    #######################################################
    # Public API
    #######################################################

    def load(self, filename, escape=False):
        self.buf.worksheet.load(filename, escape=escape)
        self.buf.place_cursor(self.buf.get_start_iter())
        self.config_state = application.state.get_worksheet_state(filename)
        sidebar_width = self.config_state.get_sidebar_width()
        if sidebar_width >= 0:
            self.widget.sidebar_width = sidebar_width

    def calculate(self, end_at_insert=False):
        self.view.calculate(end_at_insert)

    def interrupt(self):
        self.buf.worksheet.interrupt()

    def undo(self):
        self.buf.worksheet.undo()

    def redo(self):
        self.buf.worksheet.redo()
コード例 #5
0
class WorksheetEditor(Editor):
    DISCARD_FORMAT = 'Discard unsaved changes to worksheet "%s"?'
    DISCARD_FORMAT_BEFORE_QUIT = 'Save the changes to worksheet "%s" before quitting?'

    def __init__(self, notebook):
        Editor.__init__(self, notebook)

        self.buf = ShellBuffer(self.notebook)
        self.view = ShellView(self.buf)
        self.config_state = None

        self.view.connect('notify::sidebar-open', self.on_notify_sidebar_open)

        global_settings.watch('editor-font-is-custom', self.__update_font)
        global_settings.watch('editor-font-name', self.__update_font)
        self.__update_font()

        self.widget = ViewSidebarLayout()
        self.widget.set_view(self.view)
        self.widget.set_sidebar(self.view.sidebar)
        self.widget.set_sidebar_open(self.view.sidebar_open)
        self.widget.connect('notify::sidebar-width',
                            self.on_notify_sidebar_width)

        self.widget.show_all()

        self.buf.worksheet.sig_filename_changed.connect(
            lambda *args: self._update_filename())
        self.buf.worksheet.sig_file.connect(lambda *args: self._update_file())
        self.buf.worksheet.sig_code_modified.connect(
            lambda *args: self._update_modified())
        self.buf.worksheet.sig_state.connect(
            lambda *args: self._update_state())

    def do_destroy(self):
        self.buf.destroy()
        Editor.do_destroy(self)

    #######################################################
    # Callbacks
    #######################################################

    def __update_font(self):
        font_name = "monospace"
        if global_settings.editor_font_is_custom:
            font_name = global_settings.editor_font_name

        self.view.modify_font(pango.FontDescription(font_name))

    def on_notify_sidebar_open(self, *args):
        self.widget.set_sidebar_open(self.view.sidebar_open)

    def on_notify_sidebar_width(self, *args):
        if self.config_state is not None:
            self.config_state.set_sidebar_width(self.widget.sidebar_width)

    #######################################################
    # Overrides
    #######################################################

    def _get_display_name(self):
        if self.buf.worksheet.filename is None:
            return "Unsaved Worksheet %d" % self._unsaved_index
        else:
            return os.path.basename(self.buf.worksheet.filename)

    def _get_filename(self):
        return self.buf.worksheet.filename

    def _get_file(self):
        return self.buf.worksheet.file

    def _get_modified(self):
        return self.buf.worksheet.code_modified

    def _get_state(self):
        return self.buf.worksheet.state

    def _get_extension(self):
        return "rws"

    def _save(self, filename):
        old_config_state = self.config_state
        self.buf.worksheet.save(filename)
        self.config_state = application.state.get_worksheet_state(filename)
        if old_config_state:
            old_sidebar_width = old_config_state.get_sidebar_width()
            if old_sidebar_width >= 0:
                self.config_state.set_sidebar_width(old_sidebar_width)

    def _create_print_operation(self):
        return WorksheetPrintOperation(self.buf.worksheet)

    def _export_to_pdf(self, filename, page_setup):
        export_to_pdf(self.buf.worksheet, filename, page_setup)

    @classmethod
    def _validate_name(cls, name):
        return reunicode.validate_name(name)

    #######################################################
    # Public API
    #######################################################

    def load(self, filename, escape=False):
        self.buf.worksheet.load(filename, escape=escape)
        self.buf.place_cursor(self.buf.get_start_iter())
        self.config_state = application.state.get_worksheet_state(filename)
        sidebar_width = self.config_state.get_sidebar_width()
        if sidebar_width >= 0:
            self.widget.sidebar_width = sidebar_width

    def calculate(self, end_at_insert=False):
        self.view.calculate(end_at_insert)

    def interrupt(self):
        self.buf.worksheet.interrupt()

    def undo(self):
        self.buf.worksheet.undo()

    def redo(self):
        self.buf.worksheet.redo()