#Boa:Frame:wxFrame1
# -*- 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 os
import wx, wx.grid
import wx_util
from library.ftp import read_conf
from library.wizard import wiz_fb
def create(parent, db_inst, paths):
return wxFrame1(parent, db_inst, paths)
[wxID_WXFRAME1, wxID_WXFRAME1BT_CONFIGURE, wxID_WXFRAME1BT_DEL,
wxID_WXFRAME1BT_DEL_CONNECTION, wxID_WXFRAME1BT_NEW, wxID_WXFRAME1GR_FB,
wxID_WXFRAME1LBL_FB,
] = [wx.NewId() for _init_ctrls in range(7)]
class wxFrame1(wx.Frame):
def _init_ctrls(self, prnt):
# generated method, don't edit
wx.Frame.__init__(self, id=wxID_WXFRAME1, name='', parent=prnt,
pos=wx.Point(321, 315), size=wx.Size(434, 250),
style=wx.DEFAULT_FRAME_STYLE, title='Configure faxbook')
self.SetClientSize(wx.Size(426, 223))
self.SetBackgroundColour(wx.Colour(225, 225, 225))
self.SetToolTipString('')
self.Bind(wx.EVT_CLOSE, self.OnWxFrame1Close)
self.lbl_fb = wx.StaticText(id=wxID_WXFRAME1LBL_FB,
label='List of faxbook', name='lbl_fb', parent=self,
pos=wx.Point(24, 8), size=wx.Size(69, 13), style=0)
self.lbl_fb.SetToolTipString('')
self.gr_fb = wx.grid.Grid(id=wxID_WXFRAME1GR_FB, name='gr_fb',
parent=self, pos=wx.Point(24, 40), size=wx.Size(304, 160),
style=0)
self.gr_fb.SetRowLabelSize(25)
self.gr_fb.SetDefaultColSize(30)
self.gr_fb.SetColLabelSize(20)
self.gr_fb.SetToolTipString('')
self.gr_fb.EnableEditing(False)
self.gr_fb.Bind(wx.grid.EVT_GRID_CELL_LEFT_DCLICK,
self.OnGr_fbGridCellLeftDclick)
self.bt_new = wx.Button(id=wxID_WXFRAME1BT_NEW, label='New faxbook',
name='bt_new', parent=self, pos=wx.Point(336, 48),
size=wx.Size(83, 23), style=0)
self.bt_new.SetToolTipString('')
self.bt_new.Bind(wx.EVT_BUTTON, self.OnBt_newButton,
id=wxID_WXFRAME1BT_NEW)
self.bt_del = wx.Button(id=wxID_WXFRAME1BT_DEL, label='Delete faxbook',
name='bt_del', parent=self, pos=wx.Point(336, 112),
size=wx.Size(83, 23), style=0)
self.bt_del.SetToolTipString('')
self.bt_del.Bind(wx.EVT_BUTTON, self.OnBt_delButton,
id=wxID_WXFRAME1BT_DEL)
self.bt_configure = wx.Button(id=wxID_WXFRAME1BT_CONFIGURE,
label='Configure', name='bt_configure', parent=self,
pos=wx.Point(336, 80), size=wx.Size(83, 23), style=0)
self.bt_configure.SetToolTipString('')
self.bt_configure.Bind(wx.EVT_BUTTON, self.OnBt_configureButton,
id=wxID_WXFRAME1BT_CONFIGURE)
self.bt_del_connection = wx.Button(id=wxID_WXFRAME1BT_DEL_CONNECTION,
label='Cancella con', name='bt_del_connection', parent=self,
pos=wx.Point(336, 176), size=wx.Size(83, 23), style=0)
self.bt_del_connection.Bind(wx.EVT_BUTTON,
self.OnBt_del_connectionButton,
id=wxID_WXFRAME1BT_DEL_CONNECTION)
def __init__(self, parent, db_inst, paths):
self._init_ctrls(parent)
self.parent = parent
self.paths = paths
self.db_inst = db_inst
#For i18n
ren = wx_util.rename_ctrls(self, 'configure_fb',
lang = self.paths.language, path=self.paths.my_path)
ren.rename()
self.gr_fb.CreateGrid(0,3)
self.gr_fb.SetColSize(0, 160)
self.gr_fb.SetColSize(1, 50)
self.gr_fb.SetColSize(2, 50)
ren.SetGridFieldNames('gr_fb')
#'Faxbook name', 'Order', 'Type'
self.my_init()
def my_init(self):
#self.parent.init_tree()
status, ret = self.db_inst.queryReturn(
'SELECT name, fb_order, fb_type FROM fb ORDER BY fb_order')
self._numPhoneBook = len(ret)
nr = self.gr_fb.GetNumberRows()
if nr: self.gr_fb.DeleteRows(0, nr)
for num, i in enumerate(ret):
self.gr_fb.AppendRows()
self.gr_fb.SetCellValue(num, 0, i[0])
self.gr_fb.SetCellValue(num, 1, str(i[1]))
self.gr_fb.SetCellValue(num, 2, i[2])
def OnBt_newButton(self, event):
wiz_fb.create(self, self.db_inst, self.paths).Show()
def OnBt_delButton(self, event):
sel = self.gr_fb.GetSelectedRows()
if not sel:
return
db_name = self.gr_fb.GetCellValue(sel[0], 0)
conf = read_conf.conf_parser(self.paths.file_db_fb_link, db_name)
conf.exist()
if not conf.exist():
try:
conf.remove_section()
except conf.NoSection:
pass
conf.exit()
status, type = self.db_inst.queryReturn('SELECT fb_type FROM fb WHERE name = "%s"' % (db_name))
type = type[0][0]
self.db_inst.queryNoReturn('DELETE FROM fb WHERE name = "%s"' % (db_name))
self.gr_fb.DeleteRows(sel[0])
self.parent.init_tree()
if type == 'local':
db_file = os.path.join(self.paths.conf_dir, 'local_' + db_name + '.db')
else:
db_file = os.path.join(self.paths.conf_dir, 'mysql_' + db_name + '.db')
if os.path.exists(db_file):
try:
os.remove(db_file)
except:
pass
def OnGr_fbGridCellLeftDclick(self, event):
self.OnBt_configureButton(event, event.GetRow())
#event.Skip()
def OnBt_configureButton(self, event, row=-1):
#Need for row control, when I'm called from cellDclick envent
if row == -1:
row = self.gr_fb.GetSelectedRows()
if len(row) == 0:
event.Skip()
return
row = row[0]
name = self.gr_fb.GetCellValue(row, 0)
order = self.gr_fb.GetCellValue(row, 1)
type = self.gr_fb.GetCellValue(row, 2)
wiz = wiz_fb.create(self, self.db_inst, self.paths)
if type == 'file':
#not able to modify the file phonebook
return
wiz.goToPage(type, name)
def OnBt_del_connectionButton(self, event):
self.parent.opt_cls.set('fax_col', '')
self.parent.opt_cls.set('comp_col', '')
#event.Skip()
def OnWxFrame1Close(self, event):
#Update if need
self.parent.init_tree()
event.Skip()
|