source: orange/Orange/OrangeCanvas/application/schemeinfo.py @ 11166:52723f19e7a2

Revision 11166:52723f19e7a2, 4.5 KB checked in by Ales Erjavec <ales.erjavec@…>, 18 months ago (diff)

Moved the saving of "Don't show ..." check state out of SchemeInfoDialog widget.

Line 
1"""
2Scheme Info editor widget.
3
4"""
5
6from PyQt4.QtGui import (
7    QWidget, QDialog, QLabel, QTextEdit, QCheckBox, QFormLayout,
8    QVBoxLayout, QHBoxLayout, QDialogButtonBox, QSizePolicy
9)
10
11from PyQt4.QtCore import Qt
12
13from ..gui.lineedit import LineEdit
14from ..gui.utils import StyledWidget_paintEvent, StyledWidget
15
16
17class SchemeInfoEdit(QWidget):
18    """Scheme info editor widget.
19    """
20    def __init__(self, *args, **kwargs):
21        QWidget.__init__(self, *args, **kwargs)
22        self.scheme = None
23        self.__setupUi()
24
25    def __setupUi(self):
26        layout = QFormLayout()
27        layout.setRowWrapPolicy(QFormLayout.WrapAllRows)
28        layout.setFieldGrowthPolicy(QFormLayout.ExpandingFieldsGrow)
29
30        self.name_edit = LineEdit(self)
31        self.name_edit.setPlaceholderText(self.tr("untitled"))
32        self.name_edit.setSizePolicy(QSizePolicy.Expanding,
33                                     QSizePolicy.Fixed)
34        self.desc_edit = QTextEdit(self)
35
36        layout.addRow(self.tr("Name"), self.name_edit)
37        layout.addRow(self.tr("Description"), self.desc_edit)
38
39        self.setLayout(layout)
40
41    def setScheme(self, scheme):
42        """Set the scheme to display/edit
43
44        """
45        self.scheme = scheme
46        self.name_edit.setText(scheme.title or "")
47        self.desc_edit.setPlainText(scheme.description or "")
48
49    def commit(self):
50        """Commit the current contents of the editor widgets
51        back to the scheme.
52
53        """
54        name = unicode(self.name_edit.text()).strip()
55        description = unicode(self.desc_edit.toPlainText()).strip()
56        self.scheme.title = name
57        self.scheme.description = description
58
59    def paintEvent(self, event):
60        return StyledWidget_paintEvent(self, event)
61
62
63class SchemeInfoDialog(QDialog):
64    def __init__(self, *args, **kwargs):
65        QDialog.__init__(self, *args, **kwargs)
66        self.scheme = None
67        self.__setupUi()
68
69    def __setupUi(self):
70        layout = QVBoxLayout()
71        layout.setContentsMargins(0, 0, 0, 0)
72        layout.setSpacing(0)
73
74        self.editor = SchemeInfoEdit(self)
75        self.editor.layout().setContentsMargins(20, 20, 20, 20)
76        self.editor.layout().setSpacing(15)
77        self.editor.setSizePolicy(QSizePolicy.MinimumExpanding,
78                                  QSizePolicy.MinimumExpanding)
79
80        heading = self.tr("Scheme Info")
81        heading = "<h3>{0}</h3>".format(heading)
82        self.heading = QLabel(heading, self, objectName="heading")
83
84        # Insert heading
85        self.editor.layout().insertRow(0, self.heading)
86
87        self.buttonbox = QDialogButtonBox(
88            QDialogButtonBox.Ok | QDialogButtonBox.Cancel,
89            Qt.Horizontal,
90            self
91            )
92
93        # Insert button box
94        self.editor.layout().addRow(self.buttonbox)
95
96        widget = StyledWidget(self, objectName="auto-show-container")
97        check_layout = QHBoxLayout()
98        check_layout.setContentsMargins(20, 10, 20, 10)
99        self.__dontShowAtNewSchemeCheck = \
100            QCheckBox(self.tr("Don't show again when I make a New Scheme."),
101                      self,
102                      objectName="auto-show-check",
103                      checked=False,
104                      )
105
106        check_layout.addWidget(self.__dontShowAtNewSchemeCheck)
107        check_layout.addWidget(
108               QLabel(self.tr("You can edit and add Scheme Info later at the "
109                              "bottom of the menu"),
110                      self,
111                      objectName="auto-show-info"),
112               alignment=Qt.AlignRight)
113        widget.setLayout(check_layout)
114        widget.setSizePolicy(QSizePolicy.MinimumExpanding,
115                             QSizePolicy.Fixed)
116
117        self.buttonbox.accepted.connect(self.editor.commit)
118        self.buttonbox.accepted.connect(self.accept)
119        self.buttonbox.rejected.connect(self.reject)
120
121        layout.addWidget(self.editor, stretch=10)
122        layout.addWidget(widget)
123
124        self.setLayout(layout)
125
126    def setDontShowAtNewScheme(self, checked):
127        """Set the 'Dont show at new scheme' check state.
128        """
129        self.__dontShowAtNewSchemeCheck.setChecked(checked)
130
131    def dontShowAtNewScheme(self):
132        """Return the check state of the 'Dont show at new scheme' check box.
133        """
134        return self.__dontShowAtNewSchemeCheck.isChecked()
135
136    def setScheme(self, scheme):
137        """Set the scheme to display/edit.
138        """
139        self.scheme = scheme
140        self.editor.setScheme(scheme)
Note: See TracBrowser for help on using the repository browser.