Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Data-shapes
#Copyright (c) mostafa el ayoubi , 2016
#Data-Shapes www.data-shapes.net , elayoubi.mostafa@gmail.com
import clr
clr.AddReference('System.Windows.Forms')
clr.AddReference('System.Drawing')
from System.Drawing import Point
from System.Windows.Forms import Application, Button, Form, Label, TextBox, CheckBox, FolderBrowserDialog, OpenFileDialog, DialogResult
class MultiTextBoxForm(Form):
def __init__(self):
self.Text = 'Data-Shapes | Multi Input UI'
self.output = []
self.values = []
def setclose(self, sender, event):
for f in self.output:
if f.GetType() == TextBox:
self.values.append(f.Text)
if f.GetType() == CheckBox:
self.values.append(f.Checked)
if f.GetType() == Button:
self.values.append(f.Text)
self.Close()
def reset(self, sender, event):
pass
def openfile(self, sender, event):
ofd = OpenFileDialog()
dr = ofd.ShowDialog()
if dr == DialogResult.OK:
sender.Text = ofd.FileName
def opendirectory(self, sender, event):
fbd = FolderBrowserDialog()
dr = fbd.ShowDialog()
if dr == DialogResult.OK:
sender.Text = fbd.SelectedPath
form = MultiTextBoxForm()
xlabel = 25
xinput = 125
y = 10
fields = []
error = 0
#Input form
if isinstance(IN[0],list):
inputnames = IN[0]
else:
inputnames = [IN[0]]
if isinstance(IN[1],list):
inputtypes = IN[1]
else:
inputtypes = [IN[1]]
for i,j in zip(inputnames,inputtypes):
label = Label()
label.Location = Point(xlabel,y+4)
label.Height = 20
label.Width = 80
label.Text = str(i)
form.Controls.Add(label)
if j == 's':
tb = TextBox()
tb.Text = 'Default'
tb.Width = 120
tb.Location = Point(xinput,y)
y += 30
form.Controls.Add(tb)
form.Controls.Add(label)
form.output.append(tb)
elif j == 'bool':
yn = CheckBox()
yn.Location = Point(xinput,y)
yn.Text = 'Yes/No'
form.Controls.Add(yn)
y += 30
form.output.append(yn)
elif j == 'fp':
fp = Button()
fp.Width = 100
fp.Text = 'FilePath'
fp.Location = Point(xinput,y)
y+= 30
form.Controls.Add(fp)
fp.Click += form.openfile
form.output.append(fp)
elif j == 'dp':
dp = Button()
dp.Width = 100
dp.Text = 'DirectoryPath'
dp.Location = Point(xinput,y)
y+= 30
form.Controls.Add(dp)
dp.Click += form.opendirectory
form.output.append(dp)
else :
error = 1
button = Button()
button.Text = 'Set values'
button.Width = 150
button.Location = Point (100,y+30)
button.Click += form.setclose
form.Controls.Add(button)
form.Height = y + 120
if error == 0:
Application.Run(form)
result = form.values
else :
result = 'one or more input types are incorrect'
OUT = result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment