Giter Site home page Giter Site logo

Bind Tab Key on Text Editor about tksheet HOT 4 CLOSED

ragardner avatar ragardner commented on May 26, 2024
Bind Tab Key on Text Editor

from tksheet.

Comments (4)

PatLechevallier avatar PatLechevallier commented on May 26, 2024

Re,

I did a monkey patch.

def create_text_editor(self, r = 0, c = 0, text = None, state = "normal", see = True, set_data_ref_on_destroy = False, binding = None):
. . .
elif binding is None and set_data_ref_on_destroy:
        self.text_editor.textedit.bind("<Return>", lambda x: self.get_text_editor_value((r, c, "Return")))
        self.text_editor.textedit.bind("<FocusOut>", lambda x: self.get_text_editor_value((r, c, "FocusOut")))
        self.text_editor.textedit.bind("<Escape>", lambda x: self.get_text_editor_value((r, c, "Escape")))
        self.text_editor.textedit.bind("<Tab>", lambda x: self.get_text_editor_value((r, c, "Return"), move_down=False, move_right=True))
. . .

def bind_text_editor_destroy(self, binding, r, c):
    self.text_editor.textedit.bind("<Return>", lambda x: binding((r, c, "Return")))
    self.text_editor.textedit.bind("<FocusOut>", lambda x: binding((r, c, "FocusOut")))
    self.text_editor.textedit.bind("<Escape>", lambda x: binding((r, c, "Escape")))
    self.text_editor.textedit.bind("<Tab>", lambda x: binding((r, c, "Return")))
    self.text_editor.textedit.focus_set()

def get_text_editor_value(self, destroy_tup = None, r = None, c = None, set_data_ref_on_destroy = True, event = None, destroy = True, move_down = True, move_right=False, redraw = True, recreate = True):
. . .
if move_right:
            if r is None and c is None and destroy_tup:
                r, c = destroy_tup[0], destroy_tup[1]
            currently_selected = self.currently_selected()
            if r is not None and c is not None:
                if (
                    currently_selected and
                    r == currently_selected[0] and
                    c == currently_selected[1] and
                    (self.single_selection_enabled or self.toggle_selection_enabled)
                    ):
                    self.select_cell(r , c+1 if c<len(self.col_positions) - 2 else c)
                    self.see(r, c+1 if c < len(self.col_positions) - 2 else c, keep_xscroll = True, bottom_right_corner = True, check_cell_visibility = True)
. . .

Plus I added <Tab> in the bind of arrowkeys.
It's 90% the same behavior as in excel. It does job.

from tksheet.

ragardner avatar ragardner commented on May 26, 2024

It should be added in 4.9.7 but try it out and let me know if it's not working correctly

from tksheet.

ragardner avatar ragardner commented on May 26, 2024

@PatLechevallier

Regarding

In a more generic way, can we just add the possibility of binding other keys on the text editor?

I added the below code in version 4.9.7

def bind_key_text_editor(self, key, function):
    self.MT.text_editor_user_bound_keys[key] = function

def unbind_key_text_editor(self, key):
    if key == "all":
        for key in self.MT.text_editor_user_bound_keys:
            try:
                self.MT.text_editor.textedit.unbind(key)
            except:
                pass
        self.MT.text_editor_user_bound_keys = {}
    else:
        if key in self.MT.text_editor_user_bound_keys:
            del self.MT.text_editor_user_bound_keys[key]
        try:
            self.MT.text_editor.textedit.unbind(key)
        except:
            pass

It's not perfect though because you can't really bind keys to the text widgets actual functions, I might add this functionality later, but I can't give you a time frame sorry

from tksheet.

PatLechevallier avatar PatLechevallier commented on May 26, 2024

The functionality for the event <Tab> is working fine. 👍
No worries, it's not a priority.

from tksheet.

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.