nomad-software / tkd

GUI toolkit for the D programming language based on Tcl/Tk
MIT License
117 stars 16 forks source link

Text bind (<<Modified>>) only happens once #40

Closed taylorh140 closed 8 years ago

taylorh140 commented 8 years ago

I was assuming this was like an onChange event for the text element, and it works that way for the first input change. But for subsequent changes no event occurs. Is there a flag that needs to be reset?

nomad-software commented 8 years ago

@taylorh140 Have you got a sample program that highlights the issue?

taylorh140 commented 8 years ago
module main;

import std.ascii;
import std.array;
import std.stdio;
import std.xml:Element,ElementParser,Tag,Document,DocumentParser;
import std.string;
import std.conv;
import std.typecons;
import std.uni;

import tkd.tkdapplication;                               // Import Tkd.

alias TextBox = tkd.widget.Text;
alias isAlpha = std.uni.isAlpha;

TextBox xmlTextBox;
TextBox registerTextBox;
TextBox bitFieldsTextBox;
TextBox mutabilityTextBox;
TextBox dTextBox;

class Application : TkdApplication                       // Extend TkdApplication.
{

    public void regmodifyText(CommandArgs args)
    {
        try{
            xmlTextBox.appendText("Good");
        }catch(Throwable s){
            xmlTextBox.appendText("Bad");
        }
    }

    override protected void initInterface()              // Initialise user interface.
    {
        auto panedwindow = new PanedWindow(Orientation.horizontal).pack(10, 0, GeometrySide.bottom, GeometryFill.both, AnchorPosition.northWest, true);
        auto FirstF  = new Frame(panedwindow,4, ReliefStyle.groove);
        auto SecondF = new Frame(panedwindow,4, ReliefStyle.groove);
        auto ThirdF  = new Frame(panedwindow,4, ReliefStyle.groove);

        auto FourthF       = new Frame(FirstF,4, ReliefStyle.groove).pack(10, 0, GeometrySide.top, GeometryFill.both, AnchorPosition.northWest, true);
            auto reglabel      = new Label(FourthF,"register").pack(10);
            registerTextBox    = new Text (FourthF).setHeight(0).bind("<<Modified>>", &this.regmodifyText ).pack(10, 0, GeometrySide.bottom, GeometryFill.both, AnchorPosition.northWest, true);
        auto FifthF        = new Frame(FirstF,4, ReliefStyle.groove).pack(10, 0, GeometrySide.top, GeometryFill.both, AnchorPosition.northWest, true);
            auto blabel        = new Label(FifthF,"Bit Fields").pack(10);
            bitFieldsTextBox   = new Text (FifthF).setHeight(0).pack(10, 0, GeometrySide.bottom, GeometryFill.both, AnchorPosition.northWest, true);
        auto SixthF        = new Frame(FirstF,4, ReliefStyle.groove).pack(10, 0, GeometrySide.top, GeometryFill.both, AnchorPosition.northWest, true);
            auto mlabel        = new Label(SixthF,"Mutability").pack(10);
            mutabilityTextBox  = new Text (SixthF).setHeight(0).pack(10, 0, GeometrySide.bottom, GeometryFill.both, AnchorPosition.northWest, true);
        auto xmllabel      = new Label(SecondF,"xml").pack(10);
        xmlTextBox         = new Text (SecondF).bind("<<Modified>>", &this.regmodifyText ).pack(10, 0, GeometrySide.left, GeometryFill.both, AnchorPosition.northWest, true);
        auto dlabel        = new Label(ThirdF,"D Registers").pack(10);
        dTextBox           = new Text (ThirdF).pack(10, 0, GeometrySide.left, GeometryFill.both, AnchorPosition.northWest, true);

         panedwindow
        .addPane(FirstF)
        .addPane(SecondF)
        .addPane(ThirdF);

    }
}

void main ()
{

    auto app = new Application();                        // Create the application.
    app.run();                                           // Run the application.

}
nomad-software commented 8 years ago

I was assuming this was like an onChange event for the text element, and it works that way for the first input change. But for subsequent changes no event occurs. Is there a flag that needs to be reset?

The <<Modified>> virtual event flags that particular widget as being modified. So in this case, when you type in your widgets, they have indeed been modified. This is normal behaviour. There are Tcl/Tk commands that enable you to read this flag later.

For your particular use case try using the <KeyRelease> event instead.