This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Python Plasmoid Configuration Ui Problems

Tags: None
(comma "," separated)
halcyon
Registered Member
Posts
3
Karma
0
OS
Hi everybody,

I'm currently writing my first "proper" plasmoid using python. Its purpose is to play an audio stream from a url provided by the user with a very simple ui. Basically click once -> play , click again -> stop. It's working so far (with the stream address hardcoded) and i had id working with a very simple configuration ui which was just a lineEdit to enter the stream address. The problem i have now is that i wanted to integrate the option to the config ui to save a couple of streams in a list and to select one to be played. The interface looks like this now http://imagebin.ca/view/IpevFN.html.
I've added two custom slots to the dialog (addItem, removeItem) to handle the urls in the lineEdit and listWidget, i've just got no idea how to implement the functions while still keeping KconfigXT working. The code I've got so far is:
content/code/main.py
Code: Select all
# <Copyright and license information goes here.>
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyKDE4.plasma import Plasma
from PyKDE4 import plasmascript
from PyKDE4.kdecore import KConfigGroup
from PyKDE4.kdeui import *
from PyKDE4.phonon import Phonon

class SimpleStream(plasmascript.Applet):

  mediaObject = None
  stream = None
  playPauseButton = None

  def __init__(self,parent,args=None):
    plasmascript.Applet.__init__(self, parent)
    self.mediaObject = Phonon.createPlayer(Phonon.MusicCategory)
    self.connect(self.mediaObject, SIGNAL('finished()'), self.play)
    self.connect(self.mediaObject, SIGNAL('stateChanged(Phonon::State, Phonon::State)'), self.handleStateChange)

  def init(self):
    self.setHasConfigurationInterface(True)
    self.playPauseButton = Plasma.IconWidget(self.applet)
    self.playPauseButton.setIcon("media-playback-start")
    self.layout = QGraphicsLinearLayout(Qt.Horizontal, self.applet)
    self.layout.addItem(self.playPauseButton)
    self.setLayout(self.layout)
    self.resize(75, 75)
    self.connect(self.playPauseButton, SIGNAL('clicked()'), self.playStop)

    #self.config().group("simplestream").writeEntry("currentStream","http://202.6.74.107:8060/triplej.mp3")
    #print "Hello"
    #print self.config().group("simplestream").readEntry("currentStream")

# Playback Control

  def playStop(self):
    if self.mediaObject.state() != Phonon.PlayingState:
      self.play()
    else:
      self.stop()

  def play(self):
    print self.stream
#    if self.stream == None:
#      self.handleError("Initial Configuration required.")
#      return
    self.mediaObject.setCurrentSource( Phonon.MediaSource( "http://202.6.74.107:8060/triplej.mp3" ))#self.stream ) )
    self.mediaObject.play() # async

  def stop(self):
    self.mediaObject.stop()
    self.playPauseButton.setIcon("media-playback-start")

  def handleStateChange(self, new, old):
    if new == Phonon.BufferingState:
      self.setBusy(True)
    if new == Phonon.PlayingState:
      self.setBusy(False)
      self.playPauseButton.setIcon("media-playback-stop")

# Configuration

  def readStream(self):
    self.stream = self.kcfg_currentStream.text()

# Error Handling

  def handleError(self, message):
    self.setBusy(False)
    KMessageBox.error(None, message, "Stream Configuration")

#  def addItem(self):
#    if self.kcfg_currentStream.text().length() > 0:
#      self.kcfg_streamList.addItem( self.kcfg_currentStream.text() )

#  def removeItem(self):
#    if self.kcfg_streamList.currentRow() > -1:
#      self.kcfg_streamList.takeItem( self.kcfg_streamList.currentRow() )

def CreateApplet(parent):
  return SimpleStream(parent)


and content/config/main.xml
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
                          http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
  <kcfgfile name="simplestreamrc"/>
  <group name="simplestream">
   <entry name="currentStream" type="Url">
      <default>"http://202.6.74.107:8060/triplej.mp3"</label>
      <label>Stream Url</label>
    </entry>
  <entry name="streamList" type="StringList">
      <label>Stream List</label>
    </entry>
  </group>
</kcfg>

the ui file is content/ui/config.ui http://pastebin.ca/1580454
I've tried to use pyuic and manually create the configuration interface like this plasmoid does (http://www.kde-look.org/content/show.php/WakeClose?content=106451) , but it broke the KConfig stuff. So, does anybody have an idea how to make my config dialog do what i want? Thanks in advance for any help you could give me!


Edit: I've decided on the create-my-own-config approch with createConfigurationInterface now. It'a not as straight-forward as I would have liked, but it's working. For anybody interested in the final outcome, see http://kde-look.org/content/show.php/Si ... ent=112825


Bookmarks



Who is online

Registered users: Bing [Bot], daret, Google [Bot], sandyvee, Sogou [Bot]