Python

Problem with Modal Dialog

This is a Work-in-Progress of Hello World 3. It is intended to show how to add a menu to a PyQt dialog, which it does successfully (see screenshot below). The problem I have is with the misbehaviour of the modal About Dialog.

The About Dialog is implemented in about_dialog.py. That Python file is stand-alone: you can run it from a Python command prompt with key-in python about_dialog.py . That pops a small dialog having a menu and a large pushbutton in the centre of the dialog. Using either menu Help->About or the pushbutton pops the modal About Dialog. Press OK in that dialog to dismiss it …

In other words, from Python's point of view that About Dialog behaves as it should.

The problem arises when running the Hello World 3 example (PyQt-HelloWorld3.py) in MicroStation. That too is a simple window that has a menu and a pushbutton. They invoke the About Dialog in the same way as described. The pushbutton behaves as expected and pops the About Dialog. The Help->About menu attempts to load the About Dialog but causes MicroStation to crash with no error message.

The Python source code of Hello World V3 is available for download below.

Hello World using PyQt

Version 3

Q How do I show a menu on a dialog?

Q How do I pop an About Dialog showing product version details?

Q How do I specify an icon for the dialog?

Q How do I pop a dialog with 'Hello World' using MicroStation Python?

A Here's a small Python program that uses the PyQt library. It shows a small dialog …

Python Implementation

The Hello World 3 example borrows from Python articles and examples you can find on the Internet. It adds the MicroStation requirements for a dialog to work harmoniously as a Python app. It adds a menu bar to the dialog …

Class Inheritance

This example builds on the first Hello World and second Hello World 2 examples. It uses class inheritance by providing a main window base class MainWindowBase, which is defined in file la_solutions_qt_widgets.py. That base class performs some actions that are required by any QMainWindow. Those actions include that windows messages are passed to MicroStation, so that the Python application doesn't make MicroStation unresponsive.

The base class sets the main window caption …

class MainWindow(la_widgets.MainWindowBase):
    # Initialize the main window class
    def __init__(self):
        # Call the parent class's constructor to initialize the main window
        super().__init__("MicroStation Python")

It sets the main window's icon, which in this example is a smiley face …

Smiley
	iconPath = la_utilities.getFileFromScriptFolder ('smiley-icon.png')
	self.setWindowIcon(QIcon(iconPath))

There are three Python utility modules …

The Python source code of Hello World V3 is available for download. The ZIP package includes several files …

The app file is HelloWorld3.py. It uses several Python library files …

The About Dialog has no dependencies on MicroStation. You can run it in a command window from a Python prompt.

Download PyQt-HelloWorld3NotWorking.zip

Unpack the ZIP file and copy the Python file into a folder that MicroStation knows about.

Python Manager

Use MicroStation's Python Manager to find and execute the script.

Questions

Post questions about MicroStation Python programming to the MicroStation Programming Forum.