From 697a9efb513c706446ac2f7f6db652338896fd1b Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Tue, 19 Jul 2016 23:19:42 +0300 Subject: [PATCH] message menu update - plugins, quotes --- toxygen/list_items.py | 21 +++++++++++++++++++++ toxygen/mainscreen.py | 5 +++-- toxygen/plugin_support.py | 10 ++++++++++ toxygen/plugins/plugin_super_class.py | 9 +++++++++ toxygen/profile.py | 2 +- 5 files changed, 44 insertions(+), 3 deletions(-) diff --git a/toxygen/list_items.py b/toxygen/list_items.py index 4932f96..a297a18 100644 --- a/toxygen/list_items.py +++ b/toxygen/list_items.py @@ -42,10 +42,31 @@ class MessageEdit(QtGui.QTextBrowser): def contextMenuEvent(self, event): menu = create_menu(self.createStandardContextMenu(event.pos())) + quote = menu.addAction(QtGui.QApplication.translate("MainWindow", 'Quote selected text', None, QtGui.QApplication.UnicodeUTF8)) + quote.triggered.connect(self.quote_text) + text = self.textCursor().selection().toPlainText() + if not text: + quote.setEnabled(False) + else: + import plugin_support + submenu = plugin_support.PluginLoader.get_instance().get_message_menu(menu, text) + if len(submenu): + plug = menu.addMenu(QtGui.QApplication.translate("MainWindow", 'Plugins', None, QtGui.QApplication.UnicodeUTF8)) + plug.addActions(submenu) menu.popup(event.globalPos()) menu.exec_(event.globalPos()) del menu + def quote_text(self): + text = self.textCursor().selection().toPlainText() + if text: + import mainscreen + window = mainscreen.MainWindow.get_instance() + text = '>' + '\n>'.join(text.split('\n')) + if window.messageEdit.toPlainText(): + text = '\n' + text + window.messageEdit.appendPlainText(text) + def on_anchor_clicked(self, url): text = str(url.toString()) if text.startswith('tox:'): diff --git a/toxygen/mainscreen.py b/toxygen/mainscreen.py index 7079bf5..5e1fab1 100644 --- a/toxygen/mainscreen.py +++ b/toxygen/mainscreen.py @@ -8,10 +8,11 @@ import plugin_support from mainscreen_widgets import * -class MainWindow(QtGui.QMainWindow): +class MainWindow(QtGui.QMainWindow, Singleton): def __init__(self, tox, reset, tray): - super(MainWindow, self).__init__() + super().__init__() + Singleton.__init__(self) self.reset = reset self.tray = tray self.setAcceptDrops(True) diff --git a/toxygen/plugin_support.py b/toxygen/plugin_support.py index 944c353..a4f5891 100644 --- a/toxygen/plugin_support.py +++ b/toxygen/plugin_support.py @@ -147,6 +147,16 @@ class PluginLoader(util.Singleton): continue return result + def get_message_menu(self, menu, selected_text): + result = [] + for elem in self._plugins.values(): + if elem[1]: + try: + result.extend(elem[0].get_message_menu(menu, selected_text)) + except: + continue + return result + def stop(self): """ App is closing, stop all plugins diff --git a/toxygen/plugins/plugin_super_class.py b/toxygen/plugins/plugin_super_class.py index 4eb833e..84c4a3e 100644 --- a/toxygen/plugins/plugin_super_class.py +++ b/toxygen/plugins/plugin_super_class.py @@ -88,6 +88,15 @@ class PluginSuperClass: """ return [] + def get_message_menu(self, menu, text): + """ + This method creates items for menu which called on right click in message + :param menu: menu instance + :param text: selected text + :return list of QAction's + """ + return [] + def get_window(self): """ This method should return window for plugins with GUI or None diff --git a/toxygen/profile.py b/toxygen/profile.py index e6cf877..cdaf19f 100644 --- a/toxygen/profile.py +++ b/toxygen/profile.py @@ -171,7 +171,7 @@ class Profile(contact.Contact, Singleton): self.send_typing(False) self._screen.typing.setVisible(False) if value is not None: - if self._active_friend + 1: + if self._active_friend + 1 and self._active_friend != value: try: self._friends[self._active_friend].curr_text = self._screen.messageEdit.toPlainText() except: