Esempio n. 1
0
    def __init__(self,
                 content="",
                 font_name="monospace",
                 font_size=10,
                 wrap=False,
                 set_statusbar_msg=None):
        self.content = "\n" * 11 + content  # Dirty offset for the logo
        self.layout = None
        self.font_name = font_name
        self.font_size = font_size
        self.wrap = wrap
        self._linesppage = 0
        self._current_line = 0

        self.operation = gtk.PrintOperation()
        self.operation.set_unit(gtk.UNIT_MM)

        # Setting paper size as A4
        paper_size = gtk.PaperSize(gtk.PAPER_NAME_A4)
        setup = gtk.PageSetup()
        setup.set_paper_size(paper_size)
        self.operation.set_default_page_setup(setup)

        self.operation.connect("begin_print", self.begin_print)
        self.operation.connect("draw_page", self.draw_page)
        if set_statusbar_msg is not None:
            self.operation.connect("status-changed", status_cb,
                                   set_statusbar_msg)
Esempio n. 2
0
    def print_cb(self):
        sourceview = self.tw
        window = sourceview.get_toplevel()
        buffer = sourceview.get_buffer()

        compositor = gtksourceview2.print_compositor_new_from_view(sourceview)
        compositor.set_wrap_mode(gtk.WRAP_WORD_CHAR)
        compositor.set_highlight_syntax(True)
        #compositor.set_print_line_numbers(5)
        #compositor.set_header_format(False, 'Printed on %A', None, '%F')
        filename = self.get_filepath()
        compositor.set_footer_format(True, '%T %F', filename, 'Page %N/%Q')
        compositor.set_print_header(False)
        compositor.set_print_footer(True)

        print_op = gtk.PrintOperation()
        print_op.connect("begin-print", self.begin_print_cb, compositor)
        print_op.connect("draw-page", self.draw_page_cb, compositor)
        res = print_op.run(gtk.PRINT_OPERATION_ACTION_PRINT_DIALOG, window)

        if res == gtk.PRINT_OPERATION_RESULT_ERROR:
            #error_dialog(window, "Error printing file:\n\n" + filename)
            return common.view.popup_error("Error printing file '%s'" %
                                           (filename))
        elif res == gtk.PRINT_OPERATION_RESULT_APPLY:
            common.view.statusMsg('File printed: %s' % filename)
Esempio n. 3
0
def print_cb(action, sourceview):
    window = sourceview.get_toplevel()
    buffer = sourceview.get_buffer()

    compositor = gtksourceview2.print_compositor_new_from_view(sourceview)
    compositor.set_wrap_mode(gtk.WRAP_CHAR)
    compositor.set_highlight_syntax(True)
    compositor.set_print_line_numbers(5)
    compositor.set_header_format(False, 'Imprimé dans %A', None, '%F')
    filename = buffer.get_data('filename')
    compositor.set_footer_format(True, '%T', filename, 'Page %N/%Q')
    compositor.set_print_header(True)
    compositor.set_print_footer(True)

    print_op = gtk.PrintOperation()
    print_op.connect("begin-print", begin_print_cb, compositor)
    print_op.connect("draw-page", draw_page_cb, compositor)
    res = print_op.run(gtk.PRINT_OPERATION_ACTION_PRINT_DIALOG, window)

    if res == gtk.PRINT_OPERATION_RESULT_ERROR:
        error_dialog(
            window,
            "Une erreur est survenue lors de l'impression du fichier :\n\n" +
            filename)
    elif res == gtk.PRINT_OPERATION_RESULT_APPLY:
        print('Le fichier suivant a bien été imprimé "%s"' % filename)
Esempio n. 4
0
 def __render(self, action, filename=None):
     """
     Render page and either save or print result
     
     Parameters
     ----------
     action : string ("save", "print")
     filename : string
     """
     
     # create print operation
     self.op = gtk.PrintOperation()
     self.op.set_default_page_setup(self.page_setup)
     self.op.set_use_full_page(True)
     self.op.set_unit(self.unit)
     self.op.connect("begin-print", self.__paginate)
     self.op.connect("draw-page", self.__draw_page)
     self.op.set_show_progress(True)
     self.op.set_allow_async(True)
     
     # run print operation
     if action == "save":
         self.op.set_export_filename(filename)
         res = self.op.run(gtk.PRINT_OPERATION_ACTION_EXPORT, None)
     else:
         res = self.op.run(gtk.PRINT_OPERATION_ACTION_PRINT_DIALOG, None)
     
     # check for exceptions during print operation
     # see comment about workaround in `__init__()` method
     if self.error != None:
         raise self.error
     
     if res == gtk.PRINT_OPERATION_RESULT_ERROR:
         raise RenderError("UNKNOWN_ERROR")
Esempio n. 5
0
 def menu_meet_printprefs_activate_cb(self, menuitem=None, data=None):
     """Edit the printer properties."""
     dlg = gtk.PrintOperation()
     dlg.set_print_settings(self.printprefs)
     res = dlg.run(gtk.PRINT_OPERATION_ACTION_PRINT_DIALOG, self.window)
     if res == gtk.PRINT_OPERATION_RESULT_APPLY:
         self.printprefs = dlg.get_print_settings()
         self.log.info('Updated print preferences.')
Esempio n. 6
0
def setup_printer(pp):
    po = gtk.PrintOperation()
    po.set_n_pages(pp.d.get_n_pages())
    po.connect('draw_page', pp.draw_page)
    po.connect('begin-print', pp.begin_print)
    po.connect('create-custom-widget', pp.create_custom_widget)
    po.connect('custom-widget-apply', pp.custom_widget_apply)
    po.run(gtk.PRINT_OPERATION_ACTION_PRINT_DIALOG)
Esempio n. 7
0
    def run(self, print_action):
        """Run the Gtk Print operation.
        """
        global PRINT_SETTINGS

        # get a page setup from the paper style we have
        page_setup = paperstyle_to_pagesetup(self.paper)

        # set up a print operation
        operation = gtk.PrintOperation()
        operation.set_default_page_setup(page_setup)
        operation.connect("begin_print", self.on_begin_print)
        operation.connect("draw_page", self.on_draw_page)
        operation.connect("paginate", self.on_paginate)
        operation.connect("preview", self.on_preview)

        # set print settings if it was stored previously
        if PRINT_SETTINGS is not None:
            operation.set_print_settings(PRINT_SETTINGS)

        # run print dialog
        while True:
            self.preview = None
            try:
                res = operation.run(print_action, self._parent)
            except gobject.GError:
                # Windows only. Rare case where the user clicks cancel in the
                # dialog to choose a filename for printing to a file.
                res = None
            if self.preview is None or print_action != PRINT_ACTION_DIALOG:
                # cancel, print or non-printing action
                break
            # set up printing again; can't reuse PrintOperation?
            operation = gtk.PrintOperation()
            operation.set_default_page_setup(page_setup)
            operation.connect("begin_print", self.on_begin_print)
            operation.connect("draw_page", self.on_draw_page)
            operation.connect("paginate", self.on_paginate)
            operation.connect("preview", self.on_preview)
            # set print settings if it was stored previously
            if PRINT_SETTINGS is not None:
                operation.set_print_settings(PRINT_SETTINGS)

        # store print settings if printing was successful
        if res == gtk.PRINT_OPERATION_RESULT_APPLY:
            PRINT_SETTINGS = operation.get_print_settings()
Esempio n. 8
0
File: graph.py Progetto: MorS25/wasp
    def _on_print(self, sender, graph, name):
        def on_print_page(operation, context, page_nr):
            cr = context.get_cairo_context()
            graph.drawIntoCairoContext(cr, name=name)

        print_op = gtk.PrintOperation()
        print_op.set_n_pages(1)
        print_op.connect("draw_page", on_print_page)
        res = print_op.run(gtk.PRINT_OPERATION_ACTION_PRINT_DIALOG, None)
Esempio n. 9
0
    def export_to_pdf(self, path=None):
        if path is None:
            path = time.strftime("%m%d%y-%H%M%S.pdf")

        operation = gtk.PrintOperation()
        operation.set_export_filename(path)
        operation.connect("begin-print", self.__begin_print_cb)
        operation.connect("draw-page", self.__draw_page_cb)
        operation.run(gtk.PRINT_OPERATION_ACTION_EXPORT, self)
Esempio n. 10
0
 def setup_printer(self, parent=None):
     po = gtk.PrintOperation()
     #po.set_n_pages(self.d.get_n_pages())
     po.connect('draw_page', self.draw_page)
     po.connect('begin-print', self.begin_print)
     po.connect('create-custom-widget', self.create_custom_widget)
     po.props.custom_tab_label = _('Page Layout')
     po.connect('custom-widget-apply', self.custom_widget_apply)
     po.run(gtk.PRINT_OPERATION_ACTION_PRINT_DIALOG, parent=parent)
Esempio n. 11
0
 def do_print(self):
     print_op = gtk.PrintOperation()
     print_op.set_n_pages(1)
     print_op.connect("draw_page", self.print_text)
     res = print_op.run(gtk.PRINT_OPERATION_ACTION_PRINT_DIALOG, self.padre)
     if res == gtk.PRINT_OPERATION_RESULT_APPLY:
         sql = 'UPDATE numeroRecibo SET numero = numero +1'
         self.cursor.execute(sql, )
         self.conexion.commit()
Esempio n. 12
0
 def get_print_operation(self):
     """Return a Print Operation"""
     print_operation = gtk.PrintOperation()
     print_operation.set_show_progress(True)
     if self.page_setup is None: self.page_setup = gtk.PageSetup()
     if self.settings is None: self.settings = gtk.PrintSettings()
     print_operation.set_default_page_setup(self.page_setup)
     print_operation.set_print_settings(self.settings)
     return print_operation
Esempio n. 13
0
def main(argv):
  ## Test some random drawing, with per-page paper settings
  print_ = gtk.PrintOperation()
  print_.set_nr_of_pages(2)
  print_.set_unit(gtk.UNIT_MM)
  print_.set_pdf_target("test.pdf")
  print_.connect("draw_page", draw_page)
  print_.connect("request_page_setup", request_page_setup)
  res = print_.run()
  return 0
Esempio n. 14
0
    def on_button_print_clicked(self, widget=None, data=None):
        print_operation = gtk.PrintOperation()
        print_operation.set_n_pages(2)
        print_operation.set_use_full_page(True)
        #print_operation.set_unit(10)

        print_operation.connect("draw_page", self.print_page)
        response = print_operation.run(gtk.PRINT_OPERATION_ACTION_PRINT_DIALOG,
                                       None)
        print response
Esempio n. 15
0
 def print_contents(self, preview=False):
     """Send content of editor to printer."""
     view = self.textview
     compositor = gtksourceview2.print_compositor_new_from_view(view)
     operation = gtk.PrintOperation()
     operation.connect('paginate', self.on_print_paginate, compositor)
     operation.connect('draw-page', self.on_print_draw_page, compositor)
     if preview:
         action = gtk.PRINT_OPERATION_ACTION_PREVIEW
     else:
         action = gtk.PRINT_OPERATION_ACTION_PRINT_DIALOG
     operation.run(action)
Esempio n. 16
0
 def on_print_clicked(self, widget):
     printop = gtk.PrintOperation()
     page_setup = gtk.PageSetup()
     page_setup.set_paper_size(gtk.PaperSize(gtk.PAPER_NAME_A4))
     printop.set_default_page_setup(page_setup)
     order_products = OrderProduct.find_all_not_yet_ordered_on(
         self.calendardate())
     self.printer = OrderProductPrinter(order_products)
     n_pages = self.printer.calc_n_pages()
     printop.set_n_pages(n_pages)
     printop.connect("draw_page", self.print_ordered_products)
     printop.run(gtk.PRINT_OPERATION_ACTION_PRINT_DIALOG)
Esempio n. 17
0
def run_print_operation(inventory, entry):
    op = gtk.PrintOperation()
    state = PrintState(inventory, entry)
    op.connect("begin-print", state.begin_print)
    op.connect("draw-page", state.draw_page)
    try:
        op.run(gtk.PRINT_OPERATION_ACTION_PRINT_DIALOG, None)
    except gobject.GError:
        # Canceling the print operation can result in the error
        #   GError: Error from StartDoc
        # http://seclists.org/nmap-dev/2012/q4/161
        pass
Esempio n. 18
0
    def run(self):
        """Run the Gtk Print operation.
        """
        global PRINT_SETTINGS

        # get a page setup from the paper style we have
        page_setup = paperstyle_to_pagesetup(self.paper)

        # set up a print operation
        operation = gtk.PrintOperation()
        operation.set_default_page_setup(page_setup)
        operation.connect("begin_print", self.on_begin_print)
        operation.connect("draw_page", self.on_draw_page)
        operation.connect("paginate", self.on_paginate)
        operation.connect("preview", self.on_preview)

        # set print settings if it was stored previously
        if PRINT_SETTINGS is not None:
            operation.set_print_settings(PRINT_SETTINGS)

        # run print dialog
        while True:
            self.preview = None
            res = operation.run(gtk.PRINT_OPERATION_ACTION_PRINT_DIALOG)
            if self.preview is None:  # cancel or print
                break
            # set up printing again; can't reuse PrintOperation?
            operation = gtk.PrintOperation()
            operation.set_default_page_setup(page_setup)
            operation.connect("begin_print", self.on_begin_print)
            operation.connect("draw_page", self.on_draw_page)
            operation.connect("paginate", self.on_paginate)
            operation.connect("preview", self.on_preview)
            # set print settings if it was stored previously
            if PRINT_SETTINGS is not None:
                operation.set_print_settings(PRINT_SETTINGS)

        # store print settings if printing was successful
        if res == gtk.PRINT_OPERATION_RESULT_APPLY:
            PRINT_SETTINGS = operation.get_print_settings()
Esempio n. 19
0
 def __init__(self,error_file,window):
     self.error_file = error_file 
     self.page_starts = []
     self.line_array = []
     self.paginated_pages = 0
     self.window = window
     print_op = gtk.PrintOperation()
     print_op.connect("begin_print",self.begin_print,None)
     print_op.connect("paginate",self.paginate,None)
     print_op.connect("request_page_setup",self.request_page_setup,None)
     print_op.connect("draw_page",self.draw_page,None)
     print_op.connect("end_print",self.end_print,None)
     res = print_op.run(gtk.PRINT_OPERATION_ACTION_PRINT_DIALOG, self.window)
Esempio n. 20
0
    def print_report(self, title='', lines=[], header=''):
        """Print the pre-formatted text lines in a standard report."""
        self.log.info('Printing report ' + repr(title) + '...')

        ptupl = (title, lines, header)

        print_op = gtk.PrintOperation()
        print_op.set_print_settings(self.printprefs)
        print_op.connect("begin_print", self.begin_print, ptupl)
        print_op.connect("draw_page", self.draw_print_page, ptupl)
        res = print_op.run(gtk.PRINT_OPERATION_ACTION_PREVIEW, self.window)
        self.docindex += 1
        return False
Esempio n. 21
0
    def show_print_dialogue(self):
        """Display a print dialogue box and print the puzzle"""

        print_operation = gtk.PrintOperation()
        if self.print_settings != None:
            print_operation.set_print_settings(self.print_settings)
        print_operation.connect("draw_page", self.draw_to_printer)
        print_operation.set_n_pages(1)
        print_operation.set_default_page_setup(self.page_setup)
        print_result = print_operation.run(
            gtk.PRINT_OPERATION_ACTION_PRINT_DIALOG, self.main_window)
        if print_result == gtk.PRINT_OPERATION_RESULT_APPLY:
            settings = print_operation.get_print_settings()
Esempio n. 22
0
 def _print(self, frame):
     print_op = gtk.PrintOperation()
     print_settings = print_op.get_print_settings() or gtk.PrintSettings()
     print_settings.set_paper_size(self._paper_size)
     print_op.set_print_settings(print_settings)
     print_op.set_export_filename(os.path.abspath(self.outfile))
     logging.info('Exporting PDF...')
     print_op.connect('end-print', self._end_print_cb)
     try:
         frame.print_full(print_op, gtk.PRINT_OPERATION_ACTION_EXPORT)
         while gtk.events_pending():
             gtk.main_iteration()
     except gobject.GError, e:
         logging.error(e.message)
Esempio n. 23
0
 def __init__(self, data_array, window):
     #data array is last_vote_counts from calling App class
     self.data = data_array
     self.window = window
     self.page_breaks = []
     self.paginated_pages = 0
     print_op = gtk.PrintOperation()
     print_op.connect("begin_print", self.begin_print, self.data)
     print_op.connect("paginate", self.paginate, self.data)
     print_op.connect("request_page_setup", self.request_page_setup,
                      self.data)
     print_op.connect("draw_page", self.draw_page, self.data)
     print_op.connect("end_print", self.end_print, self.data)
     res = print_op.run(gtk.PRINT_OPERATION_ACTION_PRINT_DIALOG,
                        self.window)
Esempio n. 24
0
 def _load_finished_cb(self, view, frame, outfile):
     self._print_status('Loading done')
     print_op = gtk.PrintOperation()
     print_settings = print_op.get_print_settings() or gtk.PrintSettings()
     print_settings.set_paper_size(self._paper_size)
     print_op.set_print_settings(print_settings)
     print_op.set_export_filename(os.path.abspath(outfile))
     self._print_status('Exporting PDF...')
     print_op.connect('end-print', self._end_print_cb)
     try:
         frame.print_full(print_op, gtk.PRINT_OPERATION_ACTION_EXPORT)
         while gtk.events_pending():
             gtk.main_iteration()
     except gobject.GError, e:
         self._print_error(e.message)
    def doPrint(self,
                printer,
                wikiDocument,
                wordList,
                printType,
                addopt,
                doPreview=False):
        """
        To print with webkit we load the pages into a temporary frame
        that contains a WKHtmlWindow and use webkits print function.

        The frame does not need to be shown as a preview is builtin
        """
        self.setContext(printer, wikiDocument, wordList, printType, addopt)
        if self.checkWebkit():
            import gtk
            htpath = self._buildHtml()
            frame = None

            try:
                # Get page setup dialog data (wxPython) and translate to pyGTK
                psddata = self.printer.getPageSetupDialogData()

                tl = psddata.GetMarginTopLeft()
                br = psddata.GetMarginBottomRight()

                print_op = gtk.PrintOperation()
                page_setup = gtk.PageSetup()
                page_setup.set_top_margin(tl.y, gtk.UNIT_MM)
                page_setup.set_left_margin(tl.x, gtk.UNIT_MM)
                page_setup.set_right_margin(br.x, gtk.UNIT_MM)
                page_setup.set_bottom_margin(br.y, gtk.UNIT_MM)
                print_op.set_default_page_setup(page_setup)

                frame = WKPrintFrame(htpath)
                if doPreview:
                    opCode = gtk.PRINT_OPERATION_ACTION_PREVIEW
                    frame.print_full(print_op, opCode)
                    return False
                else:
                    opCode = gtk.PRINT_OPERATION_ACTION_PRINT_DIALOG
                    result = frame.print_full(print_op, opCode)
                    return result in (gtk.PRINT_OPERATION_RESULT_APPLY,
                                      gtk.PRINT_OPERATION_RESULT_IN_PROGRESS)
            finally:
                if frame:
                    frame.Destroy()
                self._freeHtml()
Esempio n. 26
0
 def __init__(
     self,
     sudokus,
     main_window,
     margin=50,
     sudokus_per_page=1,
 ):
     self.drawn = False
     self.margin = margin
     self.sudokus_per_page = sudokus_per_page
     self.n_sudokus = len(sudokus)
     self.sudokus = sudokus
     self.print_op = gtk.PrintOperation()
     self.print_op.connect("begin-print", self.begin_print)
     self.print_op.connect("draw-page", self.draw_page)
     self.main_window = main_window
Esempio n. 27
0
    def print_puzzle(self, win):
        op = gtk.PrintOperation()

        if PuzzlePrinter.settings != None:
            op.set_print_settings(PuzzlePrinter.settings)

        if PuzzlePrinter.page_setup != None:
            op.set_default_page_setup(PuzzlePrinter.page_setup)

        op.connect('begin-print', self.begin_print)
        op.connect('draw-page', self.draw_page)
        op.connect('create-custom-widget', self.create_custom_widget)
        op.connect('custom-widget-apply', self.custom_widget_apply)

        r = op.run(gtk.PRINT_OPERATION_ACTION_PRINT_DIALOG, win)
        if r == gtk.PRINT_OPERATION_RESULT_APPLY:
            PuzzlePrinter.settings = op.get_print_settings()
Esempio n. 28
0
    def do_print(self):
        print_op = gtk.PrintOperation()

        # Page size and orientation
        # FIXME: sizes other than letter do not work
        print "paper size:", self.papersize
        paper_size = gtk.PaperSize(gtk.PAPER_NAME_LETTER)
        if self.papersize[0] > self.papersize[1]:
            print " landscape"
            paper_size.set_size(self.papersize[1], self.papersize[0],
                                gtk.UNIT_POINTS)
            orientation = gtk.PAGE_ORIENTATION_LANDSCAPE
        else:
            print " portrait"
            paper_size.set_size(self.papersize[0], self.papersize[1],
                                gtk.UNIT_POINTS)
            orientation = gtk.PAGE_ORIENTATION_PORTRAIT
        print "is_custom:", paper_size.is_custom()

        page_setup = gtk.PageSetup()
        page_setup.set_paper_size_and_default_margins(paper_size)
        page_setup.set_orientation(orientation)
        print_op.set_default_page_setup(page_setup)

        #if self.print_settings is not None:
        #	print_op.set_print_settings(self.print_settings)

        print_op.set_show_progress(False)  # appears late
        print_op.set_use_full_page(True)
        print_op.set_embed_page_setup(True)
        print_op.connect('draw_page', self.draw_page)

        print_op.set_n_pages(1)
        result = print_op.run(gtk.PRINT_OPERATION_ACTION_PRINT_DIALOG,
                              self.main_window)

        print "Printing result:", result
        if self.map_failure:
            return self.map_failure
        elif result == gtk.PRINT_OPERATION_RESULT_ERROR:
            return print_op.get_error()
        #elif result == gtk.PRINT_OPERATION_RESULT_APPLY:
        #	self.print_settings = print_op.get_print_settings()
        #	return None
        else:
            return None
Esempio n. 29
0
    def __init__(self, content, cols_width, heading=None):
        #        self.lines_per_page = 24
        self.cell_margin = 4
        self.line = 2  #the thinest possible width of lines.
        self.row_height = 2 * (config.contentfont + self.cell_margin)
        self.header_height = 0
        self.heading_height = 35

        self.operation = gtk.PrintOperation()
        settings = gtk.PrintSettings()
        paper_size = gtk.paper_size_new_from_ppd(config.paper_ppd,
                                                 config.paper_name,
                                                 config.paper_width,
                                                 config.paper_height)
        self.page_setup = gtk.PageSetup()
        self.page_setup.set_paper_size(paper_size)
        self.page_setup.set_orientation(config.paper_orientation)
        #        self.page_setup = gtk.print_run_page_setup_dialog(None, self.page_setup, settings)

        self.page_setup.set_top_margin(config.topmargin, gtk.UNIT_POINTS)
        self.page_setup.set_bottom_margin(config.botmargin, gtk.UNIT_POINTS)
        self.page_setup.set_right_margin(config.rightmargin, gtk.UNIT_POINTS)
        self.page_setup.set_left_margin(config.leftmargin, gtk.UNIT_POINTS)

        self.operation.set_default_page_setup(self.page_setup)
        self.operation.set_unit(gtk.UNIT_POINTS)

        self.content = content
        tablewidth = self.page_setup.get_page_width(gtk.UNIT_POINTS)
        tablewidth -= (len(cols_width) *
                       (self.line + self.cell_margin)) + self.line + (
                           config.rightmargin + config.leftmargin)
        self.cols_width = []
        for percent in cols_width:
            self.cols_width.append(math.floor((percent * tablewidth) / 100))
#        self.cols_width = cols_width
        self.heading = heading

        self.operation.connect("begin_print", self.beginPrint)
        self.operation.connect("draw-page", self.printPage)
        self.type = 0
        self.title = ""
        self.fields = {}
Esempio n. 30
0
    def do_print(self, *args):
        # print_op is ephemeral
        print_op = gtk.PrintOperation()

        if self.settings != None:
            print_op.set_print_settings(self.settings)

        print_op.connect("begin_print", self.begin_print)
        print_op.connect("draw_page", self.draw_page)

        # Second parameter is the parent widget of the print dialog.
        # Here None means top level, ie not a child of the app window or view.
        # port.surface did not work.
        res = print_op.run(gtk.PRINT_OPERATION_ACTION_PRINT_DIALOG, None)

        # Signals are emitted here at the conclusion of the print dialog

        if res == gtk.PRINT_OPERATION_RESULT_APPLY:
            self.settings = print_op.get_print_settings()