Filebrowser and Gcode editor

More
08 Jun 2022 01:32 #244744 by cakeslob
shit, that seriously works for you?

Im sorry this is getting tedious. I really appreciate the help. Well, that probably means I have bigger issues then doesnt it? For reference, Im using a premade RPI image of Buster with a RIP 2.9

Alright if the code works for you and not me, then I guess I have a problem on my end I have to figure out.

I copied that code exactly into a new file, and added rC = root_window.tk.call to the top, and got pretty much the same error
### we will change this back to w later  ####
rC = root_window.tk.call

def page_switched(page):
    print('switched to', page)

def save_editfile():
    print('saving', s.file)

def load_editfile():
    print('loading', s.file)

TclCommands.page_switched = page_switched
TclCommands.save_editfile = save_editfile
TclCommands.load_editfile = load_editfile

rC('.pane.top.tabs','bindtabs','<ButtonPress-1>','page_switched')
rC('.pane.top.tabs','insert','end','edit','-text',' edit ','-raisecmd','load_editfile','-leavecmd','save_editfile')
TCL error in asynchronous code:
invalid command name "page_switched"
    while executing
"page_switched [NoteBook::_get_page_name .pane.top.tabs current 1]"
    (command bound to event)

Please Log in or Create an account to join the conversation.

More
08 Jun 2022 03:09 #244746 by phillc54
For some reason this stupid forum is not sending me notifications, it really is a POS...

​​​​​​​Well, that is strange, if I leave out the quotes then I get the same errors you were getting.

I have a Pi4 I can try on later, are you using a 32bit or or 64bit OS, mine has the 64bit from somewhere on the forum.

 

Please Log in or Create an account to join the conversation.

More
08 Jun 2022 03:43 #244750 by cakeslob
I have buster looks like 32bit on this one. ill try loading a bullseye, maybe its a python thing, or something outdated with my setup

Please Log in or Create an account to join the conversation.

More
08 Jun 2022 05:28 #244751 by phillc54
I should have seen this earlier, to run that test script stand alone it requires:
commands = TclCommands(root_window) after the TclCommands...

Please Log in or Create an account to join the conversation.

More
09 Jun 2022 03:46 #244791 by cakeslob
hmm for some reason I didnt copy it over, thats a rookie move on my part. Thanks for the help, that took care of the issue, and it now opens and saves automatically , I added a reload_file() on exit also, so the tab functions pretty well.

It might be pretty basic, but its nice having it right there in the same window. Last major thing on the ol TODO list, is this keybinding. Im pretty sure Ive figured out why keybinds dont happen with entry and they do with text, it was in axis.tcl
# Handle Tk 8.6+ where virtual events are used for cursor motion
foreach {k v} {
    Left    PrevChar        Right   NextChar
    Up      PrevLine        Down    NextLine
    Home    LineStart       End     LineEnd
} {
    set b [bind Entry <<$v>>]
    if {$b != {}} { bind Entry <$k> $b }
}

# any key that causes an entry or spinbox action should not continue to perform
# a binding on "."
foreach c {Entry Spinbox} {
        foreach b [bind $c] {
            switch -glob $b {
                <*-Key-*> {
                    bind $c $b {+if {[%W cget -state] == "normal"} break}
                }
            }
    }

    foreach b { Left Right
            Up Down Prior Next Home
            End } {
        bind $c <KeyPress-$b> {+if {[%W cget -state] == "normal"} break}
        bind $c <KeyRelease-$b> {+if {[%W cget -state] == "normal"} break}
    }
    bind $c <Control-KeyPress-Home> {+if {[%W cget -state] == "normal"} break}
    bind $c <Control-KeyRelease-Home> {+if {[%W cget -state] == "normal"} \
                                                                        break}
    bind $c <Control-KeyPress-KP_Home> {+if {[%W cget -state] == "normal"} \
                                                                        break}
    bind $c <Control-KeyRelease-KP_Home> {+if {[%W cget -state] == "normal"} \
                                                                        break}
    set bb [bind $c <KeyPress>]
    foreach k { Left Right Up Down Prior Next
                Home End } {
        set b [bind $c <$k>]
        if {$b == {}} { set b $bb }
        bind $c <KeyPress-KP_$k> "if {%A == \"\"} { $b } { $bb; break }"
        bind $c <KeyRelease-KP_$k> {+if {[%W cget -state] == "normal"} break}
    }

    foreach k {0 1 2 3 4 5 6 7 8 9} {
        bind $c <KeyPress-KP_$k> "$bb; break"
        bind $c <KeyRelease-KP_$k> {+if {[%W cget -state] == "normal"} break}
    }

    bind $c <Key> {+if {[%W cget -state] == "normal" && [string length %A]} \
                                                                        break}
}

I dont 100% understand, but I think it says its binding entry/spinbox, and then it checks state, and then breaks the keybind. Im assuming this only breaks keybind when the widget is in focus?

Please Log in or Create an account to join the conversation.

More
13 Jun 2022 00:36 #245040 by cakeslob
I am very close on the binding. by close I mean usable. I am on the key binding section, I started with the letter keys (I think), and will work my way through the rest.
#######   EDIT TAB   ######

def load_editfile():
    print (s.file)
    open_filea = open(s.file,'r')
    rC('.pane.top.tabs.fedit.t.text','delete','1.0','end')
    rC('.pane.top.tabs.fedit.t.text','insert','end',open_filea.read())
    rC('bind','.pane.top.tabs.fedit.t.text','<Key>', '%A' )
    



def save_editfile():
    print (s.file)
    open_filea = open(s.file,'w')
    edit_gcode = rC('.pane.top.tabs.fedit.t.text','get','1.0','end')
    open_filea.write(edit_gcode)
    reload_file()
    return 1

###   this is mine, it took me much longer to get here than I will admit.
  rC('bind','.pane.top.tabs.fedit.t.text','<Key>', '%A' )


####   this is what i want to copy for axis.tcl

 bind $c <Key> {+if {[%W cget -state] == "normal" && [string length %A]} \
                                                                        break}

I almost understand it all, but the last part still eludes me, but I think this is the one I want.

The problem - Keybindngs apply to all widgets except for entry and spinbox, as per this section of axis.tcl as far as i understand.
github.com/LinuxCNC/linuxcnc/blob/master...s/tcl/axis.tcl#L1997

What I think this section does, it send break to the binding event to stop it from happening. and then something does something to make the keystrokes work normally. because once I send break to the bind, all key strokes do nothing anymore withing the text widget. O does not open file, but it does not "o" either.
I think that is this section right here,
bind $c <Key> {+if {[%W cget -state] == "normal" && [string length %A]} \
                                                                        break}

my understanding of it is, bind key, check if( state of the widget is normal) and [string length %A], then break

I see %A means www.tcl.tk/man/tcl/TkCmd/bind.html#M42

it means/turns keybind events into the corresponding unicode character...... something something. thats where im stuck


edit, and also, bug, if you open a file with the edit tab open, it will not update and over write current file with the old file....I need to...compare something....or something....
Attachments:

Please Log in or Create an account to join the conversation.

More
15 Jul 2022 03:26 #247350 by cakeslob
Phil, thank you for all the help
, I have a pretty usable editor with minimal bugs. I dont know yet how to keep the gcode files in sync between axis and the editor, so dont open a file with the editor tab open, or it will over write it with the previous file. or undo too many times. 

There was no pretty way to do the keybinding.

 
Attachments:

Please Log in or Create an account to join the conversation.

Time to create page: 0.111 seconds
Powered by Kunena Forum