/usr/share/pyshared/PyMca/DoubleSlider.py is in pymca 4.5.0-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | #/*##########################################################################
# Copyright (C) 2004-2010 European Synchrotron Radiation Facility
#
# This file is part of the PyMCA X-ray Fluorescence Toolkit developed at
# the ESRF by the Beamline Instrumentation Software Support (BLISS) group.
#
# This toolkit 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.
#
# PyMCA 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
# PyMCA; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
# Suite 330, Boston, MA 02111-1307, USA.
#
# PyMCA follows the dual licensing model of Trolltech's Qt and Riverbank's PyQt
# and cannot be used as a free plugin for a non-free program.
#
# Please contact the ESRF industrial unit (industry@esrf.fr) if this license
# is a problem for you.
#############################################################################*/
__author__ = "V.A. Sole - ESRF BLISS Group"
import sys
import PyMcaQt as qt
QTVERSION = qt.qVersion()
if QTVERSION < '4.0.0':
try:
import Qwt5 as qwt
except:
try:
import Qwt4 as qwt
except:
import qwt
else:
from PyQt4 import Qwt5 as qwt
DEBUG = 0
class DoubleSlider(qt.QWidget):
def __init__(self, parent = None, scale = False):
qt.QWidget.__init__(self, parent)
self.mainLayout = qt.QVBoxLayout(self)
self.mainLayout.setMargin(6)
self.mainLayout.setSpacing(1)
orientation = qt.Qt.Horizontal
self.minSliderContainer = MySlider(self, orientation)
self.minSlider = self.minSliderContainer.slider
if scale:
self.minSlider.setScalePosition(qwt.QwtSlider.BottomScale)
self.minSlider.setRange(0.0, 100.0, 0.01)
self.minSlider.setValue(0.0)
self.maxSliderContainer = MySlider(self, orientation)
self.maxSlider = self.maxSliderContainer.slider
self.maxSlider.setRange(0.0, 100.0, 0.01)
self.maxSlider.setValue(100.)
self.mainLayout.addWidget(self.maxSliderContainer)
self.mainLayout.addWidget(self.minSliderContainer)
self.connect(self.minSlider,
qt.SIGNAL("valueChanged(double)"),
self._sliderChanged)
self.connect(self.maxSlider,
qt.SIGNAL("valueChanged(double)"),
self._sliderChanged)
def __getDict(self):
ddict = {}
ddict['event'] = "doubleSliderValueChanged"
m = self.minSlider.value()
M = self.maxSlider.value()
if m > M:
ddict['max'] = m
ddict['min'] = M
else:
ddict['min'] = m
ddict['max'] = M
return ddict
def _sliderChanged(self, value):
if DEBUG:
print("DoubleSlider._sliderChanged()")
ddict = self.__getDict()
if QTVERSION < '4.0.0':
self.emit(qt.PYSIGNAL("doubleSliderValueChanged"), (ddict,))
else:
self.emit(qt.SIGNAL("doubleSliderValueChanged"), ddict)
def setMinMax(self, m, M):
self.minSlider.setValue(m)
self.maxSlider.setValue(M)
def getMinMax(self):
m = self.minSlider.value()
M = self.maxSlider.value()
if m > M:
return M, m
else:
return m, M
class MySlider(qt.QWidget):
def __init__(self, parent = None, orientation=qt.Qt.Horizontal):
qt.QWidget.__init__(self, parent)
if orientation == qt.Qt.Horizontal:
alignment = qt.Qt.AlignHCenter | qt.Qt.AlignTop
layout = qt.QHBoxLayout(self)
else:
alignment = qt.Qt.AlignVCenter | qt.Qt.AlignLeft
layout = qt.QVBoxLayout(self)
layout.setMargin(0)
layout.setSpacing(0)
self.slider = qwt.QwtSlider(self, orientation)
self.label = qt.QLabel("0", self)
self.label.setAlignment(alignment)
self.label.setFixedWidth(self.label.fontMetrics().width('100.99'))
layout.addWidget(self.slider)
layout.addWidget(self.label)
self.connect(self.slider,
qt.SIGNAL('valueChanged(double)'),
self.setNum)
def setNum(self, value):
self.label.setText('%s' % value)
def test():
app = qt.QApplication([])
qt.QObject.connect(app,
qt.SIGNAL("lastWindowClosed()"),
app,
qt.SLOT('quit()'))
w = DoubleSlider()
w.show()
if QTVERSION < '4.0.0':
app.exec_loop()
else:
app.exec_()
if __name__ == "__main__":
test()
|