But, at the same time, I'm working on projects in Perl and C++ (which I'm also learning) and I've installed Qt on my system, which is an iMac running OS X 10.8.4. I downloaded and built Qt 5.1.1, then installed Sip and PyQt. Then I wanted to test and be sure PyQt was working and the new Qt install overall, too. I figured it'd be quicker to test in Python than with a C++ example (and I'm having difficulties dealing with Perl - Qt on Perl is on hold).
I found this page http://pyqt.sourceforge.net/Docs/PyQt5/designer.html with some basic information on using PyQt. Other pages talk about using pyuic, but this page says it's included and that .ui files from Qt Designer will be parsed automatically by the Qt modules. So I used Qt Designer and tried to create a simple dialog - with just Cancel and Okay buttons and I saved the file, using the names specified on the linked page. Then I renamed ui_imagedialog.ui to ui-imagedialog.py (as specified in the tutorial) and created the program file by cutting and pasting this code in my text editor:
- Code: Select all
from PyQt5.QtWidgets import QApplication, QDialog
from ui_imagedialog import Ui_ImageDialog
app = QApplication(sys.argv)
window = QDialog()
ui = Ui_ImageDialog()
(I added the 1st 2 lines.)
When I first set this up and tried it, I had not renamed ui_imagedialog.ui to ui_imagedialog.py and I got an error on the 5th line ("from ui_imagedialog import..."), which tells me that in Python, if a resource is not there, I get an error at the line where I'm trying to import. Since I didn't get any errors from the 4th line, that makes me think PyQt5 is visible and available (meaning I installed it correctly).
But once I did rename ui_imagedialog.ui to ui_imagedialog.py, I find I get this error:
- Code: Select all
Traceback (most recent call last):
File "./QtTest.py", line 5, in <module>
from ui_imagedialog import ImageDialog
File "/Users/hal/Documents/Dev/Puttering/ui_imagedialog.py", line 1
<?xml version="1.0" encoding="UTF-8"?>
SyntaxError: invalid syntax
It's having trouble from the very first line in ui_imagedialog.py. According to the information on the page with this example, the .ui file is supposed to be renamed to a .py file and is supposed to be parsed by the uic module that PyQt5 uses. I figure it is being read and treated as a Python file and not being parsed as the page the code is from states.
What am I doing wrong and what do I need to change so the .ui file is parsed as it should be?