#Boa:FramePanel:panel
# -*- coding: utf-8 -*-
#
# hylaPEx, an hylafax client written in python
#
# www.unipex.it/hylapex/
#
# License:
# GNU General Public License (GPL)
# For more info see LICENSE.txt and LICENSE-GPL.txt
#
# Copyright (C) 2004-2006 Unipex s.r.l., All Rights Reserved.
# Via Vittorio Veneto 83/A
# 33050 Gonars (UD) - Italy
# phone 0039 0432 931511 - fax 0039 0432 931378
# www.unipex.it - michele.petrazzo@unipex.it
import wx
import os, sys, subprocess, traceback
from time import sleep
[wxID_PANEL, wxID_PANELBOX_ADMINI, wxID_PANELBT_GS, wxID_PANELBT_GS_HOME,
wxID_PANELBT_PORT, wxID_PANELBT_PRINTER, wxID_PANELBT_REDMON,
wxID_PANELCHK_DB_ODBC_READONLY, wxID_PANELCHO_LANGUAGE,
wxID_PANELLBL_DB_ODBC_READONLY, wxID_PANELLBL_GS, wxID_PANELLBL_GS_HOME,
wxID_PANELLBL_LANGUAGE, wxID_PANELTXT_GS, wxID_PANELTXT_GS_HOME,
wxID_PANELTXT_HELP_ADMIN,
] = [wx.NewId() for _init_ctrls in range(16)]
class panel(wx.Panel):
def _init_ctrls(self, prnt):
# generated method, don't edit
wx.Panel.__init__(self, id=wxID_PANEL, name='panel', parent=prnt,
pos=wx.Point(374, 447), size=wx.Size(450, 244),
style=wx.TAB_TRAVERSAL)
self.SetClientSize(wx.Size(442, 217))
self.SetToolTipString('')
self.Enable(True)
self.Bind(wx.EVT_CLOSE, self.OnWxframe1Close)
self.cho_language = wx.Choice(choices=[], id=wxID_PANELCHO_LANGUAGE,
name='cho_language', parent=self, pos=wx.Point(96, 176),
size=wx.Size(88, 21), style=0)
self.cho_language.SetToolTipString('')
self.bt_gs = wx.Button(id=wxID_PANELBT_GS, label='Search', name='bt_gs',
parent=self, pos=wx.Point(376, 168), size=wx.Size(59, 21),
style=0)
self.bt_gs.SetToolTipString('')
self.bt_gs.Bind(wx.EVT_BUTTON, self.OnBt_gsButton, id=wxID_PANELBT_GS)
self.txt_gs = wx.TextCtrl(id=wxID_PANELTXT_GS, name='txt_gs',
parent=self, pos=wx.Point(264, 168), size=wx.Size(100, 21),
style=0, value='')
self.txt_gs.SetToolTipString('')
self.txt_help_admin = wx.TextCtrl(id=wxID_PANELTXT_HELP_ADMIN,
name='txt_help_admin', parent=self, pos=wx.Point(24, 64),
size=wx.Size(392, 72), style=wx.TE_MULTILINE, value='')
self.txt_help_admin.SetToolTipString('')
self.bt_redmon = wx.Button(id=wxID_PANELBT_REDMON, label='1 - Redmon',
name='bt_redmon', parent=self, pos=wx.Point(24, 32),
size=wx.Size(75, 23), style=0)
self.bt_redmon.SetToolTipString('')
self.bt_redmon.Bind(wx.EVT_BUTTON, self.OnBt_redmonButton,
id=wxID_PANELBT_REDMON)
self.bt_port = wx.Button(id=wxID_PANELBT_PORT, label=' 2 - Port ',
name='bt_port', parent=self, pos=wx.Point(184, 32),
size=wx.Size(75, 23), style=0)
self.bt_port.SetToolTipString('')
self.bt_port.Enable(False)
self.bt_port.Bind(wx.EVT_BUTTON, self.OnBt_portButton,
id=wxID_PANELBT_PORT)
self.bt_printer = wx.Button(id=wxID_PANELBT_PRINTER,
label='3 - Printer', name='bt_printer', parent=self,
pos=wx.Point(344, 32), size=wx.Size(75, 23), style=0)
self.bt_printer.SetToolTipString('')
self.bt_printer.Enable(False)
self.bt_printer.Bind(wx.EVT_BUTTON, self.OnBt_printerButton,
id=wxID_PANELBT_PRINTER)
self.lbl_language = wx.StaticText(id=wxID_PANELLBL_LANGUAGE,
label='Language', name='lbl_language', parent=self,
pos=wx.Point(16, 179), size=wx.Size(64, 13), style=0)
self.lbl_language.SetToolTipString('')
self.lbl_gs = wx.StaticText(id=wxID_PANELLBL_GS, label='Gs path',
name='lbl_gs', parent=self, pos=wx.Point(200, 171),
size=wx.Size(48, 13), style=0)
self.box_admini = wx.StaticBox(id=wxID_PANELBOX_ADMINI,
label='Administrative - first use', name='box_admini',
parent=self, pos=wx.Point(8, 8), size=wx.Size(424, 136), style=0)
self.box_admini.SetToolTipString('')
self.lbl_gs_home = wx.StaticText(id=wxID_PANELLBL_GS_HOME,
label='Gs home', name='lbl_gs_home', parent=self,
pos=wx.Point(200, 192), size=wx.Size(48, 13), style=0)
self.txt_gs_home = wx.TextCtrl(id=wxID_PANELTXT_GS_HOME,
name='txt_gs_home', parent=self, pos=wx.Point(264, 192),
size=wx.Size(100, 21), style=0, value='')
self.txt_gs_home.SetToolTipString('')
self.bt_gs_home = wx.Button(id=wxID_PANELBT_GS_HOME, label='Search',
name='bt_gs_home', parent=self, pos=wx.Point(376, 192),
size=wx.Size(59, 23), style=0)
self.bt_gs_home.SetToolTipString('')
self.bt_gs_home.Bind(wx.EVT_BUTTON, self.OnBt_gs_homeButton,
id=wxID_PANELBT_GS_HOME)
self.lbl_db_odbc_readonly = wx.StaticText(id=wxID_PANELLBL_DB_ODBC_READONLY,
label=u'Db odbc readonly', name=u'lbl_db_odbc_readonly',
parent=self, pos=wx.Point(16, 152), size=wx.Size(84, 13),
style=0)
self.lbl_db_odbc_readonly.SetToolTipString(u'')
self.chk_db_odbc_readonly = wx.CheckBox(id=wxID_PANELCHK_DB_ODBC_READONLY,
label=u'', name=u'chk_db_odbc_readonly', parent=self,
pos=wx.Point(136, 152), size=wx.Size(24, 13), style=0)
self.chk_db_odbc_readonly.SetToolTipString(u'')
def __init__(self, parent, val_pass):
self._init_ctrls(parent)
self.paths, self.ren, self.opt_cls = val_pass
self.PP = 0
def ctrlWidgetsStatus(self):
#Enable or disable the controls
pass
def OnWxframe1Close(self, event):
event.Skip()
def OnBt_gsButton(self, event):
filename = self.__get_file_name(self.txt_gs.GetValue())
if filename != '':
self.txt_gs.SetValue(filename)
def __get_file_name(self, dir = ''):
if sys.platform == 'win32':
dlg = wx.FileDialog(self, self.ren.get('choose_file', 1), dir, "", "*.exe", 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_redmonButton(self, event):
#Install redmon
out,err = self._execute_command(self.paths.my_path, 'redmon', 'setup.exe')
#self._execute_command(r"V:\hylapex\dist\Copia di redmon", "setup.exe")
self.bt_port.Enable(True)
wx.FutureCall(500, self.Raise)
def OnBt_portButton(self, event):
if self.PP:
event.Skip()
return
self.PP = 1
hylaprint = os.path.join(self.paths.my_path, 'hylaprint.exe')
import _winreg
regkey_set = 'SYSTEM\\CurrentControlSet\\Control\\Print\\Monitors\\Redirected Port\\Ports\\RPT'
hkey_m = _winreg.HKEY_LOCAL_MACHINE
for pn in range(1,10):
try:
h_obj_u = _winreg.OpenKey(hkey_m, regkey_set + str(pn) + ':')
except:
break
self.pn = pn
title = 'Windows Registry Editor Version 5.00'
port_num_set1 = '[HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Control\\Print\\Monitors\\Redirected Port\\Ports\\RPT%s:]' % str(pn)
port_num_set = '[HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Print\\Monitors\\Redirected Port\\Ports\\RPT%s:]' % str(pn)
vars2write = ['"Description"="Redirected Port"', '"Command"="%s"' % hylaprint.replace('\\', '\\\\'),
'"Arguments"=""',
'"Printer"=""', '"Output"=dword:00000000', '"ShowWindow"=dword:00000002','"RunUser"=dword:00000000',
'"Delay"=dword:0000012c','"LogFileUse"=dword:00000000','"LogFileName"=""',
'"LogFileDebug"=dword:00000000','"PrintError"=dword:00000000', '"RunUser"=dword:00000001']
pr_reg = os.path.join(self.paths.tmp_dir, 'rpt.reg')
f = file(pr_reg, 'w')
f.write(title +'\n\n')
f.write(port_num_set +'\n')
for i in vars2write:
f.write(i +'\n')
f.write('\n')
f.write(port_num_set1 + '\n')
for i in vars2write:
f.write(i +'\n')
f.close()
sleep(0.3)
self._execute_command('regedit.exe', '/s', pr_reg, join=False)
sleep(0.3)
self.bt_printer.Enable(True)
#self.bt_printer.Enable(True)
self.Raise()
def OnBt_printerButton(self, event):
#If not is win9x
if not sys.getwindowsversion()[3] == 1:
pr_script = '@echo off\n'
pr_script += 'rundll32 printui.dll,PrintUIEntry /if /b "LINUX-FAX" /f '
pr_script += '%windir%\\inf\\ntprint.inf /m "HP LaserJet 8000 Series PS" /r '
pr_script += "RPT%s:" % str(self.pn)
pr_file = os.path.join(os.path.join(self.paths.tmp_dir, 'printer.bat'))
f = file(pr_file, 'w')
f.write(pr_script +'\n\n')
f.close()
sleep(0.3)
self._execute_command(self.paths.tmp_dir, 'printer.bat')
sleep(0.3)
else:
wx.MessaggeBox(self.ren.get("no_win9x"),
self.ren.get("attention", 1), wx.ICON_ERROR)
self.Raise()
def OnBt_gs_homeButton(self, event):
oldDir = self.txt_gs_home.GetValue()
dlg = wx.DirDialog(self, self.ren.get('_choose_dir_gs'), oldDir)
directory = ''
try:
if dlg.ShowModal() == wx.ID_OK:
directory = dlg.GetPath()
finally:
dlg.Destroy()
if directory != '':
self.txt_gs_home.SetValue(directory)
def _execute_command(self, *cmd, **kw):
""" Execute a command with the new subprocess. remove the popen3
dependancy due a problem with the spaces
"""
if kw.get('join', True):
cmds = os.path.join(*cmd)
else:
cmds = cmd
self.paths.log4write.write('I execute: %s' % str(cmds))
try:
sp = subprocess.Popen(cmds,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
out, err = sp.communicate()
self.paths.log4write.write("Out from cmd: %s" % str(out))
self.paths.log4write.write("Err from cmd: %s" % str(err))
except:
trb = str(traceback.format_exc())
print trb
wx.MessageBox( "Executing: %s\nError:%s" % ( cmds, trb ),
"Error", wx.ICON_ERROR)
return ("","")
|