Winforms with dynamo

python
dynamo
developers

#1

Good day dears,
i’m trying to learn winforms using python in dynamo to achieve project idea.
the idea that i have 2 inputs:

  • one with changed number values … here in this example i use days name, i shall choose from them using CheckBox
  • the other one with 2 constant value like true false … here in this example i use ( week1, week2), i shall use Radio Button to choose between them

the output must be 2 list , the result from 2 inputs

i have tried to do it , but it keeps give warnings

if anybody could help please

the window should be somthing like this , but with one button

radiobutton

the code :

  import clr
  clr.AddReference("System.Windows.Forms")
  clr.AddReference("System.Drawing")

  from System.Windows.Forms import Application, Form, StatusBar
  from System.Windows.Forms import RadioButton, GroupBox, CheckBox, Label, 
  Button, AnchorStyles, DockStyle, PictureBox, PictureBoxSizeMode, TextBox
  from System.Windows.Forms import TrackBar, TickStyle
  from System.Drawing import Size, Point, Font, Color, Image

in1 = IN[0]
   


class IForm(Form):

def __init__(self):

	        
	self.checkval = []
	self.output1 = []
	self.output2 = []
	self.Font = Font("Arial",12)
	self.BackColor = Color.White
	
	self.label = Label()
	self.label.Text = "Choose"
	self.label.Location = Point(25, 100)
	self.label.Height = 25
	self.label.Width = 225
	self.label.Font = Font("OpenSans",12)
	

		
	j=150
	for i in range(len(in1)):
	   self.checkbox = CheckBox()
	   self.checkbox.Text=in1[i]
	   self.checkbox.Location = Point(25,j)
	   j+=25
	   self.checkbox.Width = 200
	   self.checkbox.Font= Font("OpenSans",10)
	   self.Controls.Add(self.checkbox)
	   self.checkval.append(self.checkbox)
	
	self.button1 = Button()
	self.button1.Text = 'apply and close'
	self.button1.Location = Point(25, j+50)
	self.button1.Click += self.update
	self.button1.Width = 250

	self.AcceptButton = self.button1

	self.Controls.Add(self.label)
	self.Controls.Add(self.button1)
	
			
	self.CenterToScreen()
	self.AutoSize = True
	
	gb = GroupBox()
    gb.Text = "Week"
    gb.Size = Size(120, 110)
    gb.Location = Point(20, 20)
    gb.Parent = self

    week1 = RadioButton()
    week1.Text = "Week 1"
    week1.Parent = gb
    week1.Location = Point(10, 30)
    week1.CheckedChanged += self.OnChanged


    week2 = RadioButton()
    week2.Text = "week2"
    week2.Parent = gb
    week2.Location = Point(10, 60)
    week2.CheckedChanged += self.OnChanged
    
def OnChanged(self, sender, event):
    if sender.Checked:
       self.output2.append(sender.Text)        

def update(self, sender, event):
	for f in self.checkval:
	    self.output1.append(f.Checked)
	 
	self.Close()



form = IForm()
Application.Run(form)
OUT = form.output1, form.output2

#2

first, use the same method for indention, dont mix blank spaces and tabulator. PEP8 recommends to use blank spaces instead of tabulator (many IDE’s use 4 blank spaces for indention).

after a class is introduced you need to indent the definitions belonging to the class.

class IForm(Form):
    def __init__(self):
        self.checkval = []
        self.output1 = []
        self.output2 = []

form.py (2.5 KB)


#3

Dear @erfajo ,
that’s a good advises i should follow and take , really appreciate for your help
thank you


#4

maybe that will answer your questions:
http://www.voidspace.org.uk/ironpython/winforms/


#5

thanks you @Peter_Kompolschek
this website is addition useful source to learn from


#6

have you taked a look in this dynamo packaged?