source: orange/Orange/OrangeCanvas/application/schemeinfo.py @ 11512:4aade1f630e1

Revision 11512:4aade1f630e1, 5.4 KB checked in by Ales Erjavec <ales.erjavec@…>, 11 months ago (diff)

Changed "Don't show at ..." check box text to "Show at ...".

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        self.desc_edit.setTabChangesFocus(True)
36
37        layout.addRow(self.tr("Name"), self.name_edit)
38        layout.addRow(self.tr("Description"), self.desc_edit)
39
40        self.__schemeIsUntitled = True
41
42        self.setLayout(layout)
43
44    def setScheme(self, scheme):
45        """Set the scheme to display/edit
46
47        """
48        self.scheme = scheme
49        if not scheme.title:
50            self.name_edit.setText(self.tr("untitled"))
51            self.name_edit.selectAll()
52            self.__schemeIsUntitled = True
53        else:
54            self.name_edit.setText(scheme.title)
55            self.__schemeIsUntitled = False
56        self.desc_edit.setPlainText(scheme.description or "")
57
58    def commit(self):
59        """Commit the current contents of the editor widgets
60        back to the scheme.
61
62        """
63        if self.__schemeIsUntitled and \
64            self.name_edit.text() == self.tr("untitled"):
65            # 'untitled' text was not changed
66            name = ""
67        else:
68            name = unicode(self.name_edit.text()).strip()
69
70        description = unicode(self.desc_edit.toPlainText()).strip()
71        self.scheme.title = name
72        self.scheme.description = description
73
74    def paintEvent(self, event):
75        return StyledWidget_paintEvent(self, event)
76
77    def title(self):
78        return unicode(self.name_edit.text()).strip()
79
80    def description(self):
81        return unicode(self.desc_edit.toPlainText()).strip()
82
83
84class SchemeInfoDialog(QDialog):
85    def __init__(self, *args, **kwargs):
86        QDialog.__init__(self, *args, **kwargs)
87        self.scheme = None
88        self.__autoCommit = True
89
90        self.__setupUi()
91
92    def __setupUi(self):
93        layout = QVBoxLayout()
94        layout.setContentsMargins(0, 0, 0, 0)
95        layout.setSpacing(0)
96
97        self.editor = SchemeInfoEdit(self)
98        self.editor.layout().setContentsMargins(20, 20, 20, 20)
99        self.editor.layout().setSpacing(15)
100        self.editor.setSizePolicy(QSizePolicy.MinimumExpanding,
101                                  QSizePolicy.MinimumExpanding)
102
103        heading = self.tr("Scheme Info")
104        heading = "<h3>{0}</h3>".format(heading)
105        self.heading = QLabel(heading, self, objectName="heading")
106
107        # Insert heading
108        self.editor.layout().insertRow(0, self.heading)
109
110        self.buttonbox = QDialogButtonBox(
111            QDialogButtonBox.Ok | QDialogButtonBox.Cancel,
112            Qt.Horizontal,
113            self
114            )
115
116        # Insert button box
117        self.editor.layout().addRow(self.buttonbox)
118
119        widget = StyledWidget(self, objectName="auto-show-container")
120        check_layout = QHBoxLayout()
121        check_layout.setContentsMargins(20, 10, 20, 10)
122        self.__showAtNewSchemeCheck = \
123            QCheckBox(self.tr("Show when I make a New Scheme."),
124                      self,
125                      objectName="auto-show-check",
126                      checked=False,
127                      )
128
129        check_layout.addWidget(self.__showAtNewSchemeCheck)
130        check_layout.addWidget(
131               QLabel(self.tr("You can edit and add Scheme Info later at the "
132                              "bottom of the menu"),
133                      self,
134                      objectName="auto-show-info"),
135               alignment=Qt.AlignRight)
136        widget.setLayout(check_layout)
137        widget.setSizePolicy(QSizePolicy.MinimumExpanding,
138                             QSizePolicy.Fixed)
139
140        if self.__autoCommit:
141            self.buttonbox.accepted.connect(self.editor.commit)
142
143        self.buttonbox.accepted.connect(self.accept)
144        self.buttonbox.rejected.connect(self.reject)
145
146        layout.addWidget(self.editor, stretch=10)
147        layout.addWidget(widget)
148
149        self.setLayout(layout)
150
151    def setShowAtNewScheme(self, checked):
152        """
153        Set the 'Show at new scheme' check state.
154        """
155        self.__showAtNewSchemeCheck.setChecked(checked)
156
157    def showAtNewScheme(self):
158        """
159        Return the check state of the 'Show at new scheme' check box.
160        """
161        return self.__showAtNewSchemeCheck.isChecked()
162
163    def setAutoCommit(self, auto):
164        if self.__autoCommit != auto:
165            self.__autoCommit = auto
166            if auto:
167                self.buttonbox.accepted.connect(self.editor.commit)
168            else:
169                self.buttonbox.accepted.disconnect(self.editor.commit)
170
171    def setScheme(self, scheme):
172        """Set the scheme to display/edit.
173        """
174        self.scheme = scheme
175        self.editor.setScheme(scheme)
Note: See TracBrowser for help on using the repository browser.