Esempio n. 1
0
class EventlogDialog(QDialog):
    def __init__(self, cfg, parent):
        super().__init__(parent)
        self.setAttribute(Qt.WA_DeleteOnClose)
        self.setWindowTitle("Eventlog")

        self.cfg = cfg

        self.pauseButton = QPushButton("Pause", self)
        self.pauseButton.setCheckable(True)
        self.pauseButton.connect("toggled(bool)", self.onPauseButtonToggled)
        self.spacer = QSpacerItem(40, 20, QSizePolicy.Expanding,
                                  QSizePolicy.Minimum)
        self.maxLabel = QLabel("Maximum Events:", self)
        self.maxSpin = QSpinBox(self)
        self.maxSpin.setMaximum(10000)
        self.maxSpin.setToolTip("Set to 0 to not shrink events at all")
        self.maxSpin.setValue(cfg.getint("maximumEvents"))
        self.maxSpin.connect("valueChanged(int)", self.onMaxSpinChanged)

        self.sublay1 = QHBoxLayout()
        self.sublay1.addWidget(self.pauseButton)
        self.sublay1.addItem(self.spacer)
        self.sublay1.addWidget(self.maxLabel)
        self.sublay1.addWidget(self.maxSpin)

        self.filterLabel = QLabel("Filter:", self)
        self.filterEdit = QLineEdit(self)
        self.filterEdit.connect("textChanged(QString)",
                                self.onFilterEditChanged)
        self.filterButton = QToolButton(self)
        self.filterButton.connect("clicked()", self.filterEdit.clear)
        try:
            ico = ts3client.IconPack.current()
            ico.open()
            self.filterButton.setIcon(QIcon(ico.icon("ERROR")))
            ico.close()
        except Exception as e:
            self.filterButton.setText("X")

        self.sublay2 = QHBoxLayout()
        self.sublay2.addWidget(self.filterLabel)
        self.sublay2.addWidget(self.filterEdit)
        self.sublay2.addWidget(self.filterButton)

        self.model = EventlogModel(self)
        self.model.maximumEvents = cfg.getint("maximumEvents")
        self.proxy = QSortFilterProxyModel(self)
        self.proxy.setFilterRole(Qt.UserRole)
        self.proxy.setSourceModel(self.model)

        self.tree = QTreeView(self)
        self.tree.header().hide()
        self.tree.setModel(self.proxy)

        self.lay = QVBoxLayout(self)
        self.lay.addLayout(self.sublay1)
        self.lay.addLayout(self.sublay2)
        self.lay.addWidget(self.tree)

        self.resize(cfg.getint("width"), cfg.getint("height"))

        self.connect("finished(int)", self.onFinished)

    def onMaxSpinChanged(self, val):
        self.model.maximumEvents = val
        self.cfg["maximumEvents"] = str(val)

    def onFilterEditChanged(self, txt):
        self.proxy.setFilterRegExp(txt)

    def onPauseButtonToggled(self, checked):
        if checked:
            self.model.pause()
        else:
            self.model.unpause()

    def onFinished(self, result):
        self.cfg["width"] = str(self.width)
        self.cfg["height"] = str(self.height)

    def callback(self, name, *args):
        self.model.callback(name, *args)
Esempio n. 2
0
class InfoDialog(QDialog):
    def __init__(self):
        super(QDialog, self).__init__(None)
        
        self.setAttribute(Qt.WA_DeleteOnClose)
        
        self.splitter = QSplitter(Qt.Horizontal, self)
        self.leftwidg = QWidget(self)
        self.vlayout = QVBoxLayout(self.leftwidg)
        self.checkbox = QCheckBox("Mark selection", self)
        self.tree = QTreeView(self)
        self.tree.header().hide()
        self.vlayout.addWidget(self.checkbox)
        self.vlayout.addWidget(self.tree)
        self.table = QTableView(self)
        self.table.horizontalHeader().setStretchLastSection(True)
        
        self.splitter.addWidget(self.leftwidg)
        self.splitter.addWidget(self.table)
        
        self.hlayout = QHBoxLayout(self)
        self.hlayout.addWidget(self.splitter)   
        
        self.treemodel = WidgetModel(self.tree)
        self.tree.setModel(self.treemodel)
        
        self.tablemodel = PropertyModel(self.table)
        self.table.setModel(self.tablemodel)
        
        self.stylesheet = None

        self.connect("finished(int)", self.onClosed)
        self.tree.selectionModel().connect("currentChanged(const QModelIndex&, const QModelIndex&)", self.onTreeSelectionChanged)
        self.tree.connect("doubleClicked(const QModelIndex&)", self.onTreeDoubleClicked)
        self.checkbox.connect("toggled(bool)", self.onCheckBoxClicked)
        
        self.resize(800, 500)
        
    def onClosed(self):
        if self.checkbox.isChecked() and self.stylesheet is not None:
            index = self.tree.selectionModel().currentIndex
            if index.isValid():
                obj = index.internalPointer() 
                if hasattr(obj, "setStyleSheet"):
                    obj.setStyleSheet(self.stylesheet)
    
        
    def setWidget(self, widg):
        self.widget = widg
        
        tlw = QApplication.topLevelWidgets()
        
        if widg in tlw:
            index = self.treemodel.createIndex(tlw.index(widg), 0, widg)
        else:
            index = self.treemodel.createIndex(widg.parent().children().index(widg), 0, widg)
            
        self.tree.selectionModel().select(index, QItemSelectionModel.ClearAndSelect)
        self.tree.scrollTo(index)
        
        while index.isValid():
            self.tree.expand(index)
            index = index.parent()
        
        self.tablemodel.setWidget(widg)
        
    def onTreeDoubleClicked(self, index):
        obj = index.internalPointer()
        
        if obj.inherits("QMenu"):
            obj.popup(QCursor.pos())

        
    def onTreeSelectionChanged(self, cur, prev):
        obj = cur.internalPointer()
    
        self.tablemodel.setWidget(obj)
    
        if self.checkbox.isChecked():
            if prev.isValid() and self.stylesheet is not None:
                oldobj = prev.internalPointer()
                if hasattr(oldobj, "setStyleSheet"):
                    oldobj.setStyleSheet(self.stylesheet)
    
            if hasattr(obj, "setStyleSheet"):
                self.stylesheet = obj.styleSheet
                obj.setStyleSheet("background: red;")    
        
    def onCheckBoxClicked(self, act):
        index = self.tree.selectionModel().currentIndex
        if not index.isValid():
            return
            
        obj = index.internalPointer()
        if not hasattr(obj, "setStyleSheet"):
            return
            
        if act:
            self.stylesheet = obj.styleSheet
            obj.setStyleSheet("background: red;")
        elif self.stylesheet is not None:
            obj.setStyleSheet(self.stylesheet)