digitalmars.D.learn - TKD AddProtocolCommand example
- DaveG (60/60) May 14 2014 Hello
- DaveG (34/34) May 14 2014 Hopefully better formatting of code here:
- Gary Willoughby (2/36) May 14 2014 I'm at work at the minute I'll take a look later on.
- Gary Willoughby (5/7) May 15 2014 Added the missing import and now all works fine. Fixed in
- DaveG (12/19) May 15 2014 Thanks Gary!
- Mengu (2/9) May 15 2014 i just was about to send a PR :(
- Gary Willoughby (3/14) May 15 2014 he he, too slow. ;)
Hello
Could someone provide an example how to use addProtocolCommand?
The following is how I would expect it to work:
import tkd.tkdapplication; // Import Tkd.
class Application : TkdApplication //
Extend TkdApplication.
{
private void exitCommand(CommandArgs args) //
Create a callback.
{
this.exit(); // Exit
the application.
}
private void saveMeCommand(CommandArgs args)
{
new MessageDialog(this.mainWindow,"Saving...")
.setMessage("Bye")
.show();
}
override protected void initInterface() //
Initialise user interface.
{
this.mainWindow.addProtocolCommand(WindowProtocol.saveYourself,
&this.saveMeCommand);
auto frame = new Frame(2, ReliefStyle.groove) //
Create a frame.
.pack(10); // Place
the frame.
auto label = new Label(frame, "Hello World!") //
Create a label.
.pack(10); // Place
the label.
auto exitButton = new Button(frame, "Exit") //
Create a button.
.setCommand(&this.exitCommand) // Use
the callback.
.underlineChar(1)
.pack(10); // Place
the button.
}
}
void main(string[] args)
{
auto app = new Application(); // Create the application.
app.run(); // Run
the application.
}
I get the following when I try to compile:
tkd\window\window.d(426): Error: undefined identifier
CommandCallback
main.d(21): Error: template
tkd.window.window.Window.addProtocolCommand cannot deduce
function from argument types !()(WindowProtocol, void
delegate(CommandArgs args)), candidates are:
tkd\window\window.d(426):
tkd.window.window.Window.addProtocolCommand(this T)(string
protocol, CommandCallback callback)
If I comment out the line where I try to add the command, it
compiles and runs fine:
May 14 2014
Hopefully better formatting of code here:
import tkd.tkdapplication;
class Application : TkdApplication
{
private void exitCommand(CommandArgs args)
{
this.exit();
}
private void saveMeCommand(CommandArgs args)
{
new MessageDialog(this.mainWindow,"Saving...")
.setMessage("Bye")
.show();
}
override protected void initInterface()
{
this.mainWindow.addProtocolCommand(WindowProtocol.saveYourself,
&this.saveMeCommand);
auto frame = new Frame(2, ReliefStyle.groove)
.pack(10);
auto label = new Label(frame, "Hello World!")
.pack(10);
auto exitButton = new Button(frame, "Exit")
.setCommand(&this.exitCommand)
.underlineChar(1)
.pack(10);
}
}
void main(string[] args)
{
auto app = new Application();
app.run();
}
May 14 2014
On Wednesday, 14 May 2014 at 21:41:04 UTC, DaveG wrote:
Hopefully better formatting of code here:
import tkd.tkdapplication;
class Application : TkdApplication
{
private void exitCommand(CommandArgs args)
{
this.exit();
}
private void saveMeCommand(CommandArgs args)
{
new MessageDialog(this.mainWindow,"Saving...")
.setMessage("Bye")
.show();
}
override protected void initInterface()
{
this.mainWindow.addProtocolCommand(WindowProtocol.saveYourself,
&this.saveMeCommand);
auto frame = new Frame(2, ReliefStyle.groove)
.pack(10);
auto label = new Label(frame, "Hello World!")
.pack(10);
auto exitButton = new Button(frame, "Exit")
.setCommand(&this.exitCommand)
.underlineChar(1)
.pack(10);
}
}
void main(string[] args)
{
auto app = new Application();
app.run();
}
I'm at work at the minute I'll take a look later on.
May 14 2014
On Wednesday, 14 May 2014 at 21:23:02 UTC, DaveG wrote:tkd\window\window.d(426): Error: undefined identifier CommandCallbackAdded the missing import and now all works fine. Fixed in v1.0.5-beta. Any more issues open them up in github and i'll deal with them there. :) https://github.com/nomad-software/tkd
May 15 2014
On Thursday, 15 May 2014 at 17:30:22 UTC, Gary Willoughby wrote:On Wednesday, 14 May 2014 at 21:23:02 UTC, DaveG wrote:Thanks Gary! I was expecting it to catch when someone hits the close X on the title bar, but I changed it to this this.mainWindow.addProtocolCommand(WindowProtocol.deleteWindow, &this.saveMeCommand); And that seems to do the trick. I will post bugs on github in future, I thought I was doing something wrong. I have never messed with TCL/TK until now. BTW, Really nice job on this! Thanks for the quick reply and fixtkd\window\window.d(426): Error: undefined identifier CommandCallbackAdded the missing import and now all works fine. Fixed in v1.0.5-beta. Any more issues open them up in github and i'll deal with them there. :) https://github.com/nomad-software/tkd
May 15 2014
On Thursday, 15 May 2014 at 17:30:22 UTC, Gary Willoughby wrote:On Wednesday, 14 May 2014 at 21:23:02 UTC, DaveG wrote:i just was about to send a PR :(tkd\window\window.d(426): Error: undefined identifier CommandCallbackAdded the missing import and now all works fine. Fixed in v1.0.5-beta. Any more issues open them up in github and i'll deal with them there. :) https://github.com/nomad-software/tkd
May 15 2014
On Thursday, 15 May 2014 at 19:02:58 UTC, Mengu wrote:On Thursday, 15 May 2014 at 17:30:22 UTC, Gary Willoughby wrote:he he, too slow. ;) If you see anything else feel free to make another.On Wednesday, 14 May 2014 at 21:23:02 UTC, DaveG wrote:i just was about to send a PR :(tkd\window\window.d(426): Error: undefined identifier CommandCallbackAdded the missing import and now all works fine. Fixed in v1.0.5-beta. Any more issues open them up in github and i'll deal with them there. :) https://github.com/nomad-software/tkd
May 15 2014









"Gary Willoughby" <dev nomad.so> 