Пример #1
0
    def __init__(self, app):
        KeepNoteEditor.__init__(self, app)
        self._app = app
        self._notebook = None

        self._link_picker = None
        self._maxlinks = 10 # maximum number of links to show in link picker
                

        # state
        self._page = None                  # current NoteBookPage
        self._page_scrolls = {}            # remember scroll in each page
        self._page_cursors = {}
        self._textview_io = RichTextIO()
        
        
        # textview and its callbacks
        if SourceView:
            self._textview = SourceView(SourceBuffer())
            self._textview.get_buffer().set_highlight_syntax(True)
            #self._textview.set_show_margin(True)
            #self._textview.disable()
        else:
            self._textview = RichTextView(RichTextBuffer(
                    self._app.get_richtext_tag_table()))    # textview
            self._textview.disable()        
            self._textview.connect("modified", self._on_modified_callback)
            self._textview.connect("visit-url", self._on_visit_url)
        

        # scrollbars
        self._sw = gtk.ScrolledWindow()
        self._sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        self._sw.set_shadow_type(gtk.SHADOW_IN)       
        self._sw.add(self._textview)
        self.pack_start(self._sw)
        
        
        #self._socket = gtk.Socket()
        #self.pack_start(self._socket)
        
        # menus
        #self.editor_menus = EditorMenus(self._app, self)

        # find dialog
        #self.find_dialog = dialog_find.KeepNoteFindDialog(self)

        self.show_all()
Пример #2
0
    def __init__(self, app):
        KeepNoteEditor.__init__(self, app)
        self._app = app
        self._notebook = None

        # state
        self._page = None  # current NoteBookPage
        self._page_scrolls = {}  # remember scroll in each page
        self._page_cursors = {}
        self._textview_io = RichTextIO()

        # textview and its callbacks
        self._textview = RichTextView(
            RichTextBuffer(self._app.get_richtext_tag_table()))  # textview
        self._textview.disable()
        self._textview.connect("modified", self._on_modified_callback)
        self._textview.connect("visit-url", self._on_visit_url)

        # scrollbars
        self._sw = gtk.ScrolledWindow()
        self._sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        self._sw.set_shadow_type(gtk.SHADOW_IN)
        self._sw.add(self._textview)
        self.pack_start(self._sw)

        #self._socket = gtk.Socket()
        #self.pack_start(self._socket)

        # menus
        self.editor_menus = EditorMenus(self._app, self)

        # find dialog
        self.find_dialog = dialog_find.KeepNoteFindDialog(self)

        self.show_all()
Пример #3
0
class TextEditor(KeepNoteEditor):
    def __init__(self, app):
        KeepNoteEditor.__init__(self, app)
        self._app = app
        self._notebook = None

        self._link_picker = None
        self._maxlinks = 10  # maximum number of links to show in link picker

        # state
        self._page = None  # current NoteBookPage
        self._page_scrolls = {}  # remember scroll in each page
        self._page_cursors = {}
        self._textview_io = RichTextIO()

        # textview and its callbacks
        if SourceView:
            self._textview = SourceView(SourceBuffer())
            self._textview.get_buffer().set_highlight_syntax(True)
            # self._textview.set_show_margin(True)
            # self._textview.disable()
        else:
            self._textview = RichTextView(RichTextBuffer(self._app.get_richtext_tag_table()))  # textview
            self._textview.disable()
            self._textview.connect("modified", self._on_modified_callback)
            self._textview.connect("visit-url", self._on_visit_url)

        # scrollbars
        self._sw = gtk.ScrolledWindow()
        self._sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        self._sw.set_shadow_type(gtk.SHADOW_IN)
        self._sw.add(self._textview)
        self.pack_start(self._sw)

        # self._socket = gtk.Socket()
        # self.pack_start(self._socket)

        # menus
        # self.editor_menus = EditorMenus(self._app, self)

        # find dialog
        # self.find_dialog = dialog_find.KeepNoteFindDialog(self)

        self.show_all()

    def set_notebook(self, notebook):
        """Set notebook for editor"""
        # set new notebook
        self._notebook = notebook

        if self._notebook:
            # read default font
            pass
        else:
            # no new notebook, clear the view
            self.clear_view()

    def load_preferences(self, app_pref, first_open=False):
        """Load application preferences"""

        # self.editor_menus.enable_spell_check(
        #    self._app.pref.get("editors", "general", "spell_check",
        #                       default=True))

        if not SourceView:
            self._textview.set_default_font("Monospace 10")

    def save_preferences(self, app_pref):
        """Save application preferences"""
        # record state in preferences
        # app_pref.set("editors", "general", "spell_check",
        #             self._textview.is_spell_check_enabled())

    def get_textview(self):
        """Return the textview"""
        return self._textview

    def is_focus(self):
        """Return True if text editor has focus"""
        return self._textview.is_focus()

    def grab_focus(self):
        """Pass focus to textview"""
        self._textview.grab_focus()

    def clear_view(self):
        """Clear editor view"""
        self._page = None
        if not SourceView:
            self._textview.disable()

    def undo(self):
        """Undo the last action in the viewer"""
        self._textview.undo()

    def redo(self):
        """Redo the last action in the viewer"""
        self._textview.redo()

    def view_nodes(self, nodes):
        """View a page in the editor"""
        # editor cannot view multiple nodes at once
        # if asked to, it will view none
        if len(nodes) > 1:
            nodes = []

        # save current page before changing nodes
        self.save()
        self._save_cursor()

        if len(nodes) == 0:
            self.clear_view()

        else:
            page = nodes[0]
            self._page = page
            if not SourceView:
                self._textview.enable()

            try:
                if page.has_attr("payload_filename"):
                    # text = safefile.open(
                    #    os.path.join(page.get_path(),
                    #                 page.get_attr("payload_filename")),
                    #    codec="utf-8").read()
                    infile = page.open_file(page.get_attr("payload_filename"), "r", "utf-8")
                    text = infile.read()
                    infile.close()
                    self._textview.get_buffer().set_text(text)
                    self._load_cursor()

                    if SourceView:
                        manager = SourceLanguageManager()
                        # print manager.get_language_ids()
                        # lang = manager.get_language_from_mime_type(
                        #    page.get_attr("content_type"))
                        lang = manager.get_language("python")
                        self._textview.get_buffer().set_language(lang)

                else:
                    self.clear_view()

            except RichTextError, e:
                self.clear_view()
                self.emit("error", e.msg, e)
            except Exception, e:
                self.clear_view()
                self.emit("error", "Unknown error", e)
Пример #4
0
class TextEditor(KeepNoteEditor):
    def __init__(self, app):
        KeepNoteEditor.__init__(self, app)
        self._app = app
        self._notebook = None

        # state
        self._page = None  # current NoteBookPage
        self._page_scrolls = {}  # remember scroll in each page
        self._page_cursors = {}
        self._textview_io = RichTextIO()

        # textview and its callbacks
        self._textview = RichTextView(
            RichTextBuffer(self._app.get_richtext_tag_table()))  # textview
        self._textview.disable()
        self._textview.connect("modified", self._on_modified_callback)
        self._textview.connect("visit-url", self._on_visit_url)

        # scrollbars
        self._sw = gtk.ScrolledWindow()
        self._sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        self._sw.set_shadow_type(gtk.SHADOW_IN)
        self._sw.add(self._textview)
        self.pack_start(self._sw)

        #self._socket = gtk.Socket()
        #self.pack_start(self._socket)

        # menus
        self.editor_menus = EditorMenus(self._app, self)

        # find dialog
        self.find_dialog = dialog_find.KeepNoteFindDialog(self)

        self.show_all()

    def set_notebook(self, notebook):
        """Set notebook for editor"""

        # set new notebook
        self._notebook = notebook

        if self._notebook:
            # read default font
            pass
        else:
            # no new notebook, clear the view
            self.clear_view()

    def load_preferences(self, app_pref, first_open=False):
        """Load application preferences"""

        self.editor_menus.enable_spell_check(
            self._app.pref.get(
                "editors", "general", "spell_check", default=True))

        self._textview.set_default_font("Monospace 10")

    def save_preferences(self, app_pref):
        """Save application preferences"""

        # record state in preferences
        app_pref.set("editors", "general", "spell_check",
                     self._textview.is_spell_check_enabled())

    def get_textview(self):
        """Return the textview"""
        return self._textview

    def is_focus(self):
        """Return True if text editor has focus"""
        return self._textview.is_focus()

    def grab_focus(self):
        """Pass focus to textview"""
        self._textview.grab_focus()

    def clear_view(self):
        """Clear editor view"""
        self._page = None
        self._textview.disable()

    def undo(self):
        """Undo the last action in the viewer"""
        self._textview.undo()

    def redo(self):
        """Redo the last action in the viewer"""
        self._textview.redo()

    def view_pages(self, pages):
        """View a page in the editor"""

        # editor cannot view multiple pages at once
        # if asked to, it will view none
        if len(pages) > 1:
            pages = []

        # save current page before changing pages
        self.save()
        self._save_cursor()

        if len(pages) == 0:
            self.clear_view()

        else:
            page = pages[0]
            self._page = page
            self._textview.enable()

            try:
                if page.has_attr("payload_filename"):
                    infile = page.open_file(page.get_attr("payload_filename"))
                    text = infile.read()
                    infile.close()
                    self._textview.get_buffer().set_text(text)
                    self._load_cursor()

                else:
                    self.clear_view()

            except UnicodeDecodeError, e:
                self.clear_view()
            except RichTextError, e:
                self.clear_view()
                self.emit("error", e.msg, e)
            except Exception, e:
                keepnote.log_error()
                self.clear_view()
                self.emit("error", "Unknown error", e)