GUI enabling/disabling of controls: Difference between revisions
m
syntax highlighting fixup automation
(Add Red) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 52:
disabling.adb:
<
with Gtk.Main;
with Gtk.Handlers;
Line 220:
Gtk.Main.Main;
end Disabling;</
=={{header|AutoHotkey}}==
<
GUI, Add, button,, Increment
GUI, Add, button, xp+70 yp, Decrement ; xp+70 and yp are merely positioning options
Line 267:
GuiClose:
ExitApp
; Ensures the script ends when the GUI is closed.</
=={{header|BaCon}}==
This code requires BaCon 4.0.1 or higher.
<
PRAGMA GUI gtk3
Line 304:
CALL GUISET(gui, "spin", "sensitive", IIF(input = 0, TRUE, FALSE))
WEND</
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
<
INSTALL @lib$+"WINLIB5"
ES_NUMBER = 8192
Line 344:
SYS "GetDlgItemInt", !form%, 101, 0, 1 TO number%
SYS "SetDlgItemInt", !form%, 101, number% - 1, 1
ENDPROC</
{{out}}
<p>
Line 354:
<pre>file main.c</pre>
<
#include "resource.h"
Line 433:
EnableWindow( GetDlgItem(hwnd,IDC_INCREMENT), n<MAX_VALUE );
EnableWindow( GetDlgItem(hwnd,IDC_DECREMENT), n>MIN_VALUE );
}</
<pre>file resource.h</pre>
<
#define IDC_INPUT 1001
#define IDC_INCREMENT 1002
#define IDC_DECREMENT 1003
#define IDC_QUIT 1004</
<pre>file resource.rc</pre>
<
#include "resource.h"
Line 458:
PUSHBUTTON "Quit", IDC_QUIT, 117, 25, 30, 14
RTEXT "Value:", -1, 10, 8, 20, 8
}</
=={{header|C sharp}}==
Using Windows Forms; compile with csc -t:winexe Program.cs (on MS.NET) or gmcs -t:winexe Program.cs (on Mono)
<
using System.ComponentModel;
using System.Windows.Forms;
Line 543:
Application.Run(new RosettaInteractionForm());
}
}</
=={{header|C++}}==
with Qt 4.4, creating project file with qmake -project, Makefile with qmake -o Makefile <projectfile> and finally make
<pre>file task.h</pre>
<
#define TASK_H
Line 577:
QHBoxLayout *lowerPart ;
} ;
#endif</
<pre>file task.cpp</pre>
<
#include <QString>
#include "task.h"
Line 633:
number-- ;
entryField->setText( QString("%1").arg( number )) ;
}</
<pre>main.cpp</pre>
<
#include "task.h"
Line 644:
theWidget.show( ) ;
return app.exec( ) ;
}</
=={{header|Delphi}}==
<
TForm1 = class(TForm)
MaskEditValue: TMaskEdit; // Set Editmask on: "99;0; "
Line 677:
begin
MaskEditValue.Text := IntToStr(Succ(StrToIntDef(Trim(MaskEditValue.Text), 0)));
end;</
=={{header|Fantom}}==
<
using gfx
Line 748:
}.open
}
}</
=={{header|FreeBASIC}}==
<syntaxhighlight lang="freebasic">
#Include "windows.bi"
Line 789:
End
</syntaxhighlight>
=={{header|Gambas}}==
<
hButton0 As Button 'We need a button
hButton1 As Button 'We need another button
Line 870:
Checks 'Rune the Checks routine
End</
=={{header|Go}}==
{{libheader|Gotk3}}
Loosely based on the Vala entry.
<
import (
Line 996:
window.ShowAll()
gtk.Main()
}</
==Icon and {{header|Unicon}}==
Line 1,002:
This uses the Unicon specific graphics library.
<syntaxhighlight lang="unicon">
import gui
$include "guih.icn"
Line 1,090:
w.show_modal ()
end
</syntaxhighlight>
=={{header|J}}==
'''J 8.x'''
<
pc task nosize;
cc decrement button;cn "Decrement";
Line 1,119:
task_decrement_button=:verb define
update Value=: ": _1 + 0 ". Value
)</
'''J 6.x'''
<
pc task nosize;
xywh 6 30 48 12;cc decrement button;cn "-";
Line 1,145:
task_decrement_button=:verb define
update Value=: ": _1 + 0 ". Value
)</
Example use:
<syntaxhighlight lang="text"> task_run''</
=={{header|Java}}==
{{works with|Swing}}
{{works with|AWT}}
<
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
Line 1,306:
new Interact().setVisible(true);
}
}</
{{libheader|JavaFX}}
{{works with|Java|8}}
<
import javafx.application.Application;
import javafx.beans.property.LongProperty;
Line 1,390:
}
}
</syntaxhighlight>
=={{header|Julia}}==
<
using Tk
w = Toplevel("GUI enabling/disabling")
Line 1,443:
</syntaxhighlight>
=={{header|Kotlin}}==
{{libheader|JavaFX}}
{{trans|Java}}
<
import javafx.application.Application
Line 1,517:
fun main(args: Array<String>) {
Application.launch(InteractFX::class.java, *args)
}</
=={{header|Liberty BASIC}}==
<
textbox #demo.val, 20, 50, 90, 24
button #demo.dec, "Decrement", [btnDecrement], UL, 20, 90, 90, 24
Line 1,599:
#demo.val "!disable"
end if
End Sub</
=={{header|LiveCode}}==
Line 1,615:
4. Select Object->Card Script and enter the following to handle enabling the buttons.
<
switch
case v <= 0
Line 1,632:
put v into fld "Field1"
end switch
end enableButtons</
For the increment button, click on Button 1 (in edit mode) and the select "code" from the toolbar and enter the following to handle clicks<
put field "Field1" into x
add 1 to x
enableButtons x
end mouseUp</
Repeat for Button 2 (note we are subtracting here)<
put field "Field1" into x
subtract 1 from x
enableButtons x
end mouseUp</
Finally add the code to handle keyboard entry in text field's code. Note this code prevents entering digits outside 0-9 and limits the value between 0 and 10.<
if numToChar(k) is among the items of "1,2,3,4,5,6,7,8,9,0" then
if (numToChar(k) + the text of me) <= 10 then
Line 1,654:
pass rawKeyDown
end if
end rawKeyDown</
Switch back to the form, and enter run mode to execute.
Line 1,663:
Normally a function can't call other except something global or something defined in function (local), or for member functions in Group object, they can call other members public or private at same level or deeper but then only the public members. Using Call Local we call functions like function's part. When an event service function called (by event), interpreter provide the same name as the module's name, where form declared, so this call is a "local call". So a second local call inside event service function,also provide same name. So global local1 called as local, so code executed as part of CheckIt (but without same "current" stack, and other specific to execution object properties). Modules, functions, threads, events are all executed on "execution objects" which carries the execution code.
<syntaxhighlight lang="m2000 interpreter">
\\ this is global, but call as local in events, which means with local visibility for identifiers
\\ so thispos and this$ has to exist in caller 's context
Line 1,733:
Checkit
</syntaxhighlight>
=={{header|Maple}}==
For this problem, you will need to open up Maple, go to the Components tab on the left, and insert a Text Area, and 2 Buttons. By right clicking each button, and clicking Component Properties, change one to Increase, and the other to Decrease. Then, click on 'Edit Content Changed Action". In the one labeled increase, type:
<syntaxhighlight lang="maple">
Increase();
</syntaxhighlight>
In the one labeled Decrease, type:
<syntaxhighlight lang="maple">
Decrease();
</syntaxhighlight>
Then, by clicking the 2 gears and opening up the start-up commands, enter this:
<syntaxhighlight lang="maple">
macro(SP=DocumentTools:-SetProperty, GP=DocumentTools:-GetProperty);
with(Maplets[Elements]):
Line 1,779:
end if;
end proc;
</syntaxhighlight>
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<
InputField[Dynamic[value], Number,
Enabled -> Dynamic[value == 0]] &},
Row@{Button["increment", value++, Enabled -> Dynamic[value < 10]],
Button["decrement", value--, Enabled -> Dynamic[value > 0]]}]</
=={{header|NewLISP}}==
<
; url: http://rosettacode.org/wiki/GUI_enabling/disabling_of_controls
; author: oofoe 2012-02-02
Line 1,836:
(gs:listen)
(exit)</
Screenshot:
Line 1,845:
===Using Gtk2===
{{libheader|Gtk2}}
<
var valu: int = 0
Line 1,904:
show_all(window)
thisCheckBtns()
main()</
===Using Gtk3 (gintro)===
{{libheader|gintro}}
<
import gintro/[glib, gobject, gtk, gio]
Line 1,999:
let app = newApplication(Application, "Rosetta.GuiControls")
discard app.connect("activate", activate)
discard app.run()</
===Using IUP===
{{libheader|IUP}}
<
iup, strutils, math
Line 2,095:
discard dlg.show()
discard mainloop()
iup.close()</
=={{header|Perl}}==
<
use strict;
Line 2,132:
$dec and $dec->configure( -state => $_[0] > 0 ? 'normal' : 'disabled' );
$entry and $entry->configure( -state => $_[0] == 0 ? 'normal' : 'disabled' );
}</
=={{header|Phix}}==
Line 2,138:
{{libheader|Phix/basics}}
{{libheader|Phix/pGUI}}
<!--<
<span style="color: #008080;">include</span> <span style="color: #000000;">pGUI</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
Line 2,180:
<span style="color: #7060A8;">IupClose</span><span style="color: #0000FF;">()</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<!--</
=={{header|PicoLisp}}==
The standard PicoLisp GUI is HTTP based. Connect your browser to
http://localhost:8080 after starting the following script.
<
(load "@ext.l" "@lib/http.l" "@lib/xhtml.l" "@lib/form.l")
Line 2,201:
(server 8080 "!start")
(wait)</
=={{header|Prolog}}==
Works with SWI-Prolog and XPCE.
<
[ object :=
GUI_Interaction,
Line 2,304:
-> send(Incr, active, @off)).
</syntaxhighlight>
=={{header|PureBasic}}==
<
#TextGadget
#AddButton
Line 2,352:
EndIf
Until Event=#PB_Event_CloseWindow
EndIf</
=={{header|Python}}==
<syntaxhighlight lang="python">
#!/usr/bin/env python3
Line 2,432:
if __name__ == "__main__":
main()
</syntaxhighlight>
Result: [https://ibb.co/cEmqy5]
=={{header|R}}==
<syntaxhighlight lang="r">
library(gWidgets)
options(guiToolkit="RGtk2") ## using gWidgtsRGtk2
Line 2,464:
addHandlerChanged(down_btn, handler=rement, action=-1)
addHandlerChanged(up_btn, handler=rement, action=1)
</syntaxhighlight>
=={{header|Racket}}==
<
#lang racket/gui
Line 2,494:
(send frame show #t)
</syntaxhighlight>
=={{header|Raku}}==
(formerly Perl 6)
Extremely basic implementation using the GTK library.
<syntaxhighlight lang="raku"
use GTK::Simple::App;
Line 2,526:
$dec.clicked.tap: { my $val = $value.text; $val -= 1; $value.text = $val.Str }
$app.run;</
=={{header|Red}}==
<
enable: does [
Line 2,541:
i: button "increment" [f/text: mold n: add to-integer f/text 1 enable]
d: button "decrement" disabled [f/text: mold n: subtract to-integer f/text 1 enable]
]</
=={{header|Ring}}==
<
Load "guilib.ring"
Line 2,580:
lineedit1.settext(num)
if number(num)<0 btn2.setDisabled(True) ok
</syntaxhighlight>
Output:
[[File:CalmoSoftGui.jpg]]
Line 2,586:
=={{header|Ruby}}==
{{libheader|Shoes}}
<
@number = edit_line
@number.change {update_controls}
Line 2,600:
update_controls 0
end</
=={{header|Scala}}==
<
import swing.event.{ ButtonClicked, Key, KeyPressed, KeyTyped }
Line 2,652:
centerOnScreen()
} // def top(
}</
=={{header|Smalltalk}}==
{{works with|Smalltalk/X}}
<
vh := ValueHolder with:0.
Line 2,675:
decButton enableChannel:(BlockValue with:[:v | v > 0] argument:vh).
top open</
=={{header|Tcl}}==
{{libheader|Tk}}
<
# Model
Line 2,709:
.dec state [expr {$field > 0 ? "!disabled" : "disabled"}]
}
updateEnables; # Force initial state of buttons</
=={{header|Vala}}==
{{libheader|Gtk+-3.0}}
<
int64 val;
bool ret = int64.try_parse(str,out val);;
Line 2,825:
return 0;
}
</syntaxhighlight>
=={{header|Visual Basic}}==
Line 2,835:
by a "spinner" or "up-down" control, not by buttons.)
<
Begin VB.Form Form1
Caption = "Form1"
Line 2,905:
cmdDec.Enabled = True
End Select
End Sub</
=={{header|Wren}}==
{{libheader|DOME}}
{{libheader|Wren-polygon}}
<
import "input" for Mouse, Keyboard
import "dome" for Window
Line 3,034:
}
var Game = GUIControlEnablement.new()</
|