#!/usr/bin/env python
# -*- coding: cp1251 -*-
# generated by wxGlade 0.4.1 on Mon Feb 19 12:39:23 2007
from wxPython.wx import *
from wxPython.grid import *
import mysql_py
import wx.grid
mydb = mysql_py.mydb()
class MyFrame(wxFrame):
def __init__(self, *args, **kwds):
# begin wxGlade: MyFrame.__init__
kwds["style"] = wxDEFAULT_FRAME_STYLE
wxFrame.__init__(self, *args, **kwds)
self.window_1 = wxSplitterWindow(self, -1, style=wxSP_3D|wxSP_BORDER)
self.window_1_pane_2 = wxScrolledWindow(self.window_1, -1, style=wxTAB_TRAVERSAL)
self.window_1_pane_1 = wxPanel(self.window_1, -1)
self.label_1 = wx.StaticText(self.window_1_pane_1, -1, _("Выберите тип клиентов:"), style=wx.ALIGN_CENTRE)
self.choice_2 = wx.Choice(self.window_1_pane_1, -1, choices=[_("Юр.лица"), _("Физ.лица"), _("Предприниматели")])
self.button_1 = wx.Button(self.window_1_pane_1, -1, _("Показать!"))
self.grid_1 = wxGrid(self.window_1_pane_2, -1, size=(1, 1))
self.__set_properties()
self.__do_layout()
EVT_BUTTON(self, self.button_1.GetId(), self.on_show)
# end wxGlade
def __set_properties(self):
# begin wxGlade: MyFrame.__set_properties
self.SetTitle(_("Клиентская база - Центр 1.0"))
_icon = wxEmptyIcon()
_icon.CopyFromBitmap(wxBitmap("C:\\Python24\\py.ico", wxBITMAP_TYPE_ANY))
self.SetIcon(_icon)
self.SetSize((800, 600))
self.label_1.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
self.choice_2.SetSelection(-1)
self.button_1.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
self.window_1_pane_1.SetMinSize((40, 216))
self.grid_1.CreateGrid(100, 40)
self.grid_1.SetRowLabelSize(40)
self.grid_1.SetMinSize((560,100))
self.window_1_pane_2.SetMinSize((560, 216))
self.window_1_pane_2.SetScrollRate(10, 10)
self.window_1.SetMinSize((600, 216))
# end wxGlade
def __do_layout(self):
# begin wxGlade: MyFrame.__do_layout
sizer_1 = wxBoxSizer(wxVERTICAL)
self.sizer_4 = wxBoxSizer(wxVERTICAL)
self.sizer_5 = wxBoxSizer(wxHORIZONTAL)
sizer_2 = wxBoxSizer(wxVERTICAL)
sizer_2.Add(self.label_1, 0, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
sizer_2.Add(self.choice_2, 0, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
sizer_2.Add(self.button_1, 0, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
self.window_1_pane_1.SetAutoLayout(True)
self.window_1_pane_1.SetSizer(sizer_2)
self.sizer_4.Add(self.grid_1, 1, wxEXPAND, 0)
self.sizer_4.Add(self.sizer_5, 0, wxEXPAND, 0)
self.window_1_pane_2.SetAutoLayout(True)
self.window_1_pane_2.SetSizer(self.sizer_4)
self.window_1.SplitVertically(self.window_1_pane_1, self.window_1_pane_2)
sizer_1.Add(self.window_1, 1, wxALL|wxEXPAND, 0)
self.SetAutoLayout(True)
self.SetSizer(sizer_1)
self.Layout()
self.Centre()
# end wxGlade
def on_show(self, event): # wxGlade: MyFrame.<event_handler>
if self.choice_2.GetCurrentSelection() == 1:
d="fiz"
elif self.choice_2.GetCurrentSelection() == 0:
d="ur"
else:
d="predpr"
curs = mydb.Connect('db','localhost','root','pass')
curs.execute("set character set cp1251")
curs.execute("SELECT * FROM "+d+";")
data = curs.fetchall()
fields = curs.description
curs.execute("set character set utf8")
if len(data) > self.grid_1.GetNumberRows():
for i in range(len(data)-self.grid_1.GetNumberRows()):
self.grid_1.AppendRows()
else:
for i in range(self.grid_1.GetNumberRows()-len(data)):
self.grid_1.DeleteRows()
if len(fields) > self.grid_1.GetNumberCols():
for i in range(len(fields)-self.grid_1.GetNumberCols()):
self.grid_1.AppendCols()
else:
for i in range(self.grid_1.GetNumberCols()-len(fields)):
self.grid_1.DeleteCols()
index = 0
for item in fields:
self.grid_1.SetColLabelValue(index, item[0])
index += 1
for row in range(len(data)):
for col in range(len(data[row])):
values = data[row][col]
self.grid_1.SetCellValue(row,col,str(values))
self.Update()
event.Skip()
# end of class MyFrame
class MyApp(wxApp):
def OnInit(self):
wxInitAllImageHandlers()
frame_1 = MyFrame(None, -1, "")
self.SetTopWindow(frame_1)
frame_1.Show()
return 1
# end of class MyApp
if __name__ == "__main__":
import gettext
gettext.install("app") # replace with the appropriate catalog name
app = MyApp(0)
app.MainLoop()