Examples from 0.1 release
This commit is contained in:
parent
bac107a5b1
commit
18e9a50506
18
samples/README
Normal file
18
samples/README
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
This is a pathetic attempt to make samples for the library.
|
||||||
|
It suffers the same problem as the library itself: no time.
|
||||||
|
|
||||||
|
It should get better soon
|
||||||
|
|
||||||
|
In order to fully understand this (and use the hundreds of things not
|
||||||
|
demonstrated), you should:
|
||||||
|
|
||||||
|
a) Read the XForms docs
|
||||||
|
b) Read the Pyxform.py file
|
||||||
|
c) Read all the .c files
|
||||||
|
|
||||||
|
Anyway, it's just a sampler, this should get MUCH more complete soon
|
||||||
|
|
||||||
|
Anyway, you can email me
|
||||||
|
|
||||||
|
Roberto Alsina
|
||||||
|
ralsina@unl.edu.ar
|
34
samples/demo1.py
Executable file
34
samples/demo1.py
Executable file
@ -0,0 +1,34 @@
|
|||||||
|
#!/usr/local/bin/python
|
||||||
|
from Pyxform import *
|
||||||
|
|
||||||
|
#
|
||||||
|
# Init the library (sucks but works)
|
||||||
|
#
|
||||||
|
|
||||||
|
xfinit ('Something','1',sys.argv[0])
|
||||||
|
|
||||||
|
#
|
||||||
|
# Create a "Window" - A form in XForms parlance
|
||||||
|
|
||||||
|
win=Form()
|
||||||
|
|
||||||
|
#
|
||||||
|
# Show it
|
||||||
|
|
||||||
|
win.Show()
|
||||||
|
|
||||||
|
#
|
||||||
|
# Create a button
|
||||||
|
|
||||||
|
a_button=Button(0,10,10,100,30,"Press Me")
|
||||||
|
|
||||||
|
#
|
||||||
|
# Put it inside win
|
||||||
|
|
||||||
|
win.Add (a_button)
|
||||||
|
|
||||||
|
#
|
||||||
|
# Start the event loop
|
||||||
|
# It will run forever, because the button doesn't do anything
|
||||||
|
|
||||||
|
runforms()
|
51
samples/demo2.py
Executable file
51
samples/demo2.py
Executable file
@ -0,0 +1,51 @@
|
|||||||
|
#!/usr/local/bin/python
|
||||||
|
|
||||||
|
from Pyxform import *
|
||||||
|
from goodies import *
|
||||||
|
|
||||||
|
#
|
||||||
|
# Init the library (sucks but works)
|
||||||
|
#
|
||||||
|
|
||||||
|
xfinit ('Something','1',sys.argv[0])
|
||||||
|
|
||||||
|
#
|
||||||
|
# Create a "Window" - A form in XForms parlance
|
||||||
|
|
||||||
|
win=Form()
|
||||||
|
|
||||||
|
#
|
||||||
|
# Show it
|
||||||
|
|
||||||
|
win.Show()
|
||||||
|
|
||||||
|
#
|
||||||
|
# Create a button
|
||||||
|
|
||||||
|
a_button=Button(0,10,10,100,30,"Press Me")
|
||||||
|
|
||||||
|
#
|
||||||
|
# Put it inside win
|
||||||
|
|
||||||
|
win.Add (a_button)
|
||||||
|
|
||||||
|
#
|
||||||
|
# Define a function, that will be executed when the button is pressed
|
||||||
|
|
||||||
|
def funct (self):
|
||||||
|
# It shows a message and exits (or not)
|
||||||
|
answer=show_question ("Do you want","to exit?","")
|
||||||
|
if answer==1:
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
#
|
||||||
|
# And bind the function to the button
|
||||||
|
|
||||||
|
a_button.cb=funct
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# Start the event loop
|
||||||
|
# It will run until you press the button and say yes
|
||||||
|
|
||||||
|
runforms()
|
75
samples/demo3.py
Executable file
75
samples/demo3.py
Executable file
@ -0,0 +1,75 @@
|
|||||||
|
#!/usr/local/bin/python
|
||||||
|
|
||||||
|
from Pyxform import *
|
||||||
|
from goodies import *
|
||||||
|
|
||||||
|
#
|
||||||
|
# Init the library (sucks but works)
|
||||||
|
#
|
||||||
|
|
||||||
|
xfinit ('Something','1',sys.argv[0])
|
||||||
|
|
||||||
|
#
|
||||||
|
# Create a "Window" - A form in XForms parlance
|
||||||
|
|
||||||
|
win=Form()
|
||||||
|
|
||||||
|
#
|
||||||
|
# Show it
|
||||||
|
|
||||||
|
win.Show()
|
||||||
|
|
||||||
|
#
|
||||||
|
# Create a button, and 2 sliders
|
||||||
|
|
||||||
|
a_button=Button(0,10,10,100,30,"Press Me")
|
||||||
|
h_slider=Slider(5,0,180,200,20,"")
|
||||||
|
v_slider=Slider(4,180,0,20,180,"")
|
||||||
|
|
||||||
|
#
|
||||||
|
# Set some values for the sliders
|
||||||
|
|
||||||
|
h_slider.Setbounds(0,200)
|
||||||
|
h_slider.Set(0)
|
||||||
|
|
||||||
|
v_slider.Setbounds(0,200)
|
||||||
|
v_slider.Set(0)
|
||||||
|
|
||||||
|
#
|
||||||
|
# Put them inside win
|
||||||
|
|
||||||
|
win.Add (a_button)
|
||||||
|
win.Add (h_slider)
|
||||||
|
win.Add (v_slider)
|
||||||
|
|
||||||
|
#
|
||||||
|
# Define a function, that will be executed when the button is pressed
|
||||||
|
|
||||||
|
def funct (self):
|
||||||
|
# It shows a message and exits (or not)
|
||||||
|
answer=show_question ("Do you want","to exit?","")
|
||||||
|
if answer==1:
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
#
|
||||||
|
# And another one, for when the sliders move
|
||||||
|
|
||||||
|
def slide (self):
|
||||||
|
# It moves the button to the position of the sliders
|
||||||
|
a_button.x=h_slider.Get()
|
||||||
|
a_button.y=v_slider.Get()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# And bind the functions to the controls
|
||||||
|
|
||||||
|
a_button.cb=funct
|
||||||
|
h_slider.cb=v_slider.cb=slide
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# Start the event loop
|
||||||
|
# It will run until you press the button and say yes
|
||||||
|
|
||||||
|
runforms()
|
77
samples/demo4.py
Executable file
77
samples/demo4.py
Executable file
@ -0,0 +1,77 @@
|
|||||||
|
#!/usr/local/bin/python
|
||||||
|
|
||||||
|
from Pyxform import *
|
||||||
|
from goodies import *
|
||||||
|
|
||||||
|
#
|
||||||
|
# Init the library (sucks but works)
|
||||||
|
#
|
||||||
|
|
||||||
|
xfinit ('Something','1',sys.argv[0])
|
||||||
|
|
||||||
|
#
|
||||||
|
# Create a "Window" - A form in XForms parlance
|
||||||
|
|
||||||
|
win=Form()
|
||||||
|
|
||||||
|
#
|
||||||
|
# Show it
|
||||||
|
|
||||||
|
win.Show()
|
||||||
|
|
||||||
|
#
|
||||||
|
# Create a button, and 2 valsliders
|
||||||
|
|
||||||
|
a_button=Button(0,10,10,100,30,"Press Me")
|
||||||
|
h_slider=Valslider(5,0,180,200,20,"")
|
||||||
|
v_slider=Valslider(4,180,0,20,180,"")
|
||||||
|
|
||||||
|
#
|
||||||
|
# Set some values for the sliders
|
||||||
|
|
||||||
|
h_slider.Setbounds(0,200)
|
||||||
|
h_slider.Set(0)
|
||||||
|
h_slider.Setprecision(0)
|
||||||
|
|
||||||
|
v_slider.Setbounds(0,200)
|
||||||
|
v_slider.Set(0)
|
||||||
|
v_slider.Setprecision(0)
|
||||||
|
|
||||||
|
#
|
||||||
|
# Put them inside win
|
||||||
|
|
||||||
|
win.Add (a_button)
|
||||||
|
win.Add (h_slider)
|
||||||
|
win.Add (v_slider)
|
||||||
|
|
||||||
|
#
|
||||||
|
# Define a function, that will be executed when the button is pressed
|
||||||
|
|
||||||
|
def funct (self):
|
||||||
|
# It shows a message and exits (or not)
|
||||||
|
answer=show_question ("Do you want","to exit?","")
|
||||||
|
if answer==1:
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
#
|
||||||
|
# And another one, for when the sliders move
|
||||||
|
|
||||||
|
def slide (self):
|
||||||
|
# It moves the button to the position of the sliders
|
||||||
|
a_button.x=h_slider.Get()
|
||||||
|
a_button.y=v_slider.Get()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# And bind the functions to the controls
|
||||||
|
|
||||||
|
a_button.cb=funct
|
||||||
|
h_slider.cb=v_slider.cb=slide
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# Start the event loop
|
||||||
|
# It will run until you press the button and say yes
|
||||||
|
|
||||||
|
runforms()
|
60
samples/demo5.py
Executable file
60
samples/demo5.py
Executable file
@ -0,0 +1,60 @@
|
|||||||
|
#!/usr/local/bin/python
|
||||||
|
|
||||||
|
from Pyxform import *
|
||||||
|
from goodies import *
|
||||||
|
|
||||||
|
#
|
||||||
|
# Init the library (sucks but works)
|
||||||
|
#
|
||||||
|
|
||||||
|
xfinit ('Something','1',sys.argv[0])
|
||||||
|
|
||||||
|
#
|
||||||
|
# Create a "Window" - A form in XForms parlance
|
||||||
|
|
||||||
|
win=Form(6,640,480)
|
||||||
|
|
||||||
|
#
|
||||||
|
# Show it
|
||||||
|
|
||||||
|
win.Show()
|
||||||
|
|
||||||
|
#
|
||||||
|
# Create a browser and a Button
|
||||||
|
|
||||||
|
brow=Browser(0,10,10,620,440,"Read Me")
|
||||||
|
but1=Button (0,10,450,100,25,"Push Me")
|
||||||
|
but2=Button (0,120,450,100,25,"Exit")
|
||||||
|
#
|
||||||
|
# Put them inside win
|
||||||
|
|
||||||
|
win.Add (brow)
|
||||||
|
win.Add (but1)
|
||||||
|
win.Add (but2)
|
||||||
|
|
||||||
|
#
|
||||||
|
# The exit function
|
||||||
|
|
||||||
|
def funct (self):
|
||||||
|
# It shows a message and exits (or not)
|
||||||
|
answer=show_question ("Do you want","to exit?","")
|
||||||
|
if answer==1:
|
||||||
|
sys.exit()
|
||||||
|
but2.cb=funct
|
||||||
|
|
||||||
|
#
|
||||||
|
# And the interesting function
|
||||||
|
|
||||||
|
def browse_file(self):
|
||||||
|
# Asks for a file, and puts it in the browser
|
||||||
|
filename=show_fselector("","","","")
|
||||||
|
brow.Load (filename)
|
||||||
|
|
||||||
|
but1.cb=browse_file
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# Start the event loop
|
||||||
|
# It will run until you press the button and say yes
|
||||||
|
|
||||||
|
runforms()
|
Loading…
Reference in New Issue
Block a user