demoPySideLoader.py

demoPySideLoader.py
1 # Demonstrates loading .ui files with MaxPlus.LoadUiType
2 # Note: run this example using MAXScript: Python.ExecuteFile(demoFile)
3 # Scripting > Run Script and Tools > Evaluate All do not handle the Unicode
4 
5 import MaxPlus
6 import os
7 from PySide2.QtWidgets import QTabWidget
8 
9 class TestWidget(QTabWidget):
10  def __init__(self, ui_class, parent=MaxPlus.GetQMaxMainWindow()):
11  QTabWidget.__init__(self, parent)
12  self.ui= ui_class()
13  self.ui.setupUi(self)
14 
15 def test_load_ascii_ui_path(ui_path):
16  ui_class, base_class = MaxPlus.LoadUiType(ui_path)
17  instance = TestWidget(ui_class)
18  instance.show()
19 
20 def test_load_ui():
21  ui_path = os.path.join(os.path.dirname(__file__), "test_ui.ui")
22  test_load_ascii_ui_path(ui_path)
23  # test unicode encoding
24  test_load_ascii_ui_path(u'%s' % ui_path)
25  # test a unicode encoding with non-ascii characters
26  try:
27  test_load_ascii_ui_path(u'D:/你好')
28  except UnicodeEncodeError:
29  pass
30  else:
31  print "Error: unexpected exception"
32 
33 
34 if __name__ == "__main__":
35  test_load_ui()