Jump to content

GUI component interaction: Difference between revisions

Rename Perl 6 -> Raku, alphabetize, minor clean-up
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 111:
КонецПроцедуры
</lang>
 
=={{header|Ada}}==
{{libheader|GtkAda}}
Line 658 ⟶ 659:
}
</lang>
 
=={{header|Common Lisp}}==
{{libheader|LTK}}
Line 2,252 ⟶ 2,254:
{Roads.registerFunction 'start' Start}
{Roads.run}</lang>
 
=={{header|Phix}}==
{{libheader|pGUI}}
<lang Phix>include pGUI.e
 
Ihandle txt, increment, random, hbx, vbx, dlg
 
function action_cb(Ihandle /*ih*/, integer ch)
if not find(ch,"0123456789-") then return IUP_IGNORE end if
return IUP_CONTINUE
end function
 
function increment_cb(Ihandle /*ih*/)
integer v = IupGetInt(txt,"VALUE")+1
IupSetInt(txt,"VALUE",v)
return IUP_CONTINUE
end function
 
function random_cb(Ihandle /*ih*/)
if IupAlarm("Confirm","Replace wth random value?","Yes","No")=1 then
IupSetInt(txt,"VALUE",rand(1000))
end if
return IUP_CONTINUE
end function
 
function esc_close(Ihandle /*ih*/, atom c)
return iff(c=K_ESC?IUP_CLOSE:IUP_CONTINUE)
end function
 
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()</lang>
 
=={{header|PicoLisp}}==
Line 2,274 ⟶ 2,316:
(server 8080 "!start")
(wait)</lang>
 
=={{header|PowerShell}}==
<lang PowerShell>[xml]$XML = @"
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Title="Rosetta Code" WindowStartupLocation = "CenterScreen" Height="100" Width="210" ResizeMode="NoResize">
 
<Grid Background="#FFC1C3CB">
<Label Name="Label_Value" Content="Value" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="70"/>
<TextBox Name="TextBox_Value" HorizontalAlignment="Left" Height="23" Margin="90,10,0,0" TextWrapping="Wrap" Text="0" VerticalAlignment="Top" Width="100"/>
<Button Name="Button_Random" Content="Random" HorizontalAlignment="Left" Margin="10,41,0,0" VerticalAlignment="Top" Width="70" Height="23"/>
<Button Name="Button_Increment" Content="Increment" HorizontalAlignment="Left" Margin="90,41,0,0" VerticalAlignment="Top" Width="100" Height="23"/>
</Grid>
</Window>
"@
 
$XMLReader = New-Object System.Xml.XmlNodeReader $XML
$XMLForm = [Windows.Markup.XamlReader]::Load($XMLReader)
$buttonIncrement = $XMLForm.FindName('Button_Increment')
$buttonRandom = $XMLForm.FindName('Button_Random')
$textBoxValue = $XMLForm.FindName('TextBox_Value')
 
$buttonRandom.add_click({
$textBoxValue.Text = Get-Random -Minimum 0 -Maximum 10000
})
$buttonIncrement.add_click({++[Int]$textBoxValue.Text})
 
$XMLForm.ShowDialog() | Out-Null</lang>
 
=={{header|Prolog}}==
Line 2,389 ⟶ 2,458:
CloseWindow(0)
EndIf</lang>
 
=={{header|Perl 6}}==
 
{{libheader|GTK}}
 
<lang perl6>use GTK::Simple;
use GTK::Simple::App;
 
my GTK::Simple::App $app .= new(title => 'GUI component interaction');
 
$app.set-content(
my $box = GTK::Simple::VBox.new(
my $value = GTK::Simple::Entry.new(text => '0'),
my $increment = GTK::Simple::Button.new(label => 'Increment'),
my $random = GTK::Simple::Button.new(label => 'Random'),
)
);
 
$app.size-request(400, 100);
$app.border-width = 20;
$box.spacing = 10;
 
$value.changed.tap: {
($value.text ||= '0') ~~ s:g/<-[0..9]>//;
}
 
$increment.clicked.tap: {
my $val = $value.text; $val += 1; $value.text = $val.Str
}
 
$random.clicked.tap: {
# Dirty hack to work around the fact that GTK::Simple doesn't provide
# access to GTK message dialogs yet :P
if run «zenity --question --text "Reset to random value?"» {
$value.text = (^100).pick.Str
}
}
 
$app.run;</lang>
 
=={{header|Phix}}==
{{libheader|pGUI}}
<lang Phix>include pGUI.e
 
Ihandle txt, increment, random, hbx, vbx, dlg
 
function action_cb(Ihandle /*ih*/, integer ch)
if not find(ch,"0123456789-") then return IUP_IGNORE end if
return IUP_CONTINUE
end function
 
function increment_cb(Ihandle /*ih*/)
integer v = IupGetInt(txt,"VALUE")+1
IupSetInt(txt,"VALUE",v)
return IUP_CONTINUE
end function
 
function random_cb(Ihandle /*ih*/)
if IupAlarm("Confirm","Replace wth random value?","Yes","No")=1 then
IupSetInt(txt,"VALUE",rand(1000))
end if
return IUP_CONTINUE
end function
 
function esc_close(Ihandle /*ih*/, atom c)
return iff(c=K_ESC?IUP_CLOSE:IUP_CONTINUE)
end function
 
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()</lang>
 
=={{header|PowerShell}}==
<lang PowerShell>[xml]$XML = @"
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Title="Rosetta Code" WindowStartupLocation = "CenterScreen" Height="100" Width="210" ResizeMode="NoResize">
 
<Grid Background="#FFC1C3CB">
<Label Name="Label_Value" Content="Value" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="70"/>
<TextBox Name="TextBox_Value" HorizontalAlignment="Left" Height="23" Margin="90,10,0,0" TextWrapping="Wrap" Text="0" VerticalAlignment="Top" Width="100"/>
<Button Name="Button_Random" Content="Random" HorizontalAlignment="Left" Margin="10,41,0,0" VerticalAlignment="Top" Width="70" Height="23"/>
<Button Name="Button_Increment" Content="Increment" HorizontalAlignment="Left" Margin="90,41,0,0" VerticalAlignment="Top" Width="100" Height="23"/>
</Grid>
</Window>
"@
 
$XMLReader = New-Object System.Xml.XmlNodeReader $XML
$XMLForm = [Windows.Markup.XamlReader]::Load($XMLReader)
$buttonIncrement = $XMLForm.FindName('Button_Increment')
$buttonRandom = $XMLForm.FindName('Button_Random')
$textBoxValue = $XMLForm.FindName('TextBox_Value')
 
$buttonRandom.add_click({
$textBoxValue.Text = Get-Random -Minimum 0 -Maximum 10000
})
$buttonIncrement.add_click({++[Int]$textBoxValue.Text})
 
$XMLForm.ShowDialog() | Out-Null</lang>
 
=={{header|Python}}==
Line 2,646 ⟶ 2,609:
(send frame show #t)
</lang>
 
=={{header|Raku}}==
(formerly Perl 6)
 
{{libheader|GTK}}
 
<lang perl6>use GTK::Simple;
use GTK::Simple::App;
 
my GTK::Simple::App $app .= new(title => 'GUI component interaction');
 
$app.set-content(
my $box = GTK::Simple::VBox.new(
my $value = GTK::Simple::Entry.new(text => '0'),
my $increment = GTK::Simple::Button.new(label => 'Increment'),
my $random = GTK::Simple::Button.new(label => 'Random'),
)
);
 
$app.size-request(400, 100);
$app.border-width = 20;
$box.spacing = 10;
 
$value.changed.tap: {
($value.text ||= '0') ~~ s:g/<-[0..9]>//;
}
 
$increment.clicked.tap: {
my $val = $value.text; $val += 1; $value.text = $val.Str
}
 
$random.clicked.tap: {
# Dirty hack to work around the fact that GTK::Simple doesn't provide
# access to GTK message dialogs yet :P
if run «zenity --question --text "Reset to random value?"» {
$value.text = (^100).pick.Str
}
}
 
$app.run;</lang>
 
=={{header|Ring}}==
10,333

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.