Skip to content

Using the Python Scripting Interface

MP Software (Keller Hydle) edited this page Sep 25, 2024 · 4 revisions

Using the Python Scripting Interface

MPRUN provides a powerful Python Scripting Interface (PSI) to interact with its internal application functions.

Warning

Having a good understanding of the Python programming language is essential if you want to really take advantage of the PSI. It’s okay if you don’t know Python though, as you can still download other people’s Python scripts.

Part 1: Types

You can access MPRUN’s types and objects simply by inputting mprun and using the access modifier .

All GUI is written in PyQt, so a knowledge of the Qt framework can really help!

MPRUN has types for accessing GUI widgets and functions, here is a full list:

  • mprun.panel_container: the right QToolBox containing all panels (properties panel, libraries panel, etc.)
  • mprun.left_toolbar: the left QToolBar containing all tool button QActions (select tool, pan tool, etc.)
  • mprun.top_toolbar the top QToolBar containing edit button QActions (align tools, layer tools, etc.)
  • mprun.menubar: the QMenuBar containing all sub menus (file, tools, etc.)
  • mprun.scene: the main QGraphicsScene containing all items
  • mprun.view: the main QGraphicsView encapsulating mprun.scene

Part 2: Using the Types

After you have seen all types, you can start using them. Let’s create an example script:

# No need to import mprun, as it is executed at run time

my_widget = QPushButton(mprun, ‘This is a test’)
mprun.toolbar.addWidget(my_widget)

This will create a button on the left toolbar that says “This is a test”

Part 3: Your Turn!

Since the GUI is written in PyQt, and assuming you have a knowledge in Python and Qt, start developing! You can create your own dialogs using mprun as the parent window, or even make panels and extend the functionality of MPRUN. The cool thing about the PSI is you won’t be able to break the code, or create irreversible changes. If you mess up, just restart it!

Clone this wiki locally