pyxforms/examples/demo4.py

81 lines
1.3 KiB
Python
Raw Permalink Normal View History

2024-06-03 21:07:23 +00:00
#!/usr/bin/env python
2024-05-31 21:13:07 +00:00
2024-06-03 21:07:23 +00:00
from pyxforms import *
from pyxforms.goodies import *
2024-05-31 21:13:07 +00:00
#
# Init the library (sucks but works)
#
2024-06-03 14:38:36 +00:00
xfinit("Something", "1", sys.argv[0])
2024-05-31 21:13:07 +00:00
#
# Create a "Window" - A form in XForms parlance
2024-06-03 14:38:36 +00:00
win = Form()
2024-05-31 21:13:07 +00:00
#
# Show it
win.Show()
#
# Create a button, and 2 valsliders
2024-06-03 14:38:36 +00:00
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, "")
2024-05-31 21:13:07 +00:00
#
# Set some values for the sliders
2024-06-03 14:38:36 +00:00
h_slider.Setbounds(0, 200)
2024-05-31 21:13:07 +00:00
h_slider.Set(0)
h_slider.Setprecision(0)
2024-06-03 14:38:36 +00:00
v_slider.Setbounds(0, 200)
2024-05-31 21:13:07 +00:00
v_slider.Set(0)
v_slider.Setprecision(0)
#
# Put them inside win
2024-06-03 14:38:36 +00:00
win.Add(a_button)
win.Add(h_slider)
win.Add(v_slider)
2024-05-31 21:13:07 +00:00
#
# Define a function, that will be executed when the button is pressed
2024-06-03 14:38:36 +00:00
def funct(self):
# It shows a message and exits (or not)
answer = show_question("Do you want", "to exit?", "")
if answer == 1:
sys.exit()
2024-05-31 21:13:07 +00:00
#
# And another one, for when the sliders move
2024-06-03 14:38:36 +00:00
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()
2024-05-31 21:13:07 +00:00
#
# And bind the functions to the controls
2024-06-03 14:38:36 +00:00
a_button.cb = funct
h_slider.cb = v_slider.cb = slide
2024-05-31 21:13:07 +00:00
#
# Start the event loop
# It will run until you press the button and say yes
2024-06-03 14:38:36 +00:00
runforms()