source: orange/Orange/OrangeCanvas/application/schemeinfo.py @ 11144:5183fcc7e13e

Revision 11144:5183fcc7e13e, 4.4 KB checked in by Ales Erjavec <ales.erjavec@…>, 18 months ago (diff)

Fixes for compatibility with Qt 4.6.

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