[Pyamp-cvs] pyamp/src config.py,NONE,1.1 fontbutton.py,NONE,1.1 optiondialog.py,NONE,1.1 listitem.py
Status: Alpha
Brought to you by:
sayap
Update of /cvsroot/pyamp/pyamp/src
In directory sc8-pr-cvs1:/tmp/cvs-serv14710/src
Modified Files:
listitem.py mainwindow.py playlist.py pyamp.py tooltip.py
Added Files:
config.py fontbutton.py optiondialog.py
Log Message:
Added GUI configuration menu, currently capable to customize playlist
font, color, and transparency
--- NEW FILE: config.py ---
# Copyright 2003 Sok Ann Yap
#
# This file is part of Pyamp.
#
# Pyamp 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.
#
# Pyamp 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 Pyamp; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
from kdecore import *
class Config:
_instance = KInstance("pyamp")
_config = _instance.config()
def config(self):
return self._config
config = classmethod(config)
--- NEW FILE: fontbutton.py ---
# Copyright 2003 Sok Ann Yap
#
# This file is part of Pyamp.
#
# Pyamp 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.
#
# Pyamp 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 Pyamp; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
from qt import *
from kdeui import *
class FontButton(QPushButton):
def __init__(self, parent, font):
QPushButton.__init__(self, parent)
self.font = QFont()
self.dialog = KFontDialog(self)
self.setFont(font)
self.connect(self, SIGNAL("clicked()"), self.showFontDialog)
self.connect(self.dialog, SIGNAL("okClicked()"), self.fontSelected)
def showFontDialog(self):
self.dialog.setFont(self.font)
self.dialog.show()
def fontSelected(self):
self.setFont(self.dialog.font())
def setFont(self, font):
QPushButton.setFont(self, font)
text = str(font.family()) + " " + str(font.pointSize())
self.setText(text)
self.font = font
def getFont(self):
return self.font
--- NEW FILE: optiondialog.py ---
# Copyright 2003 Sok Ann Yap
#
# This file is part of Pyamp.
#
# Pyamp 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.
#
# Pyamp 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 Pyamp; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
from qt import *
from kdeui import *
from kdecore import *
from fontbutton import FontButton
from listitem import ListItem
from config import Config
class OptionDialog(QTabDialog):
def __init__(self, parent):
QTabDialog.__init__(self, parent)
self.config = Config.config()
self.appearanceTab = QWidget(self)
self.createAppearanceTab()
self.addTab(self.appearanceTab, "Appearance")
self.setCancelButton()
self.setApplyButton()
self.connect(self, SIGNAL("applyButtonPressed()"), self.applyOptions)
# Manually apply to initialize settings
self.applyOptions()
def applyOptions(self):
self.config.setGroup("appearance")
self.config.writeEntry("normalBase", self.normalBaseButton.color())
self.config.writeEntry("normalText", self.normalTextButton.color())
self.config.writeEntry("normalFont", self.normalFontButton.getFont())
self.config.writeEntry("selectedBase", self.selectedBaseButton.color())
self.config.writeEntry("selectedText", self.selectedTextButton.color())
self.config.writeEntry("selectedFont", self.selectedFontButton.getFont())
self.config.writeEntry("playingBase", self.playingBaseButton.color())
self.config.writeEntry("playingText", self.playingTextButton.color())
self.config.writeEntry("playingFont", self.playingFontButton.getFont())
self.config.writeEntry("playSelBase", self.playSelBaseButton.color())
self.config.writeEntry("playSelText", self.playSelTextButton.color())
self.config.writeEntry("playSelFont", self.playSelFontButton.getFont())
self.config.writeEntry("transparency", self.transCheckBox.isChecked())
self.config.writeEntry("fade", self.fadeButton.color())
self.config.writeEntry("opacity", self.opacitySlider.value())
ListItem.readConfig()
self.parent().playList.readConfig()
self.parent().playList.triggerUpdate()
def createAppearanceTab(self):
boxLayout = QGridLayout(self.appearanceTab)
self.config.setGroup("appearance")
normalBox = QGroupBox("Normal", self.appearanceTab)
layout = QGridLayout(normalBox, 4, 2, normalBox.insideMargin(), 1)
layout.setRowSpacing(0, 6)
layout.setRowStretch(1, 1)
layout.setRowStretch(2, 1)
layout.setRowStretch(3, 1)
baseColor = self.config.readColorEntry("normalBase", KGlobalSettings.baseColor())
textColor = self.config.readColorEntry("normalText", KGlobalSettings.textColor())
font = self.config.readFontEntry("normalFont", KGlobalSettings.generalFont())
self.normalBaseButton = KColorButton(baseColor, normalBox)
self.normalTextButton = KColorButton(textColor,normalBox)
self.normalFontButton = FontButton(normalBox, font)
layout.addWidget(QLabel("Base Color", normalBox), 1, 0)
layout.addWidget(self.normalBaseButton, 1, 1)
layout.addWidget(QLabel("Text Color", normalBox), 2, 0)
layout.addWidget(self.normalTextButton, 2, 1)
layout.addWidget(QLabel("Font", normalBox), 3, 0)
layout.addWidget(self.normalFontButton, 3, 1)
selectedBox = QGroupBox("Selected", self.appearanceTab)
layout = QGridLayout(selectedBox, 4, 2, selectedBox.insideMargin(), 1)
layout.setRowSpacing(0, 6)
layout.setRowStretch(1, 1)
layout.setRowStretch(2, 1)
layout.setRowStretch(3, 1)
baseColor = self.config.readColorEntry("selectedBase", KGlobalSettings.highlightColor())
textColor = self.config.readColorEntry("selectedText", KGlobalSettings.highlightedTextColor())
font = self.config.readFontEntry("selectedFont", KGlobalSettings.generalFont())
self.selectedBaseButton = KColorButton(baseColor, selectedBox)
self.selectedTextButton = KColorButton(textColor, selectedBox)
self.selectedFontButton = FontButton(selectedBox, font)
layout.addWidget(QLabel("Base Color", selectedBox), 1, 0)
layout.addWidget(self.selectedBaseButton, 1, 1)
layout.addWidget(QLabel("Text Color", selectedBox), 2, 0)
layout.addWidget(self.selectedTextButton, 2, 1)
layout.addWidget(QLabel("Font", selectedBox), 3, 0)
layout.addWidget(self.selectedFontButton, 3, 1)
playingBox = QGroupBox("Playing", self.appearanceTab)
layout = QGridLayout(playingBox, 4, 2, playingBox.insideMargin(), 1)
layout.setRowSpacing(0, 6)
layout.setRowStretch(1, 1)
layout.setRowStretch(2, 1)
layout.setRowStretch(3, 1)
font = self.config.readFontEntry("playingFont", KGlobalSettings.generalFont())
baseColor = self.config.readColorEntry("playingBase", KGlobalSettings.highlightColor().dark())
textColor = self.config.readColorEntry("playingText", KGlobalSettings.highlightedTextColor())
self.playingBaseButton = KColorButton(baseColor, playingBox)
self.playingTextButton = KColorButton(textColor, playingBox)
self.playingFontButton = FontButton(playingBox, font)
layout.addWidget(QLabel("Base Color", playingBox), 1, 0)
layout.addWidget(self.playingBaseButton, 1, 1)
layout.addWidget(QLabel("Text Color", playingBox), 2, 0)
layout.addWidget(self.playingTextButton, 2, 1)
layout.addWidget(QLabel("Font", playingBox), 3, 0)
layout.addWidget(self.playingFontButton, 3, 1)
playSelBox = QGroupBox("Playing+Selected", self.appearanceTab)
layout = QGridLayout(playSelBox, 4, 2, playSelBox.insideMargin(), 1)
layout.setRowSpacing(0, 6)
layout.setRowStretch(1, 1)
layout.setRowStretch(2, 1)
layout.setRowStretch(3, 1)
baseColor = self.config.readColorEntry("playSelBase", KGlobalSettings.highlightColor())
textColor = self.config.readColorEntry("playSelText", KGlobalSettings.highlightedTextColor())
font = KGlobalSettings.generalFont()
font.setItalic(True)
font = self.config.readFontEntry("playSelFont", font)
self.playSelBaseButton = KColorButton(baseColor, playSelBox)
self.playSelTextButton = KColorButton(textColor, playSelBox)
self.playSelFontButton = FontButton(playSelBox, font)
layout.addWidget(QLabel("Base Color", playSelBox), 1, 0)
layout.addWidget(self.playSelBaseButton, 1, 1)
layout.addWidget(QLabel("Text Color", playSelBox), 2, 0)
layout.addWidget(self.playSelTextButton, 2, 1)
layout.addWidget(QLabel("Font", playSelBox), 3, 0)
layout.addWidget(self.playSelFontButton, 3, 1)
transBox = QGroupBox("Transparency", self.appearanceTab)
layout = QGridLayout(transBox, 4, 2, transBox.insideMargin(), 1)
layout.setRowSpacing(0, 6)
layout.setRowStretch(1, 1)
layout.setRowStretch(2, 1)
layout.setRowStretch(3, 1)
transparency = self.config.readBoolEntry("transparency", False)
fade = self.config.readColorEntry("fade", QColor("black"))
opacity = self.config.readNumEntry("opacity", 80)
self.transCheckBox = QCheckBox("Enabled", transBox)
self.transCheckBox.setChecked(transparency)
self.fadeButton = KColorButton(fade, transBox)
self.opacitySlider = QSlider(0, 100, 10, opacity, Qt.Horizontal, transBox)
layout.addWidget(self.transCheckBox, 1, 0)
layout.addWidget(QLabel("Fade to", transBox), 2, 0)
layout.addWidget(self.fadeButton, 2, 1)
layout.addWidget(QLabel("Opacity", transBox), 3, 0)
layout.addWidget(self.opacitySlider, 3, 1)
boxLayout.addWidget(normalBox, 0, 0)
boxLayout.addWidget(selectedBox, 0, 1)
boxLayout.addWidget(playingBox, 1, 0)
boxLayout.addWidget(playSelBox, 1, 1)
boxLayout.addMultiCellWidget(transBox, 2, 2, 0, 1)
Index: listitem.py
===================================================================
RCS file: /cvsroot/pyamp/pyamp/src/listitem.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** listitem.py 15 Sep 2003 11:38:13 -0000 1.2
--- listitem.py 26 Sep 2003 04:51:32 -0000 1.3
***************
*** 19,23 ****
--- 19,25 ----
from qt import *
from kdeui import *
+ from kdecore import *
from os import path
+ from config import Config
class ListItem(QListViewItem):
***************
*** 27,30 ****
--- 29,66 ----
"""
+ # Font and color settings for all ListItem's are stored as class variables
+ # for faster access
+ config = Config.config()
+ transparency = False
+ normalBase = QColor()
+ normalText = QColor()
+ normalFont = QFont()
+ selectedBase = QColor()
+ selectedText = QColor()
+ selectedFont = QFont()
+ playingBase = QColor()
+ playingText = QColor()
+ playingFont = QFont()
+ playSelBase = QColor()
+ playSelText = QColor()
+ playSelFont = QFont()
+
+ def readConfig(self):
+ self.config.setGroup("appearance")
+ self.transparency = self.config.readBoolEntry("transparency")
+ self.normalBase = self.config.readColorEntry("normalBase")
+ self.normalText = self.config.readColorEntry("normalText")
+ self.normalFont = self.config.readFontEntry("normalFont")
+ self.selectedBase = self.config.readColorEntry("selectedBase")
+ self.selectedText = self.config.readColorEntry("selectedText")
+ self.selectedFont = self.config.readFontEntry("selectedFont")
+ self.playingBase = self.config.readColorEntry("playingBase")
+ self.playingText = self.config.readColorEntry("playingText")
+ self.playingFont = self.config.readFontEntry("playingFont")
+ self.playSelBase = self.config.readColorEntry("playSelBase")
+ self.playSelText = self.config.readColorEntry("playSelText")
+ self.playSelFont = self.config.readFontEntry("playSelFont")
+ readConfig = classmethod(readConfig)
+
def __init__(self, parent, index, fullpath):
QListViewItem.__init__(self, parent)
***************
*** 68,76 ****
cg = QColorGroup(cg)
if self.isPlaying():
- cg.setColor(QColorGroup.Base, QColor(173, 235, 255))
if self.isSelected():
! f = p.font()
! f.setItalic(True)
! p.setFont(f)
QListViewItem.paintCell(self, p, cg, column, width, align)
--- 104,124 ----
cg = QColorGroup(cg)
if self.isPlaying():
if self.isSelected():
! cg.setColor(QColorGroup.Highlight, self.playSelBase)
! cg.setColor(QColorGroup.HighlightedText, self.playSelText)
! p.setFont(self.playSelFont)
! else:
! cg.setColor(QColorGroup.Base, self.playingBase)
! cg.setColor(QColorGroup.Text, self.playingText)
! p.setFont(self.playingFont)
! elif self.isSelected():
! cg.setColor(QColorGroup.Highlight, self.selectedBase)
! cg.setColor(QColorGroup.HighlightedText, self.selectedText)
! p.setFont(self.selectedFont)
! else:
! if not self.transparency:
! cg.setColor(QColorGroup.Base, self.normalBase)
! cg.setColor(QColorGroup.Text, self.normalText)
! p.setFont(self.normalFont)
QListViewItem.paintCell(self, p, cg, column, width, align)
Index: mainwindow.py
===================================================================
RCS file: /cvsroot/pyamp/pyamp/src/mainwindow.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** mainwindow.py 20 Sep 2003 20:06:30 -0000 1.5
--- mainwindow.py 26 Sep 2003 04:51:32 -0000 1.6
***************
*** 28,31 ****
--- 28,33 ----
from systemtray import SystemTray
from playlist import PlayList
+ from listitem import ListItem
+ from optiondialog import OptionDialog
from searchdialog import SearchDialog
from searchitem import SearchItem
***************
*** 33,37 ****
from songtimer import SongTimer
from songfactory import SongFactory
!
class MainWindow(KMainWindow):
--- 35,40 ----
from songtimer import SongTimer
from songfactory import SongFactory
! from config import Config
!
class MainWindow(KMainWindow):
***************
*** 42,46 ****
def __init__(self):
KMainWindow.__init__(self)
! self.config = KSimpleConfig("pyamprc")
self.tray = SystemTray(self)
self.playList = PlayList(self)
--- 45,49 ----
def __init__(self):
KMainWindow.__init__(self)
! self.config = Config.config()
self.tray = SystemTray(self)
self.playList = PlayList(self)
***************
*** 62,65 ****
--- 65,69 ----
self.actionCollection = KActionCollection(self)
self.selectedItem = None
+ self.optionDialog = OptionDialog(self)
icons = KIconLoader()
***************
*** 78,81 ****
--- 82,86 ----
self.playList.setTarget(
self.config.readBoolEntry("isTarget", False))
+ # Load the auto-saved-on-exit playlist
self.playList.load()
***************
*** 102,107 ****
def setupActions(self):
- self.config.setGroup("shortcut")
-
self.actions["saveList"] = KAction(qApp.translate("MainWindow", "Save Playlist..."),
"filesave",
--- 107,110 ----
***************
*** 240,250 ****
"about")
- #~ self.actions["songInfo"] = KAction(qApp.translate("MainWindow", "Show Song Info"),
- #~ "info",
- #~ KShortcut(self.readConfigEntry("songInfo")),
- #~ self.showSongInfo,
- #~ self.actionCollection,
- #~ "songInfo")
-
self.actions["selAll"] = KAction(qApp.translate("MainWindow", "Select All"),
"",
--- 243,246 ----
***************
*** 303,306 ****
--- 299,305 ----
self.actions["bindKey"] = KStdAction.keyBindings(self.showKeyDialog, self.actionCollection)
self.actions["bindKey"].setShortcut(KShortcut(self.readConfigEntry("bindKey")))
+
+ self.actions["option"] = KStdAction.preferences(self.showOptionDialog, self.actionCollection)
+ self.actions["option"].setShortcut(KShortcut(self.readConfigEntry("option")))
def setupMenus(self):
***************
*** 339,342 ****
--- 338,342 ----
self.configureMenu.insertSeparator()
self.actions["bindKey"].plug(self.configureMenu)
+ self.actions["option"].plug(self.configureMenu)
self.actions["about"].plug(self.helpMenu)
***************
*** 452,455 ****
--- 452,456 ----
# with QString that has ";" (e.g. "x;y") and string that ends with
# space (e.g. "Del ")
+ self.config.setGroup("shortcut")
value = self.config.readEntry(key, default)
return str(value).strip()
***************
*** 538,543 ****
def showKeyDialog(self):
self.keyDialog.configure(self.actionCollection, True)
!
def saveList(self):
filename = KFileDialog.getSaveFileName(
self.config.readPathEntry("saveListPath"),
--- 539,548 ----
def showKeyDialog(self):
self.keyDialog.configure(self.actionCollection, True)
!
! def showOptionDialog(self):
! self.optionDialog.show()
!
def saveList(self):
+ self.config.setGroup("window")
filename = KFileDialog.getSaveFileName(
self.config.readPathEntry("saveListPath"),
***************
*** 551,554 ****
--- 556,560 ----
def loadList(self):
+ self.config.setGroup("window")
filename = KFileDialog.getOpenFileName(
self.config.readPathEntry("loadListPath"),
***************
*** 562,565 ****
--- 568,572 ----
def addFile(self):
+ self.config.setGroup("window")
filenames = KFileDialog.getOpenFileNames(
self.config.readPathEntry("addFilePath"),
***************
*** 577,580 ****
--- 584,588 ----
def addDir(self):
+ self.config.setGroup("window")
dir = KDirSelectDialog.selectDirectory(
self.config.readPathEntry("addDirPath"),
Index: playlist.py
===================================================================
RCS file: /cvsroot/pyamp/pyamp/src/playlist.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** playlist.py 20 Sep 2003 17:11:06 -0000 1.4
--- playlist.py 26 Sep 2003 04:51:32 -0000 1.5
***************
*** 26,29 ****
--- 26,30 ----
from listitem import ListItem
from tooltip import ToolTip
+ from config import Config
class PlayList(KListView):
***************
*** 43,46 ****
--- 44,48 ----
def __init__(self, *args):
KListView.__init__(self, *args)
+ self.config = Config.config()
self.tooltip = ToolTip(self)
self.songThread = SongThread(self)
***************
*** 59,62 ****
--- 61,65 ----
self.playing = False
self.draggedOrders = []
+ self.root = KRootPixmap(self.viewport())
# The order column is used for ordering only, so we hide it
***************
*** 71,74 ****
--- 74,79 ----
self.header().setResizeEnabled(False)
self.setAcceptDrops(True)
+ self.setStaticBackground(True)
+ self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self.connect(self, SIGNAL("executed(QListViewItem *)"), self.userSetSong)
***************
*** 79,91 ****
self.songThread.start()
def acceptDrag(self, event):
#~ return self.acceptDrops() and self.itemsMovable() and event.source() == self
return True
- def minimumSizeHint(self):
- # Causes the playlist to be the first one to disappear when the main
- # window shrinks small enough
- return QSize(0, 0)
-
def customEvent(self, event):
# We get a next event from songThread when the current song has
--- 84,115 ----
self.songThread.start()
+ def readConfig(self):
+ transparency = self.config.readBoolEntry("transparency")
+ if transparency:
+ fade = self.config.readColorEntry("fade")
+ opacity = self.config.readNumEntry("opacity")
+ self.connect(self.root,
+ SIGNAL("backgroundUpdated(const QPixmap &)"),
+ self.updateBackground)
+ self.root.setCustomPainting(True)
+ self.root.setFadeEffect(opacity / 100.0, fade)
+ self.root.start()
+ else:
+ try:
+ self.disconnect(self.root,
+ SIGNAL("backgroundUpdated(const QPixmap &)"),
+ self.updateBackground)
+ except:
+ pass
+ self.root.stop()
+
+ def updateBackground(self, pixmap):
+ self.pixmap = pixmap
+ self.setPaletteBackgroundPixmap(pixmap)
+
def acceptDrag(self, event):
#~ return self.acceptDrops() and self.itemsMovable() and event.source() == self
return True
def customEvent(self, event):
# We get a next event from songThread when the current song has
***************
*** 405,409 ****
self.clear()
else:
! for i in selection():
self.removeSong(i)
self.compress()
--- 429,433 ----
self.clear()
else:
! for i in selection:
self.removeSong(i)
self.compress()
Index: pyamp.py
===================================================================
RCS file: /cvsroot/pyamp/pyamp/src/pyamp.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** pyamp.py 15 Sep 2003 11:38:13 -0000 1.2
--- pyamp.py 26 Sep 2003 04:51:32 -0000 1.3
***************
*** 20,26 ****
from kdecore import *
from os import system
from sys import argv, setappdefaultencoding
from mainwindow import MainWindow
- from playlist import PlayList
class Pyamp(KUniqueApplication):
--- 20,26 ----
from kdecore import *
from os import system
+ from locale import getdefaultlocale
from sys import argv, setappdefaultencoding
from mainwindow import MainWindow
class Pyamp(KUniqueApplication):
***************
*** 81,85 ****
def main():
! setappdefaultencoding("UTF-8")
about = KAboutData("pyamp", "Pyamp", "0.1.2",
"Pyamp: yet another music player",
--- 81,85 ----
def main():
! setappdefaultencoding(getdefaultlocale()[1])
about = KAboutData("pyamp", "Pyamp", "0.1.2",
"Pyamp: yet another music player",
Index: tooltip.py
===================================================================
RCS file: /cvsroot/pyamp/pyamp/src/tooltip.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** tooltip.py 20 Sep 2003 20:06:30 -0000 1.1
--- tooltip.py 26 Sep 2003 04:51:32 -0000 1.2
***************
*** 30,35 ****
length = song.getLength()
rect = self.playList.itemRect(item)
! text = fullpath \
! +"\nLength: " + secondsToStr(length) \
+ "\nFile size: " + str(path.getsize(fullpath)) + " bytes" \
+ "\nSample Frequency: " + str(sample) + " Hz" \
--- 30,36 ----
length = song.getLength()
rect = self.playList.itemRect(item)
! text = path.basename(fullpath) \
! + "\n" + path.dirname(fullpath) \
! + "\nLength: " + secondsToStr(length) \
+ "\nFile size: " + str(path.getsize(fullpath)) + " bytes" \
+ "\nSample Frequency: " + str(sample) + " Hz" \
|