wiz_file.py :  » Business-Application » hylaPEx » hylapex » library » wizard » 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 » wizard » wiz_file.py
# -*- coding: utf-8 -*-

from traceback import format_exc
import wx

from library import i18n
_ = i18n.i18n()

import db_lib

class pnl(wx.Panel):
    """
    """
    def __init__(self, parent, paths, db_inst, modify):
        """
        """
        super(pnl, self).__init__(parent)

        self.parent = parent
        self.db_inst = db_inst
        self.paths = paths
        self.modify, self.name = modify
        
        self._txt_fb_name = wx.TextCtrl(self)
        self._txt_path = wx.TextCtrl(self, size=(200, -1))
        bt_search = wx.Button(self, label=_("bt_search"))
        
        self._ch_table_list = wx.Choice(self)
        
        bt_save = wx.Button(self, label=_("bt_save"))
        
        sz_all = wx.FlexGridSizer(0, 3, 5, 5)
        
        flags = wx.ALIGN_CENTER | wx.ALL
        
        sz_all.Add(wx.StaticText(self, label=_("lbl_wizard_file_fb_name")), 0, flags, 10)
        sz_all.Add(self._txt_fb_name, 0, flags | wx.EXPAND, 10)
        sz_all.Add((0,0))
        
        sz_all.Add(wx.StaticText(self, label=_("lbl_wizard_file_path")), 0, flags, 10)
        sz_all.Add(self._txt_path, 0, flags, 10)
        sz_all.Add(bt_search, 0, flags, 10)
        
        sz_all.Add(wx.StaticText(self, label=_("lbl_wizard_file_tables")), 0, flags, 10)
        sz_all.Add(self._ch_table_list, 0, flags | wx.EXPAND, 10)
        sz_all.Add((0,0))
        
        sz_all.Add((0,0))
        sz_all.Add(bt_save, 0, flags)
        sz_all.Add((0,0))
        
        #event bind
        bt_search.Bind(wx.EVT_BUTTON, self.OnButtonSearch)
        bt_save.Bind(wx.EVT_BUTTON, self.OnButtonSave)
        
        self.SetSizerAndFit(sz_all)
        
    def OnButtonSearch(self, evt):
        """
        """
        dlg = wx.FileDialog(self)
        if dlg.ShowModal() == wx.ID_OK:
            file_path = dlg.GetPath()
        else:
            file_path = None
        
        if not file_path:
            return
        
        self._txt_path.SetValue(file_path)
        
        try:
            self.paths.log4write.write("Try to open %s" % file_path)
            self._db = db_lib.Sqlite(file_path)
            table_list = self._db.conn()
        except:
            err = format_exc()
            self.paths.log4write.write("Error on open db:, %s" % err)
            wx.MessageBox(err, _("error"), wx.ICON_ERROR)
            return
        
        self._ch_table_list.Clear()
        
        if table_list:
            self._ch_table_list.AppendItems(table_list)
    
    def OnButtonSave(self, evt):
        """
        """
        fb_name = self._txt_fb_name.GetValue().strip()
        db_path = self._txt_path.GetValue().strip()
        table_name = self._ch_table_list.GetStringSelection()
        
        if not (fb_name and table_name and db_path):
            return
        
        fb_other = "%s," % db_path
        
        ret, cols = self._db.get_cols(table_name)
        if ret:
            return
        
        #delete id if found
        cols = [x for x in cols if not x == "id"]
            
        status, ret = self.db_inst.queryReturn('SELECT name FROM fb WHERE name = ?',  (fb_name, ))

        if ret:
            wx.MessageBox(_("_db_exist"), _("error", 1), wx.ICON_ERROR)
            self.paths.log4write.write("db exists, %s" % fb_name)
            self.paths.log4write.write("db exists query: %s, %s" % (status, ret))
            return

        status, ret_order = self.db_inst.queryReturn('SELECT fb_order FROM fb ORDER BY fb_order')
        if status:
            self.err_generic(ret)
            return
        if ret_order:
            last_number = ret_order[len(ret_order) -1][0]
        else:
            last_number = 0
        
        self.db_inst.queryReturn('INSERT INTO fb (name, fb_type, fb_order, fb_fields, fb_db_name, fb_other) VALUES \
                ("%s", "file", %s, "%s", "%s", "%s")' %\
                (fb_name, last_number +1 , ','.join(cols), table_name, fb_other)
                )
        
        self.parent.update_parent(fb_name)

        
    
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.