September Morn Update
This commit is contained in:
parent
4e2d22a71d
commit
aac6731f2c
6856 changed files with 141342 additions and 21127 deletions
97
Task/User-input-Graphical/Go/user-input-graphical.go
Normal file
97
Task/User-input-Graphical/Go/user-input-graphical.go
Normal 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()
|
||||
}
|
||||
|
|
@ -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
|
||||
31
Task/User-input-Graphical/Julia/user-input-graphical.julia
Normal file
31
Task/User-input-Graphical/Julia/user-input-graphical.julia
Normal 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()
|
||||
39
Task/User-input-Graphical/Perl/user-input-graphical.pl
Normal file
39
Task/User-input-Graphical/Perl/user-input-graphical.pl
Normal 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;
|
||||
19
Task/User-input-Graphical/REXX/user-input-graphical.rexx
Normal file
19
Task/User-input-Graphical/REXX/user-input-graphical.rexx
Normal 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. */
|
||||
Loading…
Add table
Add a link
Reference in a new issue