options_p_print.py :  » Business-Application » hylaPEx » hylapex » library » options » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Business Application » hylaPEx 
hylaPEx » hylapex » library » options » options_p_print.py
# -*- coding: utf-8 -*-
import os, os.path, sys

import wx, wx.grid


class panel(wx.Panel):
    def _init_ctrls(self, prnt):
        super(panel, self).__init__(prnt)
        
        #tiff view
        self.lbl_tiff = wx.StaticText(self, -1, 'Tiff view')
        self.lbl_ps_view = wx.StaticText(self, -1, label='Ps view')
        self.chk_int_view = wx.CheckBox(self, -1, 'Use internal viewer')
        self.txt_tiff_view = wx.TextCtrl(self)
        self.bt_tiff_view = wx.Button(self, -1, label='Search')
        self.txt_ps_view = wx.TextCtrl(self)
        self.bt_ps_view = wx.Button(self, -1, label='Search')
        
        #print on receive
        self.lbl_fontsize = wx.StaticText(self, -1, 'Font size')
        self.lbl_zoom = wx.StaticText(self, -1, 'Zoom')
        
        self.chk_print_str = wx.CheckBox(self, -1, 'Not print string')
        self.txt_fontsize = wx.TextCtrl(self)
        self.cho_zoom = wx.Choice(self)

        #Other
        self.lbl_freeimage_path = wx.StaticText(self, -1, 'Path')
        
        self.chk_use_freeimage = wx.CheckBox(self, -1, "Use FreeImage library")
        self.chk_concatenate = wx.CheckBox(self, -1, 'Concatenate file before send')
        self.chk_print_on_receive = wx.CheckBox(self, -1, 'Print on receive new fax')
        self.txt_prt_name_on_new = wx.TextCtrl(self)
        self.bt_search_print_on_new = wx.Button(self, -1, 'Search')
        self.txt_freeimage_path = wx.TextCtrl(self)
        self.bt_search_freeimage = wx.Button(self, -1, 'Search')
        self.chk_modify_preview = wx.CheckBox(self, -1, 'Enable modify preview')
        
        #report
        self._gr = wx.grid.Grid(self, size=(300, 150))
        self._gr.SetRowLabelSize(25)
        self._gr.SetDefaultColSize(30)
        self._gr.SetColLabelSize(20)
        
        self.lbl_exe_report = wx.StaticText(self, -1, "Path")
        self.txt_exe_report = wx.TextCtrl(self, size=(100, -1))
        self.bt_exe_report = wx.Button(self,-1, "Search")
        self.lbl_report_msg_ok = wx.StaticText(self, -1, "Message OK")
        self.txt_report_msg_ok = wx.TextCtrl(self, size=(100, -1))
        self.lbl_report_msg_failed = wx.StaticText(self, -1, "Message Failed")
        self.txt_report_msg_failed = wx.TextCtrl(self, size=(100, -1))
        self.lbl_report_date_hour = wx.StaticText(self, -1, "Date and hour")
        self.txt_report_date_hour = wx.TextCtrl(self, size=(100, -1))
        self.lbl_report_page_separator = wx.StaticText(self, -1, "Page Separator")
        self.txt_report_page_separator = wx.TextCtrl(self, size=(100, -1))
        
        bmp_add = wx.Bitmap(os.path.join(self.paths.imgs_dir, "add.png"), wx.BITMAP_TYPE_PNG)
        bt_more_line = wx.BitmapButton(self, -1, bmp_add)
        bmp_del = wx.Bitmap(os.path.join(self.paths.imgs_dir, "delete.png"), wx.BITMAP_TYPE_PNG)
        bt_less_line = wx.BitmapButton(self, -1, bmp_del)
        
        #bind
        self.bt_tiff_view.Bind(wx.EVT_BUTTON, self.OnBt_tiff_viewButton)
        self.bt_ps_view.Bind(wx.EVT_BUTTON, self.OnBt_ps_viewButton)
        self.bt_search_freeimage.Bind(wx.EVT_BUTTON, self.OnBt_search_freeimageButton)
        self.bt_search_print_on_new.Bind(wx.EVT_BUTTON, self.OnBt_search_print_on_newButton)
        bt_more_line.Bind(wx.EVT_BUTTON, self.OnBt_gr_more)
        bt_less_line.Bind(wx.EVT_BUTTON, self.OnBt_gr_less)
        self.bt_exe_report.Bind(wx.EVT_BUTTON, self.OnBt_exe_report)
        
        self.chk_int_view.Bind(wx.EVT_CHECKBOX, self.OnChk_int_view)
        self.chk_concatenate.Bind(wx.EVT_CHECKBOX, self.OnChk_concatenate)
        self.chk_use_freeimage.Bind(wx.EVT_CHECKBOX, self.OnChk_use_freeimage)
        self.chk_modify_preview.Bind(wx.EVT_CHECKBOX, self.OnChk_modify_preview)
        self.chk_print_on_receive.Bind(wx.EVT_CHECKBOX, self.OnChk_print_on_receive)
        self.chk_print_str.Bind(wx.EVT_CHECKBOX, self.OnChk_print_str)
        
        #
        # sizers
        #
        
        #static box
        self.box_view = wx.StaticBox(self, -1, 'View fax - Internal Viewer')
        self.box_print = wx.StaticBox(self, -1, 'Print')
        self.box_other = wx.StaticBox(self, -1, 'Other')
        self.box_send_report = wx.StaticBox(self, -1, 'Report')
        
        #box sizer
        sz_fax_view_box = wx.StaticBoxSizer(self.box_view, wx.VERTICAL)
        sz_fax_print_box = wx.StaticBoxSizer(self.box_print, wx.VERTICAL)
        sz_fax_other_box = wx.StaticBoxSizer(self.box_other, wx.VERTICAL)
        sz_fax_report_box = wx.StaticBoxSizer(self.box_send_report, wx.HORIZONTAL)
        
        #sizers
        sz_fax_view = wx.FlexGridSizer(3, 3)
        sz_fax_print = wx.FlexGridSizer(3, 2)
        sz_fax_other = wx.FlexGridSizer(3, 2)
        sz_fax_report = wx.BoxSizer(wx.HORIZONTAL)
        sz_fax_report_bt = wx.BoxSizer(wx.VERTICAL)
        sz_fax_report_right = wx.BoxSizer(wx.VERTICAL)
        sz_fax_report_exe = wx.BoxSizer(wx.HORIZONTAL)
        sz_fax_report_msg = wx.FlexGridSizer(2,2, 5,5)
        sz_freeimage = wx.BoxSizer(wx.HORIZONTAL)
        sz_row_1 = wx.BoxSizer(wx.HORIZONTAL)
        sz_row_2 = wx.BoxSizer(wx.HORIZONTAL)
        sz_row_3 = wx.BoxSizer(wx.HORIZONTAL)
        sz_all = wx.BoxSizer(wx.VERTICAL)
        
        #sizer fax view
        flags = wx.ALL | wx.ALIGN_CENTER_VERTICAL
        sz_fax_view.Add((0,0))
        sz_fax_view.Add(self.chk_int_view,0, flags, 5)
        sz_fax_view.Add((0,0))
        sz_fax_view.Add(self.lbl_tiff,0, flags, 5)
        sz_fax_view.Add(self.txt_tiff_view,0, flags, 5)
        sz_fax_view.Add(self.bt_tiff_view,0, flags, 5)
        sz_fax_view.Add(self.lbl_ps_view,0, flags, 5)
        sz_fax_view.Add(self.txt_ps_view,0, flags, 5)
        sz_fax_view.Add(self.bt_ps_view,0, flags, 5)
        
        #sizer print 
        sz_fax_print.Add((0,0))
        sz_fax_print.Add(self.chk_print_str,0, flags, 5)
        sz_fax_print.Add(self.lbl_fontsize,0, flags, 5)
        sz_fax_print.Add(self.txt_fontsize,0, flags, 5)
        sz_fax_print.Add(self.lbl_zoom,0, flags, 5)
        sz_fax_print.Add(self.cho_zoom,0, flags, 5)
        
        sz_freeimage.Add(self.lbl_freeimage_path, 0, flags, 5)
        sz_freeimage.Add(self.txt_freeimage_path, 0, flags, 5)
        sz_freeimage.Add(self.bt_search_freeimage, 0, flags, 5)
        
        #sizer other
        sz_fax_other.Add(self.chk_use_freeimage,0, flags, 5)
        sz_fax_other.Add(sz_freeimage,0, flags, 5)
        sz_fax_other.Add(self.chk_concatenate,0, flags, 5)
        sz_fax_other.Add(self.chk_modify_preview,0, flags, 5)
        
        sz_fax_other.Add(self.chk_print_on_receive,0, flags, 5)
        sz_fax_other.Add((0,0))
        sz_fax_other.Add(self.txt_prt_name_on_new,0, flags, 5)
        sz_fax_other.Add(self.bt_search_print_on_new,0, flags, 5)
        
        #report
        sz_fax_report.Add(self._gr,0, flags, 5)
        sz_fax_report_bt.Add(bt_more_line,0, flags, 5)
        sz_fax_report_bt.Add(bt_less_line,0, flags, 5)
        sz_fax_report.Add(sz_fax_report_bt, 0, wx.ALIGN_CENTER)
        
        sz_fax_report_exe.Add(self.lbl_exe_report,0, flags, 5)
        sz_fax_report_exe.Add(self.txt_exe_report,0, flags, 5)
        sz_fax_report_exe.Add(self.bt_exe_report,0, flags, 5)
        sz_fax_report_msg.Add(self.lbl_report_msg_ok)
        sz_fax_report_msg.Add(self.txt_report_msg_ok)
        sz_fax_report_msg.Add(self.lbl_report_msg_failed)
        sz_fax_report_msg.Add(self.txt_report_msg_failed)
        sz_fax_report_msg.Add(self.lbl_report_date_hour)
        sz_fax_report_msg.Add(self.txt_report_date_hour)
        sz_fax_report_msg.Add(self.lbl_report_page_separator)
        sz_fax_report_msg.Add(self.txt_report_page_separator)
        
        sz_fax_view_box.Add(sz_fax_view)
        sz_fax_print_box.Add(sz_fax_print)
        sz_fax_other_box.Add(sz_fax_other)
        sz_fax_report_right.Add(sz_fax_report_exe)
        sz_fax_report_right.Add(sz_fax_report_msg)
        sz_fax_report_box.Add(sz_fax_report)
        sz_fax_report_box.Add( wx.StaticLine(self, style=wx.VERTICAL), 0, 
                wx.EXPAND | wx.ALL, 3)
        sz_fax_report_box.Add(sz_fax_report_right)
        
        sz_row_1.Add(sz_fax_view_box, 1, wx.EXPAND)
        sz_row_1.Add(sz_fax_print_box, 1, wx.EXPAND)
        sz_row_2.Add(sz_fax_other_box, 1, wx.EXPAND)
        sz_row_3.Add(sz_fax_report_box, 1, wx.EXPAND)
        #sz_row_3.Add(sz_fax_report_bt, 0, wx.ALIGN_CENTER)
        
        sz_all.Add(sz_row_1, 0, wx.EXPAND)
        sz_all.Add(sz_row_2, 0, wx.EXPAND)
        sz_all.Add(sz_row_3, 0, wx.EXPAND)
        
        self.SetSizerAndFit(sz_all)
        
    def __init__(self, parent, val_pass):
        """
        """
        self.paths, self.ren, self.opt_cls = val_pass
        
        self._init_ctrls(parent)
        
        lst_chk_zoom = range(30, 120, 10)
        for i in lst_chk_zoom:
            self.cho_zoom.Append(str(i))
        if self.cho_zoom.GetSelection() == -1:
            self.cho_zoom.SetSelection(0)
        if not self.txt_fontsize.GetValue():
            if sys.platform == 'win32':
                font_dim = '9'
            else:
                font_dim = '15'
            self.txt_fontsize.SetValue(font_dim)
        
    def _set_gr(self):
        """ Set the grid
        """
        self._gr.CreateGrid(0, 1)
        self._gr.SetColLabelValue(0, self.ren.get("row", 1))
        self._gr.SetColSize(0, self._gr.GetClientSize().width - (self._gr.GetRowLabelSize() + 10))
        
        #set the data
        sep = (";;;")
        data = self.opt_cls.get("gr_report").strip()
        for num_row, data_row in enumerate(data.split(sep)):
            data_row = data_row.strip(" ")
            if not data_row: continue
            if data_row == "\n":
                data_row = "\\n"
            self._gr.AppendRows()
            self._gr.SetCellValue(num_row, 0, data_row)
    
    def get_parameters(self):
        """ Return the grid data
        """
        return ";;;".join( (self._gr.GetCellValue(x, 0) for x  in xrange(self._gr.GetNumberRows()) ) )
    
    def set_parameters(self):
        """ Set the paramters
        """
        self._set_gr()
        
    def ctrlWidgetsStatus(self):
        #Enable or disable the controls
        self._modify_enable(self.chk_int_view.GetValue())
        self._modify_enable(self.chk_use_freeimage.GetValue(), 'FI')
        self._enablePrintOnNew( self.chk_print_on_receive.GetValue() )
        
    def OnBt_tiff_viewButton(self, event):
        filename = self.__get_file_name(self.txt_tiff_view.GetValue())
        if filename != '':
            self.txt_tiff_view.SetValue(filename)

    def __get_file_name(self, dir_ = './', ext='exe'):
        """
        """
        dir_ = os.path.abspath(os.path.split(dir_)[0])
        if sys.platform.startswith('win32'):
            dlg = wx.FileDialog(self, self.ren.get('choose_file', 1), dir_, "", "*.%s" % ext, wx.OPEN)
        else:
            dlg = wx.FileDialog(self, self.ren.get('choose_file', 1), dir_, "", "*", wx.OPEN)
        filename = ''
        try:
            if dlg.ShowModal() == wx.ID_OK:
                filename = dlg.GetPath()
        finally:
            dlg.Destroy()
        return filename

    def OnBt_ps_viewButton(self, event):
        filename = self.__get_file_name(self.txt_ps_view.GetValue())
        if filename != '':
            self.txt_ps_view.SetValue(filename)

    def OnChk_concatenate(self, event):
        if self.chk_concatenate.GetValue():
            self._msg()

    def OnChk_modify_preview(self, event):
        if self.chk_modify_preview.GetValue():
            self._msg()

    def _msg(self):
        if sys.platform == 'win32':
            return
        dlg = wx.MessageDialog(self, self.ren.get('_msg_tiff_version'), '', wx.ICON_INFORMATION)
        dlg.ShowModal()
        dlg.Destroy()

    def OnChk_internal_view(self, evt):
        self._modify_enable(evt.GetInt())

    def OnChk_use_freeimage(self, evt):
        self._modify_enable(evt.GetInt(), 'FI')
        
    def _modify_enable(self, state, type='INT'):
        if type == 'INT':
            ctrls2disable = [self.txt_fontsize, self.cho_zoom, ]
            ctrls2enable = [self.bt_ps_view,  self.bt_tiff_view,
                            self.txt_ps_view,  self.txt_tiff_view]
        elif type == 'FI':
            ctrls2enable = ()
            ctrls2disable = [self.lbl_freeimage_path,  self.txt_freeimage_path, 
                            self.bt_search_freeimage, self.chk_concatenate,
                            self.chk_modify_preview ]
        else:
            return
        
        for v in ctrls2enable:
            v.Enable(not state)
        for v in ctrls2disable:
            v.Enable(state)

    def OnChk_int_view(self, event):
        self._modify_enable(event.IsChecked())

    def OnChk_use_freeimageCheckbox(self, event):
        self._modify_enable(event.IsChecked(), 'FI')

    def OnBt_search_freeimageButton(self, event):
        filename = self.__get_file_name(self.txt_freeimage_path.GetValue(), 'dll')
        if filename != '':
            self.txt_freeimage_path.SetValue(filename)

    def OnChk_print_str(self, event):
        self.txt_fontsize.Enable(not event.GetInt())
        
    def OnChk_print_on_receive(self, event):
        self._enablePrintOnNew( event.GetInt() )

    def OnBt_search_print_on_newButton(self, event):
        """
        """
        dlg = wx.PrintDialog(self)
        ret = dlg.ShowModal()
        prName = dlg.GetPrintDialogData().GetPrintData().GetPrinterName()
        dlg.Destroy()
        
        if ret == wx.ID_OK:
            self.txt_prt_name_on_new.SetValue( prName )
    
    def OnBt_gr_more(self, evt):
        """
        """
        self._gr.AppendRows()
    
    def OnBt_gr_less(self, evt):
        """
        """
        sel = self._gr.GetSelectedRows()
        for row in reversed(sel):
            self._gr.DeleteRows(row)
    
    def OnBt_exe_report(self, evt):
        """
        """
        filename = self.__get_file_name(self.txt_exe_report.GetValue())
        if filename != '':
            self.txt_exe_report.SetValue(filename)
    
    def _enablePrintOnNew(self, value):
        """
        """
        for ctrl in ( self.bt_search_print_on_new, self.txt_prt_name_on_new ):
            ctrl.Enable(value)
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.