~ubuntu-branches/debian/experimental/spyder/experimental

« back to all changes in this revision

Viewing changes to app_example/example.pyw

  • Committer: Package Import Robot
  • Author(s): Picca Frédéric-Emmanuel
  • Date: 2013-02-27 09:51:28 UTC
  • mfrom: (1.1.18)
  • Revision ID: package-import@ubuntu.com-20130227095128-wtx1irpvf4vl79lj
Tags: 2.2.0~beta3+dfsg-1
* Imported Upstream version 2.2.0~beta3+dfsg
* debian /patches
  - 0002-feature-forwarded-add-icon-to-desktop-file.patch (deleted)
    this patch was integrated by the upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
from spyderlib.qt.QtGui import (QApplication, QMainWindow, QWidget, QLabel,
3
 
                                QLineEdit, QHBoxLayout, QDockWidget, QFont)
4
 
from spyderlib.qt.QtCore import Qt
5
 
 
6
 
from spyderlib.widgets.internalshell import InternalShell
7
 
 
8
 
 
9
 
class MyWidget(QWidget):
10
 
    def __init__(self):
11
 
        QWidget.__init__(self)
12
 
        label = QLabel("Imagine an extraordinary complex widget right here...")
13
 
        self.edit = QLineEdit("Text")
14
 
        layout = QHBoxLayout()
15
 
        layout.addWidget(label)
16
 
        layout.addWidget(self.edit)
17
 
        self.setLayout(layout)
18
 
        
19
 
    def get_text(self):
20
 
        """Return sample edit text"""
21
 
        return self.edit.text()
22
 
        
23
 
    def set_text(self, text):
24
 
        """Set sample edit text"""
25
 
        self.edit.setText(text)
26
 
 
27
 
 
28
 
class MyWindow(QMainWindow):
29
 
    def __init__(self):
30
 
        QMainWindow.__init__(self)
31
 
        
32
 
        # Set this very simple widget as central widget
33
 
        widget = MyWidget()
34
 
        self.setCentralWidget(widget)
35
 
        
36
 
        # Create the console widget
37
 
        font = QFont("Courier new")
38
 
        font.setPointSize(10)
39
 
        ns = {'win': self, 'widget': widget}
40
 
        msg = "Try for example: widget.set_text('foobar') or win.close()"
41
 
        # Note: by default, the internal shell is multithreaded which is safer 
42
 
        # but not compatible with graphical user interface creation.
43
 
        # For example, if you need to plot data with Matplotlib, you will need 
44
 
        # to pass the option: multithreaded=False
45
 
        self.console = cons = InternalShell(self, namespace=ns, message=msg)
46
 
        
47
 
        # Setup the console widget
48
 
        cons.set_font(font)
49
 
        cons.set_codecompletion_auto(True)
50
 
        cons.set_calltips(True)
51
 
        cons.setup_calltips(size=600, font=font)
52
 
        cons.setup_completion(size=(300, 180), font=font)
53
 
        console_dock = QDockWidget("Console", self)
54
 
        console_dock.setWidget(cons)
55
 
        
56
 
        # Add the console widget to window as a dockwidget
57
 
        self.addDockWidget(Qt.BottomDockWidgetArea, console_dock)
58
 
        
59
 
        self.resize(800, 600)
60
 
        
61
 
    def closeEvent(self, event):
62
 
        self.console.exit_interpreter()
63
 
        event.accept()
64
 
        
65
 
def main():
66
 
    app = QApplication([])
67
 
    win = MyWindow()
68
 
    win.show()
69
 
    app.exec_()
70
 
        
71
 
if __name__ == "__main__":
 
1
 
 
2
from spyderlib.qt.QtGui import (QApplication, QMainWindow, QWidget, QLabel,
 
3
                                QLineEdit, QHBoxLayout, QDockWidget, QFont)
 
4
from spyderlib.qt.QtCore import Qt
 
5
 
 
6
from spyderlib.widgets.internalshell import InternalShell
 
7
 
 
8
 
 
9
class MyWidget(QWidget):
 
10
    def __init__(self):
 
11
        QWidget.__init__(self)
 
12
        label = QLabel("Imagine an extraordinary complex widget right here...")
 
13
        self.edit = QLineEdit("Text")
 
14
        layout = QHBoxLayout()
 
15
        layout.addWidget(label)
 
16
        layout.addWidget(self.edit)
 
17
        self.setLayout(layout)
 
18
        
 
19
    def get_text(self):
 
20
        """Return sample edit text"""
 
21
        return self.edit.text()
 
22
        
 
23
    def set_text(self, text):
 
24
        """Set sample edit text"""
 
25
        self.edit.setText(text)
 
26
 
 
27
 
 
28
class MyWindow(QMainWindow):
 
29
    def __init__(self):
 
30
        QMainWindow.__init__(self)
 
31
        
 
32
        # Set this very simple widget as central widget
 
33
        widget = MyWidget()
 
34
        self.setCentralWidget(widget)
 
35
        
 
36
        # Create the console widget
 
37
        font = QFont("Courier new")
 
38
        font.setPointSize(10)
 
39
        ns = {'win': self, 'widget': widget}
 
40
        msg = "Try for example: widget.set_text('foobar') or win.close()"
 
41
        # Note: by default, the internal shell is multithreaded which is safer 
 
42
        # but not compatible with graphical user interface creation.
 
43
        # For example, if you need to plot data with Matplotlib, you will need 
 
44
        # to pass the option: multithreaded=False
 
45
        self.console = cons = InternalShell(self, namespace=ns, message=msg)
 
46
        
 
47
        # Setup the console widget
 
48
        cons.set_font(font)
 
49
        cons.set_codecompletion_auto(True)
 
50
        cons.set_calltips(True)
 
51
        cons.setup_calltips(size=600, font=font)
 
52
        cons.setup_completion(size=(300, 180), font=font)
 
53
        console_dock = QDockWidget("Console", self)
 
54
        console_dock.setWidget(cons)
 
55
        
 
56
        # Add the console widget to window as a dockwidget
 
57
        self.addDockWidget(Qt.BottomDockWidgetArea, console_dock)
 
58
        
 
59
        self.resize(800, 600)
 
60
        
 
61
    def closeEvent(self, event):
 
62
        self.console.exit_interpreter()
 
63
        event.accept()
 
64
        
 
65
def main():
 
66
    app = QApplication([])
 
67
    win = MyWindow()
 
68
    win.show()
 
69
    app.exec_()
 
70
        
 
71
if __name__ == "__main__":
72
72
    main()
 
 
b'\\ No newline at end of file'