configure_fb.py :  » Business-Application » hylaPEx » hylapex » 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 » configure_fb.py
#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()
        
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.