1
# -*- coding: utf-8 -*-
2
# copyright 2009 Nik Lutz
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 3 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this library; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20
from PyQt4.QtCore import *
21
from PyQt4.QtGui import *
22
from PyKDE4.plasma import Plasma
23
from PyKDE4 import plasmascript
24
from PyKDE4.kdeui import *
25
from PyKDE4.kdecore import *
26
from PyKDE4.kdecore import *
27
from PyKDE4.plasma import *
29
class Label(Plasma.Label):
30
volumeChanged = pyqtSignal(int)
32
def __init__(self, parent=None):
35
Plasma.Label.__init__(self, parent)
37
def setText(self, text):
41
def setBoldText(self,text):
46
Plasma.Label.setText(self, "<b>"+self.bold_text+"</b> "+self.text)
48
def setMinimum(self, value):
51
def setMaximum(self, value):
54
def update_with_info(self, info):
57
class LabelSlider(Plasma.Slider):
58
volumeChanged = pyqtSignal(int)
64
d = datetime.timedelta(seconds=2)
65
self.pulse_timestamp = datetime.datetime.now() + d
66
self.plasma_timestamp = datetime.datetime.now() + d
67
Plasma.Slider.__init__(self)
68
self.label = Label(self)
69
self.label.setPos(0, -4)
71
self.connect(self, SIGNAL("geometryChanged()"), self._resize_widgets)
72
self.valueChanged.connect( self.on_slider_cb)
74
def setMaximum(self, value, showticks=True):
75
Plasma.Slider.setMaximum(self,value)
76
if value > 100 and showticks:
77
self.nativeWidget().setTickInterval(100)
78
self.nativeWidget().setTickPosition(QSlider.TicksBothSides)
80
self.nativeWidget().setTickPosition(QSlider.NoTicks)
82
def _resize_widgets(self):
83
w = self.size().width()
84
self.label.setMinimumWidth(w)
85
self.label.setMaximumWidth(w)
86
# set abs position of label, respect fonts-size
87
h = self.size().height()
88
s = Plasma.Theme.defaultTheme().fontMetrics().height() + 2
90
self.label.setPos(0,v)
92
def setText(self, text):
93
self.label.setText(text)
95
def setBoldText(self,text):
96
self.label.setBoldText(text)
98
def setValueFromPlasma(self, value):
99
if self.check_pulse_timestamp():
100
self.update_plasma_timestamp()
103
def update_with_info(self, info):
104
self.setValueFromPulse(info.getVolume())
106
def setValueFromPulse(self, value):
107
if self.check_plasma_timestamp():
108
self.update_pulse_timestamp()
111
def on_slider_cb(self, value):
112
if self.check_pulse_timestamp():
113
self.update_plasma_timestamp()
114
self.volumeChanged.emit(value)
117
def update_pulse_timestamp(self):
118
self.pulse_timestamp = datetime.datetime.now()
120
def update_plasma_timestamp(self):
121
self.plasma_timestamp = datetime.datetime.now()
124
def check_plasma_timestamp(self):
125
now = datetime.datetime.now()
126
return (now - self.plasma_timestamp ).seconds > self.DELAY
128
def check_pulse_timestamp(self):
129
now = datetime.datetime.now()
130
return (now - self.pulse_timestamp ).seconds > self.DELAY
132
class VerticalSlider(LabelSlider):
133
volumeChanged = pyqtSignal(int)
136
LabelSlider.__init__(self)
137
self.label.setRotation(-90)
139
def _resize_widgets(self):
140
h = self.size().height()
141
self.label.setPos(-6, h)
142
w = self.size().height()
143
self.label.setMinimumWidth(w)
144
self.label.setMaximumWidth(w)