wxPython 客户端登录流程的拟定

登录函数的初步实现:

def Login(self, event):
    if (self.datacenter._netstat == 0):
        lib.MyDialog(u"网路状态",u"网路异常,请检查网络...")
    else:
        lib.udpFindCcu(self.datacenter, self.devdb.getFindCcu())
        if (bool(self.datacenter.ccuArray)):
            self.login_zk_id = self.TextCtrl_login_zkid.GetValue()
            if (self.datacenter.ccuArray.has_key(self.login_zk_id)):
                lib.MyDialog(u"登录方式",u"已经搜索到对应主机开始本地登录")
            else:
                lib.MyDialog(u"登录方式",u"未搜索到对应主机开始远程登录")
        else:
            lib.MyDialog(u"登录方式",u"未搜索到主机直接远程登录")


登录函数的具体实现:

    def Login(self, event):
        if self.cpu["Handler"]._login:
            return -1
        self.datacenter = self.cpu["Handler"]
        self.devdb = self.cpu["DB"]

        self.login_zk_id = self.cpu["Button"]["TextCtrl_login_zkid"].GetValue()              #中控编号
        self.login_usr = self.cpu["Button"]["TextCtrl_login_user"].GetValue()                #用户账号
        self.cpu["Handler"]._login_account = str(self.login_usr)
        self.login_pwd = self.cpu["Button"]["TextCtrl_login_pwd"].GetValue()                 #用户密码
        if (self.datacenter._netstat == 0):
            log.info(u"网路异常,开始本地发现"+self.login_zk_id)
            lib.udpFindCcu(self.cpu)
            self.login_zk_id = self.cpu["Button"]["TextCtrl_login_zkid"].GetValue()
            if (bool(self.datacenter.ccuArray)):
                if (self.datacenter.ccuArray.has_key(self.login_zk_id)):
                    log.info(u"搜索到对应主机,开始本地登录")
                    for key in self.datacenter.ccuArray:
                        if (self.login_zk_id == key):
                            self.tcpClient = lib.TCPClient(self.cpu)
                            try:
                                self.tcpClient.connect(self.datacenter.ccuArray[key], self.datacenter.tcpServerPort)
                            except socket.error, e:
                                log.info(self.datacenter.ccuArray[key])
                                log.info(str(self.datacenter.tcpServerPort))
                                log.error("LoginMethodsRemote() occur error!\nFailed to connect to server @ip: "+self.datacenter.ccuArray[key]["ip"]+" | port: "+str(self.datacenter.tcpServerPort)+"\nThe error is"+str(e))
                                self.cpu["Button"]["loginBtn"].SetToggle(False)
                            else:
                                self.cpu["tcpClient"] = self.tcpClient
                                self.socket_recv = threading.Thread(target=self.tcpClient.recv, args=())
                                self.socket_recv.start()
                                self.tcpClient.send(lib.objLogin(self.cpu, self.login_zk_id, self.login_usr, self.login_pwd, 0))
                                self.tcpClient.loginDataSave(key, self.datacenter.ccuArray[key], self.datacenter.tcpServerPort)
                                break
            else:
                lib.MyDialog(u"网路状态",u"网路异常,请检查网络...")
        else:
            lib.udpFindCcu(self.cpu)
            self.login_zk_id = self.cpu["Button"]["TextCtrl_login_zkid"].GetValue()
            log.info(u"登录的中控编号"+self.login_zk_id)
            log.info(u"搜索中控列表"+str(self.datacenter.ccuArray))
            if (bool(self.datacenter.ccuArray)):
                if (self.datacenter.ccuArray.has_key(self.login_zk_id)):
                    log.info(u"搜索到对应主机,开始本地登录")
                    for key in self.datacenter.ccuArray:
                        if (self.login_zk_id == key):
                            self.tcpClient = lib.TCPClient(self.cpu)
                            try:
                                self.tcpClient.connect(self.datacenter.ccuArray[key], self.datacenter.tcpServerPort)
                            except socket.error, e:
                                log.info(self.datacenter.ccuArray[key])
                                log.info(str(self.datacenter.tcpServerPort))
                                log.error("LoginMethodsRemote() occur error!\nFailed to connect to server @ip: "+str(self.datacenter.ccuArray[key]["ip"])+" | port: "+str(self.datacenter.tcpServerPort)+"\nThe error is"+str(e))
                                self.cpu["Button"]["loginBtn"].SetToggle(False)
                            else:
                                self.cpu["tcpClient"] = self.tcpClient
                                self.socket_recv = threading.Thread(target=self.tcpClient.recv, args=())
                                self.socket_recv.start()
                                self.tcpClient.send(lib.objLogin(self.cpu, self.login_zk_id, self.login_usr, self.login_pwd, 0))
                                self.tcpClient.loginDataSave(key, self.datacenter.ccuArray[key], self.datacenter.tcpServerPort)
                                break
                else:
                    log.info(u"未搜索到对应主机,开始远程登录")
                    self.tcpClient = lib.TCPClient(self.cpu)
                    try:
                        self.tcpClient.connect(self.datacenter.tcpCloudIP, self.datacenter.tcpCloudPort)
                    except socket.error, e:
                        log.error("LoginMethodsRemote() occur error!\nFailed to connect to server @ip: "+self.datacenter.tcpCloudIP+" | port: "+self.datacenter.tcpCloudPort+"\nThe error is"+str(e))
                        self.cpu["Button"]["loginBtn"].SetToggle(False)
                    else:
                        self.cpu["tcpClient"] = self.tcpClient
                        self.socket_recv = threading.Thread(target=self.tcpClient.recv, args=())
                        self.socket_recv.start()
                        self.tcpClient.send(lib.objLogin(self.cpu, self.login_zk_id, self.login_usr, self.login_pwd, 0))
                        self.tcpClient.loginDataSave(self.login_zk_id, self.datacenter.tcpCloudIP, self.datacenter.tcpCloudPort)
            else:
                log.info(u"未搜索到主机,直接远程登录")
                self.tcpClient = lib.TCPClient(self.cpu)
                try:
                    self.tcpClient.connect(self.datacenter.tcpCloudIP, self.datacenter.tcpCloudPort)
                except socket.error, e:
                    log.error("LoginMethodsRemote() occur error!\nFailed to connect to server @ip: "+self.datacenter.tcpCloudIP+" | port: "+self.datacenter.tcpCloudPort+"\nThe error is"+str(e))
                    self.cpu["Button"]["loginBtn"].SetToggle(False)
                else:
                    self.cpu["tcpClient"] = self.tcpClient
                    self.socket_recv = threading.Thread(target=self.tcpClient.recv, args=())
                    self.socket_recv.start()
                    self.tcpClient.send(lib.objLogin(self.cpu, self.login_zk_id, self.login_usr, self.login_pwd, 0))
                    self.tcpClient.loginDataSave(self.login_zk_id, self.datacenter.tcpCloudIP, self.datacenter.tcpCloudPort)

您可以使用wxPython创建登录页面。以下是一个简单的示例代码: ```python import wx class LoginFrame(wx.Frame): def __init__(self): super().__init__(None, title='登录界面', size=(300, 200)) self.panel = wx.Panel(self) # 创建用户名和密码输入框 self.username_label = wx.StaticText(self.panel, label='用户名:') self.username_text = wx.TextCtrl(self.panel) self.password_label = wx.StaticText(self.panel, label='密码:') self.password_text = wx.TextCtrl(self.panel, style=wx.TE_PASSWORD) # 创建登录按钮 self.login_button = wx.Button(self.panel, label='登录') # 设置布局 sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(self.username_label, flag=wx.ALL, border=5) sizer.Add(self.username_text, flag=wx.EXPAND|wx.ALL, border=5) sizer.Add(self.password_label, flag=wx.ALL, border=5) sizer.Add(self.password_text, flag=wx.EXPAND|wx.ALL, border=5) sizer.Add(self.login_button, flag=wx.ALL, border=5) self.panel.SetSizer(sizer) # 绑定按钮事件 self.login_button.Bind(wx.EVT_BUTTON, self.on_login) def on_login(self, event): username = self.username_text.GetValue() password = self.password_text.GetValue() # 进行登录验证逻辑 if username == 'admin' and password == '123456': wx.MessageBox('登录成功!', '提示', wx.OK | wx.ICON_INFORMATION) self.Close() else: wx.MessageBox('用户名或密码错误!', '错误', wx.OK | wx.ICON_ERROR) app = wx.App() frame = LoginFrame() frame.Show() app.MainLoop() ``` 上述代码使用wxPython创建了一个简单的登录界面,包含用户名和密码输入框以及一个登录按钮。当用户点击登录按钮时,会进行简单的用户名和密码验证逻辑,如果验证通过,则显示登录成功提示框,否则显示错误提示框。 您可以根据需要修改界面和验证逻辑。希望对您有帮助!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值