GUI enabling/disabling of controls: Difference between revisions

m
syntax highlighting fixup automation
(Add Red)
m (syntax highlighting fixup automation)
Line 52:
 
disabling.adb:
<langsyntaxhighlight Adalang="ada">with Ada.Strings.Fixed;
with Gtk.Main;
with Gtk.Handlers;
Line 220:
 
Gtk.Main.Main;
end Disabling;</langsyntaxhighlight>
 
=={{header|AutoHotkey}}==
<langsyntaxhighlight AutoHotkeylang="autohotkey">GUI, Add, Edit, w150 number vValue gEnableDisable, 0 ; Number specifies a numbers-only edit field. g<Subroutine> specifies a subroutine to run when the value of control changes.
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.</langsyntaxhighlight>
 
=={{header|BaCon}}==
This code requires BaCon 4.0.1 or higher.
<langsyntaxhighlight lang="bacon">OPTION GUI TRUE
PRAGMA GUI gtk3
 
Line 304:
CALL GUISET(gui, "spin", "sensitive", IIF(input = 0, TRUE, FALSE))
 
WEND</langsyntaxhighlight>
 
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
<langsyntaxhighlight lang="bbcbasic"> INSTALL @lib$+"WINLIB2"
INSTALL @lib$+"WINLIB5"
ES_NUMBER = 8192
Line 344:
SYS "GetDlgItemInt", !form%, 101, 0, 1 TO number%
SYS "SetDlgItemInt", !form%, 101, number% - 1, 1
ENDPROC</langsyntaxhighlight>
{{out}}
<p>
Line 354:
<pre>file main.c</pre>
 
<langsyntaxhighlight lang="c">#include <windows.h>
#include "resource.h"
 
Line 433:
EnableWindow( GetDlgItem(hwnd,IDC_INCREMENT), n<MAX_VALUE );
EnableWindow( GetDlgItem(hwnd,IDC_DECREMENT), n>MIN_VALUE );
}</langsyntaxhighlight>
 
<pre>file resource.h</pre>
 
<langsyntaxhighlight lang="c">#define IDD_DLG 101
#define IDC_INPUT 1001
#define IDC_INCREMENT 1002
#define IDC_DECREMENT 1003
#define IDC_QUIT 1004</langsyntaxhighlight>
 
<pre>file resource.rc</pre>
 
<langsyntaxhighlight lang="c">#include <windows.h>
#include "resource.h"
 
Line 458:
PUSHBUTTON "Quit", IDC_QUIT, 117, 25, 30, 14
RTEXT "Value:", -1, 10, 8, 20, 8
}</langsyntaxhighlight>
 
=={{header|C sharp}}==
Using Windows Forms; compile with csc -t:winexe Program.cs (on MS.NET) or gmcs -t:winexe Program.cs (on Mono)
<langsyntaxhighlight lang="csharp">using System;
using System.ComponentModel;
using System.Windows.Forms;
Line 543:
Application.Run(new RosettaInteractionForm());
}
}</langsyntaxhighlight>
 
=={{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>
<langsyntaxhighlight lang="cpp">#ifndef TASK_H
#define TASK_H
 
Line 577:
QHBoxLayout *lowerPart ;
} ;
#endif</langsyntaxhighlight>
 
<pre>file task.cpp</pre>
<langsyntaxhighlight lang="cpp">#include <QtGui>
#include <QString>
#include "task.h"
Line 633:
number-- ;
entryField->setText( QString("%1").arg( number )) ;
}</langsyntaxhighlight>
 
<pre>main.cpp</pre>
<langsyntaxhighlight lang="cpp">#include <QApplication>
#include "task.h"
 
Line 644:
theWidget.show( ) ;
return app.exec( ) ;
}</langsyntaxhighlight>
 
=={{header|Delphi}}==
<langsyntaxhighlight lang="delphi">type
TForm1 = class(TForm)
MaskEditValue: TMaskEdit; // Set Editmask on: "99;0; "
Line 677:
begin
MaskEditValue.Text := IntToStr(Succ(StrToIntDef(Trim(MaskEditValue.Text), 0)));
end;</langsyntaxhighlight>
 
=={{header|Fantom}}==
 
<langsyntaxhighlight lang="fantom">using fwt
using gfx
 
Line 748:
}.open
}
}</langsyntaxhighlight>
 
=={{header|FreeBASIC}}==
<syntaxhighlight lang="freebasic">
<lang FreeBASIC>
#Include "windows.bi"
 
Line 789:
 
End
</syntaxhighlight>
</lang>
 
=={{header|Gambas}}==
<langsyntaxhighlight lang="gambas">hValueBox As ValueBox 'We need a ValueBox
hButton0 As Button 'We need a button
hButton1 As Button 'We need another button
Line 870:
Checks 'Rune the Checks routine
 
End</langsyntaxhighlight>
 
=={{header|Go}}==
{{libheader|Gotk3}}
Loosely based on the Vala entry.
<langsyntaxhighlight lang="go">package main
 
import (
Line 996:
window.ShowAll()
gtk.Main()
}</langsyntaxhighlight>
 
==Icon and {{header|Unicon}}==
Line 1,002:
This uses the Unicon specific graphics library.
 
<syntaxhighlight lang="unicon">
<lang Unicon>
import gui
$include "guih.icn"
Line 1,090:
w.show_modal ()
end
</syntaxhighlight>
</lang>
 
=={{header|J}}==
'''J 8.x'''
<langsyntaxhighlight lang="j">task_run=: wd bind (noun define)
pc task nosize;
cc decrement button;cn "Decrement";
Line 1,119:
task_decrement_button=:verb define
update Value=: ": _1 + 0 ". Value
)</langsyntaxhighlight>
 
'''J 6.x'''
<langsyntaxhighlight Jlang="j">task_run=: wd bind (noun define)
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
)</langsyntaxhighlight>
 
Example use:
 
<syntaxhighlight lang="text"> task_run''</langsyntaxhighlight>
 
=={{header|Java}}==
{{works with|Swing}}
{{works with|AWT}}
<langsyntaxhighlight lang="java">import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
Line 1,306:
new Interact().setVisible(true);
}
}</langsyntaxhighlight>
 
 
{{libheader|JavaFX}}
{{works with|Java|8}}
<langsyntaxhighlight lang="java">
import javafx.application.Application;
import javafx.beans.property.LongProperty;
Line 1,390:
}
}
</syntaxhighlight>
</lang>
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">
using Tk
w = Toplevel("GUI enabling/disabling")
Line 1,443:
 
 
</syntaxhighlight>
</lang>
 
=={{header|Kotlin}}==
{{libheader|JavaFX}}
{{trans|Java}}
<langsyntaxhighlight lang="scala">// version 1.2.21
 
import javafx.application.Application
Line 1,517:
fun main(args: Array<String>) {
Application.launch(InteractFX::class.java, *args)
}</langsyntaxhighlight>
 
=={{header|Liberty BASIC}}==
<langsyntaxhighlight lang="lb">nomainwin
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</langsyntaxhighlight>
 
=={{header|LiveCode}}==
Line 1,615:
 
4. Select Object->Card Script and enter the following to handle enabling the buttons.
<langsyntaxhighlight LiveCodelang="livecode">command enableButtons v
switch
case v <= 0
Line 1,632:
put v into fld "Field1"
end switch
end enableButtons</langsyntaxhighlight>
 
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<langsyntaxhighlight LiveCodelang="livecode">on mouseUp
put field "Field1" into x
add 1 to x
enableButtons x
end mouseUp</langsyntaxhighlight>
 
Repeat for Button 2 (note we are subtracting here)<langsyntaxhighlight LiveCodelang="livecode">on mouseUp
put field "Field1" into x
subtract 1 from x
enableButtons x
end mouseUp</langsyntaxhighlight>
 
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.<langsyntaxhighlight LiveCodelang="livecode">on rawKeyDown k
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</langsyntaxhighlight>
 
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">
<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>
</lang>
 
=={{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">
<lang Maple>
Increase();
</syntaxhighlight>
</lang>
 
In the one labeled Decrease, type:
 
<syntaxhighlight lang="maple">
<lang Maple>
Decrease();
</syntaxhighlight>
</lang>
 
Then, by clicking the 2 gears and opening up the start-up commands, enter this:
<syntaxhighlight lang="maple">
<lang Maple>
macro(SP=DocumentTools:-SetProperty, GP=DocumentTools:-GetProperty);
with(Maplets[Elements]):
Line 1,779:
end if;
end proc;
</syntaxhighlight>
</lang>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<langsyntaxhighlight lang="mathematica">Manipulate[Null, {{value, 0},
InputField[Dynamic[value], Number,
Enabled -> Dynamic[value == 0]] &},
Row@{Button["increment", value++, Enabled -> Dynamic[value < 10]],
Button["decrement", value--, Enabled -> Dynamic[value > 0]]}]</langsyntaxhighlight>
 
=={{header|NewLISP}}==
<langsyntaxhighlight NewLISPlang="newlisp">; file: gui-enable.lsp
; url: http://rosettacode.org/wiki/GUI_enabling/disabling_of_controls
; author: oofoe 2012-02-02
Line 1,836:
(gs:listen)
 
(exit)</langsyntaxhighlight>
 
Screenshot:
Line 1,845:
===Using Gtk2===
{{libheader|Gtk2}}
<langsyntaxhighlight lang="nim">import gtk2, strutils, glib2
var valu: int = 0
Line 1,904:
show_all(window)
thisCheckBtns()
main()</langsyntaxhighlight>
 
===Using Gtk3 (gintro)===
{{libheader|gintro}}
 
<langsyntaxhighlight Nimlang="nim">import strutils
import gintro/[glib, gobject, gtk, gio]
 
Line 1,999:
let app = newApplication(Application, "Rosetta.GuiControls")
discard app.connect("activate", activate)
discard app.run()</langsyntaxhighlight>
 
===Using IUP===
{{libheader|IUP}}
<langsyntaxhighlight lang="nim">import
iup, strutils, math
 
Line 2,095:
discard dlg.show()
discard mainloop()
iup.close()</langsyntaxhighlight>
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">#!/usr/bin/perl
 
use strict;
Line 2,132:
$dec and $dec->configure( -state => $_[0] > 0 ? 'normal' : 'disabled' );
$entry and $entry->configure( -state => $_[0] == 0 ? 'normal' : 'disabled' );
}</langsyntaxhighlight>
 
=={{header|Phix}}==
Line 2,138:
{{libheader|Phix/basics}}
{{libheader|Phix/pGUI}}
<!--<langsyntaxhighlight Phixlang="phix">-->
<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>
<!--</langsyntaxhighlight>-->
 
=={{header|PicoLisp}}==
The standard PicoLisp GUI is HTTP based. Connect your browser to
http://localhost:8080 after starting the following script.
<langsyntaxhighlight PicoLisplang="picolisp">#!/usr/bin/picolisp /usr/lib/picolisp/lib.l
 
(load "@ext.l" "@lib/http.l" "@lib/xhtml.l" "@lib/form.l")
Line 2,201:
 
(server 8080 "!start")
(wait)</langsyntaxhighlight>
 
=={{header|Prolog}}==
Works with SWI-Prolog and XPCE.
<langsyntaxhighlight Prologlang="prolog">dialog('GUI_Interaction',
[ object :=
GUI_Interaction,
Line 2,304:
-> send(Incr, active, @off)).
 
</syntaxhighlight>
</lang>
 
=={{header|PureBasic}}==
<langsyntaxhighlight PureBasiclang="purebasic">Enumeration
#TextGadget
#AddButton
Line 2,352:
EndIf
Until Event=#PB_Event_CloseWindow
EndIf</langsyntaxhighlight>
 
=={{header|Python}}==
<syntaxhighlight lang="python">
<lang Python>
#!/usr/bin/env python3
 
Line 2,432:
if __name__ == "__main__":
main()
</syntaxhighlight>
</lang>
 
Result: [https://ibb.co/cEmqy5]
 
=={{header|R}}==
<syntaxhighlight lang="r">
<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>
</lang>
 
=={{header|Racket}}==
<langsyntaxhighlight lang="racket">
#lang racket/gui
Line 2,494:
 
(send frame show #t)
</syntaxhighlight>
</lang>
 
=={{header|Raku}}==
(formerly Perl 6)
Extremely basic implementation using the GTK library.
<syntaxhighlight lang="raku" perl6line>use GTK::Simple;
use GTK::Simple::App;
 
Line 2,526:
$dec.clicked.tap: { my $val = $value.text; $val -= 1; $value.text = $val.Str }
 
$app.run;</langsyntaxhighlight>
 
=={{header|Red}}==
<langsyntaxhighlight lang="rebol">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]
]</langsyntaxhighlight>
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
Load "guilib.ring"
 
Line 2,580:
lineedit1.settext(num)
if number(num)<0 btn2.setDisabled(True) ok
</syntaxhighlight>
</lang>
Output:
[[File:CalmoSoftGui.jpg]]
Line 2,586:
=={{header|Ruby}}==
{{libheader|Shoes}}
<langsyntaxhighlight lang="ruby">Shoes.app do
@number = edit_line
@number.change {update_controls}
Line 2,600:
 
update_controls 0
end</langsyntaxhighlight>
 
=={{header|Scala}}==
<langsyntaxhighlight Scalalang="scala">import swing.{ BoxPanel, Button, GridPanel, Orientation, Swing, TextField }
import swing.event.{ ButtonClicked, Key, KeyPressed, KeyTyped }
 
Line 2,652:
centerOnScreen()
} // def top(
}</langsyntaxhighlight>
 
=={{header|Smalltalk}}==
{{works with|Smalltalk/X}}
<langsyntaxhighlight lang="smalltalk">|top input vh incButton decButton|
 
vh := ValueHolder with:0.
Line 2,675:
decButton enableChannel:(BlockValue with:[:v | v > 0] argument:vh).
 
top open</langsyntaxhighlight>
 
=={{header|Tcl}}==
{{libheader|Tk}}
<langsyntaxhighlight lang="tcl">package require Tk
 
# Model
Line 2,709:
.dec state [expr {$field > 0 ? "!disabled" : "disabled"}]
}
updateEnables; # Force initial state of buttons</langsyntaxhighlight>
 
=={{header|Vala}}==
{{libheader|Gtk+-3.0}}
 
<langsyntaxhighlight lang="vala">bool validate_input(Gtk.Window window, string str){
int64 val;
bool ret = int64.try_parse(str,out val);;
Line 2,825:
return 0;
}
</syntaxhighlight>
</lang>
 
=={{header|Visual Basic}}==
Line 2,835:
by a "spinner" or "up-down" control, not by buttons.)
 
<langsyntaxhighlight lang="vb">VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
Line 2,905:
cmdDec.Enabled = True
End Select
End Sub</langsyntaxhighlight>
 
=={{header|Wren}}==
{{libheader|DOME}}
{{libheader|Wren-polygon}}
<langsyntaxhighlight lang="ecmascript">import "graphics" for Canvas, Color
import "input" for Mouse, Keyboard
import "dome" for Window
Line 3,034:
}
 
var Game = GUIControlEnablement.new()</langsyntaxhighlight>
10,333

edits