class SnapshotPrinter(wx.Frame):
    def __init__(self, title='Snapshot Printer'):
        wx.Frame.__init__(self, None, title=title, size=(650, 400))

        self.panel = wx.Panel(self)
        self.printer = HtmlEasyPrinting(name='Printing', parentWindow=None)

        self.html = HtmlWindow(self.panel)
        self.html.SetRelatedFrame(self, self.GetTitle())

        if not os.path.exists('screenshot.htm'):
            self.createHtml()
        self.html.LoadPage('screenshot.htm')

        pageSetupBtn = wx.Button(self.panel, label='Page Setup')
        printBtn = wx.Button(self.panel, label='Print')
        cancelBtn = wx.Button(self.panel, label='Cancel')

        self.Bind(wx.EVT_BUTTON, self.onSetup, pageSetupBtn)
        self.Bind(wx.EVT_BUTTON, self.onPrint, printBtn)
        self.Bind(wx.EVT_BUTTON, self.onCancel, cancelBtn)

        sizer = wx.BoxSizer(wx.VERTICAL)
        btnSizer = wx.BoxSizer(wx.HORIZONTAL)

        sizer.Add(self.html, 1, wx.GROW)
        btnSizer.Add(pageSetupBtn, 0, wx.ALL, 5)
        btnSizer.Add(printBtn, 0, wx.ALL, 5)
        btnSizer.Add(cancelBtn, 0, wx.ALL, 5)
        sizer.Add(btnSizer)

        self.panel.SetSizer(sizer)
        self.panel.SetAutoLayout(True)

    def createHtml(self):
        '''
        Creates an html file in the home directory of the application
        that contains the information to display the snapshot
        '''
        print('creating html...')

        html = '''<html>\n<body>\n<center>
        <img src=myImage.png width=516 height=314>
        </center>\n</body>\n</html>'''
        with open('screenshot.htm', 'w') as fobj:
            fobj.write(html)

    def onSetup(self, event):
        self.printer.PageSetup()

    def onPrint(self, event):
        self.sendToPrinter()

    def sendToPrinter(self):
        self.printer.GetPrintData().SetPaperId(wx.PAPER_LETTER)
        self.printer.PrintFile(self.html.GetOpenedPage())

    def onCancel(self, event):
        self.Close()
    def print_list(self, event=None):
        #html = '''<style type=\"text/css\">td{{font-family:Arial; color:black; font-size:8pt;}}</style>
        #	{}<table border="1" cellspacing="0"><tr>\n'''.format(header)

        html = '''<table border="1" cellspacing="0"><tr>\n'''

        #write out headers
        for index, col in enumerate(range(self.GetColumnCount())):
            html += u'''<th align="left" valign="top">{}</th>\n'''.format(
                self.GetColumn(col).GetText())

        html += '</tr>'

        #write out data
        for row in range(self.GetItemCount()):
            html += '<tr>'

            for index, col in enumerate(range(self.GetColumnCount())):
                html += '''<td align="left" valign="top" nowrap>{}&nbsp;</td>\n'''.format(
                    self.GetItem(row, col).GetText())

            html += '</tr>'

        html += '</table>'

        printer = HtmlEasyPrinting()

        printer.SetHeader(
            '{}, Printed on @DATE@, Page @PAGENUM@ of @PAGESCNT@'.format(
                self.printer_header).lstrip(', '))
        printer.SetStandardFonts(self.printer_font_size)
        printer.GetPrintData().SetPaperId(self.printer_paper_type)
        printer.GetPrintData().SetOrientation(self.printer_paper_orientation)

        if self.printer_paper_margins:
            printer.GetPageSetupData().SetMarginTopLeft(
                (self.printer_paper_margins[0], self.printer_paper_margins[1]))
            printer.GetPageSetupData().SetMarginBottomRight(
                (self.printer_paper_margins[2], self.printer_paper_margins[3]))

        printer.PrintText(html)
Exemple #3
0
def on_click_print_revisions(event):
    notebook = ctrl(General.app.main_frame, 'notebook:revisions')
    item_entries = []
    for index in range(notebook.GetPageCount()):
        item_entries.append(notebook.GetPageText(index).strip().split(' ')[0])

    cursor = Database.connection.cursor()

    for item in item_entries:
        column_names = Database.get_table_column_names('revisions',
                                                       presentable=True)

        revisions = cursor.execute(
            'SELECT * FROM revisions WHERE item = \'{}\''.format(
                item)).fetchall()
        if revisions == None:
            continue

        # Revisions for Item Number: {}
        # <hr>

        html_to_print = '''<style type=\"text/css\">td{{font-family:Arial; color:black; font-size:8pt;}}</style>
            <table border="1" cellspacing="0"><tr>
            '''.format(item)

        blacklisted_columns = ['dollars_reconciled', 'related_ecr']

        for column_name in column_names:
            if column_name.replace(' ',
                                   '_').lower() not in blacklisted_columns:
                html_to_print += '<th align=\"right\" valign=\"top\">{}</th>'.format(
                    column_name.replace(' ', '&nbsp;'))

        html_to_print += '</tr>'

        for revision in revisions:
            html_to_print += '<tr>'

            for index, column_value in enumerate(revision):
                if column_names[index].replace(
                        ' ', '_').lower() not in blacklisted_columns:
                    if column_names[index] == 'When Revised':
                        column_value = General.format_date_nicely(column_value)

                    if column_names[index] != 'Description':
                        column_value = str(column_value).replace(' ', '&nbsp;')

                    html_to_print += '<td align=\"left\" valign=\"top\">{}</td>'.format(
                        column_value)

            html_to_print += '</tr>'

        html_to_print += '</table>'

        printer = HtmlEasyPrinting()
        printer.GetPrintData().SetPaperId(wx.PAPER_LETTER)
        printer.GetPrintData().SetOrientation(wx.LANDSCAPE)
        printer.SetStandardFonts(9)
        printer.GetPageSetupData().SetMarginTopLeft((0, 0))
        printer.GetPageSetupData().SetMarginBottomRight((0, 0))
        printer.PrintText(html_to_print)
class SnapshotPrinter(wx.Frame):
 
    #----------------------------------------------------------------------
    def __init__(self, title='Snapshot Printer'):
        wx.Frame.__init__(self, None, wx.ID_ANY, title, size=(650,400))
 
        self.panel = wx.Panel(self, wx.ID_ANY)
        self.printer = HtmlEasyPrinting(name='Printing', parentWindow=None)
 
        self.html = HtmlWindow(self.panel)
        self.html.SetRelatedFrame(self, self.GetTitle())
 
        if not os.path.exists('screenshot.htm'):
            self.createHtml()
        self.html.LoadPage('screenshot.htm')
 
        pageSetupBtn = wx.Button(self.panel, wx.ID_ANY, 'Page Setup')
        printBtn = wx.Button(self.panel, wx.ID_ANY, 'Print')
        cancelBtn = wx.Button(self.panel, wx.ID_ANY, 'Cancel')
 
        self.Bind(wx.EVT_BUTTON, self.onSetup, pageSetupBtn)
        self.Bind(wx.EVT_BUTTON, self.onPrint, printBtn)
        self.Bind(wx.EVT_BUTTON, self.onCancel, cancelBtn)
 
        sizer = wx.BoxSizer(wx.VERTICAL)
        btnSizer = wx.BoxSizer(wx.HORIZONTAL)
 
        sizer.Add(self.html, 1, wx.GROW)
        btnSizer.Add(pageSetupBtn, 0, wx.ALL, 5)
        btnSizer.Add(printBtn, 0, wx.ALL, 5)
        btnSizer.Add(cancelBtn, 0, wx.ALL, 5)
        sizer.Add(btnSizer)
 
        self.panel.SetSizer(sizer)
        self.panel.SetAutoLayout(True)
 
    #----------------------------------------------------------------------
    def createHtml(self):
        '''
        Creates an html file in the home directory of the application
        that contains the information to display the snapshot
        '''
        print 'creating html...'
 
        #html = '<html>\n<body>\n<center><img src=myImage.png width=700 height=800></center>\n</body>\n</html>'
        f = file('screenshot.htm', 'w')
        f.write(open('C:/Protocols/CoreProtocols/20111213_1_transfer_example.txt').read()) 
        f.write('<html>\n<body>\n<center><img src=myImage.png width=350 height=600></center>\n</body>\n</html>')
        f.close()
 
    #----------------------------------------------------------------------
    def onSetup(self, event):
        self.printer.PageSetup()
 
    #----------------------------------------------------------------------
    def onPrint(self, event):
        self.sendToPrinter()
 
    #----------------------------------------------------------------------
    def sendToPrinter(self):
        """"""
        self.printer.GetPrintData().SetPaperId(wx.PAPER_LETTER)
        self.printer.PrintFile(self.html.GetOpenedPage())
 
    #----------------------------------------------------------------------
    def onCancel(self, event):
        self.Close()