Giter Club home page Giter Club logo

Comments (9)

nomad-software avatar nomad-software commented on June 14, 2024

What about <Control-Key-a>?

from tkd.

tastyminerals avatar tastyminerals commented on June 14, 2024

Nope, doesn't work.
However, if I do the following:

private void selectText(CommandArgs args) {
    this._clientId.selectText;
    this._clientPass.selectText; // <-- added selectText for client password Entry
}

this._loginFrame = new Frame(2, ReliefStyle.groove);
this._clientId = new Entry(this._loginFrame).grid(0, 0);
this._clientId.bind("<Control-a>", &selectText);
this._clientPass = new Entry(this._loginFrame).grid(0, 1); // <-- added client password Entry

Somehow, when I hit <Control-a> while being in the client id Entry widget, the client password Entry widget gets its text selected and client id widget moves the cursor to the start of the Entry (default Tk behavior) 😮

Here is a screenshot:

2020-10-12-215753_252x106_scrot

from tkd.

nomad-software avatar nomad-software commented on June 14, 2024

Hmmm... strange. I might take a closer look at this tomorrow when I have more time. It looks like it should work, without seeing the rest of your program it's hard to tell though. Try creating a small standalone full program to test to rule out something else interfering with it.

from tkd.

tastyminerals avatar tastyminerals commented on June 14, 2024

I've only just started so there isn't much code, here is a test sample:

import std.stdio;
import std.format;
import tkd.tkdapplication;

class App : TkdApplication
{

	private Frame _loginFrame;
	private Entry _clientId;
	private Entry _clientPassword;
	private string[string] credentials;

	private void exitApplication(CommandArgs args)
	{
		this.exit();
	}

	private void youForgotMsg(string msg)
	{
		auto youForgot = new MessageDialog(this.mainWindow, "Error").setIcon(MessageDialogIcon.warning)
			.setMessage("Ooops!").setDetailMessage("You forgot %s!".format(msg)).show;
	}

	private void selectText(CommandArgs args)
	{
		this._clientId.selectText;
		this._clientPassword.selectText;
	}

	private void getClientCredentials(CommandArgs args)
	{

		if (!this._clientId.getValue)
		{
			this.youForgotMsg("client Id");
		}
		else if (!this._clientPassword.getValue)
		{
			this.youForgotMsg("client password");
		}
		else
		{
			this.credentials["client_id"] = this._clientId.getValue;
			this.credentials["client_password"] = this._clientPassword.getValue;
			this._loginFrame.destroy;
		}
	}

	private void createClientLoginWindow(int outerPadding)
	{
		// Create client login frame
		this._loginFrame = new Frame(2, ReliefStyle.groove);
		auto label1 = new Label(this._loginFrame, "Client ID").grid(0, 0);
		this._clientId = new Entry(this._loginFrame).grid(1, 0, 5);
		this._clientId.bind("<Return>", &getClientCredentials);
		this._clientId.bind("<Control-a>", &selectText);
		auto label2 = new Label(this._loginFrame, "Password").grid(0, 1);
		this._clientPassword = new Entry(this._loginFrame).grid(1, 1, 5);
		this._clientPassword.bind("<Return>", &getClientCredentials);
		//this._clientPassword.bind("<Control-a>", &selectText);
		this._loginFrame.grid(0, 0, outerPadding);
	}

	override protected void initInterface()
	{
		this.mainWindow.setTitle("Tester");
		this.mainWindow.setMinSize(300, 200);
		this.mainWindow.setProtocolCommand(WindowProtocol.deleteWindow, delegate(CommandArgs args) {
			this.exitApplication(args);
		});

         	this.createClientLoginWindow(10);
	}

}

void main()
{
	auto app = new App();
	app.run;
}

from tkd.

nomad-software avatar nomad-software commented on June 14, 2024

I've taken a look and i'm stumped. It looks like the callback is firing correctly but the selection is failing for some reason. There also looks to be another binding for <Control-a> on the Entry because it places the cursor at the start of the text when triggered. I'm out of ideas.

from tkd.

tastyminerals avatar tastyminerals commented on June 14, 2024

I've taken a look and i'm stumped. It looks like the callback is firing correctly but the selection is failing for some reason. There also looks to be another binding for <Control-a> on the Entry because it places the cursor at the start of the text when triggered. I'm out of ideas.

Yep. Tk has its own default bindings and <Control-a> puts cursor to the beginning while <Control-/> selects text.
The same behaviour in Python Tkinter and I don't remember if you can rebind there either.
I have found this so post.

from tkd.

tastyminerals avatar tastyminerals commented on June 14, 2024

I found my old Tkinter code that tackles this problem. I am going to try this with D tomorrow.

    def ctrl_a(self, callback=False):
        """
        Select all in entry or text widget.
        Overwrite tkinter default 'ctrl+/' keybind.
        """
        # checking which text widget has focus
        if self.Entry is self.focus_get():
            self.Entry.select_range(0, 'end')
        elif self.Text is self.focus_get():
            self.Text.tag_add('sel', '1.0', 'end')
        return 'break'
# (...)
self.Entry.bind('<Control-a>', self.ctrl_a)

from tkd.

tastyminerals avatar tastyminerals commented on June 14, 2024

Well, I was overly optimistic about it. It's not possible because .bind expects void function. I guess it's a bug then.

from tkd.

nomad-software avatar nomad-software commented on June 14, 2024

I'm going to archive this repository as it's not supported by me anymore.

from tkd.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.