Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all articles
Browse latest Browse all 1476

A VB6 FRM to PY Converter

$
0
0
A VB6 FRM to PY Converter


Assumptions: It is assumed that you are quite familiar with the VB6 form designer, and have at least a modicum of experience with Python and the VSCode IDE.

The development environment used for developing/testing all of this:
⦁ The VB6 SP6 IDE.
⦁ VSCode v1.79.2 (Visual Studio Code).
⦁ Python v3.11.4 from Python.org.

Additional items installed within VSCode:
⦁ Python extension v2023.15.12191008 from Microsoft.com.
⦁ Pylance v2024.2.2 from Microsoft.com.
⦁ PyQt5 library v5.15.10 (pip install pyqt5).
⦁ OS library (pip install OS).

The SYS Python library is also used, but it should be pre-installed with Python.

What's the purpose of this utility? The purpose is to provide a way to design forms using the VB6 form designer and then have the FRM's form and controls definition code translated to Python. It's very straightforward to use (after all the above is installed). Just execute the program, specify an input FRM file, specify an output PY file, and that's it. Once it's done, you should be able to load the PY file in VSCode and execute it, and then see your form as Python.

This conversion does provide some essential form and control (widget) events in which you can start programming in Python. However, this utility is not intended to be a VB6-to-Python code translator. It only converts a VB6 FRM User Interface, along with some essential properties, methods, and events for the VB6 form and controls.

Speed note: During development, Python is strictly an interpreted language. However, it can be compiled to p-code. The resulting files have the extension "pyc". Executing these "pyc" files is substantially faster than executing the source (from VSCode). There are also other "packaging" options with Python. However, you're left to your own devices regarding all of these options. I just wanted to mention it here for those who may be concerned about execution speed from within VSCode.

Controls (widgets) currently converted:
⦁ The form itself (including its menu bar).
⦁ CommandButton
⦁ CheckBox
⦁ OptionButton
⦁ TextBox
⦁ Frame
⦁ PictureBox
⦁ ListBox
⦁ ComboBox
⦁ Label
⦁ Image
⦁ Line
⦁ Shape

If you're using one of Krool's VBCCR## OCX files for control replacements, those should still get converted. I may also consider covering some of the other alternatives seen in the VB6 section of the VBForums CodeBank as well.

For reference, here are some documentation resources:

The full PyQt5 library is quite extensive, and I've only provided you with links for documentation to the sub-libraries actually used in this conversion. Regarding all the others, you're on your own.



This is an ongoing project, and more controls, along with more properties, methods, and events for the controls already converted, should be coming in the future.

Things I'm immediately considering are a TreeView, ListView, and Tab control, as I believe those may be fairly easy given the widgets that PyQt provides.

I'm also looking forward to hearing from anyone (in this thread) who may make some use of this thing. Some before (VB6) and after (Python) screenshots would be particularly nice.

I'm also more than willing to listen to critiques of all of this, especially opinions of what more people would like to see. But also, please understand that I reserve the right to consider what others may see as a "bug" as a "feature".



Here's an example of a form I grabbed to test. If you can, expand your browser so you can see them side-by-side.
(VB6 on left, Python on right):

Name:  MaintainBalanceOptions_pic.jpg
Views: 20
Size:  55.5 KBName:  MaintainBalanceOptions_PYTHON.jpg
Views: 21
Size:  54.8 KB



Update Log (reverse chronology):
  • Version 0.503:
    • Implemented code to deal with control arrays, making widget arrays.
    • Implemented a "Locked" (i.e., setReadOnly) on textboxes.
    • Added this change log to the source code files.
  • Version 0.502:
    • Fixed omission of QDesktopWidget in includes.
    • Fixed handling of extended-ANSI characters, now handling as UTF-8 in output PY file.
  • Version 0.500, initial release.



Here it is on GitHub. I've decided to just keep it on GitHub. When there are updates, I will note them on the above "Update Log".

Enjoy,
Elroy
Attached Images
  

Viewing all articles
Browse latest Browse all 1476

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>