def print_file(self, widget): def _alert_response(alert, response): self.vbox.remove(alert) view = self.get_view() buffer = view.get_buffer() path = view.get_file() if not path: alert = TimeoutAlert(10) alert.props.title = _('This file has not saved.') alert.props.msg = _('You must save this file to print.') hbox = alert.get_children()[0] buttonbox = hbox.get_children()[1] button = buttonbox.get_children()[0] buttonbox.remove(button) alert.connect('response', _alert_response) self.vbox.pack_start(alert, False, False, 0) self.vbox.reorder_child(alert, 0) return compositor = GtkSource.PrintCompositor.new_from_view(view) compositor.set_wrap_mode(view.get_wrap_mode()) compositor.set_highlight_syntax(buffer.get_highlight_syntax()) compositor.set_print_line_numbers(self.conf['show-line-numbers']) if view.buffer.language: compositor.set_header_format( False, '%s - %s' % (view.buffer.get_language_str(), view.get_file()), None, None) compositor.set_footer_format(True, '%T', path, 'Page %N/%Q') compositor.set_print_header(True) compositor.set_print_footer(True) operation = Gtk.PrintOperation() operation.set_job_name(path) operation.connect('begin-print', self.begin_print, compositor) operation.connect('draw-page', self.draw_page, compositor) res = operation.run(Gtk.PrintOperationAction.PRINT_DIALOG, None) if res == Gtk.PrintOperationResult.ERROR: dialog = Gtk.MessageDialog(self, Gtk.DialogFlags.DESTROY_WITH_PARENT, Gtk.MessageType.ERROR, Gtk.ButtonsType.OK, 'Error to print the file: %s' % path) dialog.run() dialog.destroy()
def print_file(self, widget): def _alert_response(alert, response): self.vbox.remove(alert) view = self.get_view() buffer = view.get_buffer() path = view.get_file() if not path: alert = TimeoutAlert(10) alert.props.title = G.TEXT_FILE_NOT_SAVED alert.props.msg = G.TEXT_MUST_SAVE hbox = alert.get_children()[0] buttonbox = hbox.get_children()[1] button = buttonbox.get_children()[0] buttonbox.remove(button) alert.connect("response", _alert_response) self.vbox.pack_start(alert, False, False, 0) self.vbox.reorder_child(alert, 0) return compositor = GtkSource.PrintCompositor.new_from_view(view) compositor.set_highlight_syntax(buffer.get_highlight_syntax()) compositor.set_print_line_numbers(self.conf["show-line-numbers"]) if view.buffer.language: compositor.set_header_format( False, "%s - %s" % (view.buffer.get_language_str(), view.get_file()), None, None) compositor.set_footer_format(True, "%T", path, "Page %N/%Q") compositor.set_print_header(True) compositor.set_print_footer(True) operation = Gtk.PrintOperation() operation.set_job_name(path) operation.connect("begin-print", self.begin_print, compositor) operation.connect("draw-page", self.draw_page, compositor) res = operation.run(Gtk.PrintOperationAction.PRINT_DIALOG, None) if res == Gtk.PrintOperationResult.ERROR: dialog = Gtk.MessageDialog(self, Gtk.DialogFlags.DESTROY_WITH_PARENT, Gtk.MessageType.ERROR, Gtk.ButtonsType.OK, "Error to print the file: %s" % path) dialog.run() dialog.destroy()
def create_alert(self, path): alert = TimeoutAlert(10) alert.props.title = G.TEXT_FILE_NOT_EXISTS1 alert.props.msg = G.TEXT_FILE_NOT_EXISTS2 hbox = alert.get_children()[0] buttonbox = hbox.get_children()[1] button = buttonbox.get_children()[0] buttonbox.remove(button) alert.connect("response", self.__alert_response) self.vbox.pack_start(alert, False, False, 0) self.vbox.reorder_child(alert, 2)