September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -1,5 +1,6 @@
|
|||
{{omit from|ACL2}}
|
||||
{{omit from|Applesoft BASIC|no concept of a GUI}}
|
||||
{{omit from|Commodore BASIC}}
|
||||
{{omit from|AWK|no concept of a GUI}}
|
||||
{{omit from|Batch File}}
|
||||
{{omit from|Blast}}
|
||||
|
|
|
|||
|
|
@ -28,18 +28,19 @@ implementation
|
|||
{$R *.dfm}
|
||||
|
||||
procedure TForm1.EditInputFieldChange(Sender: TObject);
|
||||
Var
|
||||
Value: Integer;
|
||||
begin
|
||||
TRY
|
||||
StrToInt(EditInputField.Text);
|
||||
EXCEPT
|
||||
ShowMessage('Error! The Input Value is not numeric!');
|
||||
if not TryStrToInt(EditInputField.Text, value) then
|
||||
begin
|
||||
ShowMessage('Error! The Input Value is not numeric!');
|
||||
EditInputField.Text := '0';
|
||||
END;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TForm1.ButtonIncrementClick(Sender: TObject);
|
||||
begin
|
||||
EditInputField.text := IntToStr(StrToInt(EditInputField.Text) + 1);
|
||||
EditInputField.text := IntToStr (StrToInt(EditInputField.Text) + 1);
|
||||
end;
|
||||
|
||||
procedure TForm1.ButtonRandomClick(Sender: TObject);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,40 @@
|
|||
(require 'interface)
|
||||
|
||||
;; helper new button with text
|
||||
(define (ui-add-button text)
|
||||
(define b (ui-create-element "button" '((type "button"))))
|
||||
(ui-set-html b text)
|
||||
(ui-add b))
|
||||
|
||||
|
||||
(define (panel )
|
||||
(ui-clear)
|
||||
(info-text "My rosetta application" "blue")
|
||||
|
||||
;; input field (checked for numeric)
|
||||
(define f-input (ui-create-element "input" '((type number))))
|
||||
(ui-set-value f-input 0)
|
||||
(ui-add f-input)
|
||||
(ui-on-focus f-input (lambda(e) (info-text "")))
|
||||
|
||||
;; Increment button
|
||||
(define btn-inc (ui-add-button "Increment"))
|
||||
(define (increment elem)
|
||||
(define val (ui-get-numvalue f-input))
|
||||
(if val ;; checked legal numeric
|
||||
(ui-set-value f-input (1+ val))
|
||||
(info-text "Need a number" "red")))
|
||||
(ui-on-click btn-inc increment)
|
||||
(ui-add btn-inc)
|
||||
|
||||
(define btn-random (ui-add-button "Random"))
|
||||
(define (set-random elem)
|
||||
(when (confirm "Really random?")
|
||||
(ui-set-value f-input (random-prime 1000000))))
|
||||
(ui-on-click btn-random set-random)
|
||||
|
||||
(ui-focus btn-inc)
|
||||
(stdout-hide #t)
|
||||
(stdin-hide #t)) ;; end panel
|
||||
|
||||
(panel)
|
||||
|
|
@ -1,70 +1,70 @@
|
|||
#import system.
|
||||
#import forms.
|
||||
#import extensions.
|
||||
|
||||
#class Window
|
||||
import forms.
|
||||
import extensions.
|
||||
|
||||
class Window
|
||||
{
|
||||
#field form.
|
||||
#field btmIncrement.
|
||||
#field btmRandom.
|
||||
#field txtNumber.
|
||||
object form.
|
||||
object btmIncrement.
|
||||
object btmRandom.
|
||||
object txtNumber.
|
||||
|
||||
#constructor new
|
||||
constructor new
|
||||
[
|
||||
form := SDIDialog new.
|
||||
btmIncrement := Button new.
|
||||
btmRandom := Button new.
|
||||
txtNumber := Edit new.
|
||||
|
||||
form controls
|
||||
+= btmIncrement
|
||||
+= btmRandom
|
||||
+= txtNumber.
|
||||
form controls;
|
||||
append:btmIncrement;
|
||||
append:btmRandom;
|
||||
append:txtNumber.
|
||||
|
||||
form set &caption:"Rosseta Code".
|
||||
form set &x:100 &y:100.
|
||||
form set &width:160 &height:120.
|
||||
form
|
||||
set caption:"Rosseta Code";
|
||||
set x:100 y:100;
|
||||
set width:160 height:120.
|
||||
|
||||
txtNumber set &x:7 &y:7.
|
||||
txtNumber set &width:140 &height:25.
|
||||
txtNumber set &caption:"0".
|
||||
txtNumber
|
||||
set x:7 y:7;
|
||||
set width:140 height:25;
|
||||
set caption:"0".
|
||||
|
||||
btmIncrement set &x:7 &y:35.
|
||||
btmIncrement set &width:140 &height:25.
|
||||
btmIncrement set &caption:"Increment".
|
||||
btmIncrement set &onClick:args
|
||||
btmIncrement
|
||||
set x:7 y:35;
|
||||
set width:140 height:25;
|
||||
set caption:"Increment";
|
||||
set onClick: (:args)
|
||||
[ $self $onButtonIncrementClick ].
|
||||
|
||||
[ $self $onButtonIncrementClick. ].
|
||||
|
||||
btmRandom set &x:7 &y:65.
|
||||
btmRandom set &width:140 &height:25.
|
||||
btmRandom set &caption:"Random".
|
||||
btmRandom set &onClick:args
|
||||
|
||||
[ $self $onButtonRandomClick. ].
|
||||
btmRandom
|
||||
set x:7 y:65;
|
||||
set width:140 height:25;
|
||||
set caption:"Random";
|
||||
set onClick(:args)
|
||||
[ $self $onButtonRandomClick ]
|
||||
]
|
||||
|
||||
#method $onButtonIncrementClick
|
||||
$onButtonIncrementClick
|
||||
[
|
||||
#var number := txtNumber value toInt.
|
||||
var number := txtNumber value; toInt.
|
||||
|
||||
number := number + 1.
|
||||
$self $changeTextBoxValue:number.
|
||||
]
|
||||
|
||||
#method $onButtonRandomClick
|
||||
$onButtonRandomClick
|
||||
[
|
||||
(messageDialog open &caption:"Inf" &question:"Really reset to random value?")?
|
||||
if(messageDialog open caption:"Inf" question:"Really reset to random value?")
|
||||
[
|
||||
$self $changeTextBoxValue:(randomGenerator eval:99999999).
|
||||
].
|
||||
$self $changeTextBoxValue(randomGenerator eval:99999999)
|
||||
]
|
||||
]
|
||||
|
||||
#method $changeTextBoxValue : number
|
||||
$changeTextBoxValue : number
|
||||
[
|
||||
txtNumber set &caption:(number literal).
|
||||
txtNumber set caption(number literal).
|
||||
]
|
||||
|
||||
#method => form.
|
||||
dispatch => form.
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,56 @@
|
|||
hValueBox As ValueBox 'We need a ValueBox
|
||||
|
||||
Public Sub Form_Open()
|
||||
Dim hButton As Button 'We need 2 Buttons
|
||||
|
||||
With Me 'Set the Form's Properties..
|
||||
.height = 95 'Set the Height
|
||||
.Width = 350 'Set the Width
|
||||
.Arrangement = Arrange.Vertical 'Arrange items vertically
|
||||
.Padding = 5 'Border area
|
||||
.Title = "GUI component interaction" 'Title displayed on the Form
|
||||
End With
|
||||
|
||||
hValueBox = New ValueBox(Me) 'Add a ValueBox to the Form
|
||||
|
||||
With hValueBox 'Set the ValueBox's Properties..
|
||||
.Expand = True 'Expand the ValueBox
|
||||
.Value = 0 'Set it's value to 0
|
||||
End With
|
||||
|
||||
hButton = New Button(Me) As "ButtonInc" 'Add a Button to the form as Event "ButtonInc"
|
||||
|
||||
With hButton 'Set the Button's Properties..
|
||||
.Height = 28 'Set the Height
|
||||
.Text = "&Increment" 'Add Text (The '&' adds a keyboard shortcut)
|
||||
End With
|
||||
|
||||
hButton = New Button(Me) As "ButtonRand" 'Add a Button to the form as Event "ButtonRand"
|
||||
|
||||
With hButton 'Set the Button's Properties..
|
||||
.Height = 28 'Set the Height
|
||||
.Text = "&Random" 'Add Text (The '&' adds a keyboard shortcut)
|
||||
End With
|
||||
|
||||
End
|
||||
|
||||
Public Sub ButtonInc_Click() 'When the 'Increment' Button is clicked..
|
||||
|
||||
hValueBox.Value += 1 'Increase the Value in the ValueBox by 1
|
||||
|
||||
End
|
||||
|
||||
Public Sub ButtonRand_Click() 'When the 'Random' Button is clicked..
|
||||
Dim siRand As Short 'To store random number
|
||||
Dim byAnswer As Byte 'To store the answer to the MessageBox question
|
||||
|
||||
siRand = Rand(1, 32767) 'Create a 'Random' mnumber
|
||||
|
||||
byAnswer = Message.Question("Would you like to set the ValueBox to " & siRand & "?", "Yes", "No") ' Ask if the number is OK
|
||||
If byAnswer = 1 Then 'If the user says 'Yes' then
|
||||
hValueBox.Value = siRand 'Display the 'Random' number in the ValueBox
|
||||
Else 'ELSE
|
||||
hValueBox.Value = 0 'Set the ValueBox Value to 0
|
||||
End If
|
||||
|
||||
End
|
||||
|
|
@ -3,50 +3,43 @@ import java.awt.event.ActionEvent
|
|||
import java.awt.event.ActionListener
|
||||
import java.awt.event.KeyEvent
|
||||
import java.awt.event.KeyListener
|
||||
|
||||
import java.lang.Long // jet.Long doesn't suit our needs here
|
||||
import javax.swing.JButton
|
||||
import javax.swing.JFrame
|
||||
import javax.swing.JOptionPane
|
||||
import javax.swing.JPanel
|
||||
import javax.swing.JTextField
|
||||
import javax.swing.*
|
||||
|
||||
class Interact : JFrame() {
|
||||
val numberField = JTextField()
|
||||
val incButton = JButton("Increment")
|
||||
val randButton = JButton("Random")
|
||||
val buttonPanel = JPanel();
|
||||
val buttonPanel = JPanel()
|
||||
|
||||
{
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
|
||||
numberField setText "0"
|
||||
init {
|
||||
defaultCloseOperation = JFrame.EXIT_ON_CLOSE
|
||||
numberField.text = "0"
|
||||
|
||||
numberField addKeyListener(object : KeyListener {
|
||||
public override fun keyTyped(e : KeyEvent) : Unit =
|
||||
if(!Character.isDigit(e.getKeyChar())) e.consume()
|
||||
public override fun keyReleased(e : KeyEvent?) {}
|
||||
public override fun keyPressed(e : KeyEvent) {}
|
||||
});
|
||||
|
||||
incButton addActionListener(object : ActionListener {
|
||||
public override fun actionPerformed(e : ActionEvent) {
|
||||
val num = Long.parseLong(numberField.getText() ?: "")
|
||||
numberField setText (num + 1).toString()
|
||||
numberField.addKeyListener(object : KeyListener {
|
||||
override fun keyTyped(e : KeyEvent) : Unit {
|
||||
if (!Character.isDigit(e.keyChar)) e.consume()
|
||||
}
|
||||
});
|
||||
override fun keyReleased(e : KeyEvent?) {}
|
||||
override fun keyPressed(e : KeyEvent) {}
|
||||
})
|
||||
|
||||
randButton addActionListener(object : ActionListener {
|
||||
incButton.addActionListener {
|
||||
val num = (numberField.text ?: "").toDouble()
|
||||
numberField.text = (num + 1).toString()
|
||||
}
|
||||
|
||||
randButton.addActionListener(object : ActionListener {
|
||||
fun proceedOrNot() = JOptionPane.showConfirmDialog(randButton, "Are you sure?")
|
||||
public override fun actionPerformed(e : ActionEvent) {
|
||||
override fun actionPerformed(e : ActionEvent) {
|
||||
if(proceedOrNot() == JOptionPane.YES_OPTION)
|
||||
numberField setText Long.toString((Math.random() * Long.MAX_VALUE).toLong())
|
||||
numberField.text = (Math.random() * Long.MAX_VALUE).toString()
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
setLayout(GridLayout(2, 1))
|
||||
buttonPanel setLayout GridLayout(1, 2)
|
||||
buttonPanel add incButton
|
||||
buttonPanel add randButton
|
||||
layout = GridLayout(2, 1)
|
||||
buttonPanel.layout = GridLayout(1, 2)
|
||||
buttonPanel.add(incButton)
|
||||
buttonPanel.add(randButton)
|
||||
add(numberField)
|
||||
add(buttonPanel)
|
||||
pack()
|
||||
|
|
@ -54,5 +47,5 @@ class Interact : JFrame() {
|
|||
}
|
||||
|
||||
fun main(args : Array<String>) {
|
||||
Interact() setVisible(true)
|
||||
Interact().isVisible = true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,68 +0,0 @@
|
|||
import
|
||||
gtk2, gdk2, glib2, strutils, math
|
||||
|
||||
var valu: int = 0
|
||||
var chngd_txt_hndler: gulong = 0
|
||||
|
||||
proc thisDestroy(widget: pWidget, data: pgpointer) {.cdecl.} =
|
||||
main_quit()
|
||||
|
||||
randomize()
|
||||
nimrod_init()
|
||||
var win = window_new(gtk2.WINDOW_TOPLEVEL)
|
||||
var content = vbox_new(TRUE,10)
|
||||
var hbox1 = hbox_new(TRUE,10)
|
||||
var hbox2 = hbox_new(FALSE,1)
|
||||
var lbl = label_new("Value:")
|
||||
var entry_fld = entry_new()
|
||||
entry_fld.set_text("0")
|
||||
var btn_quit = button_new("Quit")
|
||||
var btn_inc = button_new("Increment")
|
||||
var btn_rnd = button_new("Random")
|
||||
add(hbox2,lbl)
|
||||
add(hbox2,entry_fld)
|
||||
add(hbox1,btn_inc)
|
||||
add(hbox1,btn_rnd)
|
||||
pack_start(content, hbox2, TRUE, TRUE, 0)
|
||||
pack_start(content, hbox1, TRUE, TRUE, 0)
|
||||
pack_start(content, btn_quit, TRUE, TRUE, 0)
|
||||
set_border_width(Win, 5)
|
||||
add(win, content)
|
||||
|
||||
proc on_question_clicked: Bool =
|
||||
var dialog = win.message_dialog_new(0, MESSAGE_QUESTION,
|
||||
BUTTONS_YES_NO, "Use a Random number?")
|
||||
var response = dialog.run()
|
||||
if response == RESPONSE_YES:
|
||||
result = True
|
||||
elif response == RESPONSE_NO:
|
||||
result = False
|
||||
dialog.destroy()
|
||||
|
||||
proc thisInc(widget: pWidget, data: pgpointer){.cdecl.} =
|
||||
inc(valu)
|
||||
entry_fld.set_text($valu)
|
||||
|
||||
proc thisRnd(widget: pWidget, data: pgpointer){.cdecl.} =
|
||||
if on_question_clicked():
|
||||
valu = random(20)
|
||||
entry_fld.set_text($valu)
|
||||
|
||||
proc thisTextChanged(widget: pWidget, data: pgpointer) {.cdecl.} =
|
||||
#signal_handler_block(entry_fld, chngd_txt_hndler)
|
||||
try:
|
||||
valu = parseInt($entry_fld.get_text())
|
||||
except EInvalidValue:
|
||||
valu = 0
|
||||
entry_fld.set_text($valu)
|
||||
#signal_handler_unblock(entry_fld, chngd_txt_hndler)
|
||||
#signal_emit_stop(entry_fld, signal_lookup("changed",TYPE_EDITABLE()),0)
|
||||
|
||||
discard signal_connect(win, "destroy", SIGNAL_FUNC(thisDestroy), nil)
|
||||
discard signal_connect(btn_quit, "clicked", SIGNAL_FUNC(thisDestroy), nil)
|
||||
discard signal_connect(btn_inc, "clicked", SIGNAL_FUNC(thisInc), nil)
|
||||
discard signal_connect(btn_rnd, "clicked", SIGNAL_FUNC(thisRnd), nil)
|
||||
chngd_txt_hndler = signal_connect(entry_fld, "changed", SIGNAL_FUNC(thisTextChanged), nil)
|
||||
|
||||
win.show_all()
|
||||
main()
|
||||
|
|
@ -24,14 +24,14 @@ function esc_close(Ihandle /*ih*/, atom c)
|
|||
return iff(c=K_ESC?IUP_CLOSE:IUP_CONTINUE)
|
||||
end function
|
||||
|
||||
IupOpen("../pGUI/")
|
||||
txt = IupText(Icallback("action_cb"),"EXPAND=YES")
|
||||
increment = IupButton("increment",Icallback("increment_cb"))
|
||||
random = IupButton("random",Icallback("random_cb"))
|
||||
hbx = IupHbox({increment,random},"MARGIN=0x10, GAP=20")
|
||||
vbx = IupVbox({txt,hbx},"MARGIN=40x20")
|
||||
dlg = IupDialog(vbx)
|
||||
IupSetCallback(dlg, "K_ANY", Icallback("esc_close"))
|
||||
IupShow(dlg)
|
||||
IupMainLoop()
|
||||
IupClose()
|
||||
IupOpen()
|
||||
txt = IupText(Icallback("action_cb"),"EXPAND=YES")
|
||||
increment = IupButton("increment",Icallback("increment_cb"))
|
||||
random = IupButton("random",Icallback("random_cb"))
|
||||
hbx = IupHbox({increment,random},"MARGIN=0x10, GAP=20")
|
||||
vbx = IupVbox({txt,hbx},"MARGIN=40x20")
|
||||
dlg = IupDialog(vbx)
|
||||
IupSetCallback(dlg, "K_ANY", Icallback("esc_close"))
|
||||
IupShow(dlg)
|
||||
IupMainLoop()
|
||||
IupClose()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue