source: orange/Orange/OrangeCanvas/application/schemeinfo.py @ 11190:2518a61b3e42

Revision 11190:2518a61b3e42, 4.9 KB checked in by Ales Erjavec <ales.erjavec@…>, 17 months ago (diff)

Select the 'untitled' text placeholder, tab in 'Description' box changes focus.

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
78class SchemeInfoDialog(QDialog):
79    def __init__(self, *args, **kwargs):
80        QDialog.__init__(self, *args, **kwargs)
81        self.scheme = None
82        self.__setupUi()
83
84    def __setupUi(self):
85        layout = QVBoxLayout()
86        layout.setContentsMargins(0, 0, 0, 0)
87        layout.setSpacing(0)
88
89        self.editor = SchemeInfoEdit(self)
90        self.editor.layout().setContentsMargins(20, 20, 20, 20)
91        self.editor.layout().setSpacing(15)
92        self.editor.setSizePolicy(QSizePolicy.MinimumExpanding,
93                                  QSizePolicy.MinimumExpanding)
94
95        heading = self.tr("Scheme Info")
96        heading = "<h3>{0}</h3>".format(heading)
97        self.heading = QLabel(heading, self, objectName="heading")
98
99        # Insert heading
100        self.editor.layout().insertRow(0, self.heading)
101
102        self.buttonbox = QDialogButtonBox(
103            QDialogButtonBox.Ok | QDialogButtonBox.Cancel,
104            Qt.Horizontal,
105            self
106            )
107
108        # Insert button box
109        self.editor.layout().addRow(self.buttonbox)
110
111        widget = StyledWidget(self, objectName="auto-show-container")
112        check_layout = QHBoxLayout()
113        check_layout.setContentsMargins(20, 10, 20, 10)
114        self.__dontShowAtNewSchemeCheck = \
115            QCheckBox(self.tr("Don't show again when I make a New Scheme."),
116                      self,
117                      objectName="auto-show-check",
118                      checked=False,
119                      )
120
121        check_layout.addWidget(self.__dontShowAtNewSchemeCheck)
122        check_layout.addWidget(
123               QLabel(self.tr("You can edit and add Scheme Info later at the "
124                              "bottom of the menu"),
125                      self,
126                      objectName="auto-show-info"),
127               alignment=Qt.AlignRight)
128        widget.setLayout(check_layout)
129        widget.setSizePolicy(QSizePolicy.MinimumExpanding,
130                             QSizePolicy.Fixed)
131
132        self.buttonbox.accepted.connect(self.editor.commit)
133        self.buttonbox.accepted.connect(self.accept)
134        self.buttonbox.rejected.connect(self.reject)
135
136        layout.addWidget(self.editor, stretch=10)
137        layout.addWidget(widget)
138
139        self.setLayout(layout)
140
141    def setDontShowAtNewScheme(self, checked):
142        """Set the 'Dont show at new scheme' check state.
143        """
144        self.__dontShowAtNewSchemeCheck.setChecked(checked)
145
146    def dontShowAtNewScheme(self):
147        """Return the check state of the 'Dont show at new scheme' check box.
148        """
149        return self.__dontShowAtNewSchemeCheck.isChecked()
150
151    def setScheme(self, scheme):
152        """Set the scheme to display/edit.
153        """
154        self.scheme = scheme
155        self.editor.setScheme(scheme)
Note: See TracBrowser for help on using the repository browser.