コード例 #1
0
ファイル: main.py プロジェクト: selam/ublog
    def init(self):
        """
        create interface, this method invoked by plasma it self
        """
        self.setHasConfigurationInterface(True)
        self.setAspectRatioMode(Plasma.IgnoreAspectRatio)
        self.setBackgroundHints(Plasma.Applet.DefaultBackground)

        #
        self.flash = Plasma.FlashingLabel(self.applet)
        self.flash.setAutohide(True)
        self.flash.setMinimumSize(0, 20)
        self.flash.setDuration(2000)
        self.tab_bar = Plasma.TabBar()

        self._layout = QGraphicsLinearLayout(Qt.Vertical, self.applet)
        self._layout.setSpacing(3)

        flash_layout = QGraphicsLinearLayout(Qt.Horizontal)
        flash_layout.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)

        fnt = Plasma.Theme.defaultTheme().font(Plasma.Theme.DefaultFont)
        fnt.setBold(True)
        fm = QFontMetrics(fnt)

        self.flash.setFont(fnt)
        self.flash.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)

        title_layout = QGraphicsLinearLayout(Qt.Vertical)

        flash_layout.addItem(self.flash)
        flash_layout.addItem(title_layout)

        self.main_frame = Plasma.Frame(self.applet)
        m_header_layout = QGraphicsAnchorLayout(self.main_frame)
        m_header_layout.setSpacing(5)

        self.icon = Plasma.IconWidget(self.main_frame)
        self.icon.setIcon(KIcon("user-identity"))
        self.icon.setTextBackgroundColor(QColor())
        icon_size = self.icon.sizeFromIconSize(48)
        self.icon.setMinimumSize(icon_size)
        self.icon.setMaximumSize(icon_size)

        m_header_layout.addAnchor(self.icon, Qt.AnchorVerticalCenter, m_header_layout, Qt.AnchorVerticalCenter)
        m_header_layout.addAnchor(self.icon, Qt.AnchorLeft, m_header_layout, Qt.AnchorLeft)

        status_edit_frame = Plasma.Frame(self.main_frame)
        status_edit_frame.setFrameShadow(Plasma.Frame.Sunken)
        status_edit_layout = QGraphicsLinearLayout(status_edit_frame)
        self.status_edit = Plasma.TextEdit()
        self.status_edit.setPreferredHeight(fm.height() * 4)
        self.status_edit.setEnabled(False)
        status_edit_layout.addItem(self.status_edit)

        edit_pal = self.status_edit.palette()
        m_color_scheme = KColorScheme(QPalette.Active, KColorScheme.View, Plasma.Theme.defaultTheme().colorScheme())
        edit_pal.setColor(QPalette.Text, m_color_scheme.foreground().color())
        self.status_edit.nativeWidget().setPalette(edit_pal)
        self.status_edit.nativeWidget().installEventFilter(self)
        m_header_layout.addAnchor(self.icon, Qt.AnchorRight, status_edit_frame, Qt.AnchorLeft)
        m_header_layout.addAnchors(status_edit_frame, m_header_layout, Qt.Vertical)
        m_header_layout.addAnchor(status_edit_frame, Qt.AnchorRight, m_header_layout, Qt.AnchorRight)
        m_header_layout.activate()
        m_header_layout.setMaximumHeight(m_header_layout.effectiveSizeHint(Qt.PreferredSize).height())

        self.scroll_widget = Plasma.ScrollWidget(self.applet)
        self.tweets_widget = QGraphicsWidget(self.scroll_widget)
        self.scroll_widget.setWidget(self.tweets_widget)
        self.tweets_layout = QGraphicsLinearLayout(Qt.Vertical, self.tweets_widget)
        self.tweets_layout.setSpacing(3)
        self.tweets_layout.addItem(self.main_frame)

        self.tab_bar.addTab(self.trUtf8("Timeline"))
        self.tab_bar.addTab(self.trUtf8("Replies"))
        self.tab_bar.addTab(self.trUtf8("Messages"))

        self._layout.addItem(flash_layout)
        self._layout.addItem(self.tab_bar)
        self._layout.addItem(self.scroll_widget)

        self.applet.setLayout(self._layout)
        self.connect(self.tab_bar, SIGNAL('currentChanged(int)'), self.mode_changed)
        self.connect(self.status_edit, SIGNAL('textChanged()'), self.edit_text_changed)
        self.check_config()
コード例 #2
0
class VeroMix(QGraphicsWidget):
    sinkOutputChanged = pyqtSignal()

    def __init__(self,parent):
        QGraphicsWidget.__init__(self)
        self.applet = parent
        self.pa = None
        self.last_resize_running = datetime.datetime.now()
        self.last_resize_running_timer_running = False
        self.card_infos = {}
        self.ladspa_index = 1

        self.setFocusPolicy(Qt.TabFocus)

    def init(self):
        self.setAcceptsHoverEvents (True)
        self.layout = QGraphicsLinearLayout(Qt.Vertical, self)
        self.layout.setSizePolicy(QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum))

        self.scroller = LockableScrollWidget(self)
        self.scroller.setMinimumSize(120,90)
        self.layout.addItem(self.scroller)
        if self.applet.formFactor() != Plasma.Planar  :
            self.scroller.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)

        self.source_panel = QGraphicsWidget()
        self.sink_panel = QGraphicsWidget()

        self.scrolled_panel_layout = QGraphicsLinearLayout(Qt.Vertical)
        self.scrolled_panel_widget = QGraphicsWidget()
        self.scrolled_panel_widget.setLayout(self.scrolled_panel_layout)
        self.scrolled_panel_layout.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding))
        self.scrolled_panel_layout.setContentsMargins(0,0,0,6)

        self.showsTabs =  not self.applet.useTabs()
        self.switchView(True)

        self.source_panel_layout = SortedLayout(Qt.Vertical, False)
        self.source_panel_layout.setSpacing(0)
        self.source_panel.setLayout(self.source_panel_layout)
        self.source_panel_layout.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding))
        if self.showsTabs:
            self.source_panel_layout.addStretch()

        self.sink_panel_layout = SortedLayout(Qt.Vertical, False)
        self.sink_panel_layout.setSpacing(0)

        self.sink_panel.setLayout(self.sink_panel_layout)
        self.sink_panel_layout.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding))

        self.layout.setContentsMargins(0,0,0,0)
        self.source_panel_layout.setContentsMargins(0,0,0,0)
        self.sink_panel_layout.setContentsMargins(0,0,0,0)

        #QTimer.singleShot(4000, self.start_pa)
        self.start_pa()
        self.connect_mediaplayers()

    def switchView(self, startup=False):
        if self.showsTabs:
            self.scrolled_panel_layout = QGraphicsLinearLayout(Qt.Vertical)
            scrolled_panel = QGraphicsWidget()
            scrolled_panel.setLayout(self.scrolled_panel_layout)
            self.scrolled_panel_layout.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding))
            self.scrolled_panel_layout.addItem(self.source_panel)
            self.scrolled_panel_layout.addItem(self.sink_panel)
        else:
            scrolled_panel = Plasma.TabBar()
            scrolled_panel.addTab(i18n("Playback"), self.sink_panel)
            scrolled_panel.addTab(i18n("Record"), self.source_panel)
            self.source_panel.show()

        self.scrolled_panel = scrolled_panel
        self.showsTabs = not self.showsTabs
        self.scroller.setWidget(self.scrolled_panel)
        if not startup:
            self.check_geometries()

    def on_update_configuration(self):
        for source in self.source_panel_layout.getChannels().values():
            source.on_update_configuration()
        for sink in self.sink_panel_layout.getChannels().values():
            sink.on_update_configuration()

        self.pa.set_autostart_meters(bool(self.applet.is_meter_visible()))

    # connect to pulseaudio(dbus) callbacks
    def start_pa(self):
        try:
            self.pa = PulseAudio(self)
            self.pa.connect_veromix_service()
        except Exception, e:
            self.showMessage(KIcon("script-error"), i18n("There is a problem with the backgroud-service. \
                                                        <ul> \
                                                        <li>If you just upgraded try killing the process named: VeromixServiceMain.py and relaunch this plasmoid</li> \
                                                        <li>If you don't know how to do that consider rebooting</li></ul><br/>\
                                                        <a href=\"http://code.google.com/p/veromix-plasmoid/wiki/Debugging\">See wiki for more details</a> <span style=\"font-size: small;\">(right click and copy url)</span>."))
            print "\nError connecting to veromix-service:\n" , e, "\n"
            return
        self.connect(self.pa, SIGNAL("on_sink_input_info(PyQt_PyObject)"), self.on_sink_input_info)
        self.connect(self.pa, SIGNAL("on_sink_info(PyQt_PyObject)"), self.on_sink_info)
        self.connect(self.pa, SIGNAL("on_source_output_info(PyQt_PyObject)"), self.on_source_output_info)
        self.connect(self.pa, SIGNAL("on_source_info(PyQt_PyObject)"), self.on_source_info)

        self.connect(self.pa, SIGNAL("on_sink_remove(int)"), self.on_remove_sink)
        self.connect(self.pa, SIGNAL("on_sink_input_remove(int)"), self.on_remove_sink_input)
        self.connect(self.pa, SIGNAL("on_source_remove(int)"), self.on_remove_source)
        self.connect(self.pa, SIGNAL("on_source_output_remove(int)"), self.on_remove_source_output)

        self.connect(self.pa, SIGNAL("on_volume_meter_sink(int, float)"), self.on_volume_meter_sink)
        self.connect(self.pa, SIGNAL("on_volume_meter_sink_input(int, float)"), self.on_volume_meter_sink_input)
        self.connect(self.pa, SIGNAL("on_volume_meter_source(int, float)"), self.on_volume_meter_source)

        self.connect(self.pa, SIGNAL("on_card_info(PyQt_PyObject)"), self.on_card_info)
        self.connect(self.pa, SIGNAL("on_card_remove(int)"), self.on_remove_card)

        self.connect(self.pa, SIGNAL("on_module_info(int,PyQt_PyObject,PyQt_PyObject,PyQt_PyObject,PyQt_PyObject)"), self.on_module_info)
        self.pa.requestInfo()