1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
# -*- coding: utf-8 -*-
# Copyright (c) Vispy Development Team. All Rights Reserved.
# Distributed under the (new) BSD License. See LICENSE.txt for more info.
from os import path as op
import warnings
from vispy.testing import requires_application
@requires_application('pyqt4', has=['uic'])
def test_qt_designer():
"""Embed Canvas via Qt Designer"""
from PyQt4 import QtGui, uic
app = QtGui.QApplication.instance()
if app is None:
app = QtGui.QApplication([])
fname = op.join(op.dirname(__file__), 'qt-designer.ui')
with warnings.catch_warnings(record=True): # pyqt4 deprecation warning
WindowTemplate, TemplateBaseClass = uic.loadUiType(fname)
class MainWindow(TemplateBaseClass):
def __init__(self):
TemplateBaseClass.__init__(self)
self.ui = WindowTemplate()
self.ui.setupUi(self)
win = MainWindow()
try:
canvas = win.ui.canvas
# test we can access properties of the internal canvas:
canvas.central_widget.add_view()
win.show()
app.processEvents()
finally:
win.close()
return win
# Don't use run_tests_if_main(), because we want to show the win
if __name__ == '__main__':
win = test_qt_designer()
win.show()
|