~elementary-os/ubuntu-package-imports/ubiquity-bionic

« back to all changes in this revision

Viewing changes to ubiquity/qtwidgets.py

  • Committer: RabbitBot
  • Date: 2018-02-05 14:44:42 UTC
  • Revision ID: rabbitbot@elementary.io-20180205144442-vt0fvth7zus90wjh
Initial import, version 17.10.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from __future__ import print_function
 
2
 
 
3
import sys
 
4
import os.path
 
5
 
 
6
from PyQt5.QtWidgets import QWidget, QHBoxLayout, QLabel, QSizePolicy
 
7
from PyQt5.QtSvg import QSvgWidget
 
8
 
 
9
 
 
10
class SquareSvgWidget(QSvgWidget):
 
11
    def __init__(self, parent=None):
 
12
        QSvgWidget.__init__(self, parent)
 
13
        sizePolicy = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
 
14
        sizePolicy.setHeightForWidth(True)
 
15
        self.setSizePolicy(sizePolicy)
 
16
 
 
17
    def heightForWidth(self, width):
 
18
        return width
 
19
 
 
20
 
 
21
class StateBox(QWidget):
 
22
    def __init__(self, parent, text=''):
 
23
        QWidget.__init__(self, parent)
 
24
 
 
25
        self.label = QLabel(text, self)
 
26
        self.image = SquareSvgWidget(self)
 
27
 
 
28
        layout = QHBoxLayout(self)
 
29
        layout.setContentsMargins(0, 0, 0, 0)
 
30
        layout.addWidget(self.image)
 
31
        layout.addWidget(self.label)
 
32
        layout.addStretch()
 
33
 
 
34
        self.set_state(True)
 
35
 
 
36
    def set_state(self, state):
 
37
        self.status = state
 
38
        if state:
 
39
            # A tickmark
 
40
            name = "dialog-ok-apply.svg"
 
41
        else:
 
42
            # A cross
 
43
            name = "edit-delete.svg"
 
44
        icon = "/usr/share/icons/breeze/actions/22/" + name
 
45
        if not os.path.isfile(icon):
 
46
            icon = "/usr/share/icons/breeze/actions/toolbar/" + name
 
47
        self.image.load(icon)
 
48
 
 
49
    def get_state(self):
 
50
        return self.status
 
51
 
 
52
    def set_property(self, prop, value):
 
53
        if prop == "label":
 
54
            self.label.setText(value)
 
55
        else:
 
56
            print("qtwidgets.StateBox set_property() only implemented for "
 
57
                  "label", file=sys.stderr)