options_p_user_send.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_user_send.py
# -*- coding: utf-8 -*-

from subprocess import Popen,PIPE
import traceback

import wx

from library import i18n
_ = i18n.i18n()

class panel(wx.Panel):
    def __init__(self, parent, val_pass):
        
        self.paths, self.ren, self.opt_cls = val_pass
        if not self.opt_cls.has_option("max_days_last_time"):
            self.opt_cls.set("max_days_last_time", 15)
        
        if not self.opt_cls.has_option("chk_use_cover"):
            self.opt_cls.set("chk_use_cover", 1)

        self._init_ctrls(parent)


    def _init_ctrls(self, prnt):
        """ creates and initializes the ctrls
        """
        # the panel
        wx.Panel.__init__(self, prnt, style=wx.TAB_TRAVERSAL)
        
        # -- SERVER SECTION --
        
        # server section box
        self.box_server = wx.StaticBox(self, -1, 'Hylafax')
        
        # server ctrls
        self.lbl_server = wx.StaticText(self, -1, 'Server')
        self.txt_server = wx.TextCtrl(self)
        
        # user ctrls
        self.lbl_user = wx.StaticText(self, -1, 'User')
        self.txt_user = wx.TextCtrl(self)
        
        # password ctrls
        self.lbl_passwd = wx.StaticText(self, -1, 'Password')
        self.txt_pass = wx.TextCtrl(self, style=wx.TE_PASSWORD)

        # admin password ctrls
        self.lbl_passwd_admin = wx.StaticText(self, -1, 'Admin pass')
        self.txt_passwd_admin = wx.TextCtrl(self, style=wx.TE_PASSWORD)

        # passive ctrls
        self.lbl_passive_ftp = wx.StaticText(self, -1, 'Passive ftp')
        self.chk_passive = wx.CheckBox(self)
        self.chk_passive.SetValue(True)

        # sizer containing the ctrls
        sz_server = wx.GridBagSizer()
        server_flg = wx.ALIGN_LEFT | wx.ALL | wx.EXPAND
        sz_server.Add(self.lbl_server, (0, 0), flag=server_flg, border=5)
        sz_server.Add(self.txt_server, (0, 1), flag=server_flg, border=5)
        sz_server.Add(self.lbl_user, (1, 0), flag=server_flg, border=5)
        sz_server.Add(self.txt_user, (1, 1), flag=server_flg, border=5)
        sz_server.Add(self.lbl_passwd, (2, 0), flag=server_flg, border=5)
        sz_server.Add(self.txt_pass, (2, 1), flag=server_flg, border=5)
        sz_server.Add(self.lbl_passwd_admin, (3, 0), flag=server_flg, border=5)
        sz_server.Add(self.txt_passwd_admin, (3, 1), flag=server_flg, border=5)
        sz_server.Add(self.lbl_passive_ftp, (4, 0), flag=server_flg, border=5)
        sz_server.Add(self.chk_passive, (4, 1), flag=wx.ALIGN_CENTER|wx.ALL, border=5)
        
        # server static box sizer
        sz_server_box = wx.StaticBoxSizer(self.box_server, wx.HORIZONTAL)
        sz_server_box.Add(sz_server)

        
        # -- SEND SECTION --
        
        # send box
        self.box_send = wx.StaticBox(self, -1, 'Send fax',)

        # prefix ctrls
        self.lbl_prefix = wx.StaticText(self, -1, 'Line prefix')
        self.txt_prefix = wx.TextCtrl(self)

        # email ctrls
        self.lbl_email = wx.StaticText(self, -1, 'E-mail')
        self.txt_email = wx.TextCtrl(self)

        # update ctrls
        self.bt_agg = wx.StaticText(self, -1, 'Update sec')
        self.txt_update = wx.TextCtrl(self, value='30')

        # Tries ctrls
        self.lbl_maxtel = wx.StaticText(self, -1, label='Max phone') 
        self.sld_tel = wx.Slider(name='sld_tel', maxValue=15, minValue=1, 
                parent=self, style=wx.SL_HORIZONTAL, value=1,size=(100,-1))
        self.sld_tel.Bind(wx.EVT_SCROLL, self.OnSld_telScroll)
        
        # value of the Tries slider
        self.lbl_maxtel_descr = wx.StaticText(self, -1, '1')
        # Tries slider sizer
        sz_sldr_tel = wx.BoxSizer(wx.HORIZONTAL)
        sl_flag = wx.ALIGN_CENTER | wx.ALL
        sz_sldr_tel.Add(self.sld_tel, flag=sl_flag, border=5)
        sz_sldr_tel.Add(self.lbl_maxtel_descr, flag=sl_flag, border=5)
        
        # last time ctrls
        self.lbl_last_time = wx.StaticText(self, -1, 'Last time')
        self.sld_last_time = wx.Slider(maxValue=self.opt_cls.getint("max_days_last_time"),
            minValue=1, parent=self,style=wx.SL_HORIZONTAL, value=1, size=(100,-1))
        self.sld_last_time.Bind(wx.EVT_SCROLL, self.OnSld_last_timeScroll)

        # value of the last time slider
        #manual value
        self.txt_last_time_manual = wx.TextCtrl(self, -1, "0100",
                size=(self.txt_email.GetTextExtent("999999")[0], -1))
        self.txt_last_time_manual.SetMaxLength(4)
        sz_sldr_last_time = wx.BoxSizer(wx.HORIZONTAL)
        sl_flag = wx.ALIGN_LEFT | wx.ALL
        sz_sldr_last_time.Add(self.sld_last_time, flag=sl_flag, border=5)
        sz_sldr_last_time.Add(self.txt_last_time_manual, flag=sl_flag, border=5)
        
        # update ctrls
        lbl_use_cover = wx.StaticText(self, -1, 'Use cover')
        self.chk_use_cover = wx.CheckBox(self,)

        sz_send = wx.GridBagSizer()
        send_flg = wx.ALIGN_LEFT | wx.ALL | wx.EXPAND | wx.ALIGN_CENTER_VERTICAL
        sz_send.Add(self.lbl_prefix, (0, 0), flag=send_flg, border=2)
        sz_send.Add(self.txt_prefix, (0, 1), flag=send_flg, border=2)
        sz_send.Add(self.lbl_email, (1, 0), flag=send_flg, border=2)
        sz_send.Add(self.txt_email, (1, 1), flag=send_flg, border=2)
        sz_send.Add(self.bt_agg, (2, 0), flag=send_flg, border=2)
        sz_send.Add(self.txt_update, (2, 1), flag=send_flg, border=2)
        sz_send.Add(self.lbl_maxtel, (3, 0), flag=send_flg, border=2)
        sz_send.Add(sz_sldr_tel, (3, 1), flag=send_flg, border=2)
        sz_send.Add(self.lbl_last_time, (4, 0), flag=send_flg, border=2)
        sz_send.Add(sz_sldr_last_time, (4, 1), flag=send_flg, border=2)
        sz_send.Add(lbl_use_cover, (5, 0), flag=send_flg, border=2)
        sz_send.Add(self.chk_use_cover, (5, 1), flag=wx.ALL | wx.ALIGN_CENTER, border=2)

        # server static box sizer
        sz_send_box = wx.StaticBoxSizer(self.box_send)
        sz_send_box.Add(sz_send)
        
        # -- EMAIL NOTIFICATION SECTION --
        
        # notification box
        self.box_notify = wx.StaticBox(self, -1, 'Notify e-mail when send fax')
        
        # always ctrls
        self.rd_always = wx.RadioButton(self, -1, 'Always', style=wx.RB_GROUP)
        self.rd_always.SetValue(False)
        
        # when ok ctrls
        self.rd_done = wx.RadioButton(self, -1, 'When done')
        self.rd_done.SetValue(False)
        
        # never ctrls
        self.rd_none = wx.RadioButton(self, -1, 'None')
        self.rd_none.SetValue(False)
        
        sz_notify = wx.BoxSizer(wx.HORIZONTAL)
        notify_flg = wx.ALIGN_CENTER | wx.ALL
        sz_notify.Add(self.rd_always, flag=notify_flg, border=5)
        sz_notify.Add((50, -1))
        sz_notify.Add(self.rd_done, flag=notify_flg, border=5)
        sz_notify.Add((50, -1))
        sz_notify.Add(self.rd_none, flag=notify_flg, border=5)
        
        # server static box sizer
        sz_notify_box = wx.StaticBoxSizer(self.box_notify, wx.VERTICAL)
        sz_notify_box.Add(sz_notify, flag=notify_flg, border=5)

        # --Send email (smtp) section --
        self.box_program = wx.StaticBox(self, -1, 'Program send email')
        self.rd_smtp_local = wx.RadioButton(self, -1, 'Local (from the OS)', style=wx.RB_GROUP)
        self.rd_smtp_hylapex = wx.RadioButton(self, -1, 'Hylapex')
        self.rd_smtp_ext_prog = wx.RadioButton(self, -1, 'External program')
        
        self.rd_smtp_local.Bind(wx.EVT_RADIOBUTTON, self.OnRbSmtpProgramLocal)
        self.rd_smtp_hylapex.Bind(wx.EVT_RADIOBUTTON, self.OnRbSmtpProgramHylapex)
        self.rd_smtp_ext_prog.Bind(wx.EVT_RADIOBUTTON, self.OnRbSmtpProgramExternal)
        
        #smtp program box
        sz_smtp_program = wx.StaticBoxSizer(self.box_program)
        notify_flg = wx.ALIGN_CENTER | wx.ALL
        sz_smtp_program.Add(self.rd_smtp_local, flag=notify_flg, border=5)
        sz_smtp_program.Add((50, -1))
        sz_smtp_program.Add(self.rd_smtp_hylapex, flag=notify_flg, border=5)
        sz_smtp_program.Add((50, -1))
        sz_smtp_program.Add(self.rd_smtp_ext_prog, flag=notify_flg, border=5)

        # notification box
        self.box_smtp = wx.StaticBox(self, -1, 'Send email (smtp)')
        
        # always ctrls
        self.lbl_smtp_host = wx.StaticText(self, -1, 'Smtp server')
        self.txt_smtp_host = wx.TextCtrl(self)
        self.lbl_smtp_from = wx.StaticText(self, -1, 'From')
        self.txt_smtp_from = wx.TextCtrl(self)
        self.lbl_smtp_regarding = wx.StaticText(self, -1, 'Regarding')
        self.txt_smtp_regarding = wx.TextCtrl(self)
        self.lbl_smtp_user = wx.StaticText(self, -1, 'Smtp user')
        self.txt_smtp_user = wx.TextCtrl(self)
        self.lbl_smtp_pass = wx.StaticText(self, -1, 'Smtp pass')
        self.txt_smtp_pass = wx.TextCtrl(self, style=wx.TE_PASSWORD)
        
        sz_smtp = wx.GridSizer(4, 4, 5, 5)
        notify_flg = wx.ALIGN_CENTER | wx.ALL
        sz_smtp.Add(self.lbl_smtp_host, 0, notify_flg, 5)
        sz_smtp.Add(self.txt_smtp_host, 0, notify_flg, 5)
        sz_smtp.Add((0,0))
        sz_smtp.Add((0,0))
        
        sz_smtp.Add(self.lbl_smtp_from, 0, notify_flg, 5)
        sz_smtp.Add(self.txt_smtp_from, 0, notify_flg, 5)
        sz_smtp.Add(self.lbl_smtp_regarding, 0, notify_flg, 5)
        sz_smtp.Add(self.txt_smtp_regarding, 0, notify_flg, 5)
        
        sz_smtp.Add(self.lbl_smtp_user, 0, notify_flg, 5)
        sz_smtp.Add(self.txt_smtp_user, 0, notify_flg, 5)
        sz_smtp.Add(self.lbl_smtp_pass, 0, notify_flg, 5)
        sz_smtp.Add(self.txt_smtp_pass, 0, notify_flg, 5)


        # server static box sizer
        sz_smtp_box = wx.StaticBoxSizer(self.box_smtp, wx.VERTICAL)
        sz_smtp_box.Add(sz_smtp, flag=notify_flg, border=5)

        # external program
        self.box_smtp_external = wx.StaticBox(self, -1, 'External program')
        sz_smtp_external_all = wx.BoxSizer(wx.VERTICAL)
        sz_smtp_external = wx.FlexGridSizer(1, 3)
        
        self.lbl_smtp_ext_path = wx.StaticText(self, label="Program path")
        self.txt_smtp_ext_path = wx.TextCtrl(self, size=(300, -1))
        self.bt_test_ext = wx.Button(self, label="Test")
        
        flags_ext = wx.ALL | wx.ALIGN_CENTER_VERTICAL
        sz_smtp_external.Add(self.lbl_smtp_ext_path, 0, flags_ext, 10)
        sz_smtp_external.Add(self.txt_smtp_ext_path, 0, flags_ext, 10)
        sz_smtp_external.Add(self.bt_test_ext, 0, flags_ext, 10)
        
        sz_smtp_external_all.Add(wx.StaticText(self, label=_("smtp_external_explain") ), 0, wx.EXPAND)
        sz_smtp_external_all.Add(sz_smtp_external, 0, wx.EXPAND)
        
        sz_smtp_external_box = wx.StaticBoxSizer(self.box_smtp_external, wx.VERTICAL)
        sz_smtp_external_box.Add(sz_smtp_external_all, flag=wx.EXPAND | wx.ALL, border=5)
        
        self.bt_test_ext.Bind(wx.EVT_BUTTON, self.OnBtTestExt)
        
        # -- THE MAIN SIZER --
        sz_main = wx.GridBagSizer()
        main_flag = wx.ALIGN_CENTER | wx.ALL | wx.EXPAND
        sz_main.Add(sz_server_box, (0, 0), flag=main_flag, border=5)
        sz_main.Add(sz_send_box, (0, 1), flag=main_flag, border=5)
        sz_main.Add(sz_notify_box, (1, 0), span=(1, 2), flag=main_flag, border=5)
        sz_main.Add(sz_smtp_program, (2, 0), span=(1, 2), flag=main_flag, border=5)
        sz_main.Add(sz_smtp_box, (3, 0), span=(1, 2), flag=main_flag, border=5)
        sz_main.Add(sz_smtp_external_box, (4, 0), span=(1, 2), flag=wx.EXPAND, border=5)
        
        sz_container = wx.BoxSizer(wx.VERTICAL)
        sz_container.Add(sz_main, flag=wx.ALIGN_CENTER | wx.ALL, border=0)
        
        self.SetSizerAndFit(sz_container)

    def OnSld_telScroll(self, event):
        """ cathces the tel slider motion
        """
        self.lbl_maxtel_descr.SetLabel(str(self.sld_tel.GetValue()))

    def OnSld_last_timeScroll(self, event):
        """ cathces the last time slider motion
        """
        v = str(self.sld_last_time.GetValue())
        if len(v) == 1: v = "0" + v
        self.txt_last_time_manual.SetValue(v + "00")

    def OnRbSmtpProgramLocal(self, evt):
        """ On local smtp
        """
        self._enable_smtp_program(0)
        
    def OnRbSmtpProgramHylapex(self, evt):
        """ On hylapex rb
        """
        self._enable_smtp_program(1)
    
    def OnRbSmtpProgramExternal(self, evt):
        """ On hylapex rb
        """
        self._enable_smtp_program(2)
    
    def OnBtTestExt(self, evt):
        """
        """
        txt_ext_path = self.txt_smtp_ext_path.GetValue()
        values = [str(x.strip()) for x in txt_ext_path.split("'") if x.strip()]
        if not values:
            return
        
        msg = [_("smtp_external_test"), " ".join(values)]
        
        wx.MessageBox("\n".join(msg), "Test", wx.ICON_INFORMATION)
        
        #print " ".join(values)
        try:
            cmd = Popen(values, stdout=PIPE, stderr=PIPE, stdin=PIPE)
            out, err = cmd.communicate()
            cmd.wait()
        except:
            msg = traceback.format_exc()
            wx.MessageBox(msg, _("error"), wx.ICON_ERROR)
            return
        
        if err:
            wx.MessageBox(err, _("error"), wx.ICON_ERROR)
        
    def _enable_smtp_program(self, value):
        """ Enable or disable the values for smtp
        """
        if value in (0, 2):
            internal_value = False
        else:
            internal_value = True
        
        if value == 2:
            external_value = True
        else:
            external_value = False
        
        for i in (self.txt_smtp_from, self.txt_smtp_host, 
                    self.txt_smtp_pass, self.txt_smtp_regarding, 
                    self.txt_smtp_user):
            i.Enable(internal_value)
        
        self.txt_smtp_ext_path.Enable(external_value)
        
    def ctrlWidgetsStatus(self):
        # Enable or disable the controls

        self.lbl_maxtel_descr.SetLabel(str(self.sld_tel.GetValue()))
        #self.lbl_last_time_descr.SetLabel(str(self.sld_last_time.GetValue()))
        if self.opt_cls.get('notify') == 'done':
            self.rd_done.SetValue(True)
        elif self.opt_cls.get('notify') == 'always':
            self.rd_always.SetValue(True)
        else:
            self.rd_none.SetValue(True)
        
        if self.opt_cls.getint("rd_smtp_local"):
            value = 0
            widget = self.rd_smtp_local
        elif self.opt_cls.getint("rd_smtp_hylapex"):
            value = 1
            widget = self.rd_smtp_hylapex
        elif self.opt_cls.getint("rd_smtp_ext_prog"):
            widget = self.rd_smtp_ext_prog
            value = 2
        else:
            #way here???
            value = 0
            widget = self.rd_smtp_local
        
        wx.CallAfter(widget.SetValue, True)
        
        self._enable_smtp_program( 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.