[go: up one dir, main page]

Menu

[b6b71a]: / calise / widgets.py  Maximize  Restore  History

Download this file

206 lines (181 with data), 7.6 kB

  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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# -*- coding: utf-8 -*-
# Copyright (C) 2011 Nicolo' Barbon
#
# This file is part of Calise.
#
# Calise 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 3 of the License, or
# any later version.
#
# Calise 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 Calise. If not, see <http://www.gnu.org/licenses/>.
import sys
from PyQt4 import QtGui, QtCore
'''Dynamic and Interactive custom progress bar that fits backlight steps
'''
class BacklightWidget(QtGui.QWidget):
def __init__(self, pal):
super(BacklightWidget, self).__init__()
self.palette = pal # color palette
self.initData()
self.initUI()
def initData(self):
self.bar = 0 # average brightness percentage (float)
self.cur = 0 # current backlight step (int)
self.tgt = 0 # suggested backlight step (int)
self.sps = None # number of backlight steps (int)
self.MousePressed = False
self.Paused = False
def initUI(self):
self.setMinimumSize(1, 30)
self.setCursor(QtGui.QCursor(QtCore.Qt.CursorShape(2)))
# paint event override:
# creates a QPainter object, draws and then terminates that object
def paintEvent(self, e):
qp = QtGui.QPainter()
qp.begin(self)
self.drawBacklightBar(qp,105.0)
qp.end()
# draw bar function: fill, stepBars, baseScale
def drawBacklightBar(self, qp, bs=100.0):
size = self.size()
w = size.width()
h = size.height()
# draw fill
till = int( round((w / bs) * self.bar, 0) )
qp.setOpacity(0.5)
if self.Paused is True:
qp.setPen(self.palette.shadow().color())
qp.setBrush(self.palette.shadow().color())
qp.drawRect(0, 0, till, h)
elif self.bar > 60:
qp.setPen(QtGui.QColor(252,233,79))
qp.setBrush(QtGui.QColor(252,233,79))
qp.drawRect(0, 0, till, h)
elif self.bar > 40 and self.bar <= 60:
qp.setPen(QtGui.QColor(245,121,0))
qp.setBrush(QtGui.QColor(245,121,0))
qp.drawRect(0, 0, till, h)
else:
qp.setPen(QtGui.QColor(114,159,207))
qp.setBrush(QtGui.QColor(114,159,207))
qp.drawRect(0, 0, till, h)
qp.setOpacity(1.0)
pen = QtGui.QPen(
self.palette.shadow().color(), 1, QtCore.Qt.SolidLine)
qp.setPen(pen)
qp.setBrush(QtCore.Qt.NoBrush)
qp.drawRect(0, 0, w-1, h-1)
if self.sps is None: return
steps = self.sps
self.pxs = w / (steps + .5)
# draw step bars
pos = int(round(self.cur * self.pxs, 0))
qp.drawLine(pos, 1, pos, h)
qp.setOpacity(0.33)
pos = int(round(self.tgt * self.pxs, 0))
qp.drawLine(pos, 1, pos, h)
qp.setOpacity(1.00)
# draw scale
if int(round(steps, 0)) < 21:
pen = QtGui.QPen(
self.palette.buttonText().color(), 1, QtCore.Qt.SolidLine)
qp.setPen(pen)
pos = int(round(1 * self.pxs - self.pxs / 2.0, 0))
qp.drawLine(pos, 1, pos, 6)
for i in range(1, steps):
pos = int(round(i * self.pxs, 0))
pon = int(round(i * self.pxs + self.pxs / 2, 0))
qp.drawLine(pos, 1, pos, 10)
qp.drawLine(pon, 1, pon, 6)
pos = int(round((i + 1) * self.pxs, 0))
qp.drawLine(pos, 1, pos, 10)
self.setMinimumSize(10 * steps, 30)
# dummy mousePress override, initializes mouseEvent
def mousePressEvent(self, event):
if event.button() != 1: return
self.MousePressed = True
# if mouseEvent inizialized: pause trough, convert click
# position to backlight step, set backlight and finally update Wideget
def mouseReleaseEvent(self, event):
if event.button() != 1: return
if self.MousePressed == True:
self.MousePressed = False
steps = self.sps
pxs = self.width() / (steps + .5)
cur = int(round(event.x() / pxs, 0))
if (
event.x() < 0 or event.x() > self.width() or
event.y() < 0 or event.y() > self.height()
): return
if cur < 1: cur = 1
elif cur > steps: cur = steps
QtCore.QObject.emit( self, QtCore.SIGNAL('bbwBarClicked(int)'), cur )
def enPause(self,boolean):
self.Paused = boolean
class AvdancedInfo(QtGui.QWidget):
def __init__(self):
super(AvdancedInfo, self).__init__()
self.initUI()
def initUI(self):
# First part of the Description entries, relative to single captures
self.fForm = QtGui.QFormLayout()
self.fForm.setVerticalSpacing(0)
self.abLabel = QtGui.QLabel()
self.abLabel.setAlignment(QtCore.Qt.AlignRight)
self.fForm.addRow(
QtCore.QString.fromUtf8(_('Ambient brightness')), self.abLabel )
self.sbLabel = QtGui.QLabel()
self.sbLabel.setAlignment(QtCore.Qt.AlignRight)
self.fForm.addRow(
QtCore.QString.fromUtf8(_('Screen brightness')), self.sbLabel )
self.bcLabel = QtGui.QLabel()
self.bcLabel.setAlignment(QtCore.Qt.AlignRight)
self.fForm.addRow(
QtCore.QString.fromUtf8(_('Brightness correction')), self.bcLabel )
self.bpLabel = QtGui.QLabel()
self.bpLabel.setAlignment(QtCore.Qt.AlignRight)
self.fForm.addRow(
QtCore.QString.fromUtf8(_('Brightness percentage')), self.bpLabel )
# Second (and last) part of the Description entries, relative to an
# average of values
self.sForm = QtGui.QFormLayout()
self.sForm.setVerticalSpacing(0)
self.apLabel = QtGui.QLabel()
self.apLabel.setAlignment(QtCore.Qt.AlignRight)
self.sForm.addRow(
QtCore.QString.fromUtf8(_('Average percentage')), self.apLabel )
self.avLabel = QtGui.QLabel()
self.avLabel.setAlignment(QtCore.Qt.AlignRight)
self.sForm.addRow(
QtCore.QString.fromUtf8(_('Averaged values')), self.avLabel )
self.cbLabel = QtGui.QLabel()
self.cbLabel.setAlignment(QtCore.Qt.AlignRight)
self.sForm.addRow(
QtCore.QString.fromUtf8(_('Current backlight')), self.cbLabel )
self.ssLabel = QtGui.QLabel()
self.ssLabel.setAlignment(QtCore.Qt.AlignRight)
self.sForm.addRow(
QtCore.QString.fromUtf8(_('Suggested backlight')), self.ssLabel )
self.ltLabel = QtGui.QLabel()
self.ltLabel.setAlignment(QtCore.Qt.AlignRight)
self.sForm.addRow(
QtCore.QString.fromUtf8(_('Lock Expiry')), self.ltLabel )
# Group boxes
self.fGroup = QtGui.QGroupBox(
QtCore.QString.fromUtf8(_( 'Capture Data' )))
self.sGroup = QtGui.QGroupBox(
QtCore.QString.fromUtf8(_( 'Averaging Data' )))
self.fGroup.setLayout(self.fForm)
self.sGroup.setLayout(self.sForm)
# Layout Boxes
self.VBox = QtGui.QVBoxLayout()
self.VBox.addWidget(self.fGroup)
self.VBox.addWidget(self.sGroup)
self.setLayout(self.VBox)