File: modbutton.py

package info (click to toggle)
convertall 0.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,448 kB
  • ctags: 521
  • sloc: python: 2,338; makefile: 7
file content (41 lines) | stat: -rw-r--r-- 1,457 bytes parent folder | download | duplicates (2)
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
#****************************************************************************
# modbutton.py, provides a button that signals its text
#
# ConvertAll, a units conversion program
# Copyright (C) 2014, Douglas W. Bell
#
# This is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License, either Version 2 or any later
# version.  This program is distributed in the hope that it will be useful,
# but WITTHOUT ANY WARRANTY.  See the included LICENSE file for details.
#*****************************************************************************

from PyQt4 import QtCore, QtGui


class ModButton(QtGui.QPushButton):
    """Button used to add operators, change exponent or clear unit.
    """
    stateChg = QtCore.pyqtSignal()
    def __init__(self, function, param, label, parent=None):
        QtGui.QPushButton.__init__(self, label, parent)
        self.function = function
        self.param = param
        self.setFocusPolicy(QtCore.Qt.NoFocus)
        self.clicked.connect(self.exe)

    def exe(self):
        """Execute function on button push.
        """
        if self.param != None:
            self.function(self.param)
        else:
            self.function()
        self.stateChg.emit()       # update listView

    def sizeHint(self):
        """Adjust width smaller.
        """
        size = QtGui.QPushButton.sizeHint(self)
        size.setWidth(size.width() / 2)
        return size