Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,8 @@
---
category:
- GUI
- Basic language learning
from: http://rosettacode.org/wiki/User_input/Graphical
note: Text processing
requires:
- Graphics

View file

@ -0,0 +1,6 @@
In this task, the goal is to input a string and the integer 75000, from [[graphical user interface]].
See also: [[User input/Text]]
<br><br>

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,80 @@
with Gtk.Button; use Gtk.Button;
with Gtk.GEntry; use Gtk.GEntry;
with Gtk.Label; use Gtk.Label;
with Gtk.Window; use Gtk.Window;
with Gtk.Widget; use Gtk.Widget;
with Gtk.Table; use Gtk.Table;
with Gtk.Handlers;
with Gtk.Main;
procedure Graphic_Input is
Window : Gtk_Window;
Grid : Gtk_Tnetable;
Label : Gtk_Label;
Message : Gtk_Label;
Edit : Gtk_GEntry;
Button : Gtk_Button;
package Handlers is new Gtk.Handlers.Callback (Gtk_Widget_Record);
package Return_Handlers is
new Gtk.Handlers.Return_Callback (Gtk_Widget_Record, Boolean);
function Delete_Event (Widget : access Gtk_Widget_Record'Class)
return Boolean is
begin
return False;
end Delete_Event;
procedure Destroy (Widget : access Gtk_Widget_Record'Class) is
begin
Gtk.Main.Main_Quit;
end Destroy;
procedure Clicked (Widget : access Gtk_Widget_Record'Class) is
begin
if Get_Text (Label) = "Enter integer:" then
Set_Text (Message, "Entered:" & Integer'Image (Integer'Value (Get_Text (Edit))));
Set_Sensitive (Button, False);
else
Set_Text (Message, "Entered:" & Get_Text (Edit));
Set_Text (Label, "Enter integer:");
end if;
exception
when Constraint_Error =>
Set_Text (Message, "Error integer input");
end Clicked;
begin
Gtk.Main.Init;
Gtk.Window.Gtk_New (Window);
Gtk_New (Grid, 2, 3, False);
Add (Window, Grid);
Gtk_New (Label, "Enter string:");
Attach (Grid, Label, 0, 1, 0, 1);
Gtk_New (Edit);
Attach (Grid, Edit, 1, 2, 0, 1);
Gtk_New (Button, "OK");
Attach (Grid, Button, 2, 3, 0, 1);
Gtk_New (Message);
Attach (Grid, Message, 0, 3, 1, 2);
Return_Handlers.Connect
( Window,
"delete_event",
Return_Handlers.To_Marshaller (Delete_Event'Access)
);
Handlers.Connect
( Window,
"destroy",
Handlers.To_Marshaller (Destroy'Access)
);
Handlers.Connect
( Button,
"clicked",
Handlers.To_Marshaller (Clicked'Access)
);
Show_All (Grid);
Show (Window);
Gtk.Main.Main;
end Graphic_Input;

View file

@ -0,0 +1 @@
set input to text returned of (display dialog "Enter text:" default answer "")

View file

@ -0,0 +1 @@
set input to text returned of (display dialog "Enter a number:" default answer "") as integer

View file

@ -0,0 +1,3 @@
InputBox, String, Input, Enter a string:
InputBox, Int, Input, Enter an int:
Msgbox, You entered "%String%" and "%Int%"

View file

@ -0,0 +1,13 @@
Gui, Add, Text,, String:
Gui, Add, Text,, Int:
Gui, Add, Button, gGo, Go!
Gui, Add, Edit, vString ym
Gui, Add, Edit, VInt
Gui, Show, Center, Input
Return
Go:
Gui, Submit, NoHide
Msgbox, You entered "%String%" and "%Int%"
ExitApp
Return

View file

@ -0,0 +1,25 @@
INSTALL @lib$+"WINLIB2"
INSTALL @lib$+"WINLIB5"
ES_NUMBER = 8192
form% = FN_newdialog("Rosetta Code", 100, 100, 100, 64, 8, 1000)
PROC_static(form%, "String:", 100, 8, 8, 30, 14, 0)
PROC_editbox(form%, "Example", 101, 40, 6, 52, 14, 0)
PROC_static(form%, "Number:", 102, 8, 26, 30, 14, 0)
PROC_editbox(form%, "75000", 103, 40, 24, 52, 14, ES_NUMBER)
PROC_pushbutton(form%, "Read", FN_setproc(PROCread), 30, 43, 40, 16, 0)
PROC_showdialog(form%)
REPEAT
WAIT 1
UNTIL !form% = 0
QUIT
DEF PROCread
LOCAL buffer%, number%
DIM buffer% LOCAL 255
SYS "GetDlgItemText", !form%, 101, buffer%, 255
SYS "GetDlgItemInt", !form%, 103, 0, 1 TO number%
PRINT "String = """ $$buffer% """"
PRINT "Number = " ; number%
ENDPROC

View file

@ -0,0 +1,25 @@
OPTION GUI TRUE
PRAGMA GUI gtk3
DECLARE text TYPE STRING
DECLARE data TYPE FLOATING
gui = GUIDEFINE(" \
{ type=WINDOW name=window callback=delete-event title=\"Rosetta Code\" width-request=300 } \
{ type=BOX name=box parent=window orientation=GTK_ORIENTATION_VERTICAL } \
{ type=ENTRY name=entry parent=box margin=4 callback=activate } \
{ type=SPIN_BUTTON name=spin parent=box margin=4 numeric=TRUE } \
{ type=BUTTON_BOX name=bbox parent=box } \
{ type=BUTTON name=button parent=bbox margin=4 callback=clicked label=\"Exit\" }")
CALL GUISET(gui, "spin", "adjustment", gtk_adjustment_new(75000, 0, 100000, 1, 1, 0))
REPEAT
event$ = GUIEVENT$(gui)
UNTIL event$ = "button" OR event$ = "window"
CALL GUIGET(gui, "entry", "text", &text)
PRINT text FORMAT "Entered: %s\n"
CALL GUIGET(gui, "spin", "value", &data)
PRINT data FORMAT "Entered: %g\n"

View file

@ -0,0 +1,25 @@
#ifndef TASK_H
#define TASK_H
#include <QWidget>
class QLabel ;
class QLineEdit ;
class QVBoxLayout ;
class QHBoxLayout ;
class EntryWidget : public QWidget {
Q_OBJECT
public :
EntryWidget( QWidget *parent = 0 ) ;
private :
QHBoxLayout *upperpart , *lowerpart ;
QVBoxLayout *entryLayout ;
QLineEdit *stringinput ;
QLineEdit *numberinput ;
QLabel *stringlabel ;
QLabel *numberlabel ;
} ;
#endif

View file

@ -0,0 +1,28 @@
#include <QLineEdit>
#include <QLabel>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QString>
#include "task.h"
EntryWidget::EntryWidget ( QWidget *parent )
: QWidget( parent ) {
entryLayout = new QVBoxLayout( this ) ;
stringlabel = new QLabel( "Enter a string!" ) ;
stringinput = new QLineEdit( "" ) ;
stringinput->setMaxLength( 20 ) ;
stringinput->setInputMask( QString( "AAAAAAAAAAAAAAAAAAA" ) ) ;
upperpart = new QHBoxLayout ;
upperpart->addWidget( stringlabel ) ;
upperpart->addWidget( stringinput ) ;
numberlabel = new QLabel( "Enter a number!" ) ;
numberinput = new QLineEdit( "0" ) ;
numberinput->setMaxLength( 5 ) ;
numberinput->setInputMask( QString( "99999" ) ) ;
lowerpart = new QHBoxLayout ;
lowerpart->addWidget( numberlabel ) ;
lowerpart->addWidget( numberinput ) ;
entryLayout->addLayout( upperpart ) ;
entryLayout->addLayout( lowerpart ) ;
setLayout( entryLayout ) ;
}

View file

@ -0,0 +1,9 @@
#include <QApplication>
#include "task.h"
int main( int argc , char *argv[ ] ) {
QApplication app( argc , argv ) ;
EntryWidget theWidget ;
theWidget.show( ) ;
return app.exec( ) ;
}

View file

@ -0,0 +1,74 @@
#include <gtk/gtk.h>
void ok_hit(GtkButton *o, GtkWidget **w)
{
GtkMessageDialog *msg;
gdouble v = gtk_spin_button_get_value((GtkSpinButton *)w[1]);
const gchar *c = gtk_entry_get_text((GtkEntry *)w[0]);
msg = (GtkMessageDialog *)
gtk_message_dialog_new(NULL,
GTK_DIALOG_MODAL,
(v==75000) ? GTK_MESSAGE_INFO : GTK_MESSAGE_ERROR,
GTK_BUTTONS_OK,
"You wrote '%s' and selected the number %d%s",
c, (gint)v,
(v==75000) ? "" : " which is wrong (75000 expected)!");
gtk_widget_show_all(GTK_WIDGET(msg));
(void)gtk_dialog_run(GTK_DIALOG(msg));
gtk_widget_destroy(GTK_WIDGET(msg));
if ( v==75000 ) gtk_main_quit();
}
int main(int argc, char **argv)
{
GtkWindow *win;
GtkEntry *entry;
GtkSpinButton *spin;
GtkButton *okbutton;
GtkLabel *entry_l, *spin_l;
GtkHBox *hbox[2];
GtkVBox *vbox;
GtkWidget *widgs[2];
gtk_init(&argc, &argv);
win = (GtkWindow *)gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(win, "Insert values");
entry_l = (GtkLabel *)gtk_label_new("Insert a string");
spin_l = (GtkLabel *)gtk_label_new("Insert 75000");
entry = (GtkEntry *)gtk_entry_new();
spin = (GtkSpinButton *)gtk_spin_button_new_with_range(0, 80000, 1);
widgs[0] = GTK_WIDGET(entry);
widgs[1] = GTK_WIDGET(spin);
okbutton = (GtkButton *)gtk_button_new_with_label("Ok");
hbox[0] = (GtkHBox *)gtk_hbox_new(FALSE, 1);
hbox[1] = (GtkHBox *)gtk_hbox_new(FALSE, 1);
vbox = (GtkVBox *)gtk_vbox_new(TRUE, 1);
gtk_container_add(GTK_CONTAINER(hbox[0]), GTK_WIDGET(entry_l));
gtk_container_add(GTK_CONTAINER(hbox[0]), GTK_WIDGET(entry));
gtk_container_add(GTK_CONTAINER(hbox[1]), GTK_WIDGET(spin_l));
gtk_container_add(GTK_CONTAINER(hbox[1]), GTK_WIDGET(spin));
gtk_container_add(GTK_CONTAINER(vbox), GTK_WIDGET(hbox[0]));
gtk_container_add(GTK_CONTAINER(vbox), GTK_WIDGET(hbox[1]));
gtk_container_add(GTK_CONTAINER(vbox), GTK_WIDGET(okbutton));
gtk_container_add(GTK_CONTAINER(win), GTK_WIDGET(vbox));
g_signal_connect(G_OBJECT(win), "delete-event", (GCallback)gtk_main_quit, NULL);
g_signal_connect(G_OBJECT(okbutton), "clicked", (GCallback)ok_hit, widgs);
gtk_widget_show_all(GTK_WIDGET(win));
gtk_main();
return 0;
}

View file

@ -0,0 +1,6 @@
(import 'javax.swing.JOptionPane)
(let [number (-> "Enter an Integer"
JOptionPane/showInputDialog
Integer/parseInt)
string (JOptionPane/showInputDialog "Enter a String")]
[number string])

View file

@ -0,0 +1 @@
(capi:prompt-for-string "Enter a string:")

View file

@ -0,0 +1,4 @@
(do ((number 0) (okp t))
((or (not okp) (= 75000 number)))
(multiple-value-setq (number okp)
(capi:prompt-for-integer "Enter an integer:")))

View file

@ -0,0 +1,2 @@
(capi:prompt-for-integer "Enter an integer:"
:ok-check #'(lambda (n) (= n 75000)))

View file

@ -0,0 +1,13 @@
(capi:define-interface string/integer-prompt () ()
(:panes
(string-pane
capi:text-input-pane
:title "Enter a string:")
(integer-pane
capi:text-input-pane
:title "Enter an integer:"
:change-callback :redisplay-interface))
(:layouts
(main
capi:column-layout
'(string-pane integer-pane))))

View file

@ -0,0 +1,7 @@
(defun string/integer-prompt-value (pane)
(with-slots (string-pane integer-pane) pane
(let* ((string (capi:text-input-pane-text string-pane))
(integer-string (capi:text-input-pane-text integer-pane))
(integer (when (every 'digit-char-p integer-string)
(parse-integer integer-string :junk-allowed t))))
(values (cons string integer)))))

View file

@ -0,0 +1,6 @@
(defun do-prompting ()
(capi:popup-confirmer
(make-instance 'string/integer-prompt)
"Enter some values:"
:value-function 'string/integer-prompt-value
:ok-check #'(lambda (result) (eql (cdr result) 75000))))

View file

@ -0,0 +1,89 @@
import 'package:flutter/material.dart';
main() => runApp( OutputLabel() );
class OutputLabel extends StatefulWidget {
@override
_OutputLabelState createState() => _OutputLabelState();
}
class _OutputLabelState extends State<OutputLabel> {
String output = "output"; // This will be displayed in an output text field
TextEditingController _stringInputController = TextEditingController(); // Allows us to get the text from a text field
TextEditingController _numberInputController = TextEditingController();
@override
Widget build( BuildContext context ) {
return MaterialApp(
debugShowCheckedModeBanner: false, // Disable debug banner in top right
home: Scaffold ( // Scaffold provides a layout for the app
body: Center ( // Everything in the center widget will be centered
child: Column ( // All the widgets will be in a column
children: <Widget> [
SizedBox( height: 25 ), // Space between top and text field
TextField ( // String input Text Field
controller: _stringInputController, // Add input controller so we can grab text
textAlign: TextAlign.center, // Center text
decoration: InputDecoration( border: OutlineInputBorder(), labelText: 'Enter a string...'), // Border and default text
), // end TextField
SizedBox( height: 10 ), // Space between text fields
TextField ( // Number input Text Field
controller: _numberInputController, // Add input controller so we can grab text
textAlign: TextAlign.center, // Center text
decoration: InputDecoration( border: OutlineInputBorder(), labelText: 'Enter 75000'), // Border and default text
), // end TextField
FlatButton ( // Submit Button
child: Text('Submit Data'), // Button Text
color: Colors.blue[400] // button color
onPressed: () { // On pressed Callback for button
setState( () {
output = ''; // Reset output
int number; // Int to store number in
var stringInput = _stringInputController.text ?? ''; // Get the input from the first field, if it is null set it to an empty string
var numberString = _numberInputController.text ?? ''; // Get the input from the second field, if it is null set it to an empty string
if ( stringInput == '') { // If first field is empty
output = 'Please enter something in field 1\n';
return;
}
if (_numberInputController.text == '') { // If second field is empty
output += 'Please enter something in field 2';
return;
} else { // If we got an input in the second field
try {
number = int.parse( numberString ); // Parse numberString into an int
if ( number == 75000 )
output = 'text output: $stringInput\nnumber: $number'; // Grabs the text from the input controllers and changes the string
else
output = '$number is not 75000!';
} on FormatException { // If a number is not entered in second field
output = '$numberString is not a number!';
}
}
});
}
), // End FlatButton
Text( output ) // displays output
]
)
)
)
);
}
}

View file

@ -0,0 +1,20 @@
program UserInputGraphical;
{$APPTYPE CONSOLE}
uses SysUtils, Dialogs;
var
s: string;
lStringValue: string;
lIntegerValue: Integer;
begin
lStringValue := InputBox('User input/Graphical', 'Enter a string', '');
repeat
s := InputBox('User input/Graphical', 'Enter the number 75000', '75000');
lIntegerValue := StrToIntDef(s, 0);
if lIntegerValue <> 75000 then
ShowMessage('Invalid entry: ' + s);
until lIntegerValue = 75000;
end.

View file

@ -0,0 +1,2 @@
s = input["Enter a string: "]
i = parseInt[input["Enter an integer: "]]

View file

@ -0,0 +1,2 @@
[s,i] = input["Dialog title", ["Enter a string", "Enter an integer"]]
i = parseInt[i]

View file

@ -0,0 +1,36 @@
hTextBox As TextBox
hValueBox As ValueBox
hLabel As Label
Public Sub Form_Open()
With Me
.Height = 100
.Width = 300
.padding = 5
.Arrangement = Arrange.Vertical
.Title = "User input/Graphical"
End With
hTextBox = New TextBox(Me) As "TextBox1"
hTextBox.Expand = True
hValueBox = New ValueBox(Me) As "ValueBox1"
hValueBox.Expand = True
hLabel = New Label(Me)
hLabel.expand = True
End
Public Sub TextBox1_Change()
hLabel.text = hTextBox.Text & " - " & Str(hValueBox.value)
End
Public Sub valueBox1_Change()
TextBox1_Change
End

View file

@ -0,0 +1,97 @@
package main
import (
"github.com/gotk3/gotk3/gtk"
"log"
"math/rand"
"strconv"
"time"
)
func validateInput(window *gtk.Window, str1, str2 string) bool {
n, err := strconv.ParseFloat(str2, 64)
if len(str1) == 0 || err != nil || n != 75000 {
dialog := gtk.MessageDialogNew(
window,
gtk.DIALOG_MODAL,
gtk.MESSAGE_ERROR,
gtk.BUTTONS_OK,
"Invalid input",
)
dialog.Run()
dialog.Destroy()
return false
}
return true
}
func check(err error, msg string) {
if err != nil {
log.Fatal(msg, err)
}
}
func main() {
rand.Seed(time.Now().UnixNano())
gtk.Init(nil)
window, err := gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
check(err, "Unable to create window:")
window.SetTitle("Rosetta Code")
window.SetPosition(gtk.WIN_POS_CENTER)
window.Connect("destroy", func() {
gtk.MainQuit()
})
vbox, err := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 1)
check(err, "Unable to create vertical box:")
vbox.SetBorderWidth(1)
hbox1, err := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 1)
check(err, "Unable to create first horizontal box:")
hbox2, err := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 1)
check(err, "Unable to create second horizontal box:")
label, err := gtk.LabelNew("Enter a string and the number 75000 \n")
check(err, "Unable to create label:")
sel, err := gtk.LabelNew("String: ")
check(err, "Unable to create string entry label:")
nel, err := gtk.LabelNew("Number: ")
check(err, "Unable to create number entry label:")
se, err := gtk.EntryNew()
check(err, "Unable to create string entry:")
ne, err := gtk.EntryNew()
check(err, "Unable to create number entry:")
hbox1.PackStart(sel, false, false, 2)
hbox1.PackStart(se, false, false, 2)
hbox2.PackStart(nel, false, false, 2)
hbox2.PackStart(ne, false, false, 2)
// button to accept
ab, err := gtk.ButtonNewWithLabel("Accept")
check(err, "Unable to create accept button:")
ab.Connect("clicked", func() {
// read and validate the entered values
str1, _ := se.GetText()
str2, _ := ne.GetText()
if validateInput(window, str1, str2) {
window.Destroy() // close window if input is OK
}
})
vbox.Add(label)
vbox.Add(hbox1)
vbox.Add(hbox2)
vbox.Add(ab)
window.Add(vbox)
window.ShowAll()
gtk.Main()
}

View file

@ -0,0 +1,7 @@
import javax.swing.JOptionPane
def number = JOptionPane.showInputDialog ("Enter an Integer") as Integer
def string = JOptionPane.showInputDialog ("Enter a String")
assert number instanceof Integer
assert string instanceof String

View file

@ -0,0 +1,61 @@
import Graphics.UI.Gtk
import Control.Monad
main = do
initGUI
window <- windowNew
set window [windowTitle := "Graphical user input", containerBorderWidth := 10]
vb <- vBoxNew False 0
containerAdd window vb
hb1 <- hBoxNew False 0
boxPackStart vb hb1 PackNatural 0
hb2 <- hBoxNew False 0
boxPackStart vb hb2 PackNatural 0
lab1 <- labelNew (Just "Enter number 75000")
boxPackStart hb1 lab1 PackNatural 0
nrfield <- entryNew
entrySetText nrfield "75000"
boxPackStart hb1 nrfield PackNatural 5
strfield <- entryNew
boxPackEnd hb2 strfield PackNatural 5
lab2 <- labelNew (Just "Enter a text")
boxPackEnd hb2 lab2 PackNatural 0
accbox <- hBoxNew False 0
boxPackStart vb accbox PackNatural 5
im <- imageNewFromStock stockApply IconSizeButton
acceptButton <- buttonNewWithLabel "Accept"
buttonSetImage acceptButton im
boxPackStart accbox acceptButton PackRepel 0
txtstack <- statusbarNew
boxPackStart vb txtstack PackNatural 0
id <- statusbarGetContextId txtstack "Line"
widgetShowAll window
onEntryActivate nrfield (showStat nrfield txtstack id)
onEntryActivate strfield (showStat strfield txtstack id)
onPressed acceptButton $ do
g <- entryGetText nrfield
if g=="75000" then
widgetDestroy window
else do
msgid <- statusbarPush txtstack id "You didn't enter 75000. Try again"
return ()
onDestroy window mainQuit
mainGUI
showStat :: Entry -> Statusbar -> ContextId -> IO ()
showStat fld stk id = do
txt <- entryGetText fld
let mesg = "You entered \"" ++ txt ++ "\""
msgid <- statusbarPush stk id mesg
return ()

View file

@ -0,0 +1 @@
*Main> main

View file

@ -0,0 +1,4 @@
CHARACTER string*100
DLG(Edit=string, Edit=num_value, Button='&OK', TItle='Enter 75000 for num_value')
WRITE(Messagebox, Name) "You entered", string, num_value

View file

@ -0,0 +1,15 @@
procedure main()
WOpen("size=800,800") | stop("Unable to open window")
WWrite("Enter a string:")
s := WRead()
WWrite("You entered ",image(s))
WWrite("Enter the integer 75000:")
i := WRead()
if i := integer(i) then
WWrite("You entered: ",i)
else
WWrite(image(i)," isn't an integer")
WDone()
end
link graphics

View file

@ -0,0 +1,26 @@
SIMPLEGUI=: noun define
pc simpleGui;
cc IntegerLabel static;cn "Enter the integer 75000";
cc integer edit;
cc TextLabel static;cn "Enter text";
cc text edit;
cc accept button;cn "Accept";
pshow;
)
simpleGui_run=: wd bind SIMPLEGUI
simpleGui_close=: wd bind 'pclose'
simpleGui_cancel=: simpleGui_close
simpleGui_accept_button=: verb define
ttxt=. text
tint=. _". integer
if. tint ~: 75000 do.
wdinfo 'Integer entered was not 75000.'
else.
simpleGui_close ''
'simpleGui_text simpleGui_integer'=: ttxt;tint
end.
)
simpleGui_run''

View file

@ -0,0 +1,32 @@
SIMPLEGUI=: noun define
pc simpleGui;
xywh 136 39 44 12;cc accept button;cn "Accept";
xywh 0 14 60 11;cc IntegerLabel static ss_right;cn "Enter an integer";
xywh 65 13 60 12;cc integer edit;
xywh 0 39 60 11;cc TextLabel static ss_right;cn "Enter text";
xywh 64 38 60 12;cc text edit;
pas 6 6;pcenter;
rem form end;
)
simpleGui_run=: verb define
wd SIMPLEGUI
wd 'set integer *', ": 75000
wd 'pshow;'
)
simpleGui_accept_button=: verb define
ttxt=. text
tint=. _". integer NB. invalid integers assigned value _
if. tint ~: 75000 do.
wdinfo 'Integer entered was not 75000.'
else.
simpleGui_close ''
'simpleGui_text simpleGui_integer'=: ttxt;tint
end.
)
simpleGui_close=: wd bind 'pclose'
simpleGui_cancel=: simpleGui_close
simpleGui_run''

View file

@ -0,0 +1,9 @@
import javax.swing.*;
public class GetInputSwing {
public static void main(String[] args) throws Exception {
int number = Integer.parseInt(
JOptionPane.showInputDialog ("Enter an Integer"));
String string = JOptionPane.showInputDialog ("Enter a String");
}
}

View file

@ -0,0 +1,5 @@
var str = prompt("Enter a string");
var value = 0;
while (value != 75000) {
value = parseInt( prompt("Enter the number 75000") );
}

View file

@ -0,0 +1,31 @@
using Gtk
function twoentrywindow()
txt = "Enter Text Here"
txtchanged = false
win = GtkWindow("Keypress Test", 500, 100) |> (GtkFrame() |> (vbox = GtkBox(:v)))
lab = GtkLabel("Enter some text in the first box and 7500 into the second box.")
txtent = GtkEntry()
set_gtk_property!(txtent,:text,"Enter Some Text Here")
nument = GtkEntry()
set_gtk_property!(nument,:text,"Enter the number seventy-five thousand here")
push!(vbox, lab, txtent, nument)
function keycall(w, event)
strtxt = get_gtk_property(txtent, :text, String)
numtxt = get_gtk_property(nument, :text, String)
if strtxt != txt && occursin("75000", numtxt)
set_gtk_property!(lab, :label, "You have accomplished the task.")
end
end
signal_connect(keycall, win, "key-press-event")
cond = Condition()
endit(w) = notify(cond)
signal_connect(endit, win, :destroy)
showall(win)
wait(cond)
end
twoentrywindow()

View file

@ -0,0 +1,9 @@
// version 1.1
import javax.swing.JOptionPane
fun main(args: Array<String>) {
do {
val number = JOptionPane.showInputDialog("Enter 75000").toInt()
} while (number != 75000)
}

View file

@ -0,0 +1,48 @@
' [RC] User input/graphical
' Typical LB graphical input/output example.This shows how LB takes user input.
' You'd usually do more validating of input.
nomainwin ' No console window needed.
textbox#w.tb1, 100, 20, 200, 30
textbox#w.tb2, 100, 60, 200, 30
textbox#w.tb3, 100,160, 200, 30
statictext #w.st1, "String =", 10, 30, 90, 30
statictext #w.st2, "Integer =", 10, 70, 90, 30
button #w.b1, "Read and Show", [buttonClicked], LR, 180, 70
WindowWidth =360
WindowHeight =240
UpperLeftX = 40
UpperLeftY = 40
open "User input of integer & string" for window as #w
#w "trapclose [quit]" ' Clean exit routine.
#w.tb1 "!font courier 12"
#w.tb2 "!font courier 12"
#w.tb3 "!font courier 12 bold"
#w.st1 "!font courier 12"
#w.st2 "!font courier 12"
#w.tb1 "Change this string."
#w.tb2 "Enter an integer here."
#w.tb3 "Display will be here."
#w.tb1 "!selectall"
wait
[buttonClicked] ' Button-clicked routine collects data
#w.tb1 "!contents? in1$"
#w.tb2 "!contents? in2$"
#w.tb3 in1$; " "; int( val( in2$))
wait
[quit]
close #w
end

View file

@ -0,0 +1,13 @@
Module CheckIt {
Def aName$="No Name", Num$
\\ we open a new stack, and hold old
Stack New {
If Ask$("Give your name:",,,,,aName$)="OK" Then Read aName$
If Ask$("Give a Number: (75000)",,,,,"")="OK" Then Read Num$
if Num$<>"75000" or aName$="" Then loop
}
\ now old stack came back
Print Num$, aName$
Print Letter$ \\ Letter$ pop a string from stack
}
CheckIt "Thank You"

View file

@ -0,0 +1,51 @@
Module Checkit {
Declare Form1 Form
Declare Inp1 Textbox Form Form1
Declare Inp2 Textbox Form Form1
With Inp1, "Prompt", "String: ", "MaxCharLength", 30+8, "ShowAlways", 1, "ThisKind" as info$, "VarText" as Aname$
info$=" <write your name>"
With Inp2, "Prompt", "Integer: ", "MaxCharLength", 10+9, "VarText" as Feed$, "ThisKind"," sec", "ShowAlways", 1
feed$="0"
\\ local1, and Event service functions have module visibility.
\\ So they have to use Read New to make new references (shadow old), and use local (the same for SUBS)
\\ Event's service functions can't use parents Subs, but Local1 can be used (exist in a list visible to Events)
Function Local1 (new Feed$) {
\\ this function can be used from other Integer
\\ this$ and thispos, exist just before the call of this function
local sgn$
if feed$="" and this$="-" then thispos-- : exit
if left$(this$,1)="-" then sgn$="-": this$=mid$(this$, 2)
if this$<>Trim$(this$) then this$=Feed$ : thispos-- : exit
If Trim$(this$)="" then this$="0" : thispos=2 : exit
if instr(this$,"+")>0 and sgn$="-" then this$=filter$(this$, "+") : sgn$=""
if instr(this$,"-")>0 and sgn$="" then this$=filter$(this$, "-") : sgn$="-"
if filter$(this$,"0123456789")<>"" then this$=Feed$ : thispos-- : exit
if len(this$)>1 then While left$(this$,1)="0" {this$=mid$(this$, 2)}
this$=sgn$+this$
if this$="-0" then this$="-" : thispos=2
}
Function Inp1.ValidString {
Read New &this$
While left$(this$, 1)=" " { this$=mid$(this$, 2)}
info$=str$(30-Len(This$), "\<0\>")
}
Function Inp2.ValidString {
\\ this function called direct from textbox
Read New &this$, &thispos
Call Local local1(Feed$)
}
Function Form1.Unload {
Read New &Quit
If feed$<>"75000" Or Aname$="" then {
\\ open messagebox, pressing cancel quit Unload
Quit=Ask("Data isn't correct")=2
}
}
Method Inp1, "Move", 2000,2000, 6000, 600
Method Inp2, "Move", 2000,3000, 6000, 600
Method Form1, "Show", 1
If Feed$="75000" and Aname$<>"" Then Print "Thank You"
Declare Form1 Nothing
}
Checkit

View file

@ -0,0 +1,2 @@
str = InputString["Input a string"]; nb =
InputString["Input a number"]; Print[str, " " , ToString@nb]

View file

@ -0,0 +1,56 @@
import Nanoquery.Util.Windows
// a function to handle the main window closing
def finish(caller, event)
exit
end
// create a window
w = new(Window, "Input").setTitle("Input")
w.setSize(320, 190)
w.setHandler(w.closing, finish)
// create two labels to go next to the input boxes
stringlabel = new(Label).setParent(w)
intlabel = new(Label).setParent(w)
stringlabel.setText("String: "); stringlabel.setPosition(20, 25)
intlabel.setText("Integer: "); intlabel.setPosition(20, 75)
// create two textboxes for input
stringbox = new(Textbox).setParent(w)
intbox = new(Textbox).setParent(w)
stringbox.setPosition(100, 20); stringbox.setWidth(200); stringbox.setHeight(30)
intbox.setPosition(100, 70); intbox.setWidth(200); intbox.setHeight(30)
// a function that handles when the 'done' button is clicked
def done_clicked(caller, event)
global stringbox
global intbox
global w
s = stringbox.getText()
i = intbox.getText()
try
if int(i) = 75000
println "String: " + s
println "Integer: " + i
exit
else
w.showMessageBox("Please enter 75000 for the integer value")
end
catch
w.showMessageBox("Please enter 75000 for the integer value")
end
end
// create the 'done' button
done = new(Button).setParent(w)
done.setText("Done"); done.setPosition(250,120)
done.setHandler(done.clicked, done_clicked)
// display the window
w.show()

View file

@ -0,0 +1,18 @@
/* NetRexx */
options replace format comments java crossref symbols nobinary
import javax.swing.JOptionPane
unumber = 0
ustring = ''
do
unumber = Integer.parseInt(JOptionPane.showInputDialog("Enter an Integer"))
ustring = JOptionPane.showInputDialog("Enter a String")
catch ex = Exception
ex.printStackTrace
end
unumber = unumber * 1.0 -- just to prove unumber is really a number
say 'Number:' unumber.right(10)', String:' ustring
return

View file

@ -0,0 +1,45 @@
; file: input-gui.lsp
; url: http://rosettacode.org/wiki/User_input/Graphical
; author: oofoe 2012-02-02
; Colours
(setq ok '(.8 1 .8) fail '(1 .5 .5))
; Load library and initialize GUI server:
(load (append (env "NEWLISPDIR") "/guiserver.lsp"))
(gs:init)
; Validation Callback
; There is a bug in the "gs:get-text" function that causes it to fail
; silently if the text field is empty. Therfore, I set the field
; background to red first and only clear it if the field returns
; correctly.
(define (validate)
(gs:set-color 'string fail)
(if (not (empty? (gs:get-text 'string)))
(gs:set-color 'string ok))
(gs:set-color 'number fail)
(if (= 75000 (int (gs:get-text 'number)))
(gs:set-color 'number ok))
)
; Create main window frame and set layout.
(gs:frame 'main 100 100 256 128 "User Input/Graphical")
(gs:set-flow-layout 'main "left" 4 4)
; Create and add widgets.
(gs:label 'instructions "Please enter a string and the number 75000:")
(gs:text-field 'string 'validate 32)
(gs:text-field 'number 'validate 8)
(gs:button 'check 'validate "validate...")
(gs:add-to 'main 'instructions 'string 'number 'check)
; Show main window.
(gs:set-visible 'main true)
; Start event loop.
(gs:listen)
; No (exit) needed -- guiserver kills program on window close.

View file

@ -0,0 +1,82 @@
import strutils
import gintro/[glib, gobject, gtk, gio]
type MainWindow = ref object of ApplicationWindow
strEntry: Entry
intEntry: SpinButton
#---------------------------------------------------------------------------------------------------
proc displayValues(strval: string; intval: int) =
## Display a dialog window with the values entered by the user.
let dialog = newDialog()
dialog.setModal(true)
let label1 = newLabel(" String value is “$1”.".format(strval))
label1.setHalign(Align.start)
dialog.contentArea.packStart(label1, true, true, 5)
let msg = " Integer value is $1 which is ".format(intval) &
(if intval == 75000: "right. " else: "wrong (expected 75000). ")
let label2 = newLabel(msg)
dialog.contentArea.packStart(label2, true, true, 5)
discard dialog.addButton("OK", ord(ResponseType.ok))
dialog.showAll()
discard dialog.run()
dialog.destroy()
#---------------------------------------------------------------------------------------------------
proc onOk(button: Button; window: MainWindow) =
## Callback executed when the OK button has been clicked.
let strval = window.strEntry.text()
let intval = window.intEntry.value().toInt
displayValues(strval, intval)
if intval == 75_000:
window.destroy()
#---------------------------------------------------------------------------------------------------
proc activate(app: Application) =
## Activate the application.
let window = newApplicationWindow(MainWindow, app)
window.setTitle("User input")
let content = newBox(Orientation.vertical, 10)
content.setHomogeneous(true)
let grid = newGrid()
grid.setColumnSpacing(30)
let bbox = newButtonBox(Orientation.horizontal)
bbox.setLayout(ButtonBoxStyle.spread)
let strLabel = newLabel("Enter some text")
strLabel.setHalign(Align.start)
window.strEntry = newEntry()
grid.attach(strLabel, 0, 0, 1, 1)
grid.attach(window.strEntry, 1, 0, 1, 1)
let intLabel = newLabel("Enter 75000")
intLabel.setHalign(Align.start)
window.intEntry = newSpinButtonWithRange(0, 80_000, 1)
grid.attach(intLabel, 0, 1, 1, 1)
grid.attach(window.intEntry, 1, 1, 1, 1)
let btnOk = newButton("OK")
bbox.add(btnOk)
content.packStart(grid, true, true, 0)
content.packEnd(bbox, true, true, 0)
window.setBorderWidth(5)
window.add(content)
discard btnOk.connect("clicked", onOk, window)
window.showAll()
#———————————————————————————————————————————————————————————————————————————————————————————————————
let app = newApplication(Application, "Rosetta.UserInput")
discard app.connect("activate", activate)
discard app.run()

View file

@ -0,0 +1,37 @@
functor
import
Application
QTk at 'x-oz://system/wp/QTk.ozf'
System
define
Number NumberWidget
Text
StatusLabel
WindowClosed
GUI = td(action:OnClose
return:WindowClosed
lr(label(text:"Enter some text:" width:20)
entry(return:Text glue:ew)
glue:ew)
lr(label(text:"Enter a number:" width:20)
numberentry(max:100000 return:Number handle:NumberWidget)
label(handle:StatusLabel width:20)
glue:ew
)
button(text:"Ok" glue:ew
action:OnClose
)
)
proc {OnClose}
if {NumberWidget get($)} \= 75000 then
{StatusLabel set(text:"Invalid value")}
else
{Window close}
end
end
Window = {QTk.build GUI}
{Window show}
{Wait WindowClosed}
{System.showInfo "You entered; "#Text#", "#Number}
{Application.exit 0}
end

View file

@ -0,0 +1,39 @@
use Wx;
package MyApp;
use base 'Wx::App';
use Wx qw(wxHORIZONTAL wxVERTICAL wxALL wxALIGN_CENTER);
use Wx::Event 'EVT_BUTTON';
our ($frame, $text_input, $integer_input);
sub OnInit
{$frame = new Wx::Frame
(undef, -1, 'Input window', [-1, -1], [250, 150]);
my $panel = new Wx::Panel($frame, -1);
$text_input = new Wx::TextCtrl($panel, -1, '');
$integer_input = new Wx::SpinCtrl
($panel, -1, '', [-1, -1], [-1, -1],
0, 0, 100_000);
my $okay_button = new Wx::Button($panel, -1, 'OK');
EVT_BUTTON($frame, $okay_button, \&OnQuit);
my $sizer = new Wx::BoxSizer(wxVERTICAL);
$sizer->Add($_, 0, wxALL | wxALIGN_CENTER, 5)
foreach $text_input, $integer_input, $okay_button;
$panel->SetSizer($sizer);
$frame->Show(1);}
sub OnQuit
{print 'String: ', $text_input->GetValue, "\n";
print 'Integer: ', $integer_input->GetValue, "\n";
$frame->Close;}
# ---------------------------------------------------------------
package main;
MyApp->new->MainLoop;

View file

@ -0,0 +1,40 @@
(phixonline)-->
<span style="color: #000080;font-style:italic;">-- demo\rosetta\User_Input_Graphical.exw</span>
<span style="color: #008080;">include</span> <span style="color: #000000;">pGUI</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
<span style="color: #004080;">Ihandle</span> <span style="color: #000000;">dlg</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">label1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">input1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">label2</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">input2</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">OK</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">Cancel</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">ok_cb</span><span style="color: #0000FF;">(</span><span style="color: #004080;">Ihandle</span> <span style="color: #000000;">self</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">self</span><span style="color: #0000FF;">=</span><span style="color: #000000;">OK</span> <span style="color: #008080;">then</span>
<span style="color: #004080;">string</span> <span style="color: #000000;">in1</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupGetAttribute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">input1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"VALUE"</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">in2</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupGetInt</span><span style="color: #0000FF;">(</span><span style="color: #000000;">input2</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"VALUE"</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">string</span> <span style="color: #000000;">msg</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">(</span><span style="color: #008000;">`"%s" and %d`</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">in1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">in2</span><span style="color: #0000FF;">})</span>
<span style="color: #7060A8;">IupMessage</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"You entered"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">msg</span><span style="color: #0000FF;">)</span>
<span style="color: #000080;font-style:italic;">-- (return IUP_CONTINUE if unhappy with input)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">return</span> <span style="color: #004600;">IUP_CLOSE</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #7060A8;">IupOpen</span><span style="color: #0000FF;">()</span>
<span style="color: #000000;">label1</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupLabel</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"Please enter a string"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">input1</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupText</span><span style="color: #0000FF;">(</span><span style="color: #008000;">`VALUE="a string", EXPAND=HORIZONTAL`</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">label2</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupLabel</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"and the number 75000"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">input2</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupText</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"VALUE=75000, EXPAND=HORIZONTAL, MASK="</span><span style="color: #0000FF;">&</span><span style="color: #004600;">IUP_MASK_INT</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">OK</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupButton</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"OK"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"ACTION"</span><span style="color: #0000FF;">,</span> <span style="color: #7060A8;">Icallback</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"ok_cb"</span><span style="color: #0000FF;">))</span>
<span style="color: #000000;">Cancel</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupButton</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"Cancel"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"ACTION"</span><span style="color: #0000FF;">,</span> <span style="color: #7060A8;">Icallback</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"ok_cb"</span><span style="color: #0000FF;">))</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">buttons</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #7060A8;">IupFill</span><span style="color: #0000FF;">(),</span><span style="color: #000000;">OK</span><span style="color: #0000FF;">,</span><span style="color: #000000;">Cancel</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">IupFill</span><span style="color: #0000FF;">()}</span>
<span style="color: #004080;">Ihandle</span> <span style="color: #000000;">strbox</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupHbox</span><span style="color: #0000FF;">({</span><span style="color: #000000;">label1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">input1</span><span style="color: #0000FF;">},</span><span style="color: #008000;">"ALIGNMENT=ACENTER, PADDING=5"</span><span style="color: #0000FF;">),</span>
<span style="color: #000000;">numbox</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupHbox</span><span style="color: #0000FF;">({</span><span style="color: #000000;">label2</span><span style="color: #0000FF;">,</span><span style="color: #000000;">input2</span><span style="color: #0000FF;">},</span><span style="color: #008000;">"ALIGNMENT=ACENTER, PADDING=5"</span><span style="color: #0000FF;">),</span>
<span style="color: #000000;">btnbox</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupHbox</span><span style="color: #0000FF;">(</span><span style="color: #000000;">buttons</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"PADDING=40"</span><span style="color: #0000FF;">),</span>
<span style="color: #000000;">vbox</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupVbox</span><span style="color: #0000FF;">({</span><span style="color: #000000;">strbox</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">numbox</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">btnbox</span><span style="color: #0000FF;">},</span> <span style="color: #008000;">"MARGIN=5x5"</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">platform</span><span style="color: #0000FF;">()!=</span><span style="color: #004600;">JS</span> <span style="color: #008080;">then</span>
<span style="color: #7060A8;">IupSetAttribute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">btnbox</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"NORMALIZESIZE"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"BOTH"</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">IupSetAttribute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">vbox</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"GAP"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"5"</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #000000;">dlg</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupDialog</span><span style="color: #0000FF;">(</span><span style="color: #000000;">vbox</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">`TITLE="User Input/Graphical"`</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">IupShow</span><span style="color: #0000FF;">(</span><span style="color: #000000;">dlg</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">platform</span><span style="color: #0000FF;">()!=</span><span style="color: #004600;">JS</span> <span style="color: #008080;">then</span>
<span style="color: #7060A8;">IupMainLoop</span><span style="color: #0000FF;">()</span>
<span style="color: #7060A8;">IupClose</span><span style="color: #0000FF;">()</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<!--

View file

@ -0,0 +1,10 @@
(and
(call 'sh "-c"
(pack
"dialog \
--inputbox 'Input a string' 8 60 \
--inputbox 'Input a number' 8 20 \
2>"
(tmp "dlg") ) )
(split (in (tmp "dlg") (line)) "^I")
(cons (pack (car @)) (format (cadr @))) )

View file

@ -0,0 +1,14 @@
FUNCTION PBMAIN () AS LONG
result$ = INPUTBOX$("Enter a string.")
MSGBOX result$
DO
'This assumes that 75000 is the ONLY valid input.
result$ = INPUTBOX$("Enter the number 75000.")
IF VAL(result$) <> 75000 THEN
MSGBOX "You need to enter 75000!"
ELSE
MSGBOX "You entered the right number."
EXIT DO
END IF
LOOP
END FUNCTION

View file

@ -0,0 +1,98 @@
#region Define the Windows Form
[Void][Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$Form1 = New-Object System.Windows.Forms.Form
$label1 = New-Object System.Windows.Forms.Label
$label2 = New-Object System.Windows.Forms.Label
$txtInputText = New-Object System.Windows.Forms.TextBox
$txtInputNumber = New-Object System.Windows.Forms.TextBox
$btnAccept = New-Object System.Windows.Forms.Button
$label3 = New-Object System.Windows.Forms.Label
$btnCancel = New-Object System.Windows.Forms.Button
$SuspendLayout
#
# label1
#
$label1.AutoSize = $true
$label1.Location = New-Object System.Drawing.Point(23, 36)
$label1.Name = "label1"
$label1.Size = New-Object System.Drawing.Size(34, 13)
$label1.TabIndex = 0
$label1.Text = "String"
#
# label2
#
$label2.AutoSize = $true
$label2.Location = New-Object System.Drawing.Point(13, 62)
$label2.Name = "label2"
$label2.Size = New-Object System.Drawing.Size(44, 13)
$label2.TabIndex = 1
$label2.Text = "Number"
#
# txtInputText
#
$txtInputText.Location = New-Object System.Drawing.Point(63, 33)
$txtInputText.Name = "txtInputText"
$txtInputText.Size = New-Object System.Drawing.Size(100, 20)
$txtInputText.TabIndex = 0
#
# txtInputNumber
#
$txtInputNumber.Location = New-Object System.Drawing.Point(63, 59)
$txtInputNumber.Name = "txtInputNumber"
$txtInputNumber.Size = New-Object System.Drawing.Size(100, 20)
$txtInputNumber.TabIndex = 1
$txtInputNumber.Text = "75000"
#
# btnAccept
#
$btnAccept.DialogResult = [System.Windows.Forms.DialogResult]::OK
$btnAccept.Location = New-Object System.Drawing.Point(16, 94)
$btnAccept.Name = "btnAccept"
$btnAccept.Size = New-Object System.Drawing.Size(75, 23)
$btnAccept.TabIndex = 2
$btnAccept.Text = "Accept"
$btnAccept.UseVisualStyleBackColor = $true
$btnAccept.add_Click({$rc="Accept"; $Form1.Close()})
#
# label3
#
$label3.AutoSize = $true
$label3.Location = New-Object System.Drawing.Point(13, 9)
$label3.Name = "label3"
$label3.Size = New-Object System.Drawing.Size(173, 13)
$label3.TabIndex = 5
$label3.Text = "Please input a string and a number:"
#
# btnCancel
#
$btnCancel.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
$btnCancel.Location = New-Object System.Drawing.Point(97, 94)
$btnCancel.Name = "btnCancel"
$btnCancel.Size = New-Object System.Drawing.Size(75, 23)
$btnCancel.TabIndex = 3
$btnCancel.Text = "Cancel"
$btnCancel.UseVisualStyleBackColor = $true
#
# Form1
#
$Form1.AcceptButton = $btnAccept
$Form1.CancelButton = $btnCancel
$Form1.ClientSize = New-Object System.Drawing.Size(196, 129)
$Form1.ControlBox = $false
$Form1.Controls.Add($btnCancel)
$Form1.Controls.Add($label3)
$Form1.Controls.Add($btnAccept)
$Form1.Controls.Add($txtInputNumber)
$Form1.Controls.Add($txtInputText)
$Form1.Controls.Add($label2)
$Form1.Controls.Add($label1)
$Form1.Name = "Form1"
$Form1.Text = "RosettaCode"
#endregion Define the Windows Form
### Show the input form
$f = $Form1.ShowDialog()
if ( $f -eq [System.Windows.Forms.DialogResult]::Cancel ) { "User selected Cancel" }
else { "User entered `"{0}`" for the text and {1} for the number" -f $txtInputText.Text, $txtInputNumber.Text }

View file

@ -0,0 +1,13 @@
from javax.swing import JOptionPane
def to_int(n, default=0):
try:
return int(n)
except ValueError:
return default
number = to_int(JOptionPane.showInputDialog ("Enter an Integer"))
println(number)
a_string = JOptionPane.showInputDialog ("Enter a String")
println(a_string)

View file

@ -0,0 +1,7 @@
import javax.swing.JOptionPane;
int number = int(JOptionPane.showInputDialog ("Enter an Integer"));
println(number);
String string = JOptionPane.showInputDialog ("Enter a String");
println(string);

View file

@ -0,0 +1,2 @@
string$=InputRequester("Some Title","Enter a string","")
variable=Val(InputRequester("Some other Title","Enter a Number","75000"))

View file

@ -0,0 +1,7 @@
import Tkinter,tkSimpleDialog
root = Tkinter.Tk()
root.withdraw()
number = tkSimpleDialog.askinteger("Integer", "Enter a Number")
string = tkSimpleDialog.askstring("String", "Enter a String")

View file

@ -0,0 +1,10 @@
import tkinter
import tkinter.simpledialog as tks
root = tkinter.Tk()
root.withdraw()
number = tks.askinteger("Integer", "Enter a Number")
string = tks.askstring("String", "Enter a String")
tkinter.messagebox.showinfo("Results", f"Your input:\n {number} {string}")

View file

@ -0,0 +1,13 @@
$ \
import tkinter
import tkinter.simpledialog as tks
root = tkinter.Tk()
root.withdraw()
to_stack(tks.askinteger("Integer", "Enter a Number"))
string_to_stack(tks.askstring("String", "Enter a String"))
\ python
swap echo cr echo$

View file

@ -0,0 +1,20 @@
library(gWidgets)
options(guiToolkit="RGtk2") ## using gWidgtsRGtk2
w <- gwindow("Enter a string and a number")
lyt <- glayout(cont=w)
lyt[1,1] <- "Enter a string"
lyt[1,2] <- gedit("", cont=lyt)
lyt[2,1] <- "Enter 75000"
lyt[2,2] <- gedit("", cont=lyt)
lyt[3,2] <- gbutton("validate", cont=lyt, handler=function(h,...) {
txt <- svalue(lyt[1,2])
x <- svalue(lyt[2,2])
x <- gsub(",", "", x)
x <- as.integer(x)
if(nchar(txt) > 0 && x == 75000)
gmessage("Congratulations, you followed directions", parent=w)
else
gmessage("You failed this simple task", parent=w)
})

View file

@ -0,0 +1,58 @@
REBOL [
Title: "Graphical User Input"
URL: http://rosettacode.org/wiki/User_Input_-_graphical
]
; Simple GUI's can be defined with 'layout', a special purpose dialect
; for specifying interfaces. In this case, I describe a gradient
; background with an instruction label, followed by the input fields
; and a validation button. It's possible to check dynamically as the
; user types but I wanted to keep this example as clear as possible.
view layout [
; You can define new widget styles. Here I create a padded label style
; (so that everything will line up) and a simple indicator light to
; show if there's a problem with an input field.
style label vtext 60 "unlabeled"
style indicator box maroon 24x24
backdrop effect [gradient 0x1 black coal]
vtext "Please enter a string, and the number 75000:"
; By default, GUI widgets are arranged top down. The 'across' word
; starts stacking widgets from left to right. 'return' starts a new
; line -- just like on a typewriter!
across
; Notice I'm using my new label and indicator styles here. Widgets
; that I need to access later (the input field and the indicator) are
; assigned to variables.
label "string:" s: field 240 si: indicator return
label "number:" n: field 50 ni: indicator return
pad 66
button "validate" [
; The user may have entered bogus values, so I reset the indicators:
si/color: ni/color: maroon
; Now I check to see if the values are correct. For the string, I just
; care that there is one. For the integer, I make sure that it
; evaluates to an integer and that it's value is 75000. Because I've
; already set the indicator colour, I don't care the integer
; conversion raises an error or not, so I ignore it if anything goes
; wrong.
if 0 < length? get-face s [si/color: green]
error? try [if 75000 = to-integer get-face n [ni/color: green]]
show [si ni] ; Repainting multiple objects at once.
]
]

View file

@ -0,0 +1,19 @@
/*REXX pgm prompts (using the OS GUI) for a string & then prompts for a specific number.*/
#= 75000 /*the number that must be entered. */
x=
N=
do while x=' '; say /*string can't be blanks or null string*/
say 'Please enter a string: '
parse pull x
if x='' then say '***error*** No string entered.'
end /*while x···*/
do while N\=#; say /*the number (below) may be ill formed.*/
say 'Please enter the number:' #
parse pull N
if datatype(N, 'N') then N= N / 1 /*normalize the number: 007 4.0 +2 */
if N\=# then say '***error*** The number is not correct: ' N.
end /*while N···*/
say
say 'The string entered is:' x /*echo the values (string and number. */
say 'The number entered is:' N /*stick a fork in it, we're all done. */

View file

@ -0,0 +1,9 @@
#lang racket
(require racket/gui)
(define str (get-text-from-user "Hi" "Enter a string"))
(message-box "Hi" (format "You entered: ~a" str))
(define n (get-text-from-user "Hi" "Enter a number"))
(message-box "Hi" (format "You entered: ~a"
(or (string->number n) "bogus text")))

View file

@ -0,0 +1,27 @@
use GTK::Simple;
use GTK::Simple::App;
my GTK::Simple::App $app .= new( title => 'User Interaction' );
$app.border-width = 20;
$app.set-content(
GTK::Simple::VBox.new(
my $ = GTK::Simple::Label.new( text => 'Enter a string.' ),
my $str = GTK::Simple::Entry.new,
my $string = GTK::Simple::Label.new,
my $ = GTK::Simple::Label.new( text => 'Enter the number 75000' ),
my $val = GTK::Simple::Entry.new,
my $correct = GTK::Simple::Label.new,
)
);
$str.changed.tap: {
$string.text = "You entered: { $str.text }"
}
$val.changed.tap: {
$correct.text = "That's { 'not' unless $val.text ~~ / ^^ <ws> 75000 <ws> $$ / } 75000!"
}
$app.run;

View file

@ -0,0 +1,14 @@
import vis::Render;
import vis::Figure;
public void UserInput2(){
integer = "";
string = "";
row1 = [text("Enter a string "),
textfield("",void(str s){string = s;}),
text(str(){return " This input box will give a string by definition.\n You entered <string>";})];
row2 = [text("Enter 75000"),
textfield("",void(str v){integer = v;}),
text(str(){return " <integer == "75000" ? "Correct" : "Wrong">";})];
render(grid([row1, row2]));
}

View file

@ -0,0 +1,43 @@
Load "guilib.ring"
MyApp = New qApp {
num = 0
win1 = new qWidget() {
setwindowtitle("Hello World")
setGeometry(100,100,370,250)
btn1 = new qpushbutton(win1) {
setGeometry(130,200,100,30)
settext("Validate")
setclickevent("Validate()")}
lineedit1 = new qlineedit(win1) {
setGeometry(10,100,250,30)
settext("")}
lineedit2 = new qlineedit(win1) {
setGeometry(10,150,50,30)
settext("0")}
label1 = new qLabel(win1) {
setGeometry(270,100,50,30)
setText("")}
label2 = new qLabel(win1) {
setGeometry(70,150,50,30)
setText("")}
label3 = new qLabel(win1) {
setGeometry(10,50,250,30)
setText("Please enter a string, and the number 75000 :")}
show()}
exec()}
func Validate
lineedit1{temp1 = text()}
num1 = isdigit(temp1)
if num1 = 0 label1{settext("OK")} else label1{settext("NOT OK")} ok
lineedit2{temp2 = text()}
num2 = number(temp2)
if num2 = 75000 label2{settext("OK")} else label2{settext("NOT OK")} ok

View file

@ -0,0 +1,39 @@
require 'tk'
def main
root = TkRoot.new
l1 = TkLabel.new(root, "text" => "input a string")
e1 = TkEntry.new(root)
l2 = TkLabel.new(root, "text" => "input the number 75000")
e2 = TkEntry.new(root) do
validate "focusout"
validatecommand lambda {e2.value.to_i == 75_000}
invalidcommand lambda {focus_number_entry(e2)}
end
ok = TkButton.new(root) do
text "OK"
command lambda {validate_input(e1, e2)}
end
Tk.grid(l1, e1)
Tk.grid(l2, e2)
Tk.grid("x",ok, "sticky" => "w")
Tk.mainloop
end
def validate_input(text_entry, number_entry)
if number_entry.value.to_i != 75_000
focus_number_entry(number_entry)
else
puts %Q{You entered: "#{text_entry.value}" and "#{number_entry.value}"}
root.destroy
end
end
def focus_number_entry(widget)
widget \
.configure("background" => "red", "foreground" => "white") \
.selection_range(0, "end") \
.focus
end
main

View file

@ -0,0 +1,7 @@
Shoes.app do
string = ask('Enter a string:')
begin
number = ask('Enter the number 75000:')
end while number.to_i != 75000
para %Q{you entered the string "#{string}" and the number #{number}}
end

View file

@ -0,0 +1,21 @@
html "<TABLE BORDER=1 BGCOLOR=silver>
<TR><TD colspan=2>Please input a string and a number</TD></TR>
<TR><TD align=right>String</TD><TD><input type=text name=str size=18></TD></TR>
<TR><TD align=right>Number</TD><TD><input type=number name=num size=18 value=75000></TD></TR>
<TR><TD colspan=2 align=center>"
button #go, "Accept", [go]
button #ex, "Exit", [ex]
html "</TD></TR></TABLE>"
Wait
[go]
print #request get$("str")
print val(#request get$("num"))
wait
[ex]
end

View file

@ -0,0 +1,12 @@
import swing.Dialog.{Message, showInput}
import scala.swing.Swing
object UserInput extends App {
def responce = showInput(null,
"Complete the sentence:\n\"Green eggs and...\"",
"Customized Dialog",
Message.Plain,
Swing.EmptyIcon,
Nil, "ham")
println(responce)
}

View file

@ -0,0 +1,182 @@
var gtk2 = require('Gtk2') -> init;
var gui = %s'Gtk2::Builder'.new;
gui.add_from_string(DATA.slurp);
func clicked_ok(*_) {
var entry = gui.get_object('entry1');
var text = entry.get_text;
var spinner = gui.get_object('spinbutton1');
var number = spinner.get_text;
say "string: #{text}";
say "number: #{number}";
number == 75000 ? gtk2.main_quit : warn "Invalid number!";
}
func clicked_cancel(*_) {
gtk2.main_quit;
}
gui.get_object('button1').signal_connect('clicked', clicked_ok);
gui.get_object('button2').signal_connect('clicked', clicked_cancel);
gtk2.main;
__DATA__
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk+" version="2.24"/>
<!-- interface-naming-policy project-wide -->
<object class="GtkAdjustment" id="adjustment1">
<property name="upper">100000</property>
<property name="value">75000</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
<object class="GtkWindow" id="window1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkVBox" id="vbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Please insert a string and a number:</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkHBox" id="hbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel" id="label2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">string:</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="padding">55</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="entry1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">•</property>
<property name="primary_icon_activatable">False</property>
<property name="secondary_icon_activatable">False</property>
<property name="primary_icon_sensitive">True</property>
<property name="secondary_icon_sensitive">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkHBox" id="hbox2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel" id="label3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">number:</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkSpinButton" id="spinbutton1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">•</property>
<property name="primary_icon_activatable">False</property>
<property name="secondary_icon_activatable">False</property>
<property name="primary_icon_sensitive">True</property>
<property name="secondary_icon_sensitive">True</property>
<property name="adjustment">adjustment1</property>
<property name="numeric">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkHButtonBox" id="hbuttonbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="layout_style">spread</property>
<child>
<object class="GtkButton" id="button1">
<property name="label">gtk-ok</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button2">
<property name="label">gtk-cancel</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
</object>
</child>
</object>
</interface>

View file

@ -0,0 +1,24 @@
open XWindows ;
open Motif ;
val store : string list ref = ref [] ;
val inputWindow = fn () =>
let
val shell = XtAppInitialise "" "demo" "top" [] [ XmNwidth 320, XmNheight 100 ] ;
val main = XmCreateMainWindow shell "main" [ XmNmappedWhenManaged true ] ;
val enter = XmCreateText main "inputarea" [ XmNeditMode XmSINGLE_LINE_EDIT,
XmNscrollHorizontal false ] ;
val getinp = fn (w,s,t) => ( store := XmTextGetString enter :: !store ; t )
in
(
XtSetCallbacks enter [ (XmNactivateCallback , getinp) ] XmNarmCallback ;
XtManageChild enter ;
XtManageChild main ;
XtRealizeWidget shell
)
end ;
inputWindow () ;

View file

@ -0,0 +1,8 @@
Prgm
Dialog
Title "Rosetta Code"
Request "A string", s
DropDown "An integer", {"75000"}, n
EndDlog
74999 + n → n
EndPrgm

View file

@ -0,0 +1,5 @@
# create entry widget:
pack [entry .e1]
# read its content:
set input [.e get]

View file

@ -0,0 +1,4 @@
pack [entry .e1 -textvar input]
# show the content at any time by
puts $input

View file

@ -0,0 +1,2 @@
strUserIn = InputBox("Enter Data")
Wscript.Echo strUserIn

View file

@ -0,0 +1,3 @@
Dialog_Input_1(1, "`User Input example`,
`??Enter a string `,
`??Enter a number `")

View file

@ -0,0 +1,68 @@
import "graphics" for Canvas, Color
import "input" for Keyboard, Clipboard
import "dome" for Window, Process
var X = 10
var Y = 28
class Main {
construct new() {}
init() {
_text = ""
_enterNum = false
Keyboard.handleText = true
Keyboard.textRegion(X, Y, 8, 8)
}
update() {
var change = false
if (Keyboard.text.count > 0) {
_text = _text + Keyboard.text
change = true
}
// enable backspace key to delete last character entered
if (Keyboard["backspace"].justPressed && _text.count > 0) {
var codePoints = _text.codePoints
codePoints = codePoints.take(codePoints.count - 1)
_text = ""
for (point in codePoints) {
_text = _text + String.fromCodePoint(point)
}
change = true
}
// enable return key to terminate input
if (Keyboard["return"].justPressed) {
System.print("'%(_text)' was entered.")
if (!_enterNum) {
_text = ""
_enterNum = true
change = true
} else if (_text == "75000") {
Process.exit()
} else {
_text = ""
change = true
}
}
if (change) {
Keyboard.textRegion(X.min(_text.count * 8), Y, 8, 8)
}
}
draw(dt) {
Canvas.cls()
Canvas.rect(X, Y, 8, 8, Color.red)
if (!_enterNum) {
Canvas.print("Enter Text and press return:", 10, 10, Color.white)
} else {
Canvas.print("Enter 75000 and press return:", 10, 10, Color.white)
}
Canvas.print(_text, 10, 20, Color.white)
}
}
var Game = Main.new()