Skip to content

Commit

Permalink
Migrate example.pyw to qtpy
Browse files Browse the repository at this point in the history
  • Loading branch information
goanpeca committed Apr 10, 2016
1 parent ef9cbaa commit 78339dd
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions app_example/example.pyw
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@

from spyderlib.qt.QtGui import (QApplication, QMainWindow, QWidget, QLabel,
QLineEdit, QHBoxLayout, QDockWidget, QFont)
from spyderlib.qt.QtCore import Qt
# Third party imports
from qtpy.QtCore import Qt
from qtpy.QtGui import QFont
from qtpy.QtWidgets import (QApplication, QDockWidget, QHBoxLayout, QLabel,
QLineEdit, QMainWindow, QWidget)

# Local imports
from spyderlib.widgets.internalshell import InternalShell


Expand All @@ -15,11 +18,11 @@ class MyWidget(QWidget):
layout.addWidget(label)
layout.addWidget(self.edit)
self.setLayout(layout)

def get_text(self):
"""Return sample edit text"""
return self.edit.text()

def set_text(self, text):
"""Set sample edit text"""
self.edit.setText(text)
Expand All @@ -28,22 +31,22 @@ class MyWidget(QWidget):
class MyWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)

# Set this very simple widget as central widget
widget = MyWidget()
self.setCentralWidget(widget)

# Create the console widget
font = QFont("Courier new")
font.setPointSize(10)
ns = {'win': self, 'widget': widget}
msg = "Try for example: widget.set_text('foobar') or win.close()"
# Note: by default, the internal shell is multithreaded which is safer
# Note: by default, the internal shell is multithreaded which is safer
# but not compatible with graphical user interface creation.
# For example, if you need to plot data with Matplotlib, you will need
# For example, if you need to plot data with Matplotlib, you will need
# to pass the option: multithreaded=False
self.console = cons = InternalShell(self, namespace=ns, message=msg)

# Setup the console widget
cons.set_font(font)
cons.set_codecompletion_auto(True)
Expand All @@ -52,21 +55,23 @@ class MyWindow(QMainWindow):
cons.setup_completion(size=(300, 180), font=font)
console_dock = QDockWidget("Console", self)
console_dock.setWidget(cons)

# Add the console widget to window as a dockwidget
self.addDockWidget(Qt.BottomDockWidgetArea, console_dock)

self.resize(800, 600)

def closeEvent(self, event):
self.console.exit_interpreter()
event.accept()



def main():
app = QApplication([])
win = MyWindow()
win.show()
app.exec_()



if __name__ == "__main__":
main()
main()

0 comments on commit 78339dd

Please sign in to comment.