예제 #1
0
    def initShortcuts(self):
        self.actionCollection = KActionCollection(self)
        #self.actionCollection.setConfigGlobal(True)
        self.louder_action = self.actionCollection.addAction("VeromixVolumeUp")
        self.louder_action.setText(i18n("Veromix volume up"))
        self.louder_action.setGlobalShortcut(KShortcut())
        self.louder_action.triggered.connect(self.widget.on_step_volume_up)

        self.lower_action = self.actionCollection.addAction(
            "VeromixVolumeDown")
        self.lower_action.setText(i18n("Veromix volume down"))
        self.lower_action.setGlobalShortcut(KShortcut())
        self.lower_action.triggered.connect(self.widget.on_step_volume_down)

        self.mute_action = self.actionCollection.addAction("VeromixVolumeMute")
        self.mute_action.setText(i18n("Veromix toggle mute"))
        self.mute_action.setGlobalShortcut(KShortcut())
        self.mute_action.triggered.connect(self.widget.on_toggle_mute)
예제 #2
0
    def initShortcuts(self):
        self.actionCollection = KActionCollection(self)
        # self.actionCollection.setConfigGlobal(True)
        self.louder_action = self.actionCollection.addAction("VeromixVolumeUp")
        self.louder_action.setText(i18n("Veromix volume up"))
        self.louder_action.setGlobalShortcut(KShortcut())
        self.louder_action.triggered.connect(self.widget.on_step_volume_up)

        self.lower_action = self.actionCollection.addAction("VeromixVolumeDown")
        self.lower_action.setText(i18n("Veromix volume down"))
        self.lower_action.setGlobalShortcut(KShortcut())
        self.lower_action.triggered.connect(self.widget.on_step_volume_down)

        self.mute_action = self.actionCollection.addAction("VeromixVolumeMute")
        self.mute_action.setText(i18n("Veromix toggle mute"))
        self.mute_action.setGlobalShortcut(KShortcut())
        self.mute_action.triggered.connect(self.widget.on_toggle_mute)
예제 #3
0
파일: update.py 프로젝트: cburgmer/eclectus
    def __init__(self, mainWindow, renderThread, pluginConfig=None):
        KDialog.__init__(self, mainWindow)
        self.renderThread = renderThread

        self.databaseUrl = None
        if pluginConfig:
            self.databaseUrl = util.readConfigString(self.pluginConfig,
                "Update database url", None)

        if not self.databaseUrl:
            self.databaseUrl = unicode('sqlite:///'
                + util.getLocalData('dictionaries.db'))

        self.renderThread.setObject(DictionaryInfo,
            databaseUrl=self.databaseUrl)

        self.setCaption(i18n("Install/Update Dictionaries"))
        self.setButtons(KDialog.ButtonCode(KDialog.Close))
        self.enableButton(KDialog.Cancel, False)

        # TODO can we defer the creation of the update widget until the dialog is shown?
        self.updateWidget = UpdateWidget(mainWindow, renderThread, pluginConfig)
        self.connect(self.updateWidget, SIGNAL("working(bool)"),
            self.slotUpdateWorking)
        self.setMainWidget(self.updateWidget)

        self.connect(self, SIGNAL("finished()"), self.slotFinish)

        self.initialised = False

        self.connect(self.renderThread, SIGNAL("jobFinished"),
            self.contentRendered)
        self.connect(self.renderThread, SIGNAL("jobErrorneous"),
            self.renderingFailed)

        self.actionCollection = KActionCollection(self)
        self.setupActions()
예제 #4
0
class VeroMixPlasmoid(plasmascript.Applet):
    VERSION = "0.18.3"

    nowplaying_player_added = pyqtSignal(QString, QObject)
    nowplaying_player_removed = pyqtSignal(QString)
    nowplaying_player_dataUpdated = pyqtSignal(QString, dict)

    def __init__(self, parent, args=None):
        self.engine = None
        self.now_playing_engine = None
        self.louder_action_editor = None
        self.lower_action_editor = None
        self.mute_action_editor = None
        self.card_settings = None
        self.messageDialog = None
        self.messageOverlay = None
        self.config_ui = None
        plasmascript.Applet.__init__(self, parent)

    def init(self):
        plasmascript.Applet.init(self)
        KGlobal.locale().insertCatalog("veromix")
        if "usr/share/kde4" not in os.path.realpath(__file__):
            out = commands.getstatusoutput(
                "xdg-icon-resource install --size 128 " +
                unicode(self.package().path()) +
                "contents/icons/veromix-plasmoid-128.png veromix-plasmoid")
            if out[0] == 0:
                print "veromix icon installed"
            else:
                print "Error installing veromix icon:", out

        LADSPAPresetLoader().install_ladspa_presets_if_needed()
        if self.is_ladspa_enabled():
            # force singleton initialisation
            LADSPAPresetLoader().presets()
            LADSPAEffects().effects()

        createDbusServiceDescription(
            self.package().path() + "/dbus-service/veromix-service-qt.py",
            True)

        KGlobal.locale().insertCatalog("veromix")

        self.setHasConfigurationInterface(True)
        self.setAspectRatioMode(Plasma.IgnoreAspectRatio)
        self.theme = Plasma.Svg(self)

        self.widget = VeroMix(self)
        self.widget.init()

        defaultSize = QVariant(QSize(0, 0))
        size = self.config().readEntry("size", defaultSize).toSize()
        if self.formFactor() == Plasma.Planar:
            self.widget.setMinimumSize(275, 125)
        elif (size != defaultSize):
            self.widget.setPreferredSize(size.width(), size.height())
        else:
            self.widget.setPreferredSize(470, 145)

        self.connect(self.widget, SIGNAL("resized()"), self.dialogResized)
        #try:
        self.setGraphicsWidget(self.widget)
        self.applet.setPassivePopup(True)
        ## FIXME: see fixPopupcion
        self.setPopupIcon(KIcon("audio-volume-high"))
        #self.setPopupIcon("audio-volume-muted")
        # dont know why but adding it a second time helps (otherwise it
        # wont popup when you add it directly to the panel)
        self.setGraphicsWidget(self.widget)
        self.connect(self.applet, SIGNAL("appletDestroyed(Plasma::Applet*)"),
                     self.doExit)
        self.setBackgroundHints(Plasma.Applet.StandardBackground)
        self.applyConfig()
        #except AttributeError , e:
        #print e
        #updateMetadataDesktop(self)

        self.initTooltip()
        self.initShortcuts()
        QTimer.singleShot(1000, self.fixPopupIcon)

    def initShortcuts(self):
        self.actionCollection = KActionCollection(self)
        #self.actionCollection.setConfigGlobal(True)
        self.louder_action = self.actionCollection.addAction("VeromixVolumeUp")
        self.louder_action.setText(i18n("Veromix volume up"))
        self.louder_action.setGlobalShortcut(KShortcut())
        self.louder_action.triggered.connect(self.widget.on_step_volume_up)

        self.lower_action = self.actionCollection.addAction(
            "VeromixVolumeDown")
        self.lower_action.setText(i18n("Veromix volume down"))
        self.lower_action.setGlobalShortcut(KShortcut())
        self.lower_action.triggered.connect(self.widget.on_step_volume_down)

        self.mute_action = self.actionCollection.addAction("VeromixVolumeMute")
        self.mute_action.setText(i18n("Veromix toggle mute"))
        self.mute_action.setGlobalShortcut(KShortcut())
        self.mute_action.triggered.connect(self.widget.on_toggle_mute)

    def initTooltip(self):
        if (self.formFactor() != Plasma.Planar):
            self.tooltip = Plasma.ToolTipContent()
            self.tooltip.setImage(pixmapFromSVG("audio-volume-high"))
            self.tooltip.setMainText(i18n("Main Volume"))
            #self.tooltip.setSubText("")
            Plasma.ToolTipManager.self().setContent(self.applet, self.tooltip)
            Plasma.ToolTipManager.self().registerWidget(self.applet)

    def updateIcon(self):
        icon_state = "audio-volume-muted"
        sink = self.widget.getDefaultSink()
        if sink == None:
            QTimer.singleShot(2000, self.fixPopupIcon)
            return
        vol = sink.get_volume()
        if sink.isMuted():
            icon_state = "audio-volume-muted"
        else:
            if vol == 0:
                icon_state = "audio-volume-muted"
            elif vol < 30:
                icon_state = "audio-volume-low"
            elif vol < 70:
                icon_state = "audio-volume-medium"
            else:
                icon_state = "audio-volume-high"
        self.setPopupIcon(icon_state)
        if (self.formFactor() != Plasma.Planar):
            self.tooltip.setImage(pixmapFromSVG(icon_state))
            ## FIXME this should better go to toolTipAboutToShow but is not working:
            # https://bugs.kde.org/show_bug.cgi?id=254764
            self.tooltip.setMainText(sink.name())
            self.tooltip.setSubText(str(vol) + "%")
            Plasma.ToolTipManager.self().setContent(self.applet, self.tooltip)

    def showTooltip(self):
        if self.get_show_toolip():
            Plasma.ToolTipManager.self().show(self.applet)

    @pyqtSlot(name="toolTipAboutToShow")
    def toolTipAboutToShow(self):
        pass

    ## FIXME Looks like a bug in plasma: Only when sending a
    # KIcon instance PopUpApplet acts like a Poppupapplet...
    def fixPopupIcon(self):
        #sink = self.widget.getDefaultSink()
        #if sink:
        self.updateIcon()

    def doExit(self):
        # prevent crash in plasmoidviewer
        self.widget.doExit()
        self.widget.deleteLater()

    def dialogResized(self):
        if self.isPopupShowing():
            self.config().writeEntry("size", QVariant(self.widget.size()))

    def query_application(self, query):
        #print "query: ", query
        if not query:
            return None
        needle = query.lower()
        if self.engine == None:
            self.engine = self.dataEngine("apps")
        for source in self.engine.sources():
            key = unicode(source).replace(".desktop", "")
            if (0 <= key.find(needle)) or (0 <= needle.find(key)):
                #print "found: ",key,  needle , source
                result = self.engine.query(source)
                if QString("iconName") in result:
                    iconname = result[QString("iconName")].toString()
                    return iconname
        return None

    def wheelEvent(self, event):
        if event.orientation() == Qt.Horizontal:
            self.widget.on_step_volume((event.delta() < 0))
        else:
            self.widget.on_step_volume((event.delta() > 0))

    def mousePressEvent(self, event):
        if event.button() == Qt.MidButton:
            self.widget.on_toggle_mute()

    def createConfigurationInterface(self, parent):
        self.pp = parent
        self.config_widget = QWidget(parent)
        self.connect(self.config_widget, SIGNAL('destroyed(QObject*)'),
                     self.configWidgetDestroyed)

        self.config_ui = uic.loadUi(
            str(self.package().filePath('ui', 'appearance.ui')),
            self.config_widget)
        self.config_ui.showBackground.setCurrentIndex(self.config().readEntry(
            "background", "2").toInt()[0])
        self.config_ui.showBackground.currentIndexChanged.connect(
            parent.settingsModified)
        if self.formFactor() != Plasma.Planar:
            self.config_ui.showBackground.setEnabled(False)

        self.config_ui.popupMode.setCurrentIndex(self.config().readEntry(
            "popupMode", False).toInt()[0])
        self.config_ui.popupMode.currentIndexChanged.connect(
            parent.settingsModified)
        if self.formFactor() == Plasma.Planar:
            self.config_ui.popupMode.setEnabled(False)

        self.config_ui.useTabs.setChecked(self.useTabs())
        self.config_ui.useTabs.stateChanged.connect(parent.settingsModified)

        self.config_ui.show_tooltip.setChecked(self.get_show_toolip())
        self.config_ui.show_tooltip.stateChanged.connect(
            parent.settingsModified)

        self.config_ui.always_show_sources.setChecked(
            self.get_always_show_sources())
        self.config_ui.always_show_sources.stateChanged.connect(
            parent.settingsModified)

        self.config_ui.meter_visible.setChecked(self.is_meter_visible())
        self.config_ui.meter_visible.stateChanged.connect(
            parent.settingsModified)

        self.config_ui.expander_enabled.setChecked(self.is_expander_enabled())
        self.config_ui.expander_enabled.stateChanged.connect(
            parent.settingsModified)

        self.config_ui.unitvalues_visible.setChecked(
            self.is_slider_unit_value_visible())
        self.config_ui.unitvalues_visible.stateChanged.connect(
            parent.settingsModified)

        self.config_ui.version.setText(VeroMixPlasmoid.VERSION)
        parent.addPage(self.config_widget, i18n("Appearance"), "veromix")

        self.mediaplayer_settings_widget = QWidget(parent)
        self.mediaplayer_settings_ui = uic.loadUi(
            str(self.package().filePath('ui', 'nowplaying.ui')),
            self.mediaplayer_settings_widget)

        self.mediaplayer_settings_ui.mediaplayerBlacklist.setPlainText(
            self.get_mediaplayer_blacklist_string())
        self.mediaplayer_settings_ui.runningMediaplayers.setPlainText(
            self.get_running_mediaplayers())
        self.mediaplayer_settings_ui.runningMediaplayers.setReadOnly(True)

        self.mediaplayer_settings_ui.use_nowplaying.setChecked(
            self.is_nowplaying_enabled())
        self.mediaplayer_settings_ui.use_nowplaying.stateChanged.connect(
            self.update_mediaplayer_settings_ui)
        self.mediaplayer_settings_ui.use_nowplaying.stateChanged.connect(
            parent.settingsModified)

        self.mediaplayer_settings_ui.use_mpris2.setChecked(
            self.is_mpris2_enabled())
        self.mediaplayer_settings_ui.use_mpris2.stateChanged.connect(
            self.update_mediaplayer_settings_ui)
        self.mediaplayer_settings_ui.use_mpris2.stateChanged.connect(
            parent.settingsModified)

        self.mediaplayer_settings_ui.show_albumart.setChecked(
            self.is_albumart_enabled())
        self.mediaplayer_settings_ui.show_albumart.stateChanged.connect(
            parent.settingsModified)

        parent.addPage(self.mediaplayer_settings_widget,
                       i18n("Media Player Controls"), "veromix")

        #self.about_widget = QWidget(parent)
        #self.about_ui = uic.loadUi(str(self.package().filePath('ui', 'about.ui')), self.about_widget)
        #self.about_ui.version.setText(VeroMixPlasmoid.VERSION)
        #parent.addPage(self.about_widget, "About", "help-about")
        self.add_audio_settings(parent)
        self.add_ladspa_settings(parent)
        self.add_global_shortcut_page(parent)

        # FIXME KDE 4.6 workaround
        self.connect(parent, SIGNAL("okClicked()"), self.configChanged)
        self.connect(parent, SIGNAL("applyClicked()"), self.configChanged)
        self.connect(parent, SIGNAL("cancelClicked()"), self.configDenied)
        return self.config_widget

    def add_audio_settings(self, dialog):
        self.audio_settings_page = QWidget()
        layout = QGridLayout()
        self.audio_settings_page.setLayout(layout)

        self.max_volume_spinbox = QSpinBox()
        self.max_volume_spinbox.setRange(1, 255)
        self.max_volume_spinbox.setSingleStep(1)
        self.max_volume_spinbox.setValue(self.get_max_volume_value())
        self.max_volume_spinbox.valueChanged.connect(dialog.settingsModified)
        layout.addWidget(QLabel(i18n("Max volume value")), 0, 0)
        layout.addWidget(self.max_volume_spinbox, 0, 1)

        self.automute_checkbox = QCheckBox()
        self.automute_checkbox.setChecked(self.get_auto_mute())
        self.automute_checkbox.stateChanged.connect(dialog.settingsModified)
        layout.addWidget(QLabel(i18n("Mute if volume reaches zero")), 1, 0)
        layout.addWidget(self.automute_checkbox, 1, 1)

        layout.addItem(
            QSpacerItem(0, 20, QSizePolicy.Minimum, QSizePolicy.Fixed), 2, 0)
        layout.addWidget(QLabel("<b>" + i18n("Sound Card Profiles") + "</b>"),
                         3, 0)
        index = 4
        self.card_settings = {}
        for card in self.widget.card_infos.values():
            combo = QComboBox()
            #self.automute_checkbox.setChecked(self.get_auto_mute())
            #print card.properties
            layout.addWidget(
                QLabel(card.properties[dbus.String("device.description")]),
                index, 0)
            layout.addWidget(combo, index, 1)
            index = index + 1

            self.card_settings[combo] = card
            profiles = card.get_profiles()
            active = card.get_active_profile_name()
            active_index = 0
            for profile in profiles:
                combo.addItem(profile.description)
                if active == profile.name:
                    active_index = profiles.index(profile)
            combo.setCurrentIndex(active_index)

        layout.addItem(
            QSpacerItem(0, 0, QSizePolicy.Minimum, QSizePolicy.Expanding),
            index, 0)
        dialog.addPage(self.audio_settings_page, i18n("Pulseaudio"),
                       "preferences-desktop-sound")

    def add_ladspa_settings(self, dialog):
        self.ladspa_settings_page = QWidget()
        layout = QGridLayout()
        self.ladspa_settings_page.setLayout(layout)

        text = i18n(
            "LADSPA is a standard for handling audio filters and effects. Every linux software archive offers a large number of effects - search for LADSPA to get more.\
            Not every effect is supported by Pulseaudio and others simple don't make sense (or create only noise).<br/><br/>\
            The following list shows all available effects on your system: Only checked effects will appear in the context-menu."
        )

        if not LADSPAEffects().ladspa_sdk_available():
            text = text + i18n(
                "<br/><br/><b>Warning:</b> Cannot find the executables 'listplugins' and 'analyseplugin' which are required for dynamically detecting installed effects.<br/>\
               In OpenSUSE, Fedora and Arch Linux the package is named 'ladspa', in Debian/Ubuntu 'ladspa-sdk'.<br/><br/>"
            )

        ladspa_intro = QLabel(text)

        ladspa_intro.setWordWrap(True)
        layout.addWidget(ladspa_intro, 0, 0)

        self.ladspa_enabled_checkbox = QCheckBox()
        self.ladspa_enabled_checkbox.setText(i18n("Enable LADSPA effects."))
        self.ladspa_enabled_checkbox.setChecked(self.is_ladspa_enabled())
        self.ladspa_enabled_checkbox.stateChanged.connect(
            dialog.settingsModified)
        layout.addWidget(self.ladspa_enabled_checkbox, 1, 0)

        self.effects_list_widget = QListWidget()
        layout.addWidget(self.effects_list_widget, 2, 0)
        self.effects_list_widget.itemClicked.connect(dialog.settingsModified)

        blacklisted = LADSPAEffects().blacklist()
        effects = LADSPAEffects().all_effects()
        for effect in effects:
            item = QListWidgetItem(effect["preset_name"])
            item.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled)
            if effect["preset_name"] in blacklisted:
                item.setCheckState(Qt.Unchecked)
            else:
                item.setCheckState(Qt.Checked)
            self.effects_list_widget.addItem(item)

        layout.addItem(
            QSpacerItem(0, 0, QSizePolicy.Minimum, QSizePolicy.Expanding), 3,
            0)
        dialog.addPage(self.ladspa_settings_page, i18n("Effects / Equalizer"),
                       "preferences-desktop-sound")

    # anybody knows how to remove/extend the default shortcuts page?
    def add_global_shortcut_page(self, dialog):
        self.kb_settings_page = QWidget()

        layout = QGridLayout()
        self.kb_settings_page.setLayout(layout)

        self.louder_action_editor = KKeySequenceWidget()
        self.louder_action_editor.setKeySequence(
            self.louder_action.globalShortcut().primary())
        self.louder_action_editor.keySequenceChanged.connect(
            dialog.settingsModified)
        layout.addWidget(QLabel(i18n("Veromix volume up")), 0, 0)
        layout.addWidget(self.louder_action_editor, 0, 1)

        self.lower_action_editor = KKeySequenceWidget()
        self.lower_action_editor.setKeySequence(
            self.lower_action.globalShortcut().primary())
        self.lower_action_editor.keySequenceChanged.connect(
            dialog.settingsModified)
        layout.addWidget(QLabel(i18n("Veromix volume down")), 1, 0)
        layout.addWidget(self.lower_action_editor, 1, 1)

        self.mute_action_editor = KKeySequenceWidget()
        self.mute_action_editor.setKeySequence(
            self.mute_action.globalShortcut().primary())
        self.mute_action_editor.keySequenceChanged.connect(
            dialog.settingsModified)
        layout.addWidget(QLabel(i18n("Veromix toggle  mute")), 2, 0)
        layout.addWidget(self.mute_action_editor, 2, 1)

        layout.addItem(
            QSpacerItem(0, 0, QSizePolicy.Minimum, QSizePolicy.Expanding), 3,
            0)
        dialog.addPage(self.kb_settings_page,
                       i18n("Volume Keyboard Shortcuts"),
                       "preferences-desktop-keyboard")

    def configDenied(self):
        self.apply_nowplaying(self.is_nowplaying_enabled())
        self.apply_mpris2(self.is_mpris2_enabled())

    def configChanged(self):
        if self.config_ui:
            self.config().writeEntry(
                "background",
                str(self.config_ui.showBackground.currentIndex()))
            self.config().writeEntry(
                "popupMode", str(self.config_ui.popupMode.currentIndex()))
            tabs = self.useTabs()
            self.config().writeEntry("useTabs",
                                     bool(self.config_ui.useTabs.isChecked()))
            self.config().writeEntry(
                "show_tooltip", bool(self.config_ui.show_tooltip.isChecked()))
            self.config().writeEntry(
                "always_show_sources",
                bool(self.config_ui.always_show_sources.isChecked()))

            self.config().writeEntry(
                "meter_visible",
                bool(self.config_ui.meter_visible.isChecked()))
            self.config().writeEntry(
                "expander_enabled",
                bool(self.config_ui.expander_enabled.isChecked()))
            self.config().writeEntry(
                "unitvalues_visible",
                bool(self.config_ui.unitvalues_visible.isChecked()))

            self.config().writeEntry(
                "use_nowplaying",
                str(self.mediaplayer_settings_ui.use_nowplaying.isChecked()))
            self.config().writeEntry(
                "use_mpris2",
                str(self.mediaplayer_settings_ui.use_mpris2.isChecked()))
            self.config().writeEntry(
                "show_albumart",
                str(self.mediaplayer_settings_ui.show_albumart.isChecked()))

            #self.config().writeEntry("mpris2List",str(self.mediaplayer_settings_ui.mpris2List.toPlainText()).strip())
            self.config().writeEntry(
                "nowplayingBlacklist",
                str(self.mediaplayer_settings_ui.mediaplayerBlacklist.
                    toPlainText()).strip())

            self.config().writeEntry("max_volume",
                                     str(self.max_volume_spinbox.value()))
            self.config().writeEntry("auto_mute",
                                     str(self.automute_checkbox.isChecked()))

            self.config().writeEntry(
                "ladspa_enabled",
                str(self.ladspa_enabled_checkbox.isChecked()))
            self.ladspa_save_effects_blacklist()
            if tabs != self.useTabs():
                self.widget.switchView()
        self.applyConfig()
        self.widget.on_update_configuration()

    def update_mediaplayer_settings_ui(self):
        enable = (self.mediaplayer_settings_ui.use_nowplaying.isChecked()
                  or self.mediaplayer_settings_ui.use_mpris2.isChecked())
        self.mediaplayer_settings_ui.mediaplayerBlacklist.setEnabled(enable)
        self.mediaplayer_settings_ui.mediaplayerBlacklistLabel.setEnabled(
            enable)
        self.mediaplayer_settings_ui.runningMediaplayers.setEnabled(enable)
        self.mediaplayer_settings_ui.runningMediaplayersLabel.setEnabled(
            enable)
        self.mediaplayer_settings_ui.runningMediaplayers.setPlainText(
            self.get_running_mediaplayers())
        self.mediaplayer_settings_ui.show_albumart.setEnabled(enable)

    def apply_nowplaying(self, enabled):
        self.disable_nowplaying()
        if enabled:
            self.init_nowplaying()

    def apply_mpris2(self, enabled):
        self.widget.pa.disable_mpris2()
        self.remove_mpris2_widgets()
        if enabled:
            self.widget.pa.enable_mpris2()
            self.init_running_mpris2()

    def applyConfig(self):
        self.apply_nowplaying(self.is_nowplaying_enabled())
        self.apply_mpris2(self.is_mpris2_enabled())

        if self.formFactor() == Plasma.Planar:
            bg = self.config().readEntry("background", "2").toInt()[0]
            if bg == 0:
                self.setBackgroundHints(Plasma.Applet.NoBackground)
            elif bg == 1:
                self.setBackgroundHints(Plasma.Applet.TranslucentBackground)
            else:
                self.setBackgroundHints(Plasma.Applet.StandardBackground)

        mode = self.config().readEntry("popupMode", False).toInt()[0]
        if mode == 0:
            self.setPassivePopup(False)
        elif mode == 1:
            self.setPassivePopup(True)
        else:
            self.setPassivePopup(True)

        if self.louder_action_editor:
            sequence = self.louder_action_editor.keySequence()
            if sequence != self.louder_action.globalShortcut().primary():
                self.louder_action.setGlobalShortcut(KShortcut(sequence),
                                                     KAction.ActiveShortcut,
                                                     KAction.NoAutoloading)
        if self.lower_action_editor:
            sequence = self.lower_action_editor.keySequence()
            if sequence != self.lower_action.globalShortcut().primary():
                self.lower_action.setGlobalShortcut(KShortcut(sequence),
                                                    KAction.ActiveShortcut,
                                                    KAction.NoAutoloading)
        if self.mute_action_editor:
            sequence = self.mute_action_editor.keySequence()
            if sequence != self.mute_action.globalShortcut().primary():
                self.mute_action.setGlobalShortcut(KShortcut(sequence),
                                                   KAction.ActiveShortcut,
                                                   KAction.NoAutoloading)

        if self.card_settings:
            for combo in self.card_settings.keys():
                card = self.card_settings[combo]
                for profile in card.profiles:
                    if combo.currentText() == profile.description:
                        self.widget.pa.set_card_profile(
                            card.index, profile.name)

        self.update()

    def configWidgetDestroyed(self):
        self.config_widget = None
        self.config_ui = None

    def useTabs(self):
        return self.config().readEntry("useTabs", False).toBool()

    def is_meter_visible(self):
        return self.config().readEntry("meter_visible", False).toBool()

    def get_auto_mute(self):
        return self.config().readEntry("auto_mute", False).toBool()

    def get_show_toolip(self):
        return self.config().readEntry("show_tooltip", True).toBool()

    def get_always_show_sources(self):
        return self.config().readEntry("always_show_sources", False).toBool()

    def get_max_volume_value(self):
        default = 100
        return self.config().readEntry("max_volume", default).toInt()[0]

    def is_slider_unit_value_visible(self):
        return self.config().readEntry("unitvalues_visible", False).toBool()

    def is_ladspa_enabled(self):
        return self.config().readEntry("ladspa_enabled", True).toBool()

    def ladspa_save_effects_blacklist(self):
        blacklisted = []
        for i in range(0, self.effects_list_widget.count()):
            item = self.effects_list_widget.item(i)
            if not item.checkState():
                blacklisted.append(str(item.text()))
        LADSPAEffects().write_blacklist(blacklisted)

### now playing

    def is_nowplaying_enabled(self):
        return self.config().readEntry("use_nowplaying", False).toBool()

    def is_mpris2_enabled(self):
        return self.config().readEntry("use_mpris2", True).toBool()

    def is_albumart_enabled(self):
        return self.config().readEntry("show_albumart", True).toBool()

    def is_expander_enabled(self):
        return self.config().readEntry("expander_enabled", True).toBool()

    def disable_nowplaying(self):
        for player in self.widget.get_mediaplayer_widgets():
            if player.is_nowplaying_player():
                self.on_nowplaying_player_removed(player.controller_name())
        self.now_playing_engine = None

    def remove_mpris2_widgets(self):
        for player in self.widget.get_mediaplayer_widgets():
            if player.is_mpris2_player():
                self.on_mpris2_removed(player.controller_name())

    def init_nowplaying(self):
        self.now_playing_engine = self.dataEngine('nowplaying')
        self.connect(self.now_playing_engine, SIGNAL('sourceAdded(QString)'),
                     self.on_nowplaying_player_added)
        self.connect(self.now_playing_engine, SIGNAL('sourceRemoved(QString)'),
                     self.on_nowplaying_player_removed)
        self.connect_to_nowplaying_engine()

    def init_running_mpris2(self):
        for controller in self.widget.pa.get_mpris2_players():
            v = controller.name()
            if self.in_mediaplayer_blacklist(v):
                return
            self.nowplaying_player_added.emit(controller.name(), controller)

    def connect_to_nowplaying_engine(self):
        # get sources and connect
        for source in self.now_playing_engine.sources():
            self.on_nowplaying_player_added(source)

    def on_nowplaying_player_added(self, player):
        if player == "players":
            # FIXME 4.6 workaround
            return
        if self.in_mediaplayer_blacklist(player):
            return
        self.now_playing_engine.disconnectSource(player, self)
        self.now_playing_engine.connectSource(player, self, 2000)
        controller = self.now_playing_engine.serviceForSource(player)
        self.nowplaying_player_added.emit(
            player, NowPlayingController(self.widget, controller))

    def in_mediaplayer_blacklist(self, player):
        for entry in self.get_mediaplayer_blacklist():
            if str(player).find(entry) == 0:
                return True
        return False

    def on_nowplaying_player_removed(self, player):
        if self.now_playing_engine:
            self.now_playing_engine.disconnectSource(player, self)
            self.nowplaying_player_removed.emit(player)

    def on_mpris2_removed(self, player):
        self.nowplaying_player_removed.emit(player)

    def get_running_mediaplayers(self):
        val = "nowplaying:\n"
        engine = self.now_playing_engine
        if engine == None:
            engine = self.dataEngine('nowplaying')
        for source in engine.sources():
            val += source + "\n"
        val += "\nmpris2:\n"
        for controller in self.widget.pa.get_mpris2_players():
            val += controller.name() + "\n"
        return val

    def get_mediaplayer_blacklist(self):
        return self.get_mediaplayer_blacklist_string().split("\n")

    def get_mediaplayer_blacklist_string(self):
        default = "org.mpris.bangarang"
        return self.config().readEntry("nowplayingBlacklist",
                                       default).toString()

    @pyqtSignature(
        'dataUpdated(const QString&, const Plasma::DataEngine::Data&)')
    def dataUpdated(self, sourceName, data):
        self.nowplaying_player_dataUpdated.emit(sourceName, data)


## Modal Widget

    def showModalWidget(self, mainWidget):
        #mainWidget.widgetClose.connect(self.destroyMessageOverlay)
        if self.messageOverlay:
            return
        if self.messageDialog:
            return

        corona = self.scene()
        mainWidget.adjustSize()
        hint = mainWidget.preferredSize()
        if (hint.height() > self.widget.size().height()) or (
                hint.width() > self.widget.size().width()):
            ## either a collapsed popup in h/v form factor or just too small,
            ## so show it in a dialog associated with ourselves
            #pass
            if (corona):
                corona.addOffscreenWidget(mainWidget)

            if (self.messageDialog):
                pass
            else:
                self.messageDialog = Plasma.Dialog()

            self.messageDialog.setGraphicsWidget(mainWidget)
            mainWidget.setParentItem(self.messageDialog.graphicsWidget())
        else:
            self.messageOverlay = self.createMessageOverlay()
            self.formatOverlay()
            self.messageOverlay.opacity = 0.8
            mainWidget.setParentItem(self.messageOverlay)
            l = QGraphicsLinearLayout(self.messageOverlay)
            l.addItem(mainWidget)

        if self.messageDialog:
            pos = self.geometry().topLeft().toPoint()
            if (corona):
                pos = corona.popupPosition(self.applet,
                                           self.messageDialog.size())

            self.messageDialog.move(pos)
            #self.locationToDirection(self.location())
            self.messageDialog.animatedShow(Plasma.Direction(0))
            self.hidePopup()
        else:
            self.messageOverlay.show()

    def createMessageOverlay(self):
        if self.messageOverlay == None:
            messageOverlay = QGraphicsWidget(self.widget)
            return messageOverlay

    def formatOverlay(self):
        self.messageOverlay.resize(self.widget.contentsRect().size())
        self.messageOverlay.setPos(self.widget.contentsRect().topLeft())

        zValue = 100
        for child in self.widget.children():
            if (child.zValue() > zValue):
                zValue = child.zValue() + 1
        self.messageOverlay.setZValue(zValue)

    def destroyMessageOverlay(self):
        if self.messageDialog != None:
            #Plasma::locationToInverseDirection(q->location())
            self.messageDialog.animatedHide(Plasma.Direction(0))
            self.messageDialog.deleteLater()
            self.messageDialog.hide()
            self.messageDialog = None
            self.showPopup(0)

        if self.messageOverlay == None:
            return

        self.messageOverlay.hide()
        self.messageOverlay = None
예제 #5
0
    def create_toolbar(self):

        self.toolbar = KToolBar(self, True, True)
        self.toolbar.setIconDimensions(16)
        self.toolbar.setAllowedAreas(QtCore.Qt.BottomToolBarArea)
        self.toolbar.setMovable(False)
        self.toolbar.setFloatable(False)
        self.toolbar.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)
        self.addToolBar(QtCore.Qt.BottomToolBarArea, self.toolbar)

        self.toolbar.show()
        self.action_collection = KActionCollection(self)
        self.action_collection.addAssociatedWidget(self.toolbar)

        self.clear_live_action = self.action_collection.addAction(
            "clear_live_action")
        icon = QtGui.QIcon(":texter/images/edit-clear.png")
        self.clear_live_action.setIcon(icon)
        self.clear_live_action.setIconText("clear live")
        self.clear_live_action.setShortcut(
            KShortcut(QtGui.QKeySequence(QtCore.Qt.ALT + QtCore.Qt.Key_Q)),
            KAction.ShortcutTypes(KAction.ActiveShortcut
                                  | KAction.DefaultShortcut))

        self.save_live_action = self.action_collection.addAction(
            "save_live_action")
        icon = QtGui.QIcon(":texter/images/document-new.png")
        self.save_live_action.setIcon(icon)
        self.save_live_action.setIconText("save live")
        self.save_live_action.setShortcut(
            KShortcut(QtGui.QKeySequence(QtCore.Qt.ALT + QtCore.Qt.Key_W)),
            KAction.ShortcutTypes(KAction.ActiveShortcut
                                  | KAction.DefaultShortcut))

        self.clear_preview_action = self.action_collection.addAction(
            "clear_preview_action")
        icon = QtGui.QIcon(":texter/images/edit-clear.png")
        self.clear_preview_action.setIcon(icon)
        self.clear_preview_action.setIconText("clear preview")
        self.clear_preview_action.setShortcut(
            KShortcut(QtGui.QKeySequence(QtCore.Qt.ALT + QtCore.Qt.Key_A)),
            KAction.ShortcutTypes(KAction.ActiveShortcut
                                  | KAction.DefaultShortcut))

        self.save_preview_action = self.action_collection.addAction(
            "save_preview_action")
        icon = QtGui.QIcon(":texter/images/document-new.png")
        self.save_preview_action.setIcon(icon)
        self.save_preview_action.setIconText("save preview")
        self.save_preview_action.setShortcut(
            KShortcut(QtGui.QKeySequence(QtCore.Qt.ALT + QtCore.Qt.Key_S)),
            KAction.ShortcutTypes(KAction.ActiveShortcut
                                  | KAction.DefaultShortcut))

        self.publish_action = self.action_collection.addAction(
            "publish_action")
        icon = QtGui.QIcon(":texter/images/edit-copy.png")
        self.publish_action.setIcon(icon)
        self.publish_action.setIconText("publish")
        self.publish_action.setShortcutConfigurable(True)
        self.publish_action.setShortcut(
            KShortcut(QtGui.QKeySequence(QtCore.Qt.ALT +
                                         QtCore.Qt.Key_Return)),
            KAction.ShortcutTypes(KAction.ActiveShortcut
                                  | KAction.DefaultShortcut))

        self.toolbar.insertSeparator(self.publish_action)

        self.auto_publish_action = KToggleAction(self.action_collection)
        self.action_collection.addAction("auto publish",
                                         self.auto_publish_action)
        icon = QtGui.QIcon(":texter/images/view-refresh.png")
        self.auto_publish_action.setIcon(icon)
        self.auto_publish_action.setObjectName("auto_publish_action")
        self.auto_publish_action.setIconText("auto publish")
        self.auto_publish_action.setShortcut(
            KShortcut(QtGui.QKeySequence(QtCore.Qt.ALT + QtCore.Qt.Key_P)),
            KAction.ShortcutTypes(KAction.ActiveShortcut
                                  | KAction.DefaultShortcut))

        self.typer_animation_action = KToggleAction(self.action_collection)
        icon = QtGui.QIcon(":texter/images/media-playback-stop.png")
        self.typer_animation_action.setIcon(icon)
        self.typer_animation_action.setIconText("animate")
        self.typer_animation_action.setObjectName("typer_animation_action")
        self.typer_animation_action.setShortcut(
            KShortcut(QtGui.QKeySequence(QtCore.Qt.ALT + QtCore.Qt.Key_M)),
            KAction.ShortcutTypes(KAction.ActiveShortcut
                                  | KAction.DefaultShortcut))
        self.action_collection.addAction("typer_animation_action",
                                         self.typer_animation_action)

        self.text_editor_action = self.action_collection.addAction(
            "text_editor_action")
        icon = QtGui.QIcon(":texter/images/document-open-data.png")
        self.text_editor_action.setIcon(icon)
        self.text_editor_action.setIconText("edit")
        self.text_editor_action.setShortcut(
            KShortcut(QtGui.QKeySequence(QtCore.Qt.CTRL + QtCore.Qt.Key_O)),
            KAction.ShortcutTypes(KAction.ActiveShortcut
                                  | KAction.DefaultShortcut))

        self.toolbar.insertSeparator(self.text_editor_action)

        self.save_action = self.action_collection.addAction("save_action")
        icon = QtGui.QIcon(":texter/images/document-save.png")
        self.save_action.setIcon(icon)
        self.save_action.setIconText("save")
        self.save_action.setShortcut(
            KShortcut(QtGui.QKeySequence(QtCore.Qt.CTRL + QtCore.Qt.Key_S)),
            KAction.ShortcutTypes(KAction.ActiveShortcut
                                  | KAction.DefaultShortcut))

        self.streaming_action = KToggleAction(self.action_collection)
        icon = QtGui.QIcon(":texter/images/media-record.png")
        self.streaming_action.setIcon(icon)
        self.streaming_action.setIconText("stream")
        self.streaming_action.setObjectName("stream")
        self.streaming_action.setShortcut(
            KShortcut(QtGui.QKeySequence(QtCore.Qt.CTRL + QtCore.Qt.Key_1)),
            KAction.ShortcutTypes(KAction.ActiveShortcut
                                  | KAction.DefaultShortcut))
        self.action_collection.addAction("stream", self.streaming_action)

        spacer = KToolBarSpacerAction(self.action_collection)
        self.action_collection.addAction("1_spacer", spacer)

        self.previous_action = self.action_collection.addAction(
            "previous_action")
        icon = QtGui.QIcon(":texter/images/go-previous-view-page.png")
        self.previous_action.setIcon(icon)
        self.previous_action.setIconText("previous")
        self.previous_action.setShortcut(
            KShortcut(QtGui.QKeySequence(QtCore.Qt.ALT + QtCore.Qt.Key_Left)),
            KAction.ShortcutTypes(KAction.ActiveShortcut
                                  | KAction.DefaultShortcut))

        self.text_combo = KSelectAction(self.action_collection)
        self.text_combo.setEditable(False)
        icon = QtGui.QIcon(":texter/images/document-open-recent.png")
        self.text_combo.setIcon(icon)
        self.text_combo.setIconText("saved texts")
        self.text_combo.setObjectName("text_combo")
        self.action_collection.addAction("saved texts", self.text_combo)

        self.next_action = self.action_collection.addAction("next_action")
        icon = QtGui.QIcon(":texter/images/go-next-view-page.png")
        self.next_action.setIcon(icon)
        self.next_action.setIconText("next")
        self.next_action.setShortcut(
            KShortcut(QtGui.QKeySequence(QtCore.Qt.ALT + QtCore.Qt.Key_Right)),
            KAction.ShortcutTypes(KAction.ActiveShortcut
                                  | KAction.DefaultShortcut))

        self.toolbar.addSeparator()

        self.save_action.triggered.connect(self.slot_save)

        self.publish_action.triggered.connect(self.slot_publish)
        self.clear_live_action.triggered.connect(self.slot_clear_live)
        self.clear_preview_action.triggered.connect(self.slot_clear_preview)
        self.text_combo.triggered[int].connect(self.slot_load_preview_text)
        self.text_editor_action.triggered.connect(self.slot_open_dialog)
        self.save_live_action.triggered.connect(self.slot_save_live_text)
        self.save_preview_action.triggered.connect(self.slot_save_preview_text)
        self.streaming_action.triggered.connect(self.slot_toggle_streaming)
        self.auto_publish_action.toggled.connect(self.slot_auto_publish)
        self.typer_animation_action.toggled.connect(self.slot_toggle_animation)
        self.preview_size_action.triggered[QtGui.QAction].connect(
            self.slot_preview_font_size)
        self.live_size_action.triggered[QtGui.QAction].connect(
            self.slot_live_font_size)

        self.next_action.triggered.connect(self.slot_next_item)
        self.previous_action.triggered.connect(self.slot_previous_item)
        self.streaming_action.setChecked(True)
예제 #6
0
    def __init__(self, args, parent=None):
        self.args = args
        #super(MainWindow, self).__init__()
        #PsyQtClientBase.__init__(self)
        KMainWindow.__init__(self, parent)
        self.is_streaming = False

        self.live_center_action = None
        self.preview_center_action = None
        self.live_size_action = None
        self.preview_font_action = None
        self.live_font_action = None
        self.preview_size_action = None
        self.default_size = 28
        self.default_align_text = "format_align_center"
        self.preview_actions = list()
        self.live_actions = list()
        self.current = 0
        self.model = TextModel(self)
        self.animation = TextAnimation(self)
        self.db_dirty = False
        self.is_animate = False
        self.fade_animation = None
        self.dialog = None
        self.current_object = None
        self.current_index = -1

        self.is_auto_publish = False

        self.setupUi(self)
        self.win_id = self.live_text.winId()

        self.fps = 12.5
        self.http_server = MjpegStreamingServer(
            (args.http_host, args.http_port), self, self.fps)

        self.live_text.setLineWrapMode(
            QtGui.QTextEdit.LineWrapMode(QtGui.QTextEdit.FixedPixelWidth))
        self.live_text.setLineWrapColumnOrWidth(768)

        self.font = QtGui.QFont("monospace", self.default_size)
        self.font.setStyleHint(QtGui.QFont.TypeWriter)

        self.previous_action = None
        self.next_action = None
        self.publish_action = None
        self.auto_publish_action = None
        self.save_live_action = None
        self.save_preview_action = None
        self.save_action = None
        self.dialog_widget = None
        self.action_collection = None
        self.streaming_action = None
        self.text_combo = None
        self.clear_live_action = None
        self.clear_preview_action = None
        self.toolbar = None
        self.typer_animation_action = None
        self.text_editor_action = None

        self.preview_text.setFont(self.font)
        self.preview_text.setRichTextSupport(
            KRichTextWidget.RichTextSupport(0xffffffff))
        self.preview_editor_collection = KActionCollection(self)
        self.preview_text.createActions(self.preview_editor_collection)

        self.live_text.setRichTextSupport(
            KRichTextWidget.RichTextSupport(0xffffffff))
        self.live_text.setFont(self.font)
        self.live_editor_collection = KActionCollection(self)
        self.live_text.createActions(self.live_editor_collection)
        self.filter_editor_actions()
        self.create_toolbar()
        self.slot_load()

        qtapp.focusChanged.connect(self.focusChanged)
        self.start_streaming()

        self.show()
        timer = QtCore.QTimer()
        timer.start(2000)
        timer.timeout.connect(lambda: None)
예제 #7
0
class MainWindow(KMainWindow, Ui_MainWindow, MjpegStreamingConsumerInterface):
    def __init__(self, args, parent=None):
        self.args = args
        #super(MainWindow, self).__init__()
        #PsyQtClientBase.__init__(self)
        KMainWindow.__init__(self, parent)
        self.is_streaming = False

        self.live_center_action = None
        self.preview_center_action = None
        self.live_size_action = None
        self.preview_font_action = None
        self.live_font_action = None
        self.preview_size_action = None
        self.default_size = 28
        self.default_align_text = "format_align_center"
        self.preview_actions = list()
        self.live_actions = list()
        self.current = 0
        self.model = TextModel(self)
        self.animation = TextAnimation(self)
        self.db_dirty = False
        self.is_animate = False
        self.fade_animation = None
        self.dialog = None
        self.current_object = None
        self.current_index = -1

        self.is_auto_publish = False

        self.setupUi(self)
        self.win_id = self.live_text.winId()

        self.fps = 12.5
        self.http_server = MjpegStreamingServer(
            (args.http_host, args.http_port), self, self.fps)

        self.live_text.setLineWrapMode(
            QtGui.QTextEdit.LineWrapMode(QtGui.QTextEdit.FixedPixelWidth))
        self.live_text.setLineWrapColumnOrWidth(768)

        self.font = QtGui.QFont("monospace", self.default_size)
        self.font.setStyleHint(QtGui.QFont.TypeWriter)

        self.previous_action = None
        self.next_action = None
        self.publish_action = None
        self.auto_publish_action = None
        self.save_live_action = None
        self.save_preview_action = None
        self.save_action = None
        self.dialog_widget = None
        self.action_collection = None
        self.streaming_action = None
        self.text_combo = None
        self.clear_live_action = None
        self.clear_preview_action = None
        self.toolbar = None
        self.typer_animation_action = None
        self.text_editor_action = None

        self.preview_text.setFont(self.font)
        self.preview_text.setRichTextSupport(
            KRichTextWidget.RichTextSupport(0xffffffff))
        self.preview_editor_collection = KActionCollection(self)
        self.preview_text.createActions(self.preview_editor_collection)

        self.live_text.setRichTextSupport(
            KRichTextWidget.RichTextSupport(0xffffffff))
        self.live_text.setFont(self.font)
        self.live_editor_collection = KActionCollection(self)
        self.live_text.createActions(self.live_editor_collection)
        self.filter_editor_actions()
        self.create_toolbar()
        self.slot_load()

        qtapp.focusChanged.connect(self.focusChanged)
        self.start_streaming()

        self.show()
        timer = QtCore.QTimer()
        timer.start(2000)
        timer.timeout.connect(lambda: None)

    def pubdir(self):
        return os.path.dirname(os.path.abspath(__file__))

    def getPreviewCoords(self):
        public_rect = self.preview_text.geometry()
        global_rect = QtCore.QRect(self.mapToGlobal(public_rect.topLeft()),
                                   self.mapToGlobal(public_rect.bottomRight()))
        return global_rect.x(), global_rect.y()

    def render_image(self):
        public_rect = self.live_text_rect()
        #global_rect = QtCore.QRect(self.mapToGlobal(public_rect.topLeft()), self.mapToGlobal(public_rect.bottomRight()))
        pixmap = QPixmap.grabWindow(self.win_id,
                                    public_rect.x() + 1,
                                    public_rect.y() + 1, 768, 576)
        buf = QBuffer()
        buf.open(QIODevice.WriteOnly)
        pixmap.save(buf, "JPG", 75)
        return buf.data()

    def filter_editor_actions(self):
        disabled_action_names = [
            "action_to_plain_text", "format_painter", "direction_ltr",
            "direction_rtl", "format_font_family",
            "format_text_background_color", "format_list_style",
            "format_list_indent_more", "format_list_indent_less",
            "format_text_bold", "format_text_underline",
            "format_text_strikeout", "format_text_italic",
            "format_align_right", "manage_link", "format_text_subscript",
            "format_text_superscript", "insert_horizontal_rule"
        ]

        for action in self.live_editor_collection.actions():
            text = str(action.objectName())
            if text in disabled_action_names:
                action.setVisible(False)

            if text == self.default_align_text:
                self.live_center_action = action
            elif text == "format_font_size":
                self.live_size_action = action
            elif text == "format_font_family":
                self.live_font_action = action

        for action in self.preview_editor_collection.actions():
            text = str(action.objectName())
            if text in disabled_action_names:
                action.setVisible(False)

            if text == self.default_align_text:
                self.preview_center_action = action
            elif text == "format_font_size":
                self.preview_size_action = action
            elif text == "format_font_family":
                self.preview_font_action = action

        self.slot_set_preview_defaults()
        self.slot_set_live_defaults()

    def create_toolbar(self):

        self.toolbar = KToolBar(self, True, True)
        self.toolbar.setIconDimensions(16)
        self.toolbar.setAllowedAreas(QtCore.Qt.BottomToolBarArea)
        self.toolbar.setMovable(False)
        self.toolbar.setFloatable(False)
        self.toolbar.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)
        self.addToolBar(QtCore.Qt.BottomToolBarArea, self.toolbar)

        self.toolbar.show()
        self.action_collection = KActionCollection(self)
        self.action_collection.addAssociatedWidget(self.toolbar)

        self.clear_live_action = self.action_collection.addAction(
            "clear_live_action")
        icon = QtGui.QIcon(":texter/images/edit-clear.png")
        self.clear_live_action.setIcon(icon)
        self.clear_live_action.setIconText("clear live")
        self.clear_live_action.setShortcut(
            KShortcut(QtGui.QKeySequence(QtCore.Qt.ALT + QtCore.Qt.Key_Q)),
            KAction.ShortcutTypes(KAction.ActiveShortcut
                                  | KAction.DefaultShortcut))

        self.save_live_action = self.action_collection.addAction(
            "save_live_action")
        icon = QtGui.QIcon(":texter/images/document-new.png")
        self.save_live_action.setIcon(icon)
        self.save_live_action.setIconText("save live")
        self.save_live_action.setShortcut(
            KShortcut(QtGui.QKeySequence(QtCore.Qt.ALT + QtCore.Qt.Key_W)),
            KAction.ShortcutTypes(KAction.ActiveShortcut
                                  | KAction.DefaultShortcut))

        self.clear_preview_action = self.action_collection.addAction(
            "clear_preview_action")
        icon = QtGui.QIcon(":texter/images/edit-clear.png")
        self.clear_preview_action.setIcon(icon)
        self.clear_preview_action.setIconText("clear preview")
        self.clear_preview_action.setShortcut(
            KShortcut(QtGui.QKeySequence(QtCore.Qt.ALT + QtCore.Qt.Key_A)),
            KAction.ShortcutTypes(KAction.ActiveShortcut
                                  | KAction.DefaultShortcut))

        self.save_preview_action = self.action_collection.addAction(
            "save_preview_action")
        icon = QtGui.QIcon(":texter/images/document-new.png")
        self.save_preview_action.setIcon(icon)
        self.save_preview_action.setIconText("save preview")
        self.save_preview_action.setShortcut(
            KShortcut(QtGui.QKeySequence(QtCore.Qt.ALT + QtCore.Qt.Key_S)),
            KAction.ShortcutTypes(KAction.ActiveShortcut
                                  | KAction.DefaultShortcut))

        self.publish_action = self.action_collection.addAction(
            "publish_action")
        icon = QtGui.QIcon(":texter/images/edit-copy.png")
        self.publish_action.setIcon(icon)
        self.publish_action.setIconText("publish")
        self.publish_action.setShortcutConfigurable(True)
        self.publish_action.setShortcut(
            KShortcut(QtGui.QKeySequence(QtCore.Qt.ALT +
                                         QtCore.Qt.Key_Return)),
            KAction.ShortcutTypes(KAction.ActiveShortcut
                                  | KAction.DefaultShortcut))

        self.toolbar.insertSeparator(self.publish_action)

        self.auto_publish_action = KToggleAction(self.action_collection)
        self.action_collection.addAction("auto publish",
                                         self.auto_publish_action)
        icon = QtGui.QIcon(":texter/images/view-refresh.png")
        self.auto_publish_action.setIcon(icon)
        self.auto_publish_action.setObjectName("auto_publish_action")
        self.auto_publish_action.setIconText("auto publish")
        self.auto_publish_action.setShortcut(
            KShortcut(QtGui.QKeySequence(QtCore.Qt.ALT + QtCore.Qt.Key_P)),
            KAction.ShortcutTypes(KAction.ActiveShortcut
                                  | KAction.DefaultShortcut))

        self.typer_animation_action = KToggleAction(self.action_collection)
        icon = QtGui.QIcon(":texter/images/media-playback-stop.png")
        self.typer_animation_action.setIcon(icon)
        self.typer_animation_action.setIconText("animate")
        self.typer_animation_action.setObjectName("typer_animation_action")
        self.typer_animation_action.setShortcut(
            KShortcut(QtGui.QKeySequence(QtCore.Qt.ALT + QtCore.Qt.Key_M)),
            KAction.ShortcutTypes(KAction.ActiveShortcut
                                  | KAction.DefaultShortcut))
        self.action_collection.addAction("typer_animation_action",
                                         self.typer_animation_action)

        self.text_editor_action = self.action_collection.addAction(
            "text_editor_action")
        icon = QtGui.QIcon(":texter/images/document-open-data.png")
        self.text_editor_action.setIcon(icon)
        self.text_editor_action.setIconText("edit")
        self.text_editor_action.setShortcut(
            KShortcut(QtGui.QKeySequence(QtCore.Qt.CTRL + QtCore.Qt.Key_O)),
            KAction.ShortcutTypes(KAction.ActiveShortcut
                                  | KAction.DefaultShortcut))

        self.toolbar.insertSeparator(self.text_editor_action)

        self.save_action = self.action_collection.addAction("save_action")
        icon = QtGui.QIcon(":texter/images/document-save.png")
        self.save_action.setIcon(icon)
        self.save_action.setIconText("save")
        self.save_action.setShortcut(
            KShortcut(QtGui.QKeySequence(QtCore.Qt.CTRL + QtCore.Qt.Key_S)),
            KAction.ShortcutTypes(KAction.ActiveShortcut
                                  | KAction.DefaultShortcut))

        self.streaming_action = KToggleAction(self.action_collection)
        icon = QtGui.QIcon(":texter/images/media-record.png")
        self.streaming_action.setIcon(icon)
        self.streaming_action.setIconText("stream")
        self.streaming_action.setObjectName("stream")
        self.streaming_action.setShortcut(
            KShortcut(QtGui.QKeySequence(QtCore.Qt.CTRL + QtCore.Qt.Key_1)),
            KAction.ShortcutTypes(KAction.ActiveShortcut
                                  | KAction.DefaultShortcut))
        self.action_collection.addAction("stream", self.streaming_action)

        spacer = KToolBarSpacerAction(self.action_collection)
        self.action_collection.addAction("1_spacer", spacer)

        self.previous_action = self.action_collection.addAction(
            "previous_action")
        icon = QtGui.QIcon(":texter/images/go-previous-view-page.png")
        self.previous_action.setIcon(icon)
        self.previous_action.setIconText("previous")
        self.previous_action.setShortcut(
            KShortcut(QtGui.QKeySequence(QtCore.Qt.ALT + QtCore.Qt.Key_Left)),
            KAction.ShortcutTypes(KAction.ActiveShortcut
                                  | KAction.DefaultShortcut))

        self.text_combo = KSelectAction(self.action_collection)
        self.text_combo.setEditable(False)
        icon = QtGui.QIcon(":texter/images/document-open-recent.png")
        self.text_combo.setIcon(icon)
        self.text_combo.setIconText("saved texts")
        self.text_combo.setObjectName("text_combo")
        self.action_collection.addAction("saved texts", self.text_combo)

        self.next_action = self.action_collection.addAction("next_action")
        icon = QtGui.QIcon(":texter/images/go-next-view-page.png")
        self.next_action.setIcon(icon)
        self.next_action.setIconText("next")
        self.next_action.setShortcut(
            KShortcut(QtGui.QKeySequence(QtCore.Qt.ALT + QtCore.Qt.Key_Right)),
            KAction.ShortcutTypes(KAction.ActiveShortcut
                                  | KAction.DefaultShortcut))

        self.toolbar.addSeparator()

        self.save_action.triggered.connect(self.slot_save)

        self.publish_action.triggered.connect(self.slot_publish)
        self.clear_live_action.triggered.connect(self.slot_clear_live)
        self.clear_preview_action.triggered.connect(self.slot_clear_preview)
        self.text_combo.triggered[int].connect(self.slot_load_preview_text)
        self.text_editor_action.triggered.connect(self.slot_open_dialog)
        self.save_live_action.triggered.connect(self.slot_save_live_text)
        self.save_preview_action.triggered.connect(self.slot_save_preview_text)
        self.streaming_action.triggered.connect(self.slot_toggle_streaming)
        self.auto_publish_action.toggled.connect(self.slot_auto_publish)
        self.typer_animation_action.toggled.connect(self.slot_toggle_animation)
        self.preview_size_action.triggered[QtGui.QAction].connect(
            self.slot_preview_font_size)
        self.live_size_action.triggered[QtGui.QAction].connect(
            self.slot_live_font_size)

        self.next_action.triggered.connect(self.slot_next_item)
        self.previous_action.triggered.connect(self.slot_previous_item)
        self.streaming_action.setChecked(True)

    def closeEvent(self, event):
        logger.info("closeEvent")
        if self.db_dirty:
            self.dialog = KDialog(self)
            self.dialog.setCaption("4.48 texter - text db not saved")
            label = QtGui.QLabel(
                "The Text database is not saved. Do you want to save before exit?",
                self.dialog)
            self.dialog.setMainWidget(label)
            self.dialog.setButtons(
                KDialog.ButtonCodes(KDialog.Ok | KDialog.Cancel))
            self.dialog.okClicked.connect(self.slot_save)
            self.dialog.exec_()
        event.accept()

    def live_text_rect(self):
        return self.live_text.geometry()

    def stop_streaming(self):
        self.is_streaming = False
        self.http_server.stop()

    def start_streaming(self):
        self.http_server.listen(port=self.args.http_port)
        self.is_streaming = True

    def fill_combo_box(self):
        if self.dialog is not None:
            self.dialog.deleteLater()
            self.dialog = None

        self.text_combo.clear()
        current_row = -1
        for index, list_obj in enumerate(self.model.text_db):
            preview, text = list_obj
            self.text_combo.addAction(preview)
            if list_obj == self.current_object:
                current_row = index

        if current_row == -1:
            current_row = self.current_index
            self.slot_load_preview_text(current_row)
        self.text_combo.setCurrentItem(current_row)

    def focusChanged(self, old, new):
        if new == self.preview_text:
            self.live_editor_collection.clearAssociatedWidgets()
            self.preview_editor_collection.addAssociatedWidget(self.toolbar)
        elif new == self.live_text:
            self.preview_editor_collection.clearAssociatedWidgets()
            self.live_editor_collection.addAssociatedWidget(self.toolbar)

    def slot_auto_publish(self, state):
        self.is_auto_publish = bool(state)

    def slot_toggle_animation(self, state):
        self.is_animate = bool(state)

    def slot_toggle_streaming(self):
        if self.is_streaming:
            self.stop_streaming()
        else:
            self.start_streaming()

    def slot_next_item(self):
        try:
            self.current = (self.text_combo.currentItem() + 1) % len(
                self.model.text_db)
            self.text_combo.setCurrentItem(self.current)
            self.slot_load_preview_text(self.current)
        except ZeroDivisionError:
            pass

    def slot_previous_item(self):
        try:
            self.current = (self.text_combo.currentItem() - 1) % len(
                self.model.text_db)
            self.text_combo.setCurrentItem(self.current)
            self.slot_load_preview_text(self.current)
        except ZeroDivisionError:
            pass

    def slot_publish(self):
        if self.is_animate:
            self.animation.start_animation(self.preview_text, self.live_text,
                                           0)
        else:
            self.live_text.setTextOrHtml(self.preview_text.textOrHtml())

    def slot_live_font_size(self, action):
        self.default_size = self.live_size_action.fontSize()
        self.slot_set_preview_defaults()
        self.slot_set_live_defaults()

    def slot_preview_font_size(self, action):
        self.default_size = self.preview_size_action.fontSize()
        self.slot_set_live_defaults()
        self.slot_set_preview_defaults()

    def slot_toggle_publish(self, state=None):

        if state:
            self.slot_publish()
        else:
            self.slot_clear_live()

    def slot_set_preview_defaults(self):
        self.preview_center_action.setChecked(True)
        self.preview_text.alignCenter()
        self.font.setPointSize(self.default_size)
        self.preview_text.setFontSize(self.default_size)
        self.preview_text.setFont(self.font)
        self.preview_size_action.setFontSize(self.default_size)
        self.preview_text.document().setDefaultFont(self.font)

    def slot_set_live_defaults(self):
        self.live_center_action.setChecked(True)
        self.live_text.alignCenter()
        self.live_text.setFontSize(self.default_size)
        self.live_size_action.setFontSize(self.default_size)
        self.live_text.document().setDefaultFont(self.font)

    def slot_clear_live(self):
        self.live_text.clear()
        self.slot_set_live_defaults()

    def slot_clear_preview(self):
        self.preview_text.clear()
        self.slot_set_preview_defaults()

    def slot_fade(self):
        if self.fade_animation.timer is None:
            self.fade_animation.start_animation()

    def slot_load_preview_text(self, index):
        try:
            preview, text = self.model.text_db[index]
        except IndexError:
            return
        self.preview_text.setTextOrHtml(text)
        if self.is_auto_publish:
            self.slot_publish()

    def slot_save_live_text(self):
        text = self.live_text.toHtml()
        preview = get_preview_text(unicode(self.live_text.toPlainText()))
        if not preview:
            return
        old_item = self.model.text_by_preview(preview)
        if old_item is not None:
            suffix = 1
            while 1:
                tmp_preview = "%s_%d" % (preview, suffix)
                tmp = self.model.text_by_preview(tmp_preview)
                if tmp is None:
                    preview = tmp_preview
                    break
                else:
                    suffix += 1

        self.model.text_db.append([preview, text])
        self.model.modelReset.emit()
        action = self.text_combo.addAction(preview)
        self.text_combo.setCurrentAction(action)
        self.db_dirty = True

    def slot_save_preview_text(self):
        text = self.preview_text.toHtml()
        preview = get_preview_text(unicode(self.preview_text.toPlainText()))

        if not preview:
            return
        old_item = self.model.text_by_preview(preview)
        if old_item is not None:
            ix, old_preview, old_text = old_item
            self.model.text_db[ix][1] = text
        else:
            self.model.text_db.append([preview, text])
            action = self.text_combo.addAction(preview)
            self.model.modelReset.emit()
            self.text_combo.setCurrentAction(action)
        self.db_dirty = True

    def slot_save(self):
        path = os.path.expanduser("~/.texter")
        if not os.path.isdir(path):
            os.mkdir(path)
        try:
            f = open(os.path.join(path, "texter.db"), "w")
        except IOError:
            return
        else:
            cPickle.dump(self.model.text_db, f, cPickle.HIGHEST_PROTOCOL)
        self.db_dirty = False

    def slot_open_dialog(self):
        self.current_index = self.text_combo.currentItem()
        self.current_object = self.model.text_db[self.current_index]
        if self.dialog is not None:
            self.dialog.deleteLater()
            self.dialog = None

        self.dialog = KDialog(self)
        self.dialog.setButtons(KDialog.Close)
        self.dialog_widget = EditDialog(self.dialog)
        self.dialog.setMainWidget(self.dialog_widget)
        pos_x, pos_y = self.getPreviewCoords()
        self.dialog.move(pos_x, self.pos().y())
        self.dialog.exec_()
        self.fill_combo_box()

    def slot_load(self):
        path = os.path.expanduser("~/.texter")
        if not os.path.isdir(path):
            os.mkdir(path)
        try:
            db_file = open(os.path.join(path, "texter.db"))
        except IOError:
            return

        try:
            self.model.text_db = [list(i) for i in cPickle.load(db_file)]
        except ValueError, error:
            logger.exception(error)

        self.fill_combo_box()
        self.text_combo.setCurrentItem(0)
        self.slot_load_preview_text(0)
예제 #8
0
class VeroMixPlasmoid(plasmascript.Applet):
    VERSION = "0.18.3"

    nowplaying_player_added = pyqtSignal(QString, QObject)
    nowplaying_player_removed = pyqtSignal(QString)
    nowplaying_player_dataUpdated = pyqtSignal(QString, dict)

    def __init__(self, parent, args=None):
        self.engine = None
        self.now_playing_engine = None
        self.louder_action_editor = None
        self.lower_action_editor = None
        self.mute_action_editor = None
        self.card_settings = None
        self.messageDialog = None
        self.messageOverlay = None
        self.config_ui = None
        plasmascript.Applet.__init__(self, parent)

    def init(self):
        plasmascript.Applet.init(self)
        KGlobal.locale().insertCatalog("veromix")
        if "usr/share/kde4" not in os.path.realpath(__file__):
            out = commands.getstatusoutput(
                "xdg-icon-resource install --size 128 "
                + unicode(self.package().path())
                + "contents/icons/veromix-plasmoid-128.png veromix-plasmoid"
            )
            if out[0] == 0:
                print "veromix icon installed"
            else:
                print "Error installing veromix icon:", out

        LADSPAPresetLoader().install_ladspa_presets_if_needed()
        if self.is_ladspa_enabled():
            # force singleton initialisation
            LADSPAPresetLoader().presets()
            LADSPAEffects().effects()

        createDbusServiceDescription(self.package().path() + "/dbus-service/veromix-service-qt.py", True)

        KGlobal.locale().insertCatalog("veromix")

        self.setHasConfigurationInterface(True)
        self.setAspectRatioMode(Plasma.IgnoreAspectRatio)
        self.theme = Plasma.Svg(self)

        self.widget = VeroMix(self)
        self.widget.init()

        defaultSize = QVariant(QSize(0, 0))
        size = self.config().readEntry("size", defaultSize).toSize()
        if self.formFactor() == Plasma.Planar:
            self.widget.setMinimumSize(275, 125)
        elif size != defaultSize:
            self.widget.setPreferredSize(size.width(), size.height())
        else:
            self.widget.setPreferredSize(470, 145)

        self.connect(self.widget, SIGNAL("resized()"), self.dialogResized)
        # try:
        self.setGraphicsWidget(self.widget)
        self.applet.setPassivePopup(True)
        ## FIXME: see fixPopupcion
        self.setPopupIcon(KIcon("audio-volume-high"))
        # self.setPopupIcon("audio-volume-muted")
        # dont know why but adding it a second time helps (otherwise it
        # wont popup when you add it directly to the panel)
        self.setGraphicsWidget(self.widget)
        self.connect(self.applet, SIGNAL("appletDestroyed(Plasma::Applet*)"), self.doExit)
        self.setBackgroundHints(Plasma.Applet.StandardBackground)
        self.applyConfig()
        # except AttributeError , e:
        # print e
        # updateMetadataDesktop(self)

        self.initTooltip()
        self.initShortcuts()
        QTimer.singleShot(1000, self.fixPopupIcon)

    def initShortcuts(self):
        self.actionCollection = KActionCollection(self)
        # self.actionCollection.setConfigGlobal(True)
        self.louder_action = self.actionCollection.addAction("VeromixVolumeUp")
        self.louder_action.setText(i18n("Veromix volume up"))
        self.louder_action.setGlobalShortcut(KShortcut())
        self.louder_action.triggered.connect(self.widget.on_step_volume_up)

        self.lower_action = self.actionCollection.addAction("VeromixVolumeDown")
        self.lower_action.setText(i18n("Veromix volume down"))
        self.lower_action.setGlobalShortcut(KShortcut())
        self.lower_action.triggered.connect(self.widget.on_step_volume_down)

        self.mute_action = self.actionCollection.addAction("VeromixVolumeMute")
        self.mute_action.setText(i18n("Veromix toggle mute"))
        self.mute_action.setGlobalShortcut(KShortcut())
        self.mute_action.triggered.connect(self.widget.on_toggle_mute)

    def initTooltip(self):
        if self.formFactor() != Plasma.Planar:
            self.tooltip = Plasma.ToolTipContent()
            self.tooltip.setImage(pixmapFromSVG("audio-volume-high"))
            self.tooltip.setMainText(i18n("Main Volume"))
            # self.tooltip.setSubText("")
            Plasma.ToolTipManager.self().setContent(self.applet, self.tooltip)
            Plasma.ToolTipManager.self().registerWidget(self.applet)

    def updateIcon(self):
        icon_state = "audio-volume-muted"
        sink = self.widget.getDefaultSink()
        if sink == None:
            QTimer.singleShot(2000, self.fixPopupIcon)
            return
        vol = sink.get_volume()
        if sink.isMuted():
            icon_state = "audio-volume-muted"
        else:
            if vol == 0:
                icon_state = "audio-volume-muted"
            elif vol < 30:
                icon_state = "audio-volume-low"
            elif vol < 70:
                icon_state = "audio-volume-medium"
            else:
                icon_state = "audio-volume-high"
        self.setPopupIcon(icon_state)
        if self.formFactor() != Plasma.Planar:
            self.tooltip.setImage(pixmapFromSVG(icon_state))
            ## FIXME this should better go to toolTipAboutToShow but is not working:
            # https://bugs.kde.org/show_bug.cgi?id=254764
            self.tooltip.setMainText(sink.name())
            self.tooltip.setSubText(str(vol) + "%")
            Plasma.ToolTipManager.self().setContent(self.applet, self.tooltip)

    def showTooltip(self):
        if self.get_show_toolip():
            Plasma.ToolTipManager.self().show(self.applet)

    @pyqtSlot(name="toolTipAboutToShow")
    def toolTipAboutToShow(self):
        pass

    ## FIXME Looks like a bug in plasma: Only when sending a
    # KIcon instance PopUpApplet acts like a Poppupapplet...
    def fixPopupIcon(self):
        # sink = self.widget.getDefaultSink()
        # if sink:
        self.updateIcon()

    def doExit(self):
        # prevent crash in plasmoidviewer
        self.widget.doExit()
        self.widget.deleteLater()

    def dialogResized(self):
        if self.isPopupShowing():
            self.config().writeEntry("size", QVariant(self.widget.size()))

    def query_application(self, query):
        # print "query: ", query
        if not query:
            return None
        needle = query.lower()
        if self.engine == None:
            self.engine = self.dataEngine("apps")
        for source in self.engine.sources():
            key = unicode(source).replace(".desktop", "")
            if (0 <= key.find(needle)) or (0 <= needle.find(key)):
                # print "found: ",key,  needle , source
                result = self.engine.query(source)
                if QString("iconName") in result:
                    iconname = result[QString("iconName")].toString()
                    return iconname
        return None

    def wheelEvent(self, event):
        if event.orientation() == Qt.Horizontal:
            self.widget.on_step_volume((event.delta() < 0))
        else:
            self.widget.on_step_volume((event.delta() > 0))

    def mousePressEvent(self, event):
        if event.button() == Qt.MidButton:
            self.widget.on_toggle_mute()

    def createConfigurationInterface(self, parent):
        self.pp = parent
        self.config_widget = QWidget(parent)
        self.connect(self.config_widget, SIGNAL("destroyed(QObject*)"), self.configWidgetDestroyed)

        self.config_ui = uic.loadUi(str(self.package().filePath("ui", "appearance.ui")), self.config_widget)
        self.config_ui.showBackground.setCurrentIndex(self.config().readEntry("background", "2").toInt()[0])
        self.config_ui.showBackground.currentIndexChanged.connect(parent.settingsModified)
        if self.formFactor() != Plasma.Planar:
            self.config_ui.showBackground.setEnabled(False)

        self.config_ui.popupMode.setCurrentIndex(self.config().readEntry("popupMode", False).toInt()[0])
        self.config_ui.popupMode.currentIndexChanged.connect(parent.settingsModified)
        if self.formFactor() == Plasma.Planar:
            self.config_ui.popupMode.setEnabled(False)

        self.config_ui.useTabs.setChecked(self.useTabs())
        self.config_ui.useTabs.stateChanged.connect(parent.settingsModified)

        self.config_ui.show_tooltip.setChecked(self.get_show_toolip())
        self.config_ui.show_tooltip.stateChanged.connect(parent.settingsModified)

        self.config_ui.always_show_sources.setChecked(self.get_always_show_sources())
        self.config_ui.always_show_sources.stateChanged.connect(parent.settingsModified)

        self.config_ui.meter_visible.setChecked(self.is_meter_visible())
        self.config_ui.meter_visible.stateChanged.connect(parent.settingsModified)

        self.config_ui.expander_enabled.setChecked(self.is_expander_enabled())
        self.config_ui.expander_enabled.stateChanged.connect(parent.settingsModified)

        self.config_ui.unitvalues_visible.setChecked(self.is_slider_unit_value_visible())
        self.config_ui.unitvalues_visible.stateChanged.connect(parent.settingsModified)

        self.config_ui.version.setText(VeroMixPlasmoid.VERSION)
        parent.addPage(self.config_widget, i18n("Appearance"), "veromix")

        self.mediaplayer_settings_widget = QWidget(parent)
        self.mediaplayer_settings_ui = uic.loadUi(
            str(self.package().filePath("ui", "nowplaying.ui")), self.mediaplayer_settings_widget
        )

        self.mediaplayer_settings_ui.mediaplayerBlacklist.setPlainText(self.get_mediaplayer_blacklist_string())
        self.mediaplayer_settings_ui.runningMediaplayers.setPlainText(self.get_running_mediaplayers())
        self.mediaplayer_settings_ui.runningMediaplayers.setReadOnly(True)

        self.mediaplayer_settings_ui.use_nowplaying.setChecked(self.is_nowplaying_enabled())
        self.mediaplayer_settings_ui.use_nowplaying.stateChanged.connect(self.update_mediaplayer_settings_ui)
        self.mediaplayer_settings_ui.use_nowplaying.stateChanged.connect(parent.settingsModified)

        self.mediaplayer_settings_ui.use_mpris2.setChecked(self.is_mpris2_enabled())
        self.mediaplayer_settings_ui.use_mpris2.stateChanged.connect(self.update_mediaplayer_settings_ui)
        self.mediaplayer_settings_ui.use_mpris2.stateChanged.connect(parent.settingsModified)

        self.mediaplayer_settings_ui.show_albumart.setChecked(self.is_albumart_enabled())
        self.mediaplayer_settings_ui.show_albumart.stateChanged.connect(parent.settingsModified)

        parent.addPage(self.mediaplayer_settings_widget, i18n("Media Player Controls"), "veromix")

        # self.about_widget = QWidget(parent)
        # self.about_ui = uic.loadUi(str(self.package().filePath('ui', 'about.ui')), self.about_widget)
        # self.about_ui.version.setText(VeroMixPlasmoid.VERSION)
        # parent.addPage(self.about_widget, "About", "help-about")
        self.add_audio_settings(parent)
        self.add_ladspa_settings(parent)
        self.add_global_shortcut_page(parent)

        # FIXME KDE 4.6 workaround
        self.connect(parent, SIGNAL("okClicked()"), self.configChanged)
        self.connect(parent, SIGNAL("applyClicked()"), self.configChanged)
        self.connect(parent, SIGNAL("cancelClicked()"), self.configDenied)
        return self.config_widget

    def add_audio_settings(self, dialog):
        self.audio_settings_page = QWidget()
        layout = QGridLayout()
        self.audio_settings_page.setLayout(layout)

        self.max_volume_spinbox = QSpinBox()
        self.max_volume_spinbox.setRange(1, 255)
        self.max_volume_spinbox.setSingleStep(1)
        self.max_volume_spinbox.setValue(self.get_max_volume_value())
        self.max_volume_spinbox.valueChanged.connect(dialog.settingsModified)
        layout.addWidget(QLabel(i18n("Max volume value")), 0, 0)
        layout.addWidget(self.max_volume_spinbox, 0, 1)

        self.automute_checkbox = QCheckBox()
        self.automute_checkbox.setChecked(self.get_auto_mute())
        self.automute_checkbox.stateChanged.connect(dialog.settingsModified)
        layout.addWidget(QLabel(i18n("Mute if volume reaches zero")), 1, 0)
        layout.addWidget(self.automute_checkbox, 1, 1)

        layout.addItem(QSpacerItem(0, 20, QSizePolicy.Minimum, QSizePolicy.Fixed), 2, 0)
        layout.addWidget(QLabel("<b>" + i18n("Sound Card Profiles") + "</b>"), 3, 0)
        index = 4
        self.card_settings = {}
        for card in self.widget.card_infos.values():
            combo = QComboBox()
            # self.automute_checkbox.setChecked(self.get_auto_mute())
            # print card.properties
            layout.addWidget(QLabel(card.properties[dbus.String("device.description")]), index, 0)
            layout.addWidget(combo, index, 1)
            index = index + 1

            self.card_settings[combo] = card
            profiles = card.get_profiles()
            active = card.get_active_profile_name()
            active_index = 0
            for profile in profiles:
                combo.addItem(profile.description)
                if active == profile.name:
                    active_index = profiles.index(profile)
            combo.setCurrentIndex(active_index)

        layout.addItem(QSpacerItem(0, 0, QSizePolicy.Minimum, QSizePolicy.Expanding), index, 0)
        dialog.addPage(self.audio_settings_page, i18n("Pulseaudio"), "preferences-desktop-sound")

    def add_ladspa_settings(self, dialog):
        self.ladspa_settings_page = QWidget()
        layout = QGridLayout()
        self.ladspa_settings_page.setLayout(layout)

        text = i18n(
            "LADSPA is a standard for handling audio filters and effects. Every linux software archive offers a large number of effects - search for LADSPA to get more.\
            Not every effect is supported by Pulseaudio and others simple don't make sense (or create only noise).<br/><br/>\
            The following list shows all available effects on your system: Only checked effects will appear in the context-menu."
        )

        if not LADSPAEffects().ladspa_sdk_available():
            text = text + i18n(
                "<br/><br/><b>Warning:</b> Cannot find the executables 'listplugins' and 'analyseplugin' which are required for dynamically detecting installed effects.<br/>\
               In OpenSUSE, Fedora and Arch Linux the package is named 'ladspa', in Debian/Ubuntu 'ladspa-sdk'.<br/><br/>"
            )

        ladspa_intro = QLabel(text)

        ladspa_intro.setWordWrap(True)
        layout.addWidget(ladspa_intro, 0, 0)

        self.ladspa_enabled_checkbox = QCheckBox()
        self.ladspa_enabled_checkbox.setText(i18n("Enable LADSPA effects."))
        self.ladspa_enabled_checkbox.setChecked(self.is_ladspa_enabled())
        self.ladspa_enabled_checkbox.stateChanged.connect(dialog.settingsModified)
        layout.addWidget(self.ladspa_enabled_checkbox, 1, 0)

        self.effects_list_widget = QListWidget()
        layout.addWidget(self.effects_list_widget, 2, 0)
        self.effects_list_widget.itemClicked.connect(dialog.settingsModified)

        blacklisted = LADSPAEffects().blacklist()
        effects = LADSPAEffects().all_effects()
        for effect in effects:
            item = QListWidgetItem(effect["preset_name"])
            item.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled)
            if effect["preset_name"] in blacklisted:
                item.setCheckState(Qt.Unchecked)
            else:
                item.setCheckState(Qt.Checked)
            self.effects_list_widget.addItem(item)

        layout.addItem(QSpacerItem(0, 0, QSizePolicy.Minimum, QSizePolicy.Expanding), 3, 0)
        dialog.addPage(self.ladspa_settings_page, i18n("Effects / Equalizer"), "preferences-desktop-sound")

    # anybody knows how to remove/extend the default shortcuts page?
    def add_global_shortcut_page(self, dialog):
        self.kb_settings_page = QWidget()

        layout = QGridLayout()
        self.kb_settings_page.setLayout(layout)

        self.louder_action_editor = KKeySequenceWidget()
        self.louder_action_editor.setKeySequence(self.louder_action.globalShortcut().primary())
        self.louder_action_editor.keySequenceChanged.connect(dialog.settingsModified)
        layout.addWidget(QLabel(i18n("Veromix volume up")), 0, 0)
        layout.addWidget(self.louder_action_editor, 0, 1)

        self.lower_action_editor = KKeySequenceWidget()
        self.lower_action_editor.setKeySequence(self.lower_action.globalShortcut().primary())
        self.lower_action_editor.keySequenceChanged.connect(dialog.settingsModified)
        layout.addWidget(QLabel(i18n("Veromix volume down")), 1, 0)
        layout.addWidget(self.lower_action_editor, 1, 1)

        self.mute_action_editor = KKeySequenceWidget()
        self.mute_action_editor.setKeySequence(self.mute_action.globalShortcut().primary())
        self.mute_action_editor.keySequenceChanged.connect(dialog.settingsModified)
        layout.addWidget(QLabel(i18n("Veromix toggle  mute")), 2, 0)
        layout.addWidget(self.mute_action_editor, 2, 1)

        layout.addItem(QSpacerItem(0, 0, QSizePolicy.Minimum, QSizePolicy.Expanding), 3, 0)
        dialog.addPage(self.kb_settings_page, i18n("Volume Keyboard Shortcuts"), "preferences-desktop-keyboard")

    def configDenied(self):
        self.apply_nowplaying(self.is_nowplaying_enabled())
        self.apply_mpris2(self.is_mpris2_enabled())

    def configChanged(self):
        if self.config_ui:
            self.config().writeEntry("background", str(self.config_ui.showBackground.currentIndex()))
            self.config().writeEntry("popupMode", str(self.config_ui.popupMode.currentIndex()))
            tabs = self.useTabs()
            self.config().writeEntry("useTabs", bool(self.config_ui.useTabs.isChecked()))
            self.config().writeEntry("show_tooltip", bool(self.config_ui.show_tooltip.isChecked()))
            self.config().writeEntry("always_show_sources", bool(self.config_ui.always_show_sources.isChecked()))

            self.config().writeEntry("meter_visible", bool(self.config_ui.meter_visible.isChecked()))
            self.config().writeEntry("expander_enabled", bool(self.config_ui.expander_enabled.isChecked()))
            self.config().writeEntry("unitvalues_visible", bool(self.config_ui.unitvalues_visible.isChecked()))

            self.config().writeEntry("use_nowplaying", str(self.mediaplayer_settings_ui.use_nowplaying.isChecked()))
            self.config().writeEntry("use_mpris2", str(self.mediaplayer_settings_ui.use_mpris2.isChecked()))
            self.config().writeEntry("show_albumart", str(self.mediaplayer_settings_ui.show_albumart.isChecked()))

            # self.config().writeEntry("mpris2List",str(self.mediaplayer_settings_ui.mpris2List.toPlainText()).strip())
            self.config().writeEntry(
                "nowplayingBlacklist", str(self.mediaplayer_settings_ui.mediaplayerBlacklist.toPlainText()).strip()
            )

            self.config().writeEntry("max_volume", str(self.max_volume_spinbox.value()))
            self.config().writeEntry("auto_mute", str(self.automute_checkbox.isChecked()))

            self.config().writeEntry("ladspa_enabled", str(self.ladspa_enabled_checkbox.isChecked()))
            self.ladspa_save_effects_blacklist()
            if tabs != self.useTabs():
                self.widget.switchView()
        self.applyConfig()
        self.widget.on_update_configuration()

    def update_mediaplayer_settings_ui(self):
        enable = (
            self.mediaplayer_settings_ui.use_nowplaying.isChecked()
            or self.mediaplayer_settings_ui.use_mpris2.isChecked()
        )
        self.mediaplayer_settings_ui.mediaplayerBlacklist.setEnabled(enable)
        self.mediaplayer_settings_ui.mediaplayerBlacklistLabel.setEnabled(enable)
        self.mediaplayer_settings_ui.runningMediaplayers.setEnabled(enable)
        self.mediaplayer_settings_ui.runningMediaplayersLabel.setEnabled(enable)
        self.mediaplayer_settings_ui.runningMediaplayers.setPlainText(self.get_running_mediaplayers())
        self.mediaplayer_settings_ui.show_albumart.setEnabled(enable)

    def apply_nowplaying(self, enabled):
        self.disable_nowplaying()
        if enabled:
            self.init_nowplaying()

    def apply_mpris2(self, enabled):
        self.widget.pa.disable_mpris2()
        self.remove_mpris2_widgets()
        if enabled:
            self.widget.pa.enable_mpris2()
            self.init_running_mpris2()

    def applyConfig(self):
        self.apply_nowplaying(self.is_nowplaying_enabled())
        self.apply_mpris2(self.is_mpris2_enabled())

        if self.formFactor() == Plasma.Planar:
            bg = self.config().readEntry("background", "2").toInt()[0]
            if bg == 0:
                self.setBackgroundHints(Plasma.Applet.NoBackground)
            elif bg == 1:
                self.setBackgroundHints(Plasma.Applet.TranslucentBackground)
            else:
                self.setBackgroundHints(Plasma.Applet.StandardBackground)

        mode = self.config().readEntry("popupMode", False).toInt()[0]
        if mode == 0:
            self.setPassivePopup(False)
        elif mode == 1:
            self.setPassivePopup(True)
        else:
            self.setPassivePopup(True)

        if self.louder_action_editor:
            sequence = self.louder_action_editor.keySequence()
            if sequence != self.louder_action.globalShortcut().primary():
                self.louder_action.setGlobalShortcut(KShortcut(sequence), KAction.ActiveShortcut, KAction.NoAutoloading)
        if self.lower_action_editor:
            sequence = self.lower_action_editor.keySequence()
            if sequence != self.lower_action.globalShortcut().primary():
                self.lower_action.setGlobalShortcut(KShortcut(sequence), KAction.ActiveShortcut, KAction.NoAutoloading)
        if self.mute_action_editor:
            sequence = self.mute_action_editor.keySequence()
            if sequence != self.mute_action.globalShortcut().primary():
                self.mute_action.setGlobalShortcut(KShortcut(sequence), KAction.ActiveShortcut, KAction.NoAutoloading)

        if self.card_settings:
            for combo in self.card_settings.keys():
                card = self.card_settings[combo]
                for profile in card.profiles:
                    if combo.currentText() == profile.description:
                        self.widget.pa.set_card_profile(card.index, profile.name)

        self.update()

    def configWidgetDestroyed(self):
        self.config_widget = None
        self.config_ui = None

    def useTabs(self):
        return self.config().readEntry("useTabs", False).toBool()

    def is_meter_visible(self):
        return self.config().readEntry("meter_visible", False).toBool()

    def get_auto_mute(self):
        return self.config().readEntry("auto_mute", False).toBool()

    def get_show_toolip(self):
        return self.config().readEntry("show_tooltip", True).toBool()

    def get_always_show_sources(self):
        return self.config().readEntry("always_show_sources", False).toBool()

    def get_max_volume_value(self):
        default = 100
        return self.config().readEntry("max_volume", default).toInt()[0]

    def is_slider_unit_value_visible(self):
        return self.config().readEntry("unitvalues_visible", False).toBool()

    def is_ladspa_enabled(self):
        return self.config().readEntry("ladspa_enabled", True).toBool()

    def ladspa_save_effects_blacklist(self):
        blacklisted = []
        for i in range(0, self.effects_list_widget.count()):
            item = self.effects_list_widget.item(i)
            if not item.checkState():
                blacklisted.append(str(item.text()))
        LADSPAEffects().write_blacklist(blacklisted)

    ### now playing

    def is_nowplaying_enabled(self):
        return self.config().readEntry("use_nowplaying", False).toBool()

    def is_mpris2_enabled(self):
        return self.config().readEntry("use_mpris2", True).toBool()

    def is_albumart_enabled(self):
        return self.config().readEntry("show_albumart", True).toBool()

    def is_expander_enabled(self):
        return self.config().readEntry("expander_enabled", True).toBool()

    def disable_nowplaying(self):
        for player in self.widget.get_mediaplayer_widgets():
            if player.is_nowplaying_player():
                self.on_nowplaying_player_removed(player.controller_name())
        self.now_playing_engine = None

    def remove_mpris2_widgets(self):
        for player in self.widget.get_mediaplayer_widgets():
            if player.is_mpris2_player():
                self.on_mpris2_removed(player.controller_name())

    def init_nowplaying(self):
        self.now_playing_engine = self.dataEngine("nowplaying")
        self.connect(self.now_playing_engine, SIGNAL("sourceAdded(QString)"), self.on_nowplaying_player_added)
        self.connect(self.now_playing_engine, SIGNAL("sourceRemoved(QString)"), self.on_nowplaying_player_removed)
        self.connect_to_nowplaying_engine()

    def init_running_mpris2(self):
        for controller in self.widget.pa.get_mpris2_players():
            v = controller.name()
            if self.in_mediaplayer_blacklist(v):
                return
            self.nowplaying_player_added.emit(controller.name(), controller)

    def connect_to_nowplaying_engine(self):
        # get sources and connect
        for source in self.now_playing_engine.sources():
            self.on_nowplaying_player_added(source)

    def on_nowplaying_player_added(self, player):
        if player == "players":
            # FIXME 4.6 workaround
            return
        if self.in_mediaplayer_blacklist(player):
            return
        self.now_playing_engine.disconnectSource(player, self)
        self.now_playing_engine.connectSource(player, self, 2000)
        controller = self.now_playing_engine.serviceForSource(player)
        self.nowplaying_player_added.emit(player, NowPlayingController(self.widget, controller))

    def in_mediaplayer_blacklist(self, player):
        for entry in self.get_mediaplayer_blacklist():
            if str(player).find(entry) == 0:
                return True
        return False

    def on_nowplaying_player_removed(self, player):
        if self.now_playing_engine:
            self.now_playing_engine.disconnectSource(player, self)
            self.nowplaying_player_removed.emit(player)

    def on_mpris2_removed(self, player):
        self.nowplaying_player_removed.emit(player)

    def get_running_mediaplayers(self):
        val = "nowplaying:\n"
        engine = self.now_playing_engine
        if engine == None:
            engine = self.dataEngine("nowplaying")
        for source in engine.sources():
            val += source + "\n"
        val += "\nmpris2:\n"
        for controller in self.widget.pa.get_mpris2_players():
            val += controller.name() + "\n"
        return val

    def get_mediaplayer_blacklist(self):
        return self.get_mediaplayer_blacklist_string().split("\n")

    def get_mediaplayer_blacklist_string(self):
        default = "org.mpris.bangarang"
        return self.config().readEntry("nowplayingBlacklist", default).toString()

    @pyqtSignature("dataUpdated(const QString&, const Plasma::DataEngine::Data&)")
    def dataUpdated(self, sourceName, data):
        self.nowplaying_player_dataUpdated.emit(sourceName, data)

    ## Modal Widget

    def showModalWidget(self, mainWidget):
        # mainWidget.widgetClose.connect(self.destroyMessageOverlay)
        if self.messageOverlay:
            return
        if self.messageDialog:
            return

        corona = self.scene()
        mainWidget.adjustSize()
        hint = mainWidget.preferredSize()
        if (hint.height() > self.widget.size().height()) or (hint.width() > self.widget.size().width()):
            ## either a collapsed popup in h/v form factor or just too small,
            ## so show it in a dialog associated with ourselves
            # pass
            if corona:
                corona.addOffscreenWidget(mainWidget)

            if self.messageDialog:
                pass
            else:
                self.messageDialog = Plasma.Dialog()

            self.messageDialog.setGraphicsWidget(mainWidget)
            mainWidget.setParentItem(self.messageDialog.graphicsWidget())
        else:
            self.messageOverlay = self.createMessageOverlay()
            self.formatOverlay()
            self.messageOverlay.opacity = 0.8
            mainWidget.setParentItem(self.messageOverlay)
            l = QGraphicsLinearLayout(self.messageOverlay)
            l.addItem(mainWidget)

        if self.messageDialog:
            pos = self.geometry().topLeft().toPoint()
            if corona:
                pos = corona.popupPosition(self.applet, self.messageDialog.size())

            self.messageDialog.move(pos)
            # self.locationToDirection(self.location())
            self.messageDialog.animatedShow(Plasma.Direction(0))
            self.hidePopup()
        else:
            self.messageOverlay.show()

    def createMessageOverlay(self):
        if self.messageOverlay == None:
            messageOverlay = QGraphicsWidget(self.widget)
            return messageOverlay

    def formatOverlay(self):
        self.messageOverlay.resize(self.widget.contentsRect().size())
        self.messageOverlay.setPos(self.widget.contentsRect().topLeft())

        zValue = 100
        for child in self.widget.children():
            if child.zValue() > zValue:
                zValue = child.zValue() + 1
        self.messageOverlay.setZValue(zValue)

    def destroyMessageOverlay(self):
        if self.messageDialog != None:
            # Plasma::locationToInverseDirection(q->location())
            self.messageDialog.animatedHide(Plasma.Direction(0))
            self.messageDialog.deleteLater()
            self.messageDialog.hide()
            self.messageDialog = None
            self.showPopup(0)

        if self.messageOverlay == None:
            return

        self.messageOverlay.hide()
        self.messageOverlay = None
예제 #9
0
파일: update.py 프로젝트: cburgmer/eclectus
class UpdateDialog(KDialog):
    def __init__(self, mainWindow, renderThread, pluginConfig=None):
        KDialog.__init__(self, mainWindow)
        self.renderThread = renderThread

        self.databaseUrl = None
        if pluginConfig:
            self.databaseUrl = util.readConfigString(self.pluginConfig,
                "Update database url", None)

        if not self.databaseUrl:
            self.databaseUrl = unicode('sqlite:///'
                + util.getLocalData('dictionaries.db'))

        self.renderThread.setObject(DictionaryInfo,
            databaseUrl=self.databaseUrl)

        self.setCaption(i18n("Install/Update Dictionaries"))
        self.setButtons(KDialog.ButtonCode(KDialog.Close))
        self.enableButton(KDialog.Cancel, False)

        # TODO can we defer the creation of the update widget until the dialog is shown?
        self.updateWidget = UpdateWidget(mainWindow, renderThread, pluginConfig)
        self.connect(self.updateWidget, SIGNAL("working(bool)"),
            self.slotUpdateWorking)
        self.setMainWidget(self.updateWidget)

        self.connect(self, SIGNAL("finished()"), self.slotFinish)

        self.initialised = False

        self.connect(self.renderThread, SIGNAL("jobFinished"),
            self.contentRendered)
        self.connect(self.renderThread, SIGNAL("jobErrorneous"),
            self.renderingFailed)

        self.actionCollection = KActionCollection(self)
        self.setupActions()

    def showEvent(self, event):
        if not self.initialised:
            self.initialised = True
            self.loadDatabaseBuilder()
            self.updateWidget.setup()

    def setupActions(self):
        # update dictionaries
        self._updateAction = KAction(KIcon('system-software-update'),
            i18n("&Update..."), self)
        self.actionCollection.addAction("updatedictionaries",
            self._updateAction)
        self._updateAction.setWhatsThis(
            i18n("Download and update dictionaries."))
        self.connect(self._updateAction, SIGNAL("triggered(bool)"),
            self.exec_)
        # optimise database
        self._optimiseAction = KAction(KIcon('system-run'),
            i18n("&Optimise database"), self)
        self.actionCollection.addAction("optimisedatabase",
            self._optimiseAction)
        self._optimiseAction.setWhatsThis(
            i18n("Rearranges and optimises the database."))
        self._optimiseAction.setEnabled(True) # TODO
        self.connect(self._optimiseAction, SIGNAL("triggered(bool)"),
            self.slotOptimiseDatabase)

    def updateAction(self, actionCollection):
        actionCollection.addAction(self._updateAction.objectName(),
            self._updateAction)
        return self._updateAction

    def optimiseAction(self, actionCollection):
        actionCollection.addAction(self._optimiseAction.objectName(),
            self._optimiseAction)
        return self._optimiseAction

    def slotUpdateWorking(self, working):
        if working:
            self.setButtons(KDialog.ButtonCode(KDialog.Cancel))
        else:
            self.setButtons(KDialog.ButtonCode(KDialog.Close))

    def slotFinish(self):
        if self.updateWidget.isWorking():
            self.updateWidget.cancel()

    def slotOptimiseDatabase(self):
        self.loadDatabaseBuilder()
        dbBuild = self.renderThread.getObjectInstance(build.DatabaseBuilder)
        if dbBuild.isOptimizable():
            if KMessageBox.warningContinueCancel(self,
                i18n("This operation might take some time."),
                i18n("Optimise Database"), KStandardGuiItem.cont(),
                KStandardGuiItem.cancel(), 'database_optimise') \
                    == KMessageBox.Continue:
                QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
                self.currentJob = self.renderThread.enqueue(
                    build.DatabaseBuilder, 'optimize')

    def loadDatabaseBuilder(self):
        if not self.renderThread.hasObject(build.DatabaseBuilder):
            options = EclectusCommandLineBuilder.getDefaultOptions()

            db = getDBConnector(getDatabaseConfiguration(self.databaseUrl))

            self.renderThread.setObject(build.DatabaseBuilder, dbConnectInst=db,
                **options)

    def contentRendered(self, id, classObject, method, args, param, content):
        if classObject == build.DatabaseBuilder and method == 'optimize':
            QApplication.restoreOverrideCursor()

    def renderingFailed(self, id, classObject, method, args, param, e,
            stacktrace):
        if classObject == build.DatabaseBuilder and method == 'optimize':
            print >>sys.stderr, stacktrace
            QApplication.restoreOverrideCursor()