class CustomTreeItem(QtGui.QTreeWidgetItem):

    def __init__(self, window, parent, name, view=None, color=True):
        #print "creating ", name, " under ", parent
        if view:
            self.view = view
        if not view:
            try:
                self.view = parent.view
            except AttributeError:
                self.view = parent
        self.window = window
        self._name = name
        ## Init super class ( QtGui.QTreeWidgetItem )
        super(CustomTreeItem, self).__init__(parent)

        ## Column 0 - Text:
        self.setText(0, name)

        ## Column 1 - Color:
        if color:
            #print type(self.view.view)
            self.colorChooser = KColorButton(self.view)
            self.colorChooser.setColor(QtGui.QColor(randint(0, 255), randint(0, 255), randint(0, 255)))
            #self.colorChooser.setGeometry(QtCore.QRect(0, 0, 10, 10))
            self.colorChooser.setFixedSize(30,20)
            self.view.setItemWidget(self, 1, self.colorChooser)
            self.view.connect(self.colorChooser, QtCore.SIGNAL("changed (const QColor&)"), self.colorChanged)

        ## Column 2 - CheckBox:
        self.button = QtGui.QCheckBox(self.view)
        self.button.setChecked(True)
        self.view.setItemWidget(self, 2, self.button)

        ## Column 3 - Current value:
        if color:
            self.setText(3, 'N/A')
        else:
            self.setText(3, '')

        ## Signals
        self.view.connect(self.button, QtCore.SIGNAL("clicked()"), self.buttonPressed)


    def setDataValue(self, value):
        self.setText(3, str(value))

    def buttonPressed(self):
        if self.childCount():
            for i in range(self.childCount()):
                self.child(i).button.setChecked(self.button.isChecked())
                self.child(i).buttonPressed()

        elif self.button.isChecked():
            self.window.enablePlot(self._name)
            self.window.setPlotColor(self._name, self.colorChooser.color())
        else:
            self.window.disablePlot(self._name)

    def colorChanged(self):
        self.window.setPlotColor(self._name, self.colorChooser.color())
Beispiel #2
0
class PylouApplet(Applet):

    """Main Applet containing the UI of Pylou."""

    def __init__(self, parent, args=None):
        """Init class."""
        Applet.__init__(self, parent)

    def init(self):
        """Start the Applet."""
        self._widget = None
        self.setHasConfigurationInterface(True)
        self.setAspectRatioMode(Plasma.IgnoreAspectRatio)
        self.configurations = self.config()
        self._widget = PylouWidget(self)
        self._widget.init()
        self.setGraphicsWidget(self._widget)
        self.applet.setPassivePopup(True)
        self.setPopupIcon(QIcon.fromTheme("edit-find"))
        # for some odd reason this has to be called twice?
        self.setGraphicsWidget(self._widget)
        self.prepareConfigDialog()

    def update_db(self):
        """Update the DB."""
        return call("kdesudo --noignorebutton -c updatedb", shell=True)

    def prepareConfigDialog(self):
        """Prepare the Configuration Dialog."""
        self.bcolor, self.dialog = QColor(), KDialog()
        self.dialog.setWindowTitle(__package__ + "Settings")
        self.layBox = QGridLayout(self.dialog.mainWidget())
        self.title = KTitleWidget(self.dialog)
        self.title.setText(__doc__ + " !")
        self.title.setAutoHideTimeout(3000)
        self.FontButton = KFontRequester(self.dialog)
        self.tfont = QFont(QVariant(self.configurations.readEntry("TextFont",
                           QVariant(QFont()))))
        self.FontButton.setFont(self.tfont)
        self.ColorButton = KColorButton(self.dialog)
        self.tcolor = QColor(self.configurations.readEntry("TextColor",
                             QColor("#000").name()))
        self.ColorButton.setColor(self.tcolor)
        self.BColorButton = KColorButton(self.dialog)
        # button to update the DB via sudo updatedb

        self.UpdateDB = KPushButton("Update Database", self.dialog,
                                    clicked=lambda: self.update_db())
        self.UpdateDB.setToolTip("Database is Updated every Reboot and Daily!")
        self.Histor = KPushButton("Delete my History", self.dialog,
                                  clicked=delete_my_history)
        self.Histor.setToolTip("History is Deleted every Reboot !")
        # list of banned words separated by spaces
        self.banned = KTextEdit(self.dialog)
        self.banned.setPlainText(self.configurations.readEntry(
            "Banned", "sex p**n drugs suicide decapitate religion").toString())
        # set the colors
        cg = KConfig("kdeglobals")
        color = cg.group("Colors:View").readEntry(
            "BackgroundAlternate").split(",")
        self.bcolor = QColor(int(color[0]), int(color[1]), int(color[2]))
        self.BColorButton.setColor(self.bcolor)
        self.history_file_path_field = KLineEdit(HISTORY_FILE_PATH)
        self.history_file_path_field.setDisabled(True)
        self.python_file_path_field = KLineEdit(__file__)
        self.python_file_path_field.setDisabled(True)
        self.kill_baloo = QCheckBox("Disable Baloo")
        self.kill_baloo.setToolTip("Enable/Disable Desktop Search Indexing")
        self.kill_baloo.stateChanged.connect(lambda: call(
            DISABLE_BALOO_CMD.format(str(
                not self.kill_baloo.isChecked()).lower()), shell=True))
        self.kill_baloo.stateChanged.connect(lambda: QMessageBox.information(
            self.dialog, __doc__, """
            <b>Indexing Disabled, Baloo is Dead !
            """ if self.kill_baloo.isChecked() else """
            <b>Indexing Enabled, Baloo is Running !"""))
        self.updatez = KPushButton("Check for Updates", self.dialog,
                                   clicked=lambda: self.check_for_updates())
        self.updatez.setToolTip("Check for Pylou updates from the internet")
        self.home_sweet_home = QCheckBox("Only Search Home")
        self.home_sweet_home.setToolTip("Only Search on my Home folders")
        self.home_sweet_home.setChecked(
            bool(self.configurations.readEntry("Home", True)))
        # pack all widgets
        self.layBox.addWidget(self.title, 0, 1)
        self.layBox.addWidget(QLabel("Font"), 1, 0)
        self.layBox.addWidget(self.FontButton, 1, 1)
        self.layBox.addWidget(QLabel("Text Color"), 2, 0)
        self.layBox.addWidget(self.ColorButton, 2, 1)
        self.layBox.addWidget(QLabel("Alternate Color"), 3, 0)
        self.layBox.addWidget(self.BColorButton, 3, 1)
        self.layBox.addWidget(QLabel(), 4, 0)
        self.layBox.addWidget(QLabel("Mainteniance"), 5, 0)
        self.layBox.addWidget(self.UpdateDB, 5, 1)
        self.layBox.addWidget(QLabel("Privacy"), 6, 0)
        self.layBox.addWidget(self.Histor, 6, 1)
        self.layBox.addWidget(QLabel("History file"), 7, 0)
        self.layBox.addWidget(self.history_file_path_field, 7, 1)
        self.layBox.addWidget(QLabel(__package__ + "file"), 8, 0)
        self.layBox.addWidget(self.python_file_path_field, 8, 1)
        self.layBox.addWidget(QLabel("Banned Words"), 9, 0)
        self.layBox.addWidget(self.banned, 9, 1)
        self.layBox.addWidget(QLabel("SelfUpdating"), 10, 0)
        self.layBox.addWidget(self.updatez, 10, 1)
        self.layBox.addWidget(QLabel("<b>Disable Indexing"), 12, 0)
        self.layBox.addWidget(self.kill_baloo, 12, 1)
        self.layBox.addWidget(QLabel("Search Paths"), 13, 0)
        self.layBox.addWidget(self.home_sweet_home, 13, 1)
        # button box on the bottom
        self.dialog.setButtons(KDialog.ButtonCodes(
            KDialog.ButtonCode(KDialog.Ok | KDialog.Cancel | KDialog.Apply)))
        # connect
        self.dialog.applyClicked.connect(self.configAccepted)
        self.dialog.okClicked.connect(self.configAccepted)

    @pyqtSignature("configAccepted()")
    def configAccepted(self):
        """Save configuration settings."""
        self.tcolor = self.ColorButton.color()
        self.bcolor = self.BColorButton.color()
        self._widget.treeview.nativeWidget().setFont(self.tfont)
        self._widget.treeview.nativeWidget().setStyleSheet(
            "color:{};alternate-background-color:{}".format(
                self.tcolor.name(), self.bcolor.name()))
        self.configurations.writeEntry("TextColor", self.tcolor.name())
        self.configurations.writeEntry("AlternateBColor", self.bcolor.name())
        self.configurations.writeEntry("TextFont", QVariant(self.tfont))
        self.configurations.writeEntry("Banned", self.banned.toPlainText())
        self.configurations.writeEntry("Home",
                                       self.home_sweet_home.isChecked())

    def showConfigurationInterface(self):
        """Show configuration dialog."""
        self.dialog.show()
        self.dialog.raise_()

    def check_for_updates(self):
        """Method to check for updates from Git repo versus this version."""
        this_version = str(open(__file__).read())
        last_version = str(urlopen(__source__).read())
        if this_version != last_version:
            m = "Theres new Version available!<br>Download update from the web"
        else:
            m = "No new updates!<br>You have the lastest version of this app!."
        return QMessageBox.information(None, __doc__.title(), "<b>" + m)
Beispiel #3
0
class CustomTreeItem(QtGui.QTreeWidgetItem):
    def __init__(self, window, parent, name, view=None, color=True):
        #print "creating ", name, " under ", parent
        if view:
            self.view = view
        if not view:
            try:
                self.view = parent.view
            except AttributeError:
                self.view = parent
        self.window = window
        self._name = name
        ## Init super class ( QtGui.QTreeWidgetItem )
        super(CustomTreeItem, self).__init__(parent)

        ## Column 0 - Text:
        self.setText(0, name)

        ## Column 1 - Color:
        if color:
            #print type(self.view.view)
            self.colorChooser = KColorButton(self.view)
            self.colorChooser.setColor(
                QtGui.QColor(randint(0, 255), randint(0, 255), randint(0,
                                                                       255)))
            #self.colorChooser.setGeometry(QtCore.QRect(0, 0, 10, 10))
            self.colorChooser.setFixedSize(30, 20)
            self.view.setItemWidget(self, 1, self.colorChooser)
            self.view.connect(self.colorChooser,
                              QtCore.SIGNAL("changed (const QColor&)"),
                              self.colorChanged)

        ## Column 2 - CheckBox:
        self.button = QtGui.QCheckBox(self.view)
        self.button.setChecked(True)
        self.view.setItemWidget(self, 2, self.button)

        ## Column 3 - Current value:
        if color:
            self.setText(3, 'N/A')
        else:
            self.setText(3, '')

        ## Signals
        self.view.connect(self.button, QtCore.SIGNAL("clicked()"),
                          self.buttonPressed)

    def setDataValue(self, value):
        self.setText(3, str(value))

    def buttonPressed(self):
        if self.childCount():
            for i in range(self.childCount()):
                self.child(i).button.setChecked(self.button.isChecked())
                self.child(i).buttonPressed()

        elif self.button.isChecked():
            self.window.enablePlot(self._name)
            self.window.setPlotColor(self._name, self.colorChooser.color())
        else:
            self.window.disablePlot(self._name)

    def colorChanged(self):
        self.window.setPlotColor(self._name, self.colorChooser.color())