Thread overview | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
May 14, 2014 TKD AddProtocolCommand example | ||||
---|---|---|---|---|
| ||||
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 Re: TKD AddProtocolCommand example | ||||
---|---|---|---|---|
| ||||
Posted in reply to DaveG | 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 15, 2014 Re: TKD AddProtocolCommand example | ||||
---|---|---|---|---|
| ||||
Posted in reply to DaveG | 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 15, 2014 Re: TKD AddProtocolCommand example | ||||
---|---|---|---|---|
| ||||
Posted in reply to DaveG | On Wednesday, 14 May 2014 at 21:23:02 UTC, DaveG wrote: > tkd\window\window.d(426): Error: undefined identifier CommandCallback Added 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 Re: TKD AddProtocolCommand example | ||||
---|---|---|---|---|
| ||||
Posted in reply to Gary Willoughby | 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: >> tkd\window\window.d(426): Error: undefined identifier CommandCallback > > Added 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 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 fix |
May 15, 2014 Re: TKD AddProtocolCommand example | ||||
---|---|---|---|---|
| ||||
Posted in reply to Gary Willoughby | 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:
>> tkd\window\window.d(426): Error: undefined identifier CommandCallback
>
> Added 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
i just was about to send a PR :(
|
May 15, 2014 Re: TKD AddProtocolCommand example | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mengu | 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:
>> On Wednesday, 14 May 2014 at 21:23:02 UTC, DaveG wrote:
>>> tkd\window\window.d(426): Error: undefined identifier CommandCallback
>>
>> Added 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
>
> i just was about to send a PR :(
he he, too slow. ;)
If you see anything else feel free to make another.
|
Copyright © 1999-2021 by the D Language Foundation