def on_export_writeas(self, sender: Gtk.Widget = None, event=None) -> None: """Configure Write.as client and export document asynchronously :param sender: :param event: :return: """ doc = self.document_grid.selected_document or self.editor.document if not doc: return token = self.settings.get_string("writeas-access-token") if not token: self.toast.set_title("You have to login to Write.as in Preferences -> Export") self.toast.set_default_action("Configure") self.disconnect_toast() self.toast.connect("default-action", self.get_application().on_preferences) self.toast.send_notification() else: self.header.show_spinner(True) self.writeas_client.set_token(access_token=token) GObjectWorker.call(self.writeas_client.create_post, args=(doc,), callback=self.on_export_writeas_callback)
def on_export_medium(self, sender: Gtk.Widget = None, event=None) -> None: """Configure Medium client and export document asynchronously :param sender: :param event: :return: """ doc = self.document_grid.selected_document or self.editor.document if not doc: return token = self.settings.get_string("medium-personal-token") user_id = self.settings.get_string("medium-user-id") if not token or not user_id: self.toast.set_title(_("You need to set Medium token in Preferences -> Export")) self.toast.set_default_action(_("Configure")) self.disconnect_toast() self.toast.connect("default-action", self.get_application().on_preferences) self.toast.send_notification() else: self.header.show_spinner(True) self.medium_client.set_token(token) GObjectWorker.call(self.medium_client.create_post, args=(user_id, doc, PublishStatus.DRAFT), callback=self.on_export_medium_callback)
def on_export_html(self, sender: Gtk.Widget = None, event=None) -> None: """Export document from storage to local files or web-services. :param sender: :param event: :return: """ doc = self.document_grid.selected_document or self.editor.document if not doc: return dialog = ExportFileDialog( _("Export document to file"), self, Gtk.FileChooserAction.SAVE ) dialog.set_current_name(doc.title) export_format = ExportFormat.Html dialog.set_format(export_format) dialog_result = dialog.run() if dialog_result == Gtk.ResponseType.ACCEPT: self.header.show_spinner(True) basename, ext = os.path.splitext(dialog.get_filename()) if ext not in export_format[1]: ext = export_format[1][0][1:] GObjectWorker.call(Exporter.export_html, (basename + ext, doc), callback=self.on_export_callback) dialog.destroy()
def buffer_changed(self, buffer: Gtk.TextBuffer): self.show_spinner(True) text = buffer.get_text(buffer.get_start_iter(), buffer.get_end_iter(), True) GObjectWorker.call(Exporter.export_html_preview, ( self.temp_file.name, text, ), self.update_html)
def on_medium_token(self, sender: Gtk.Entry) -> None: token = sender.get_text().strip() self.settings.set_string("medium-personal-token", token) if token: sender.set_sensitive(False) medium_client = Medium(access_token=token) GObjectWorker.call(medium_client.get_user, callback=self.on_medium_callback) else: self.settings.set_string("medium-user-id", "")
def __init__(self, parent: Gtk.Widget, text: str = None): super().__init__(modal=False) self.set_default_size(800, 600) self.set_transient_for(parent) self.header_overlay.add_overlay(self.header_revealer) self.header_revealer.set_reveal_child(True) # print_button = Gtk.Button.new_from_icon_name('document-print', Gtk.IconSize.LARGE_TOOLBAR) # print_button.set_tooltip_markup(Granite.markup_accel_tooltip(None, _('Print document'))) # print_button.connect('clicked', lambda x: self.emit('print')) # self.spinner = Gtk.Spinner(visible=False) # # header = Gtk.HeaderBar(title=_("Preview")) # header.set_has_subtitle(False) # header.set_show_close_button(True) # header.get_style_context().add_class('norka-header') # # header.pack_start(self.spinner) # header.pack_end(print_button) # self.set_titlebar(header) self.temp_file = tempfile.NamedTemporaryFile(prefix='norka-', delete=False) # Render in thread if text: GObjectWorker.call(Exporter.export_html_preview, (self.temp_file.name, text, True), self.update_html) ctx = WebKit2.WebContext.get_default() self.web: WebKit2.WebView = WebKit2.WebView.new_with_context(ctx) self.web.connect('load-changed', self.on_load_changed) web_settings = self.web.get_settings() web_settings.set_enable_developer_extras(False) web_settings.set_enable_tabs_to_links(False) self.web.set_settings(web_settings) self.empty = Granite.WidgetsWelcome() self.empty.set_title(_('Nothing to preview')) self.empty.set_subtitle(_('To render preview open a document')) # self.stack = Gtk.Stack() # self.stack.add_named(self.empty, 'empty-page') # self.stack.add_named(self.web, 'preview-page') self.content_deck.add(self.empty) self.content_deck.add(self.web) self.connect('enter-notify-event', self.on_enter_notify) self.connect('leave-notify-event', self.on_leave_notify)
def on_writeas_login(self, button: Gtk.Button): """Login to write.as and save token on success """ # Disable widgets while login self.writeas_login.set_sensitive(False) self.writeas_password.set_sensitive(False) self.writeas_login_button.set_sensitive(False) GObjectWorker.call(Writeas().login, (self.writeas_login.get_text(), self.writeas_password.get_text()), self.on_writeas_callback)
def on_backup(self, sender: Gtk.Widget = None, event=None) -> None: dialog: Gtk.FileChooserNative = Gtk.FileChooserNative.new( _("Select folder to store backup"), self, Gtk.FileChooserAction.SELECT_FOLDER, _("Select"), ) dialog.set_create_folders(True) dialog_result = dialog.run() if dialog_result == Gtk.ResponseType.ACCEPT: self.header.show_spinner(True) backup_service = BackupService(settings=self.settings) GObjectWorker.call(backup_service.save, args=(dialog.get_filename(), ), callback=self.on_backup_finished) self.toast.set_title(_("Backup started.")) self.toast.send_notification() dialog.destroy()