def OnClose(self, evt): # Replace with event handler code # print self.Parent # print self.Parent.messageFrame[self.friend] del self.Parent.messageFrame[self.friend] self.Destroy() uiDebug("messageUi OnClose()")
def closeEvent(self,evt=None): '''关闭事件''' uiDebug("parent closeEvent") #pylint: disable=E1101 reactor.stop() self.app.exit() uiDebug("parent closeEvent end")
def createMessageFrame(self,QModelIndex): '''创建对话窗口''' friend= self.userModel.data(QModelIndex) if self.userModel.indexFromItem(self.itemFriend) == QModelIndex: return if friend == "": return if friend == "inline": return uiDebug(self.messageFrame) if self.messageFrame.has_key(friend): self.messageFrame[friend].show() else: try: frame = messageWin(self,self.user,friend) frame.setWindowTitle(friend) self.messageFrame[friend]=frame frame.show() #pylint: disable=W0702 except: pass uiDebug("mainPanelUi createMessageFrame()")
def closeEvent(self,evt): '''关闭事件''' friend=self.windowTitle() del self.parent().messageFrame[friend] evt.accept() uiDebug("messageWin closeEvent")
def fileOpen(self, lineEdit, filters): openFile = QFileDialog.getOpenFileName(self, "Find Files", QDir.currentPath(), filters="*." + filters) uiDebug(openFile) if openFile != None : lineEdit.setText(openFile[0]) self.setUserConfig() self.showConfig()
def createFriendList(self): '''创建主窗口的联系人列表''' if self.friends!=None: for friend in self.friends: uiDebug("* "+friend) if friend!="": self.mainPanel.addLinkMan(friend,"linked") uiDebug("createFriendList end")
def readConfig(self, _file): '''读取服务器端配置文件''' #pylint: disable=W0201 self.Config = serverConfig(_file) self.ControlMedia = self.Config.getControlMedia() self.ControlMediaPath = self.Config.getControlMediaPath() self.language = self.Config.getLanguage() self.userConfig() uiDebug("readConfig")
def onAccepted(self): """确定动作""" host = str(self.ui.server_lineEdit.text()) port = 8002 user = str(self.ui.user_lineEdit.text()) password = str(self.ui.password_lineEdit.text()) uiDebug("host: " + host + ",user: "******",password: "******"loginPanelUi onAccepted()")
def OnButton_okButton(self, evt): # Replace with event handler code host=str(self.serverComboBox.GetValue()) port=8002 user=str(self.userComboBox.GetValue()) password=str(self.passwordTextCtrl.GetLabel()) password=str(self.passwordTextCtrl.GetValue()) uiDebug("password:"******"password:"******"loginPanelUi OnButton_okButton()")
def addUsers(self, user, instance): '''添加一条登陆用户数据''' index = self.ui.loginUsers_tableView.selectionModel().currentIndex() model = self.ui.loginUsers_tableView.model() row = model.rowCount(index.parent()) model.setItem(row, 0, QStandardItem(user)) model.setItem(row, 1, QStandardItem(str(instance))) uiDebug("loginUser")
def loadConfig(self): '''加载配置文件''' configfile = QFileDialog.getOpenFileName(self, "Load Config File", QDir.currentPath(), filter="*.cfg") uiDebug(configfile) if configfile != None : self.readConfig(configfile) self.stopServer() self.startServer() self.showConfig() uiDebug("loadConfig")
def handelFailure(self, failure, port): uiDebug( "loginPanelUi handelFailure") uiDebug(failure.getErrorMessage()) try: message=unicode(failure.getErrorMessage(), self.textencoding) except: message="Something is Err!" dlg = wx.MessageDialog(None, message, "A Message Box", wx.YES_NO ) dlg.ShowModal()
def killUser(self): '''踢出一个用户''' try: index = self.ui.loginUsers_tableView.selectionModel().currentIndex() model = self.ui.loginUsers_tableView.model() user = model.item(index.row(), 0).index().data() self.connect.killUser(user) #pylint: disable=W0702 except: pass # model.removeRow(index.row(), index.parent()) uiDebug("killUser")
def about(self): '''about''' aboutInfo = '''<HTML> <p>xdIm ver 0.2.0</p> <p>xdIm program is a software program by xd.</p> <p>Copy Right : "(C) 2008-2010 Programmers and Coders Everywhere"</p> <p><a href="http://www.xdIm.org/">http://www.xdIm.org</a></p> </HTML>"''' tranAboutInfo = QApplication.translate("MainWindow", aboutInfo, None, QApplication.UnicodeUTF8) QMessageBox.information(self, "xdIm information", tranAboutInfo) uiDebug("about")
def choiceSql(self): uiDebug("choiceMysql") self.ui.text_groupBox.setChecked(False) self.ui.xml_groupBox.setChecked(False) if self.ui.sqlTypeComboBox.currentText() == mysql: self.ui.openSqlpushButton.setDisabled(True) self.ui.userLineEdit.setEnabled(True) self.ui.passwordlineEdit.setEnabled(True) if self.ui.sqlTypeComboBox.currentText() == sqlite: self.ui.openSqlpushButton.setEnabled(True) self.ui.userLineEdit.setDisabled(True) self.ui.passwordlineEdit.setDisabled(True)
def refreshReceMessage(self,src,dst,message): '''收到服务器的消息时,更新消息接收文本框''' if self.mainPanel.messageFrame.has_key(src): pass else: #如果没有窗口,重新创建窗口 self.mainPanel.createTempMessageFrame(self.user,src) try: self.mainPanel.messageFrame[src].receMessage(message) #pylint: disable=W0702 except: uiDebug("im refreshReceMessage error " + src +" " +dst)
def stopServer(self): ''' #停止服务''' if self.connect != None: self.ui.startServer_pushButton.setEnabled(True) self.ui.stopServer_pushButton.setEnabled(False) self.ui.mysql_groupBox.setDisabled(False) self.ui.text_groupBox.setDisabled(False) self.ui.xml_groupBox.setDisabled(False) #pylint: disable=E1101 reactor.disconnectAll() # self.clearUserInfo() self.statusBar().showMessage("server is stopped!") uiDebug("stopServer")
def userInfoAddRow(self): '''添加一条用户数据''' # self.userModel.appendRow(QStandardItem("")) index = self.ui.userInfo_tableView.selectionModel().currentIndex() model = self.ui.userInfo_tableView.model() if not model.insertRow(index.row() + 1, index.parent()): return for column in range(model.columnCount(index.parent())): child = model.index(index.row() + 1, column, index.parent()) model.setData(child, "[No data]", Qt.EditRole) uiDebug("userInfoAddRow")
def setUserConfig(self): '''保留用户配置''' if self.ui.xml_groupBox.isChecked() == True: if self.ui.xml_lineEdit.text() != "": self.ControlMedia = xml self.ControlMediaPath = self.ui.xml_lineEdit.text() uiDebug("setUserConfig xml: " + xml) if self.ui.text_groupBox.isChecked() == True: if self.ui.text_lineEdit.text() != "": self.ControlMedia = txt self.ControlMediaPath = self.ui.text_lineEdit.text() uiDebug("setUserConfig txt: " + txt) if self.ui.mysql_groupBox.isChecked() == True: if self.ui.sqlTypeComboBox.currentText() == mysql: self.ControlMedia = mysql uiDebug("setUserConfig mysql: " + mysql) if self.ui.sqlTypeComboBox.currentText() == sqlite: self.ControlMedia = sqlite uiDebug("setUserConfig sqlite: " + sqlite) self.ControlMediaPath = self.ui.ServerLineEdit.text() self.Config.setContrlMedia(self.ControlMedia) self.Config.setControlMediaPath(self.ControlMediaPath) self.userConfig()
def removeUser(self, user): '''删除一条登陆用户数据''' index = self.ui.loginUsers_tableView.selectionModel().currentIndex() model = self.ui.loginUsers_tableView.model() maxRow = model.rowCount(index.parent()) # print user for row in range(maxRow): # print row # print model.item(row, 0).index().data() # print type(model.item(row, 0).index().data()) if user == model.item(row, 0).index().data(): model.removeRow(row, index.parent()) uiDebug("logoutUser")
def createTempMessageFrame(self,user,friend): uiDebug(self.messageFrame) if self.messageFrame.has_key(friend): self.messageFrame[friend].show() else: try: frame = messageWin(self,user,friend) frame.setWindowTitle(friend) self.messageFrame[friend]=frame frame.show() #pylint: disable=W0702 except: pass uiDebug("mainPanelUi createMessageFrame()")
def userInfoDelRow(self): '''删除数据,且保留此次删除的数据''' model = self.ui.userInfo_tableView.model() index = self.ui.userInfo_tableView.selectionModel().currentIndex() user = model.item(index.row(), 0).index().data() friendlist = model.item(index.row(), 1).index().data() self.delUsrInfo = [index.row(), user, friendlist] # print self.delUsrInfo try: model.removeRow(index.row(), index.parent()) self.users.deleteUser(user) self.users.userDataSave() #pylint: disable=W0702 except: pass uiDebug("userInfoDelRow")
def OnTool_sendTool(self, evt): # Replace with event handler code msg=self.sendMessageText.GetValue() if msg=="": return if self.friend != self.user : # data=u"mesS desS %s desE souS %s souE conS %s conE mesE\r\n"%(self.friend,self.user,msg) # self.Parent.Parent.connecting.protocolInstance.dataSend(data) # data=u"mesS desS %s desE souS %s souE conS %s conE mesE\r\n"%(self.friend,self.user,msg) self.Parent.Parent.connecting.protocolInstance.messageSend(self.friend,self.user,msg) self.sendMessageText.Clear() self.receMessageText.AppendText("\n"+"you said: "+msg) else: self.receMessageText.AppendText("\n"+"you said: "+msg) self.sendMessageText.Clear() pass uiDebug("messageUi OnTool_sendTool()")
def startServer(self): '''#启动服务''' self.ui.startServer_pushButton.setEnabled(False) self.ui.stopServer_pushButton.setEnabled(True) self.connect = server_twisted.serverMain(8002, self.users) self.saveConfig() # self.readConfig(configFile) self.userConfig() self.ui.mysql_groupBox.setDisabled(True) self.ui.text_groupBox.setDisabled(True) self.ui.xml_groupBox.setDisabled(True) self.statusBar().showMessage("server is starting!") if self.users != None: self.clearUserInfo() self.showUserinfo() uiDebug("startServer")
def userInfoUndoDelRow(self): '''恢复前次删除的数据''' if self.delUsrInfo != None: model = self.ui.userInfo_tableView.model() if not model.insertRow(self.delUsrInfo[0]): return user = self.delUsrInfo[1] friendlist = self.delUsrInfo[2] self.userModel.setItem(self.delUsrInfo[0], 0, QStandardItem(user)) self.userModel.setItem(self.delUsrInfo[0], 1, QStandardItem(friendlist)) if user != "[No data]": self.users.addUser(user, "admin") if friendlist != "[No data]": for friend in friendlist.split(","): self.users.addUserFriend(user, friend) self.users.userDataSave() self.delUsrInfo = None uiDebug("userInfoUndoDelRow")
def userInfoSaveData(self): '''保留用户数据''' if self.users: model = self.ui.userInfo_tableView.model() index = self.ui.userInfo_tableView.selectionModel().currentIndex() for row in range(model.rowCount(index.parent())): user = model.item(row, 0).index().data() friendlist = model.item(row, 1).index().data() if user != "[No data]": self.users.addUser(user, "admin") if friendlist != "[No data]": for friend in friendlist.split(","): if friend != '': self.users.addUserFriend(user, friend) self.users.userDataSave() self.clearUserInfo() self.showUserinfo() uiDebug("userInfoSaveData")
def updatePanel(self): '''登录服务器成功后,更新用户界面,由客户端协议调用''' uiDebug("updatePanel start") uiDebug(self.friends) self.login.hide() self.show() self.login.destroy() del self.login self.createFriendList() uiDebug("updatePanel end")
def connectServer(self,host,port,user,password): '''连接服务器,由login界面登录时调用''' self.user=user client_twisted.frame = self self.connecting=client_twisted.clientMain(host,port,user,password) uiDebug( "connectServer")
def setUserFriends(self,friends): '''设置用户Friends 由客户端协议调用''' uiDebug("im setUserFriends start") self.friends=friends uiDebug("im setUserFriends end")
def saveConfig(self): '''保留配置文件''' self.setUserConfig() self.Config.saveServerConfig() uiDebug("saveConfig")