Wed, 03 Oct 2018 19:22:07 +0200
E5TextInputDialog: added a text input dialog using the clearable line edit.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/E5Gui/E5TextInputDialog.py Wed Oct 03 19:22:07 2018 +0200 @@ -0,0 +1,133 @@ +# -*- coding: utf-8 -*- + +# Copyright (c) 2018 Detlev Offenbach <detlev@die-offenbachs.de> +# + +""" +Module implementing a dialog to enter some text. +""" + +from __future__ import unicode_literals + +from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QVBoxLayout, QLabel, \ + QLineEdit + +from E5Gui.E5LineEdit import E5ClearableLineEdit + + +class E5TextInputDialog(QDialog): + """ + Class implementing a dialog to enter some text. + """ + def __init__(self, parent=None): + """ + Constructor + + @param parent reference to the parent widget + @type QWidget + """ + super(E5TextInputDialog, self).__init__(parent) + + self.setMaximumWidth(600) + + self.__layout = QVBoxLayout(self) + + self.__label = QLabel(self) + self.__label.setWordWrap(True) + self.__layout.addWidget(self.__label) + + self.__lineEdit = E5ClearableLineEdit(self) + self.__layout.addWidget(self.__lineEdit) + + self.__buttonBox = QDialogButtonBox( + QDialogButtonBox.Ok | QDialogButtonBox.Cancel, self) + self.__layout.addWidget(self.__buttonBox) + + self.__buttonBox.accepted.connect(self.accept) + self.__buttonBox.rejected.connect(self.reject) + + msh = self.minimumSizeHint() + self.resize(max(self.width(), msh.width()), msh.height()) + + def setTextEchoMode(self, echoMode): + """ + Public method to set the echo mode of the line edit. + + @param echoMode echo mode of the line edit + @type QLineEdit.EchoMode + """ + self.__lineEdit.setEchoMode(echoMode) + + def textEchoMode(self): + """ + Public method to get the current echo mode of the line edit. + + @return echo mode of the line edit + @rtype QLineEdit.EchoMode + """ + return self.__lineEdit.echoMode() + + def setTextValue(self, text): + """ + Public method to set the text of the line edit. + + @param text text for the line edit + @type str + """ + self.__lineEdit.setText(text) + + def textValue(self): + """ + Public method to get the text of the line edit. + + @return text of the line edit + @rtype str + """ + return self.__lineEdit.text() + + def setLabelText(self, text): + """ + Public method to set the label text. + + @param text label text + @type str + """ + self.__label.setText(text) + + def labelText(self): + """ + Public method to get the current label text. + + @return current label text + @rtype str + """ + return self.label.text() + + +def getText(parent, title, label, mode=QLineEdit.Normal, text=""): + """ + Function to get create a dialog to enter some text and return it. + + @param parent reference to the parent widget + @type QWidget + @param title title of the dialog + @type str + @param label label of the dialog + @type str + @param mode echo mode of the line edit + @type QLineEdit.EchoMode + @param text initial text of the line edit + @type str + @return tuple containing a flag indicating the dialog was accepted and the + entered text + @rtype tuple of (bool, str) + """ + dlg = E5TextInputDialog(parent) + dlg.setWindowTitle(title) + dlg.setLabelText(label) + dlg.setTextEchoMode(mode) + dlg.setTextValue(text) + if dlg.exec_() == QDialog.Accepted: + return True, dlg.textValue() + else: + return False, ""
--- a/Network/IRC/IrcChannelWidget.py Wed Oct 03 18:22:26 2018 +0200 +++ b/Network/IRC/IrcChannelWidget.py Wed Oct 03 19:22:07 2018 +0200 @@ -397,123 +397,133 @@ """ msg = self.messageEdit.text() if msg: - self.messages.append( - '<font color="{0}">{2} <b><</b><font color="{1}">{3}</font>' - '<b>></b> {4}</font>'.format( - Preferences.getIrc("ChannelMessageColour"), - Preferences.getIrc("OwnNickColour"), - ircTimestamp(), self.__userName, - Utilities.html_encode(msg))) - - if msg.startswith("/"): - if self.__private: - E5MessageBox.information( - self, - self.tr("Send Message"), - self.tr( - """Messages starting with a '/' are not allowed""" - """ in private chats.""")) - else: - sendData = True - # flag set to False, if command was handled - - msgList = msg.split() - cmd = msgList[0][1:].upper() - if cmd in ["MSG", "QUERY"]: - cmd = "PRIVMSG" - if len(msgList) > 1: - if msgList[1].strip().lower() in \ - self.__serviceNamesLower: - msg = "PRIVMSG " + \ - msgList[1].strip().lower() + \ - " :" + " ".join(msgList[2:]) - else: - msg = "PRIVMSG {0} :{1}".format( - msgList[1], " ".join(msgList[2:])) + self.__processUserMessage(msg) + + def __processUserMessage(self, msg): + """ + Private method to process a message entered by the user or via the + user list context menu. + + @param msg message to be processed + @type str + """ + self.messages.append( + '<font color="{0}">{2} <b><</b><font color="{1}">{3}</font>' + '<b>></b> {4}</font>'.format( + Preferences.getIrc("ChannelMessageColour"), + Preferences.getIrc("OwnNickColour"), + ircTimestamp(), self.__userName, + Utilities.html_encode(msg))) + + if msg.startswith("/"): + if self.__private: + E5MessageBox.information( + self, + self.tr("Send Message"), + self.tr( + """Messages starting with a '/' are not allowed""" + """ in private chats.""")) + else: + sendData = True + # flag set to False, if command was handled + + msgList = msg.split() + cmd = msgList[0][1:].upper() + if cmd in ["MSG", "QUERY"]: + cmd = "PRIVMSG" + if len(msgList) > 1: + if msgList[1].strip().lower() in \ + self.__serviceNamesLower: + msg = "PRIVMSG " + \ + msgList[1].strip().lower() + \ + " :" + " ".join(msgList[2:]) else: - msgList[0] = cmd - msg = " ".join(msgList) - elif cmd == "NOTICE": - if len(msgList) > 2: - msg = "NOTICE {0} :{1}".format( + msg = "PRIVMSG {0} :{1}".format( msgList[1], " ".join(msgList[2:])) - else: - msg = "NOTICE {0}".format(" ".join(msgList[1:])) - elif cmd == "PING": - receiver = msgList[1] - msg = "PING {0} " - self.sendCtcpRequest.emit(receiver, "PING", "") - sendData = False - elif cmd == "IGNORE": - sendData = False - if len(msgList) > 1: - if msgList[1] == "-r": - ignored = False - userNamesList = msgList[2:] - else: - ignored = True - userNamesList = msgList[1:] + else: + msgList[0] = cmd + msg = " ".join(msgList) + elif cmd == "NOTICE": + if len(msgList) > 2: + msg = "NOTICE {0} :{1}".format( + msgList[1], " ".join(msgList[2:])) + else: + msg = "NOTICE {0}".format(" ".join(msgList[1:])) + elif cmd == "PING": + receiver = msgList[1] + msg = "PING {0} " + self.sendCtcpRequest.emit(receiver, "PING", "") + sendData = False + elif cmd == "IGNORE": + sendData = False + if len(msgList) > 1: + if msgList[1] == "-r": + ignored = False + userNamesList = msgList[2:] else: - userNamesList = [] - userNames = ",".join( - u.rstrip(",") for u in userNamesList).split(",") - for userName in userNames: - itm = self.__findUser(userName) - if itm: - itm.setIgnored(ignored) - elif cmd == "UNIGNORE": - sendData = False - if len(msgList) > 1: + ignored = True userNamesList = msgList[1:] - else: - userNamesList = [] - userNames = ",".join( - u.rstrip(",") for u in userNamesList).split(",") - for userName in userNames: - itm = self.__findUser(userName) - if itm: - itm.setIgnored(False) - elif cmd == "AWAY": - sendData = False - if len(msgList) > 1: - msg = " ".join(msgList[1:]) + else: + userNamesList = [] + userNames = ",".join( + u.rstrip(",") for u in userNamesList).split(",") + for userName in userNames: + itm = self.__findUser(userName) + if itm: + itm.setIgnored(ignored) + elif cmd == "UNIGNORE": + sendData = False + if len(msgList) > 1: + userNamesList = msgList[1:] + else: + userNamesList = [] + userNames = ",".join( + u.rstrip(",") for u in userNamesList).split(",") + for userName in userNames: + itm = self.__findUser(userName) + if itm: + itm.setIgnored(False) + elif cmd == "AWAY": + sendData = False + if len(msgList) > 1: + msg = " ".join(msgList[1:]) + else: + msg = "" + self.awayCommand.emit(msg) + elif cmd == "JOIN": + sendData = False + if len(msgList) > 1: + channels = msgList[1].split(",") + if len(msgList) > 2: + keys = msgList[2].split(",") else: - msg = "" - self.awayCommand.emit(msg) - elif cmd == "JOIN": - sendData = False - if len(msgList) > 1: - channels = msgList[1].split(",") - if len(msgList) > 2: - keys = msgList[2].split(",") - else: - keys = [] - for channel, key in zip_longest( - channels, keys, fillvalue=""): - self.__ircWidget.joinChannel(channel, key) - elif cmd == "PART": - sendData = False - if len(msgList) == 1: - self.leaveChannel() - else: - self.leaveChannels.emit(msgList[1:]) - elif cmd == "PARTALL": - sendData = False - self.leaveAllChannels.emit() + keys = [] + for channel, key in zip_longest( + channels, keys, fillvalue=""): + self.__ircWidget.joinChannel(channel, key) + elif cmd == "PART": + sendData = False + if len(msgList) == 1: + self.leaveChannel() else: - msg = msg[1:] - if sendData: - self.sendData.emit(msg) + self.leaveChannels.emit(msgList[1:]) + elif cmd == "PARTALL": + sendData = False + self.leaveAllChannels.emit() + else: + msg = msg[1:] + if sendData: + self.sendData.emit(msg) + else: + if self.__private: + self.sendData.emit( + "PRIVMSG " + self.__privatePartner + " :" + msg) else: - if self.__private: - self.sendData.emit( - "PRIVMSG " + self.__privatePartner + " :" + msg) - else: - self.sendData.emit( - "PRIVMSG " + self.__name + " :" + msg) - - self.messageEdit.clear() - self.unsetMarkerLine() + self.sendData.emit( + "PRIVMSG " + self.__name + " :" + msg) + + self.messageEdit.clear() + self.unsetMarkerLine() def requestLeave(self): """ @@ -1463,6 +1473,42 @@ user = self.usersList.selectedItems()[0].text() self.openPrivateChat.emit(user) + def __sendUserMessage(self): + """ + Private slot to send a private message to a specific user. + """ + # TODO: code me + user = self.usersList.selectedItems()[0].text() + + + def __sendUserQuery(self): + """ + Private slot to send a query message to a specific user. + """ + # TODO: code me + user = self.usersList.selectedItems()[0].text() + + def __sendUserNotice(self): + """ + Private slot to send a notice message to a specific user. + """ + # TODO: code me + user = self.usersList.selectedItems()[0].text() + + def __pingUser(self): + """ + Private slot to send a ping to a specific user. + """ + user = self.usersList.selectedItems()[0].text() + self.__processUserMessage("/PING {0}".format(user)) + + def __ignoreUser(self): + """ + Private slot to ignore a specific user. + """ + user = self.usersList.selectedItems()[0].text() + self.__processUserMessage("/IGNORE {0}".format(user)) + def __initUsersMenu(self): """ Private slot to initialize the users list context menu. @@ -1474,6 +1520,18 @@ self.__privateChatAct = self.__usersMenu.addAction( self.tr("Private Chat"), self.__openPrivateChat) self.__usersMenu.addSeparator() + self.__sendUserMessageAct = self.__usersMenu.addAction( + self.tr("Send Message"), self.__sendUserMessage) + self.__sendUserQueryAct = self.__usersMenu.addAction( + self.tr("Send Query"), self.__sendUserQuery) + self.__sendUserNoticeAct = self.__usersMenu.addAction( + self.tr("Send Notice"), self.__sendUserNotice) + self.__usersMenu.addSeparator() + self.__pingUserAct = self.__usersMenu.addAction( + self.tr("Send Ping"), self.__pingUser) + self.__ignoreUserAct = self.__usersMenu.addAction( + self.tr("Ignore User"), self.__ignoreUser) + self.__usersMenu.addSeparator() self.__usersListRefreshAct = self.__usersMenu.addAction( self.tr("Refresh"), self.__sendAutoWhoCommand)
--- a/eric6.e4p Wed Oct 03 18:22:26 2018 +0200 +++ b/eric6.e4p Wed Oct 03 19:22:07 2018 +0200 @@ -141,6 +141,7 @@ <Source>E5Gui/E5TabWidget.py</Source> <Source>E5Gui/E5TableView.py</Source> <Source>E5Gui/E5TextEditSearchWidget.py</Source> + <Source>E5Gui/E5TextInputDialog.py</Source> <Source>E5Gui/E5TextSpinBox.py</Source> <Source>E5Gui/E5ToolBarDialog.py</Source> <Source>E5Gui/E5ToolBarManager.py</Source>