# -*- coding: utf-8 -*-
import wx
import options_p_admin, options_p_print, options_p_view, options_p_user_send
import options_p_cover, options_p_db_archive
from library import utils
import wx_util
import os, sys
_ = None # for i18n
class frm_opt(wx.Frame):
def _init_ctrls(self, prnt):
# generated method, don't edit
wx.Frame.__init__(self, prnt, title='Options')
#self.SetBackgroundColour(wx.Colour(225, 225, 225))
self.Bind(wx.EVT_CLOSE, self.OnFrm_optClose)
self._p = wx.Panel(self)
self.nb_options = wx.Notebook(self._p, -1, style=wx.DOUBLE_BORDER)
self.bt_save = wx.Button(self._p, -1, 'Save')
self.bt_save.Bind(wx.EVT_BUTTON, self.OnBt_saveButton)
sz_all = wx.BoxSizer(wx.VERTICAL)
sz_all.Add(self.nb_options, 1, wx.ALL | wx.EXPAND, 5)
sz_all.Add(self.bt_save, 0, wx.ALIGN_RIGHT | wx.ALL, 5)
self._p.SetSizerAndFit(sz_all)
def __init__(self, parent, opt_cls, paths, all_fax_view=''):
self._init_ctrls(parent)
from library import i18n
global _
_ = i18n.i18n(default=paths.language, dir_path=paths.my_path)
self.opt_cls = opt_cls
self.paths = paths
self.parent = parent
self.my_path = os.path.dirname(os.path.abspath(sys.argv[0]))
self.file_conf_gen = self.paths.file_conf_gen
self.first = 0
self.__my_init()
self.all_fax_view = all_fax_view
def __my_init(self):
#Rename the controls
ren = wx_util.rename_ctrls(self, 'options',
lang = self.paths.language, path = self.paths.my_path)
ren.rename()
# Used for understand if it's first use
if self.opt_cls.exist(0):
self.first = 1
self.opt_cls.add_section('hylapex')
#Create the panels
self.order = ['User', 'View', 'Print', 'Cover', 'DbArchive', 'Admin']
self._idx_user = self.order.index("User")
self._idx_admin = self.order.index("Admin")
self._idx_db_archive = self.order.index("DbArchive")
self._idx_print = self.order.index("Print")
panel_names = ren.get_list('nb_options')
val2pass = (self.paths, ren, self.opt_cls)
self.panels = [ options_p_user_send.panel(self.nb_options, val2pass),
options_p_view.panel(self.nb_options, val2pass, self.all_fax_view),
options_p_print.panel(self.nb_options, val2pass),
options_p_cover.panel(self.nb_options, val2pass),
options_p_db_archive.panel(self.nb_options, val2pass),
options_p_admin.panel(self.nb_options, val2pass), ]
to_del = []
for num, v in enumerate(self.order):
try:
inst = self.panels[num]
self.nb_options.AddPage(inst, panel_names[num])
except (IndexError, KeyError):
to_del.append(v)
print v
continue
#I18n
self.ren = wx_util.rename_ctrls(inst, 'options',
lang = self.paths.language)
self.ren.rename()
inst.Refresh()
for i in to_del: self.order.remove(i)
langs = wx_util.get_available_lang(self.paths.my_path)
for lang in langs:
self.panels[ self._idx_admin ].cho_language.Append(lang[1] +' ('+ lang[0]+')')
#State of controls
#Set the default values if this is the first use
if self.first:
self.nb_options.SetSelection(self._idx_admin)
valuesDefault = dict(
cho_zoom = 100,
chk_new_fax = 1,
sld_tel = 4,
txt_fontsize = "9",
cho_state_control = "Always",
chk_send_message = 1,
chk_int_view = 1,
cho_language = "English (en)",
txt_update = "30",
view = 'send'
)
#Library path
lib_path = ''
if sys.platform.startswith('win'):
lib_path = os.path.join(self.paths.my_path, 'FreeImage.dll')
else:
lib_path = 'freeimage'
#Enable the various freeimage depend functions only if I found
#the freeimge library
setValue = 1
if sys.platform.startswith('win') and not os.path.exists(lib_path):
setValue = 0
if setValue:
valuesDefault['txt_freeimage_path'] = lib_path
valuesDefault['chk_use_freeimage'] = 1
valuesDefault['chk_modify_preview'] = 1
valuesDefault['chk_concatenate'] = 1
for k, v in valuesDefault.iteritems():
self.opt_cls.set(k, v)
if sys.platform.startswith('win'):
gs_path = os.path.join(self.paths.gs_home_tmp, 'bin', 'gswin32c.exe')
elif not sys.platform.startswith('win'):
gs_path = "/usr/bin/gs"
if os.path.exists(gs_path):
self.opt_cls.set('txt_gs', gs_path)
#I thinks that I don't need to set the ghostscript home on *nix systems
if ( sys.platform.startswith('win') and
os.path.exists(self.paths.gs_home_tmp) ):
self.opt_cls.set('txt_gs_home', self.paths.gs_home_tmp)
utils.ctrl_opt_cls_hylapex(self.opt_cls)
for inst in self.panels:
ctrls = wx_util.controls_state(inst)
ctrls.set(self.opt_cls.get_items_dict())
inst.ctrlWidgetsStatus()
if sys.platform.startswith('win'):
val = ('This three buttons are used for install the printer. Normally ' +
"you use this functions only first time of hylapex's use.\n\n"+
'Press "1-Redmon" and then press "yes". If you have yet Redmon install, press "ok".\n' +
'Press "2-Port" and then press "Yes" and "Ok".\nPress "3-Printer" for install ' +
'the printer called Linux-Fax.')
else:
self.panels[self._idx_admin].bt_redmon.Enable(False)
val = "U don't need this functions, only for winzozz :P"
self.panels[self._idx_admin].txt_help_admin.SetValue(val)
#db_archive parameters
db_arch_pars = (self.opt_cls.getint("db_archive_rcv_usage"),
self.opt_cls.getint("db_archive_rcv_type"),
self.opt_cls.get("db_archive_rcv_vals"),
self.opt_cls.get("db_archive_rcv_grid"),
)
self.panels[self._idx_db_archive].set_parameters(db_arch_pars)
self.panels[self._idx_print].set_parameters()
#Port pressed
self.PP = 0
#Set the size
self.SetClientSize( self.panels[ self._idx_user ].GetSize() + wx.Size(100,100) )
def OnFrm_optClose(self, event):
self.close()
def close(self):
self.Destroy()
if self.first == 1:
sys.exit()
def all_fax_view(self):
self.all_fax_view()
def OnBt_saveButton(self, event):
val_update = int(self.panels[self._idx_user].txt_update.GetValue())
if val_update < 20 and val_update != 0:
wx.MessageBox(self.ren.get("_number_second_min"),
self.ren.get("attention", 1), wx.ICON_ERROR)
return
if self.panels[self._idx_user].sld_tel.GetValue() == 1:
wx.MessageBox(self.ren.get("_max_tel_min_one"),
self.ren.get("attention", 1), wx.ICON_ERROR)
return
for v in self.panels:
ctrls = wx_util.controls_state(v)
vals = ctrls.get(exclude = ['txt_help_admin'])
self.opt_cls.set_dict(vals)
if self.panels[self._idx_user].rd_done.GetValue():
self.opt_cls.set('notify','done')
elif self.panels[self._idx_user].rd_always.GetValue():
self.opt_cls.set('notify','always')
else:
self.opt_cls.set('notify','none')
pnl_user = self.panels[self._idx_user]
for widget_name in ("rd_smtp_local", "rd_smtp_hylapex", "rd_smtp_ext_prog"):
self.opt_cls.set(widget_name, int( getattr(pnl_user, widget_name).GetValue() ) )
if self.opt_cls.get('txt_gs') == '':
dlg = wx.MessageBox(self.ren.get('_insert_gs_path'),
self.ren.get('error', 1), wx.ICON_ERROR)
self.opt_cls.exit()
if vals['cho_language'] != '':
self.paths.language = wx_util.get_language(vals['cho_language'])
else:
self.paths.language = wx_util.get_language('English (en)')
#db data
db_usage, db_type, db_vals, gr_data = self.panels[self._idx_db_archive].get_parameters()
#print data
self.opt_cls.set("gr_report", self.panels[self._idx_print].get_parameters())
exe_report = self.opt_cls.get("txt_exe_report")
if not os.path.exists(exe_report) and not sys.platform.startswith("win"):
self.opt_cls.set("txt_exe_report", "")
if db_usage:
#save the data
self.opt_cls.set("db_archive_rcv_usage", db_usage)
self.opt_cls.set("db_archive_rcv_type", db_type)
self.opt_cls.set("db_archive_rcv_vals", db_vals)
self.opt_cls.set("db_archive_rcv_grid", gr_data)
else:
self.opt_cls.set("db_archive_rcv_usage", "0")
if not self.first:
if self.parent.offline:
self.parent.offline = 0
if self.parent.view_fax:
self.parent.view_fax.closeLib()
self.parent.view_fax = None
self.parent._load_srv_hy()
self.parent._raname_ctrls()
self.close()
|