class LoginDialog(wx.Dialog):
def __init__(self, parent=None, compulsory_login_flag=True):
super(LoginDialog, self).__init__(parent, -1, title='登录SQLserver',
style=wx.DEFAULT_DIALOG_STYLE)
self._compulsory_login_flag = compulsory_login_flag
def InitUI(self, default_host, default_user, default_db, default_port):
self.SetSize((250, 300))
# 操作组件
self.input_host = wx.TextCtrl(self, value=str(default_host))
self.input_name = wx.TextCtrl(self, value=str(default_user))
self.input_pass = wx.TextCtrl(self, style=wx.TE_PASSWORD)
self.input_db = wx.TextCtrl(self, value=str(default_db))
self.input_port = wx.TextCtrl(self, value=str(default_port))
self.btn_1a = wx.Button(self, label='登录', size=(7, 35), id=wx.ID_OK)
# 装饰组件
label_host = wx.StaticText(self, label='服务器:')
label_name = wx.StaticText(self, label='用户名:')
label_pass = wx.StaticText(self, label='密码')
label_db = wx.StaticText(self, label='初始数据库:')
label_port = wx.StaticText(self, label='端口')
# panel_black = wx.Panel(self, size=(7, 15))
# panel_black.SetBackgroundColour(wx.Colour('#474747'))
# panel_red = wx.Panel(self, size=(7, 30))
# panel_red.SetBackgroundColour(wx.Colour('#bf0006'))
# 布局组件
fgs_2 = wx.FlexGridSizer(rows=5, cols=2, vgap=8, hgap=10)
fgs_2.AddMany([
(label_host, 1, wx.LEFT, 5), (self.input_host, 1, wx.EXPAND),
(label_port, 1, wx.LEFT, 5), (self.input_port, 1, wx.EXPAND),
(label_name, 1, wx.LEFT, 5), (self.input_name, 1, wx.EXPAND),
(label_pass, 1, wx.LEFT, 5), (self.input_pass, 1, wx.EXPAND),
(label_db, 1, wx.LEFT, 5), (self.input_db, 1, wx.EXPAND),
])
fgs_2.AddGrowableCol(1)
fgs_1 = wx.FlexGridSizer(rows=2, cols=1, vgap=0, hgap=0)
fgs_1.AddMany([
(fgs_2, 1, wx.EXPAND | wx.TOP | wx.CENTER | wx.RIGHT | wx.LEFT, 15),
(self.btn_1a, 1, wx.EXPAND | wx.ALL, 15),
])
fgs_1.AddGrowableCol(0)
fgs_1.AddGrowableRow(0, 2)
fgs_1.AddGrowableRow(1, 2)
# fgs_1.AddGrowableRow(3, 1)
# 窗口组件
self.SetSizer(fgs_1)
self.Center()
self.Bind(wx.EVT_CLOSE, self._justExit)
self.Bind(wx.EVT_BUTTON, self._handle_before_close_dialog, id=wx.ID_OK)
def _handle_before_close_dialog(self, e):
if self._compulsory_login_flag:
wx.Exit()
else:
self.loginInfo = {
'userName': self.input_name.GetValue(),
'serverName': self.input_host.GetValue(),
'dbName': self.input_db.GetValue(),
'port': self.input_port.GetValue(),
'passWord': self.input_pass.GetValue()
}
self.Destroy()
def _justExit(self, event):
self.loginInfo = False
self.Destroy()