wx.Dialog子类实例化我的dbServer类

#Boa:Dialog:DBConnectDialog 
import wx 
import wxdbtools as db 
def create(parent):
    return DBConnectDialog(parent) 
[wxID_DBCONNECTDIALOG, wxID_DBCONNECTDIALOGCANCELBTN,
 wxID_DBCONNECTDIALOGCONNECTBTN, wxID_DBCONNECTDIALOGDATABASETEXTCTRL,
 wxID_DBCONNECTDIALOGPWDTEXTCTRL, wxID_DBCONNECTDIALOGSERVERNAMETEXTCTRL,
 wxID_DBCONNECTDIALOGSTATICTEXT1, wxID_DBCONNECTDIALOGSTATICTEXT2,
 wxID_DBCONNECTDIALOGSTATICTEXT3, wxID_DBCONNECTDIALOGSTATICTEXT4,
 wxID_DBCONNECTDIALOGSTATICTEXT5, wxID_DBCONNECTDIALOGSTATUSTEXTCTRL,
 wxID_DBCONNECTDIALOGUSERNAMETEXTCTRL,
] = [wx.NewId() for _init_ctrls in range(13)] 
class DBConnectDialog(wx.Dialog):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Dialog.__init__(self, id=wxID_DBCONNECTDIALOG,
              name='DBConnectDialog', parent=prnt, pos=wx.Point(503, 380),
              size=wx.Size(385, 344),
              style=wx.STAY_ON_TOP | wx.DIALOG_MODAL | wx.TAB_TRAVERSAL | wx.SUNKEN_BORDER | wx.DEFAULT_DIALOG_STYLE,
              title='Database Connection Dialog')
        self.SetClientSize(wx.Size(377, 317))
        self.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL, False,
              'MS Shell Dlg 2'))
        self.SetThemeEnabled(True) 
        self.staticText1 = wx.StaticText(id=wxID_DBCONNECTDIALOGSTATICTEXT1,
              label='User Name', name='staticText1', parent=self,
              pos=wx.Point(16, 8), size=wx.Size(63, 16), style=0)
        self.staticText1.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL,
              False, 'MS Shell Dlg 2')) 
        self.staticText2 = wx.StaticText(id=wxID_DBCONNECTDIALOGSTATICTEXT2,
              label='Password', name='staticText2', parent=self,
              pos=wx.Point(200, 8), size=wx.Size(55, 16), style=0) 
        self.usernameTextCtrl = wx.TextCtrl(id=wxID_DBCONNECTDIALOGUSERNAMETEXTCTRL,
              name='usernameTextCtrl', parent=self, pos=wx.Point(16, 24),
              size=wx.Size(160, 24), style=0, value='barton') 
        self.servernameTextCtrl = wx.TextCtrl(id=wxID_DBCONNECTDIALOGSERVERNAMETEXTCTRL,
              name='servernameTextCtrl', parent=self, pos=wx.Point(16, 80),
              size=wx.Size(160, 24), style=0, value='genesis') 
        self.staticText3 = wx.StaticText(id=wxID_DBCONNECTDIALOGSTATICTEXT3,
              label='Server Name or IP Address', name='staticText3',
              parent=self, pos=wx.Point(16, 64), size=wx.Size(156, 16),
              style=0) 
        self.staticText5 = wx.StaticText(id=wxID_DBCONNECTDIALOGSTATICTEXT5,
              label='Default Database', name='staticText5', parent=self,
              pos=wx.Point(200, 64), size=wx.Size(97, 16), style=0) 
        self.pwdTextCtrl = wx.TextCtrl(id=wxID_DBCONNECTDIALOGPWDTEXTCTRL,
              name='pwdTextCtrl', parent=self, pos=wx.Point(200, 24),
              size=wx.Size(160, 24), style=wx.TE_PASSWORD, value='1coolSQL') 
        self.databaseTextCtrl = wx.TextCtrl(id=wxID_DBCONNECTDIALOGDATABASETEXTCTRL,
              name='databaseTextCtrl', parent=self, pos=wx.Point(200, 80),
              size=wx.Size(160, 24), style=0, value='Trails') 
        self.staticText4 = wx.StaticText(id=wxID_DBCONNECTDIALOGSTATICTEXT4,
              label='Connection Status Log', name='staticText4', parent=self,
              pos=wx.Point(16, 120), size=wx.Size(127, 16), style=0) 
        self.ConnectBtn = wx.Button(id=wxID_DBCONNECTDIALOGCONNECTBTN,
              label='Connect', name='ConnectBtn', parent=self, pos=wx.Point(104,
              280), size=wx.Size(75, 26), style=0)
        self.ConnectBtn.Bind(wx.EVT_BUTTON, self.OnConnectButton,
              id=wxID_DBCONNECTDIALOGCONNECTBTN) 
        self.cancelBtn = wx.Button(id=wxID_DBCONNECTDIALOGCANCELBTN,
              label='Cancel', name='cancelBtn', parent=self, pos=wx.Point(200,
              280), size=wx.Size(75, 26), style=0)
        self.cancelBtn.Bind(wx.EVT_BUTTON, self.OnCancelButton,
              id=wxID_DBCONNECTDIALOGCANCELBTN) 
        self.statusTextCtrl = wx.TextCtrl(id=wxID_DBCONNECTDIALOGSTATUSTEXTCTRL,
              name='statusTextCtrl', parent=self, pos=wx.Point(16, 136),
              size=wx.Size(344, 136), style=wx.TE_READONLY | wx.TE_MULTILINE,
              value='')
        self.statusTextCtrl.SetFont(wx.Font(8, wx.SWISS, wx.NORMAL, wx.NORMAL,
              False, 'MS Shell Dlg 2')) 
    def __init__(self, parent):
        self._init_ctrls(parent) 
        self.dbServer = db.DBServer(self)
        self.dbConnect = self.DBConnect()   # Don't call this guy directly (don't keep?)
        if not self.dbConnect:
            self.Show() 
    def DBConnect(self):
        user = self.usernameTextCtrl.GetValue()
        password = self.pwdTextCtrl.GetValue()
        host = self.servernameTextCtrl.GetValue()
        dbConnect = self.dbServer.Login(host, user, password)
        database = self.databaseTextCtrl.GetValue()
        if database:
            self.dbServer.Execute("CREATE DATABASE IF NOT EXISTS %s" % database)
        self.dbServer.Execute("USE %s" % database)
        return dbConnect 
    def GetDBServer(self):
        return self.dbServer 
    def GetDefaultDatabase(self):
        return self.databaseTextCtrl.GetValue() 
    def write(self, message):
        self.statusTextCtrl.AppendText("%s\n" %message) 
    def OnConnectButton(self, event):
        if self.dbConnect:
            self.dbConnect.close()
        self.dbConnect = self.DBConnect()
        if self.dbConnect:
            self.write("Ready")  
    def OnCancelButton(self, event):
        self.Hide()

From: https://bytes.com/topic/python/insights/572415-wx-dialog-subclass-instantiates-my-dbserver-class

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值