Can WinForms be used with Python to make this?

We use an old VB6 program I wrote many years ago to accomplish one of our tasks:

I would like to re-write this in Python, but I’m not really clear on how I would use WinForms to make a UI similar to this one.

Is that even possible? If so, are there any examples floating around that could help me figure out how to do this?

Thanks,

Dan

There was this guy that put out a whole tutorial. However, I think you are dependent on his own code, you will always have to have that module available.

I also found this

Maybe you want to start playing with ETO (cross-platform) - although I guess that will not be hooked up in win Rhino until V6?

–Mitch

1 Like

Thanks Mitch. Looks like I have some studying to do! :grinning:

Dan

Hi Dan,

A bit late i know. :slight_smile: below is a little test using WinForms in Python.

Dan_Form.py (11.7 KB)

c.

4 Likes

Thanks for this example.

Hi Clement,

Did you type this all out, or did you use some sort of creation tool?

Thanks
-Willem

Hi @Willem,

i’ve used SharpDevelop for that, most of it is just Drag & Drop.

c.

Hi Clement,

Thanks, looks like something I can invest some time in to setup these type of forms. Can you maybe share some quick tips/tricks to set it up to make forms like your example.

Thanks
-Willem

Hi Willem, here is a quick guide:

  1. After downloading, open SharpDevelop and click on “New” document icon
  2. In the left column, highlight “Python”, in the right column choose “Form”
  3. Then click on “Create”
  4. You now have a new unsaved doc, “Sourcecode” Tab is active
  5. Change to “Design” Tab, so you can see your current WinForm (dialog)
  6. On the left, under “Tools” you can see all items under “Windows Forms”
  7. Drag and Drop eg. a Button over into your dialog
  8. To change its behaviour, select it and look on the right under “Properties”
  9. You can also add new behaviour to an element by double clicking it

Of course you can change properties of all selected items (or the form as well) from the right “Properties” section too. The Help Text under Properties is highly recommended.

Basically that is all required for a first start. Once you´ve set up your UI elements, you need to load the dialog in Rhino. This can simply be done in the same script the class is hosted by creating an instance of your form class and running it as shown above in my example script.

Personally i think WindowsForms are extremely powerful, you have a free visual editor, access to System.Drawing and millions of examples online. I´ll post some more examples if there is interest. One downside is exeption handling when running such forms in Rhino. A single error in the code can crash it, so save often. I do most of the visual UI Design in SharpDevelop and switch to the python editor at some point to set things up. If it crashes and i forgot to save, i just open TempScript.py and have lost nothing.

c.

1 Like

Hi Clement,

Thanks fro the elaborate walkthrough. It seems easy enough to get started.
One hurdle still to take: I have no python option in SharpDevelop_5.1.0.5216_Xcopyable

Ill have to do some googling to see whats up with that.

What version are you running.

Thanks again
-Willem

Hi Willem,

it seems to be version 4.4.1 in german, i have not updated it for a long time. Here is the dialog where i choose python from the left column:

c.

Hi Clement,

YES! I got it working. Sharpdevelop 5 only has C# support.

For those reading along:

I’ve got Sharpdevelop 4.4 installed from the download ob this page:
http://www.icsharpcode.net/OpenSource/SD/Download/

Careful when clicking the download link on that page; the download is hosted on sourceforge that is littered with decoy download buttons and pop-ups. Just do nothing and wait for the download to start automatically.

Thanks Clement!
-Willem

2 Likes

Ok good to know, i will keep the old SD version. :slight_smile:

c.

Question regarding the form made in Sharp Develop. How would you open the user form from outside the module? I can get it to work from inside the module but having trouble constructing the code to call the class from another module and have the userform open.

Reference to Clements code.