Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -1,20 +1,40 @@
|
|||
{{omit from|ACL2}}
|
||||
{{omit from|Applesoft BASIC|no concept of a GUI}}
|
||||
{{omit from|AWK|no concept of a GUI}}
|
||||
{{omit from|Batch File}}
|
||||
{{omit from|Blast}}
|
||||
{{omit from|Brainf***}}
|
||||
{{omit from|GUISS|Only makes use of installed applications}}
|
||||
{{omit from|Integer BASIC|no concept of a GUI}}
|
||||
{{omit from|Lilypond}}
|
||||
{{omit from|Logtalk}}
|
||||
{{omit from|Lotus 123}}
|
||||
{{omit from|Maxima}}
|
||||
{{omit from|PARI/GP}}
|
||||
{{omit from|PostScript}}
|
||||
{{omit from|Retro}}
|
||||
|
||||
Almost every application needs to communicate with the user in some way.
|
||||
Therefore, a substantial part of the code deals with the interaction of program
|
||||
logic with GUI components. Typically, the following is needed:
|
||||
Therefore, a substantial part of the code deals with the interaction
|
||||
of program logic with GUI components.
|
||||
|
||||
Typically, the following is needed:
|
||||
|
||||
* put values into input fields under program control
|
||||
* read and check input from the user
|
||||
* pop up dialogs to query the user for further information
|
||||
|
||||
The task: For a minimal "application", write a program that presents a form with
|
||||
three components to the user: A numeric input field ("Value") and two buttons
|
||||
("increment" and "random").
|
||||
The task: For a minimal "application", write a program that presents
|
||||
a form with three components to the user:
|
||||
A numeric input field ("Value") and two buttons ("increment" and "random").
|
||||
|
||||
The field is initialized to zero. The user may manually enter a new value into
|
||||
the field, or increment its value with the "increment" button. Entering a
|
||||
non-numeric value should be either impossible, or issue an error message.
|
||||
The field is initialized to zero.
|
||||
The user may manually enter a new value into the field,
|
||||
or increment its value with the "increment" button.
|
||||
Entering a non-numeric value should be either impossible,
|
||||
or issue an error message.
|
||||
|
||||
Pressing the "random" button presents a confirmation dialog, and resets the
|
||||
field's value to a random value if the answer is "Yes".
|
||||
Pressing the "random" button presents a confirmation dialog,
|
||||
and resets the field's value to a random value if the answer is "Yes".
|
||||
|
||||
(This task may be regarded as an extension of the task [[Simple windowed application]]).
|
||||
|
|
|
|||
|
|
@ -1,32 +1,31 @@
|
|||
INTERACT=: 0 : 0
|
||||
pc interact closeok;
|
||||
xywh 6 6 48 12;cc Value edit;
|
||||
xywh 6 18 48 12;cc increment button;cn "+";
|
||||
xywh 6 30 48 12;cc random button;cn "?";
|
||||
INTERACT=: noun define
|
||||
pc interact;
|
||||
cc Value edit center;
|
||||
cc increment button;cn "Increment";
|
||||
cc random button;cn "Random";
|
||||
pas 6 6;pcenter;
|
||||
rem form end;
|
||||
)
|
||||
|
||||
interact_run=: 3 : 0
|
||||
interact_run=: verb define
|
||||
wd INTERACT
|
||||
wd 'set Value 0;'
|
||||
wd 'set Value text 0;'
|
||||
wd 'pshow;'
|
||||
)
|
||||
|
||||
interact_close=: 3 : 0
|
||||
interact_cancel=: interact_close=: verb define
|
||||
wd'pclose'
|
||||
)
|
||||
|
||||
interact_Value_button=: 3 : 0
|
||||
wd 'set Value ' , ": {. 0 ". Value
|
||||
interact_Value_button=: verb define
|
||||
wd 'set Value text ' , ": {. 0 ". Value
|
||||
)
|
||||
|
||||
interact_increment_button=: 3 : 0
|
||||
wd 'set Value ' , ": 1 + {. 0 ". Value
|
||||
interact_increment_button=: verb define
|
||||
wd 'set Value text ' , ": 1 + {. 0 ". Value
|
||||
)
|
||||
|
||||
interact_random_button=: 3 : 0
|
||||
if. 0 = 2 wdquery 'Confirm';'Reset to random number?' do.
|
||||
wd 'set Value ' , ": ?100
|
||||
interact_random_button=: verb define
|
||||
if. 2 = 2 3 wdquery 'Confirm';'Reset to random number?' do.
|
||||
wd 'set Value text ' , ": ?100
|
||||
end.
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1 +1,32 @@
|
|||
interact_run''
|
||||
INTERACT=: 0 : 0
|
||||
pc interact closeok;
|
||||
xywh 6 6 48 12;cc Value edit;
|
||||
xywh 6 18 48 12;cc increment button;cn "+";
|
||||
xywh 6 30 48 12;cc random button;cn "?";
|
||||
pas 6 6;pcenter;
|
||||
rem form end;
|
||||
)
|
||||
|
||||
interact_run=: 3 : 0
|
||||
wd INTERACT
|
||||
wd 'set Value 0;'
|
||||
wd 'pshow;'
|
||||
)
|
||||
|
||||
interact_close=: 3 : 0
|
||||
wd'pclose'
|
||||
)
|
||||
|
||||
interact_Value_button=: 3 : 0
|
||||
wd 'set Value ' , ": {. 0 ". Value
|
||||
)
|
||||
|
||||
interact_increment_button=: 3 : 0
|
||||
wd 'set Value ' , ": 1 + {. 0 ". Value
|
||||
)
|
||||
|
||||
interact_random_button=: 3 : 0
|
||||
if. 0 = 2 wdquery 'Confirm';'Reset to random number?' do.
|
||||
wd 'set Value ' , ": ?100
|
||||
end.
|
||||
)
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
interact_run''
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
import random
|
||||
from Tkinter import *
|
||||
import tkMessageBox
|
||||
|
||||
|
||||
class Application(Frame):
|
||||
def __init__(self, master):
|
||||
Frame.__init__(self, master)
|
||||
self.counter = 0
|
||||
self.contents = StringVar()
|
||||
self.contents.set(str(self.counter))
|
||||
self.pack(expand=True, fill='both', padx=10, pady=15)
|
||||
self.create_widgets()
|
||||
|
||||
def increment(self, *args):
|
||||
self.counter += 1
|
||||
self.update_entry()
|
||||
|
||||
def random(self):
|
||||
if tkMessageBox.askyesno("Confirmation", "Reset to random value ?"):
|
||||
self.counter = random.randint(0, 5000)
|
||||
self.update_entry()
|
||||
|
||||
def entry_updated(self, event, *args):
|
||||
if not event.char:
|
||||
return 'break'
|
||||
if not event.char.isdigit():
|
||||
tkMessageBox.showerror('Error', 'Invalid input !')
|
||||
return 'break'
|
||||
self.counter = int('%s%s' % (self.contents.get(), event.char))
|
||||
|
||||
def update_entry(self):
|
||||
self.contents.set(str(self.counter))
|
||||
self.entry['textvariable'] = self.contents
|
||||
|
||||
def create_widgets(self):
|
||||
options = {'expand': True, 'fill': 'x', 'side': 'left', 'padx': 5}
|
||||
self.entry = Entry(self)
|
||||
self.entry.bind('<Key>', self.entry_updated)
|
||||
self.entry.pack(**options)
|
||||
self.update_entry()
|
||||
self.increment_button = Button(self, text='Increment', command=self.increment)
|
||||
self.increment_button.pack(**options)
|
||||
self.random_button = Button(self, text='Random', command=self.random)
|
||||
self.random_button.pack(**options)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
root = Tk()
|
||||
try:
|
||||
app = Application(master=root)
|
||||
app.master.title("Rosetta code")
|
||||
app.mainloop()
|
||||
except KeyboardInterrupt:
|
||||
root.destroy()
|
||||
|
|
@ -1,18 +1,18 @@
|
|||
Shoes.app do
|
||||
Shoes.app(title: "GUI component interaction") do
|
||||
stack do
|
||||
@textbox = edit_line
|
||||
textbox = edit_line
|
||||
|
||||
@textbox.change do
|
||||
@textbox.text = @textbox.text.gsub(/[^\d]/, '') and alert "Input must be a number!" if @textbox.text !~ /^\d*$/
|
||||
textbox.change do
|
||||
textbox.text = textbox.text.gsub(/[^\d]/, '') and alert "Input must be a number!" if textbox.text !~ /^\d*$/
|
||||
end
|
||||
|
||||
flow do
|
||||
button "Increment" do
|
||||
@textbox.text = @textbox.text.to_i + 1
|
||||
textbox.text = textbox.text.to_i + 1
|
||||
end
|
||||
|
||||
button "Random" do
|
||||
@textbox.text = rand 5000 if confirm "Do you want a random number?"
|
||||
textbox.text = rand 5000 if confirm "Do you want a random number?"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue