Commits

Mathias Panzenböck committed 44dd4fd

config interface++

Comments (0)

Files changed (8)

 UI_PY=contents/code/commands_ui.py contents/code/edit_ui.py
 PY=$(UI_PY) contents/code/main.py contents/code/mediaplayer.py \
 	contents/code/playericon.py contents/code/scrollwidget.py \
-	contents/code/commandsform.py contents/code/editform.py \
-	contents/code/lbls.py
+	contents/code/commandsform.py contents/code/editform.py
 
 .PHONY: all clean install uninstall pkg ui
 

contents/code/commandsform.py

 from editform import EditForm
 
 def get_data(item):
-	return dict(
+	data = dict(
 		(unicode(key),unicode(val))
 		for key, val in item.data(Qt.UserRole).toPyObject().iteritems()
 		if val)
+	data["identity"] = unicode(item.text())
+	return data
 
 class CommandsForm(Ui_Commands,QWidget):
 	__slots__ = 'editForm',
 		if commands:
 			for cmd in commands:
 				icon = KIcon(cmd.get('icon',None) or "applications-multimedia")
-				item = QListWidgetItem(icon, cmd["identity"])
+				item = QListWidgetItem(icon, cmd.get("identity",""))
+				item.setFlags(item.flags() | Qt.ItemIsEditable)
 				item.setData(Qt.UserRole,cmd)
 				self.listPlayers.addItem(item)
 			
 			self.btnRemove.setEnabled(True)
 			self.btnEdit.setEnabled(True)
-			self.listPlayers.sortItems()
+		self.listPlayers.itemChanged.connect(self.settingsChanged)
 
 	@property
 	def commands(self):
 
 	@pyqtSlot()
 	def on_btnAdd_clicked(self):
-		name = unicode(self.txtPlayerName.text())
-		data = {"identity": name}
+		name = unicode(self.txtPlayerName.text()).strip()
+		
+		if not name:
+			msg = QtGui.qApp.tr('Please enter a player name.')
+			QMessageBox.warning(self, msg, msg, QMessageBox.Ok, QMessageBox.Ok)
+			return
+
+		data = {}
 		item = QListWidgetItem(name)
+		item.setFlags(item.flags() | Qt.ItemIsEditable)
 		item.setData(Qt.UserRole,data)
 		icon = KIcon("applications-multimedia")
 		item.setIcon(icon)
 		self.listPlayers.addItem(item)
-		self.listPlayers.sortItems()
+		self.txtPlayerName.clear()
 		self.settingsChanged.emit()
 
 	@pyqtSlot()
 			data = self.editForm.data()
 			icon = KIcon(data.get('icon',None) or "applications-multimedia")
 			item.setData(Qt.UserRole,data)
-			item.setText(data["identity"])
+			item.setText(data.get("identity",""))
 			item.setIcon(icon)
-			self.listPlayers.sortItems()
 			self.settingsChanged.emit()
 
 	@pyqtSlot()
 		item = self.listPlayers.currentItem()
 		if item:
 			data = get_data(item)
-			name = data["identity"]
+			name = data.get("identity","")
 			msg = QtGui.qApp.tr('Do you really want to delete "%1"?').arg(name)
 			btn = QMessageBox.question(self, msg, msg, QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
 			if btn == QMessageBox.Yes:

contents/code/editform.py

 ##################################################################################
 
 from PyQt4.QtCore import Qt, pyqtSlot
-from PyQt4.QtGui import QDialog
+from PyQt4 import QtGui
+from PyQt4.QtGui import QDialog, QMessageBox
 from edit_ui import Ui_Edit
 
 class EditForm(QDialog,Ui_Edit):
 		self.setWindowModality(Qt.WindowModal)
 		self.setParent(parent)
 		self.setupUi(self)
-		self.buttonBox.accepted.connect(self.accept)
 		self.buttonBox.rejected.connect(self.reject)
 		if data:
 			self.setData(data)
+	
+	@pyqtSlot()
+	def on_buttonBox_accepted(self):
+		name = unicode(self.txtIdentity.text()).strip()
+		if not name:
+			msg = QtGui.qApp.tr('Please enter a player name.')
+			QMessageBox.warning(self, msg, msg, QMessageBox.Ok, QMessageBox.Ok)
+			return
+		self.accept()
 
 	def setData(self,data):
 		self.txtIdentity.setText(data.get('identity',''))
 
 	def data(self):
 		return {
-			'identity':  unicode(self.txtIdentity.text()),
+			'identity':  unicode(self.txtIdentity.text()).strip(),
 			'icon':      unicode(self.txtIcon.text()),
 			'play':      unicode(self.txtPlay.text()),
 			'pause':     unicode(self.txtPause.text()),

contents/code/lbls.py

-# -*- coding: utf-8 -*-
-##################################################################################
-# Play Control
-# Copyright (C) 2011-2013 Mathias Panzenböck <grosser.meister.morti@gmx.net>
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
-#
-##################################################################################
-
-# TODO: proper internationalization/localization
-
-prev_lbl = 'Previous Song'
-play_pause_lbl = 'Toggle Play / Pause'
-play_lbl = 'Play'
-pause_lbl = 'Pause'
-next_lbl = 'Next Song'
-stop_lbl = 'Stop'
-forward_lbl = 'Seek Forward'
-backward_lbl = 'Seek Backward'
-quit_lbl = 'Quit Media Player'

contents/code/main.py

 ##################################################################################
 
 import sys, re
+from PyQt4 import QtGui
 from PyQt4.QtCore import Qt, QString, QSizeF
 from PyQt4.QtGui import QGraphicsGridLayout, QSizePolicy, \
 	QGraphicsLinearLayout, QGraphicsWidget
 from mediaplayer import *
 from scrollwidget import ScrollWidget
 from playericon import PlayerIcon
-from lbls import *
 
 from commandsform import CommandsForm
 
 		forward_icon    = KIcon('media-seek-forward')
 		next_icon       = KIcon('media-skip-forward')
 		quit_icon       = KIcon('application-exit')
+		
+		prev_lbl = QtGui.qApp.tr('Previous Song')
+		play_pause_lbl = QtGui.qApp.tr('Toggle Play / Pause')
+		stop_lbl = QtGui.qApp.tr('Stop')
+		next_lbl = QtGui.qApp.tr('Next Song')
+		backward_lbl = QtGui.qApp.tr('Seek Backward')
+		play_lbl = QtGui.qApp.tr('Play')
+		pause_lbl = QtGui.qApp.tr('Pause')
+		forward_lbl = QtGui.qApp.tr('Seek Forward')
+		quit_lbl = QtGui.qApp.tr('Quit Media Player')
 
 		self.prev_btn = self._add_button(prev_icon,prev_lbl,1,1)
 		self.play_pause_btn = self._add_button(play_pause_icon,play_pause_lbl,1,2)
 
 	def createConfigurationInterface(self,parent):
 		shortcuts = KShortcutsEditor(parent)
+		# will be automatically applied anyway:
+#		shortcuts.keyChange.connect(parent.settingsModified)
 		shortcuts.addCollection(self._actions)
-		parent.addPage(shortcuts, "Global Media Player Shortcuts", "preferences-desktop-keyboard")
+		parent.addPage(shortcuts, QtGui.qApp.tr("Global Media Player Shortcuts"), "preferences-desktop-keyboard")
 		self.commandsConfig = CommandsForm(parent,self._commands)
-		self.commandsConfig.settingsChanged.connect(parent.settingsChangedSlot)
-		parent.addPage(self.commandsConfig, "Command Based Player Control", "application-x-executable-script")
+		self.commandsConfig.settingsChanged.connect(parent.settingsModified)
+		parent.addPage(self.commandsConfig, QtGui.qApp.tr("Command Based Player Control"), "application-x-executable-script")
 		parent.okClicked.connect(self.configAccepted)
 		parent.applyClicked.connect(self.configAccepted)
 
 						try:
 							name = player.identity()
 						except dbus.DBusException as e:
-							print >> sys.stderr, e
+							sys.stderr.write("%s\n" % e)
 						else:
 							players[owner] = (name, player)
 		players = players.values()
 
 		for cmd in self._commands:
-			name = 'cmd:'+SPACE.sub("-",cmd['identity'].lower())
+			name = 'org.bitbucket.panzi.play-control.cmd.'+SPACE.sub("-",cmd['identity'].lower())
 			player = CommandMediaPlayer(name,cmd)
 			players.append((player.identity(), player))
 
 					if player.playing():
 						self._selected = icon_widget
 				except dbus.DBusException as e:
-					print >> sys.stderr, e
+					sys.stderr.write("%s\n" % e)
 			elif current == player.name:
 				self._selected = icon_widget
 		if self._selected is None and self.scroll_layout.count() > 0:

contents/code/playericon.py

 
 import weakref
 from PyQt4.QtCore import Qt, QSizeF
+from PyQt4 import QtGui
 from PyQt4.QtGui import QSizePolicy, QMenu
 from PyKDE4 import plasmascript
 from PyKDE4.kdeui import KIcon
 
-from lbls import *
-
 IconWidget_paint = plasmascript.Plasma.IconWidget.paint
 class PlayerIcon(plasmascript.Plasma.IconWidget):
 	__slots__ = 'applet', 'player', 'frame'
 		backward_icon = KIcon('media-seek-backward')
 		forward_icon = KIcon('media-seek-forward')
 
+		prev_lbl = QtGui.qApp.tr('Previous Song')
+		backward_lbl = QtGui.qApp.tr('Seek Backward')
+		play_pause_lbl = QtGui.qApp.tr('Toggle Play / Pause')
+		play_lbl = QtGui.qApp.tr('Play')
+		pause_lbl = QtGui.qApp.tr('Pause')
+		stop_lbl = QtGui.qApp.tr('Stop')
+		forward_lbl = QtGui.qApp.tr('Seek Forward')
+		next_lbl = QtGui.qApp.tr('Next Song')
+		quit_lbl = QtGui.qApp.tr('Quit Media Player')
+
 		menu.addAction(prev_icon,prev_lbl).triggered.connect(self.player.prev)
 		menu.addAction(backward_icon,backward_lbl).triggered.connect(self.player.backward)
 		menu.addAction(play_pause_icon,play_pause_lbl).triggered.connect(self.player.playPause)

contents/ui/commands.ui

    <string>Form</string>
   </property>
   <layout class="QGridLayout" name="gridLayout">
-   <item row="0" column="0">
+   <item row="0" column="1">
     <widget class="KLineEdit" name="txtPlayerName"/>
    </item>
-   <item row="0" column="1" rowspan="2">
+   <item row="0" column="2" rowspan="2">
     <layout class="QVBoxLayout" name="verticalLayout">
      <item>
       <widget class="QPushButton" name="btnAdd">
      </item>
     </layout>
    </item>
-   <item row="1" column="0">
+   <item row="0" column="0">
+    <widget class="QLabel" name="lblPlayerName">
+     <property name="text">
+      <string>Player &amp;Name:</string>
+     </property>
+     <property name="buddy">
+      <cstring>txtPlayerName</cstring>
+     </property>
+    </widget>
+   </item>
+   <item row="1" column="0" colspan="2">
     <widget class="QListWidget" name="listPlayers">
      <property name="iconSize">
       <size>
      <property name="uniformItemSizes">
       <bool>true</bool>
      </property>
+     <property name="sortingEnabled">
+      <bool>true</bool>
+     </property>
     </widget>
    </item>
   </layout>
   <tabstop>listPlayers</tabstop>
  </tabstops>
  <resources/>
- <connections/>
+ <connections>
+  <connection>
+   <sender>txtPlayerName</sender>
+   <signal>returnPressed()</signal>
+   <receiver>btnAdd</receiver>
+   <slot>click()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>270</x>
+     <y>11</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>726</x>
+     <y>17</y>
+    </hint>
+   </hints>
+  </connection>
+ </connections>
 </ui>
 X-KDE-PluginInfo-Author=Mathias Panzenböck
 X-KDE-PluginInfo-Email=grosser.meister.morti@gmx.net
 X-KDE-PluginInfo-Name=playctrl
-X-KDE-PluginInfo-Version=1.0.5
+X-KDE-PluginInfo-Version=1.1.0
 X-KDE-PluginInfo-Website=http://kde-look.org/content/show.php/Play+Control?content=144437
 X-KDE-PluginInfo-Category=Multimedia
 X-KDE-PluginInfo-Depends=