Beispiel #1
0
    def open_uberwriter_markdown(self, _widget=None, _data=None):
        """open a markdown mini tutorial
        """
        if self.check_change() == Gtk.ResponseType.CANCEL:
            return

        self.load_file(helpers.get_media_file('uberwriter_markdown.md'))
Beispiel #2
0
    def toggle_preview(self, widget, data=None):
        if widget.get_active():

            # Toggle buttons

            # self.preview_button.set_active(True)
            # self.preview_mnu_button.set_active(True)
            # Insert a tag with ID to scroll to
            # self.TextBuffer.insert_at_cursor('<span id="scroll_mark"></span>')
            # TODO
            # Find a way to find the next header, scroll to the next header.

            args = ['pandoc',
                    '--from=markdown',
                    '-smart',
                    '-thtml',
                    '--mathjax',
                    '--lua-filter=' + helpers.get_media_path('task-list.lua'),
                    '-c', helpers.get_media_file('uberwriter.css')]
            print(args)

            p = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE)

            text = bytes(self.get_text(), "utf-8")
            output = p.communicate(text)[0]

            # Load in Webview and scroll to #ID
            self.webview = WebKit.WebView()
            self.webview_settings = self.webview.get_settings()
            self.webview_settings.set_allow_universal_access_from_file_urls(True)
            self.webview.load_html(output.decode("utf-8"), 'file://localhost/')

            # Delete the cursor-scroll mark again
            # cursor_iter = self.TextBuffer.get_iter_at_mark(self.TextBuffer.get_insert())
            # begin_del = cursor_iter.copy()
            # begin_del.backward_chars(30)
            # self.TextBuffer.delete(begin_del, cursor_iter)

            self.ScrolledWindow.remove(self.TextEditor)
            self.ScrolledWindow.add(self.webview)
            self.webview.show()

            # This saying that all links will be opened in default browser, \
            # but local files are opened in appropriate apps:
            self.webview.connect("decide-policy", self.on_click_link)
        else:
            self.ScrolledWindow.remove(self.webview)
            self.webview.destroy()
            self.ScrolledWindow.add(self.TextEditor)
            self.TextEditor.show()
            
            # self.preview_button.set_active(False)
            # self.preview_mnu_button.set_active(False)

        self.queue_draw()
        return True
Beispiel #3
0
    def toggle_preview(self, widget, data=None):
        if widget.get_active():
            # Insert a tag with ID to scroll to
            self.TextBuffer.insert_at_cursor('<span id="scroll_mark"></span>')

            args = [
                'pandoc', '--from=markdown', '--smart', '-thtml', '--mathjax',
                '-c',
                helpers.get_media_file('uberwriter.css')
            ]

            p = subprocess.Popen(args,
                                 stdin=subprocess.PIPE,
                                 stdout=subprocess.PIPE)

            text = bytes(self.get_text(), "utf-8")
            output = p.communicate(text)[0]

            # Load in Webview and scroll to #ID
            self.webview = WebKit.WebView()
            self.webview.load_html_string(output.decode("utf-8"),
                                          'file://localhost/' + '#scroll_mark')

            # Delete the cursor-scroll mark again
            cursor_iter = self.TextBuffer.get_iter_at_mark(
                self.TextBuffer.get_insert())
            begin_del = cursor_iter.copy()
            begin_del.backward_chars(30)
            self.TextBuffer.delete(begin_del, cursor_iter)

            self.ScrolledWindow.remove(self.TextEditor)
            self.ScrolledWindow.add(self.webview)
            self.webview.show()

            # Making the background white

            white_background = helpers.get_media_path('white.png')
            surface = cairo.ImageSurface.create_from_png(white_background)
            self.background_pattern = cairo.SurfacePattern(surface)
            self.background_pattern.set_extend(cairo.EXTEND_REPEAT)
            # This saying that all links will be opened in default browser, but local files are opened in appropriate apps:

            self.webview.connect("navigation-requested", self.on_click_link)
        else:
            self.ScrolledWindow.remove(self.webview)
            self.webview.destroy()
            self.ScrolledWindow.add(self.TextEditor)
            self.TextEditor.show()
            surface = cairo.ImageSurface.create_from_png(self.background_image)
            self.background_pattern = cairo.SurfacePattern(surface)
            self.background_pattern.set_extend(cairo.EXTEND_REPEAT)
        self.queue_draw()
Beispiel #4
0
    def toggle_preview(self, widget, data=None):
        if widget.get_active():
            # Insert a tag with ID to scroll to
            # self.TextBuffer.insert_at_cursor('<span id="scroll_mark"></span>')
            # TODO
            # Find a way to find the next header, scroll to the next header.

            args = ['pandoc',
                    '--from=markdown',
                    '--smart',
                    '-thtml',
                    '--mathjax',
                    '-c', helpers.get_media_file('uberwriter.css')]

            p = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE)

            text = bytes(self.get_text(), "utf-8")
            output = p.communicate(text)[0]

            # Load in Webview and scroll to #ID
            self.webview = WebKit.WebView()
            self.webview.load_html_string(output.decode("utf-8"), 'file://localhost/')

            # Delete the cursor-scroll mark again
            # cursor_iter = self.TextBuffer.get_iter_at_mark(self.TextBuffer.get_insert())
            # begin_del = cursor_iter.copy()
            # begin_del.backward_chars(30)
            # self.TextBuffer.delete(begin_del, cursor_iter)

            self.ScrolledWindow.remove(self.TextEditor)
            self.ScrolledWindow.add(self.webview)
            self.webview.show()

            # Making the background white

            white_background = helpers.get_media_path('white.png')
            surface = cairo.ImageSurface.create_from_png(white_background)
            self.background_pattern = cairo.SurfacePattern(surface)
            self.background_pattern.set_extend(cairo.EXTEND_REPEAT)
            # This saying that all links will be opened in default browser, but local files are opened in appropriate apps:
            self.webview.connect("navigation-requested", self.on_click_link)
        else:
            self.ScrolledWindow.remove(self.webview)
            self.webview.destroy()
            self.ScrolledWindow.add(self.TextEditor)
            self.TextEditor.show()
            surface = cairo.ImageSurface.create_from_png(self.background_image)
            self.background_pattern = cairo.SurfacePattern(surface)
            self.background_pattern.set_extend(cairo.EXTEND_REPEAT)
        self.queue_draw()
Beispiel #5
0
    def export(self, export_type="html"):
        filechooser = Gtk.FileChooserDialog(
            "Export as %s" % export_type.upper(), self,
            Gtk.FileChooserAction.SAVE,
            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_SAVE,
             Gtk.ResponseType.OK))

        filechooser.set_do_overwrite_confirmation(True)
        if self.filename:
            filechooser.set_filename(self.filename[:-2] + export_type.lower())

        response = filechooser.run()
        if response == Gtk.ResponseType.OK:
            filename = filechooser.get_filename()
            if filename.endswith("." + export_type):
                filename = filename[:-len(export_type) - 1]
            filechooser.destroy()
        else:
            filechooser.destroy()
            return

        # Converting text to bytes for python 3
        text = bytes(self.get_text(), "utf-8")

        output_dir = os.path.abspath(os.path.join(filename, os.path.pardir))

        basename = os.path.basename(filename)

        args = ['pandoc', '--from=markdown', '--smart']

        if export_type == "pdf":
            args.append("-o%s.pdf" % basename)

        elif export_type == "odt":
            args.append("-o%s.odt" % basename)

        elif export_type == "html":
            css = helpers.get_media_file('uberwriter.css')
            args.append("-c%s" % css)
            args.append("-o%s.html" % basename)
            args.append("--mathjax")

        p = subprocess.Popen(args,
                             stdin=subprocess.PIPE,
                             stdout=subprocess.PIPE,
                             cwd=output_dir)
        output = p.communicate(text)[0]

        return filename
    def export(self, export_type="html"):
        filechooser = Gtk.FileChooserDialog(
            "Export as %s" % export_type.upper(),
            self,
            Gtk.FileChooserAction.SAVE,
            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
             Gtk.STOCK_SAVE, Gtk.ResponseType.OK)
            )

        filechooser.set_do_overwrite_confirmation(True)
        if self.filename:
            filechooser.set_filename(self.filename[:-2] + export_type.lower())
        
        response = filechooser.run()
        if response == Gtk.ResponseType.OK:
            filename = filechooser.get_filename()
            if filename.endswith("." + export_type):
                filename = filename[:-len(export_type)-1]
            filechooser.destroy()
        else: 
            filechooser.destroy()
            return 

        # Converting text to bytes for python 3
        text = bytes(self.get_text(), "utf-8")

        output_dir = os.path.abspath(os.path.join(filename, os.path.pardir))
        
        basename = os.path.basename(filename)

        args = ['pandoc', '--from=markdown', '--smart']
        
        if export_type == "pdf":
            args.append("-o%s.pdf" % basename) 
        
        elif export_type == "odt":
            args.append("-o%s.odt" % basename)
        
        elif export_type == "html":
            css = helpers.get_media_file('uberwriter.css')
            args.append("-c%s" % css)
            args.append("-o%s.html" % basename)
            args.append("--mathjax")

        p = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, cwd=output_dir)
        output = p.communicate(text)[0]
        
        return filename
    def toggle_preview(self, widget, data=None):
        if widget.get_active():
            # Insert a tag with ID to scroll to
            # self.TextBuffer.insert_at_cursor('<span id="scroll_mark"></span>')
            # TODO
            # Find a way to find the next header, scroll to the next header.

            args = [
                'pandoc', '--from=markdown', '--smart', '-thtml', '--mathjax',
                '-c',
                helpers.get_media_file('uberwriter.css')
            ]

            p = subprocess.Popen(args,
                                 stdin=subprocess.PIPE,
                                 stdout=subprocess.PIPE)

            text = bytes(self.get_text(), "utf-8")
            output = p.communicate(text)[0]

            # Load in Webview and scroll to #ID
            self.webview = WebKit.WebView()
            self.webview.load_html_string(output.decode("utf-8"),
                                          'file://localhost/')

            # Delete the cursor-scroll mark again
            # cursor_iter = self.TextBuffer.get_iter_at_mark(self.TextBuffer.get_insert())
            # begin_del = cursor_iter.copy()
            # begin_del.backward_chars(30)
            # self.TextBuffer.delete(begin_del, cursor_iter)

            self.ScrolledWindow.remove(self.EditorViewport)
            self.ScrolledWindow.add(self.webview)
            self.webview.show()

            # This saying that all links will be opened in default browser, but local files are opened in appropriate apps:
            self.webview.connect("navigation-requested", self.on_click_link)
        else:
            self.ScrolledWindow.remove(self.webview)
            self.webview.destroy()
            self.ScrolledWindow.add(self.EditorViewport)
            self.TextEditor.show()

        self.queue_draw()
        return True
Beispiel #8
0
    def export(self, text=""):
        """Export to pdf, html or odt the given text

        Keyword Arguments:
            text {str} -- Text to export (default: {""})
        """

        export_format = self.stack.get_visible_child_name()

        if export_format == "advanced":
            self.advanced_export(text)
        else:
            filename = self.filechoosers[export_format].get_filename()
            if filename.endswith("." + export_format):
                filename = filename[:-len(export_format)-1]

            output_dir = os.path.abspath(os.path.join(filename, os.path.pardir))
            basename = os.path.basename(filename)

            args = ['pandoc', '--from=markdown', '-s']

            if export_format == "pdf":
                args.append("-o%s.pdf" % basename)

            elif export_format == "odt":
                args.append("-o%s.odt" % basename)

            elif export_format == "html":
                css = helpers.get_media_file('github-md.css')
                relativize = helpers.get_script_path('relative_to_absolute.lua')
                task_list = helpers.get_script_path('task-list.lua')
                args.append("-c%s" % css)
                args.append("-o%s.html" % basename)
                args.append("--mathjax")
                args.append("--lua-filter=" + relativize)
                args.append("--lua-filter=" + task_list)

            proc = subprocess.Popen(args, stdin=subprocess.PIPE,
                                    stdout=subprocess.PIPE, cwd=output_dir)
            _ = proc.communicate(text)[0]
 def open_uberwriter_markdown(self, widget, data=None):
     self.load_file(helpers.get_media_file('uberwriter_markdown.md'))
 def open_uberwriter_markdown(self, widget, data=None):
     self.load_file(helpers.get_media_file('uberwriter_markdown.md'))