def on_btn_beautify_clicked(self): try: try: from css_html_prettify import css_prettify except: _t = QMessageBox.question(self, "Can't beautify", "Python package \"css_html_prettify\" could not be loaded.\nDo you want to try installing it now?", QMessageBox.Yes, QMessageBox.No) if _t == QMessageBox.Yes: from devtools import PluginInstaller PluginInstaller().installPackages(['css_html_prettify']) self.on_btn_beautify_clicked() return #import traceback; QMessageBox.Critical("Can't minify", traceback.format_exc()).exec_() index = self.tabWidget.currentIndex _old = "" if index == 0: _old = self.qssEditor.toPlainText() elif index == 1: _old = self.chatEditor.toPlainText() _beautified = css_prettify(_old) if index == 0: QApplication.instance().styleSheet = _beautified self.qssEditor.setPlainText(_beautified) elif index == 1: self.chatEditor.setPlainText(_beautified);return if QMessageBox(QMessageBox.Warning, "Use minified QSS?", "Your minified QSS code has been applied.\n\nIf you encounter any issues with the minified code you should click on cancel.", QMessageBox.Ok | QMessageBox.Cancel).exec_() == QMessageBox.Cancel: QApplication.instance().styleSheet = _old self.qssEditor.setPlainText(_old) except: try: from traceback import format_exc QMessageBox(QMessageBox.Critical, "Can't beautify", format_exc()).exec_() except: print(format_exc())
def on_btn_beautify_clicked(self): try: try: from bs4 import BeautifulSoup except Exception: from traceback import format_exc print("Error: {0}".format(format_exc())) _t = QMessageBox.question( self, "Can't beautify", "Python package \"beautifulsoup4\" could not be loaded.\nDo you want to try installing it now?", QMessageBox.Yes, QMessageBox.No) if _t == QMessageBox.Yes: from devtools import PluginInstaller PluginInstaller().installPackages(['beautifulsoup4']) self.on_btn_beautify_clicked() return #import traceback; QMessageBox.Critical("Can't minify", traceback.format_exc()).exec_() index = self.tabWidget.currentIndex _old = "" if index == 0: _old = self.qssEditor.toPlainText() elif index == 1: _old = self.chatEditor.toPlainText() elif index == 2: _old = self.tplEditor.toPlainText() elif index == 3: _old = self.chatEditor_html.toPlainText() _beautified = BeautifulSoup(_old) _beautified = _beautified.prettify() if index == 0: QApplication.instance().styleSheet = _beautified self.qssEditor.setPlainText(_beautified) elif index == 1: self.chatEditor.setPlainText(_beautified) return elif index == 2: self.tplEditor.setPlainText(_beautified) return elif index == 3: self.chatEditor_html.setPlainText(_beautified) return if QMessageBox( QMessageBox.Warning, "Use beautified code?", "Your beautified code has been applied.\n\nIf you encounter any issues with the beautified code you should click on cancel.", QMessageBox.Ok | QMessageBox.Cancel).exec_() == QMessageBox.Cancel: QApplication.instance().styleSheet = _old self.qssEditor.setPlainText(_old) except: try: from traceback import format_exc QMessageBox(QMessageBox.Critical, "Can't beautify", format_exc()).exec_() except: print(format_exc())
def on_btn_apply_clicked(self): i = self.tabWidget.currentIndex if i == 0: QApplication.instance().styleSheet = self.qssEditor.toPlainText() elif i == 1: QApp = QApplication.instance() widgets = QApp.topLevelWidgets() + QApp.allWidgets() for x in widgets: if x.objectName == "ChatTab": x.findChild(QTextDocument).defaultStyleSheet = self.chatEditor.toPlainText() elif i == 2: _i = self.getWidgetByObjectName("InfoFrame") _o = _i.styleSheet _i.styleSheet = "background:red;" _i.html = self.html _i.styleSheet = _o
def on_btn_reset_clicked(self): if QMessageBox( QMessageBox.Warning, "Reset QSS?", "This will reset your changes to the initial Stylesheet! Continue?", QMessageBox.Ok | QMessageBox.Cancel).exec_() == QMessageBox.Ok: QApplication.instance().styleSheet = self.stylesheet self.qssEditor.setPlainText(self.stylesheet)
def retrieveWidgets(self): process = False if not hasattr(self, "main"): qapp = QApplication.instance() for w in qapp.topLevelWidgets(): if "MainWindow" in str(type(w)): self.main = w process = True else: process = True if process and not hasattr(self, "splitter"): for c in self.main.children(): if type(c) is QSplitter: self.splitter = c break if not hasattr(self, "splitter"): process = False if process and (not hasattr(self, "chat") or not hasattr(self, "tabwidget")): for c in self.splitter.children(): if c.objectName == "MainWindowChatWidget": self.chat = c elif c.objectName == "MainWindowServerTabsWidget": self.tabwidget = c if not hasattr(self, "chat") or not hasattr(self, "tabwidget"): process = False if process and not hasattr(self, "tab"): for c in self.tabwidget.children(): if "ServerViewManager" in str(type(c)): self.tab = c break if not hasattr(self, "tab"): process = False if process and not hasattr(self, "svparent"): for c in self.tab.children(): if type(c) is QStackedWidget: self.svparent = c break if not process: #it's possible that this plugin is started before the client's UI is loaded QTimer.singleShot(300, self.retrieveWidgets) else: self.tab.connect("currentChanged(int)", self.onTabIndexChanged) self.startDocking()
def __init__(self, schid, parent=None): self.lay = QHBoxLayout(parent) self.tree = DragDropServerview(schid, parent) self.lay.addWidget(self.tree) self.lay.setContentsMargins(0,0,0,0) parent.setLayout(self.lay) self.tree.connect("clicked(QModelIndex)", self.tree.onItemClicked) self.tree.connect("customContextMenuRequested(QPoint)", self.tree.onContextMenu) self.searchFrame = [item for item in QApplication.instance().allWidgets() if type(item).__name__ == "SearchFrame"][0] self.searchFrame.connect("find(QString,QTextDocument::FindFlags,bool,bool,bool&)", self.tree.onSearch)
def retrieveWidgets(self): if not self.main: for w in QApplication.instance().topLevelWidgets(): if "MainWindow" in str(type(w)): self.main = w break if self.main and not self.svmanagerstack: self.svmanagerstack = findChildWidget(self.main, lambda x: x.objectName == "qt_tabwidget_stackedwidget" and "ServerViewManager" in str(type(x.parent())), True) if self.svmanagerstack: self.svmanagerstack.installEventFilter(self.svobserver) for tree in findAllChildWidgets(self.svmanagerstack, lambda x: "TreeView" in str(type(x)), True): #TODO: maybe create a new servertreeview here? tree.installEventFilter(self.treekeyobserver) else: QTimer.singleShot(300, self.retrieveWidgets)
def __init__(self, arg, parent=None): super(QDialog, self).__init__(parent) setupUi(self, os.path.join(ts3.getPluginPath(), "pyTSon", "scripts", "devTools", "editor.ui")) self.resize(1000, 900) self.setWindowTitle('Teamspeak Stylesheet Editor : : Developer Tools') self.stylesheet = QApplication.instance().styleSheet self.chatsheet = self.getWidgetByObjectName("ChatTab").findChild(QTextDocument).defaultStyleSheet self.html = self.getWidgetByObjectName("InfoFrame").html self.qssEditor.setPlainText(self.stylesheet) self.chatEditor.setPlainText(self.chatsheet) self.tplEditor.setPlainText(self.html) self.chatEditor.setReadOnly(True);self.tplEditor.setReadOnly(True) index = self.tabWidget.currentIndex if index == 0: self.btn_apply.setEnabled(True);self.btn_minify.setEnabled(True);self.btn_insert.setEnabled(True);self.btn_reset.setEnabled(True);self.chk_live.setEnabled(True) elif index == 1: self.btn_apply.setEnabled(False);self.btn_minify.setEnabled(True);self.btn_insert.setEnabled(False);self.btn_reset.setEnabled(False);self.chk_live.setEnabled(False) else: self.btn_apply.setEnabled(False);self.btn_minify.setEnabled(False);self.btn_insert.setEnabled(False);self.btn_reset.setEnabled(False);self.chk_live.setEnabled(False) self.lastSave = None
def getWidgetByClassName(self, name): QApp = QApplication.instance() widgets = QApp.topLevelWidgets() widgets = widgets + QApp.allWidgets() for x in widgets: if str(x.__class__) == name: return x
def getWidgetByObjectName(self, name): QApp = QApplication.instance() widgets = QApp.topLevelWidgets() widgets = widgets + QApp.allWidgets() for x in widgets: if str(x.objectName) == name: return x
def onHotkeyEvent(self, keyword): if keyword == "info": self.showInfo(QApplication.instance().widgetAt(QCursor.pos()))
def onQSSChanged(self): QApplication.instance().styleSheet = self.qssEditor.toPlainText()