search bar and gcode scroll

More
20 Oct 2020 04:15 #186646 by cakeslob
I am trying to add a new sidebar to the axis window, to the left of the gcode window with some basic labels like feedrate and spindle speed, maybe some buttons, like in plasmac where i got most of the how to, I am doing this in usercommand.py and im trying to create new axisui pins to go with the labels like how its done in plasmac. When I do a halcomp, the pins become pyvcp pins, for example, instead of it being axisui.feedrate-upm, the pin becomes pyvcp.feedrate-upm. I have a pyvcp doing the same thing as this side panel, so to get it to work i renamed everything, and linked all the pins in postgui hal with the rest of the pyvcp pins, i dont know why the pins im trying to make in usercommand.py are turning into pyvcp pins


here is the relevant part
## -remove bottom frame -##
root_window.tk.call('pack','forget','.pane.bottom.t.text')
root_window.tk.call('pack','forget','.pane.bottom.t.sb')

###add common frame beside t.test
root_window.tk.call('labelframe','.pane.bottom.common')
root_window.tk.call('grid','.pane.bottom.common','-column','0','-row','1','-sticky','nw')
root_window.tk.call('grid','columnconfigure','.pane.bottom.common','0','-weight','1')

##### add userframe corrdinate display as baseline working test ######
W = root_window.tk.call
W('label','.pane.bottom.common.ucs','-text','G5x')
W('grid','.pane.bottom.common.ucs','-column','0','-row','0','-sticky','w')
 
#### add feedrate lable and grid into bottom.common ####################
W('label','.pane.bottom.common.feedrate-upm','-anchor','se','-width','5','-fg','blue')
W('label','.pane.bottom.common.feedrate-upmlab','-text','FEED','-anchor','w','-width','4')
W('grid','.pane.bottom.common.feedrate-upm','-row','1','-column','1','-rowspan','1','-sticky','se')
W('grid','.pane.bottom.common.feedrate-upmlab','-row','1','-column','0','-sticky','w')
##spindle-speed
W('label','.pane.bottom.common.spindle-speed2','-anchor','se','-width','5','-fg','blue')
W('label','.pane.bottom.common.spindle-speed2lab','-text','S','-anchor','w','-width','4')
W('grid','.pane.bottom.common.spindle-speed2','-row','2','-column','1','-rowspan','1','-sticky','se')
W('grid','.pane.bottom.common.spindle-speed2lab','-row','2','-column','0','-sticky','w')
## tool number
W('label','.pane.bottom.common.tool-number2','-anchor','se','-width','5','-fg','blue')
W('label','.pane.bottom.common.tool-numberlab','-text','T','-anchor','w','-width','4')
W('grid','.pane.bottom.common.tool-number2','-row','3','-column','1','-rowspan','1','-sticky','se')
W('grid','.pane.bottom.common.tool-numberlab','-row','3','-column','0','-sticky','w')


####### update feedrate
def user_live_update():
    root_window.tk.call('.pane.bottom.common.feedrate-upm','configure','-text','%3.0f' % (comp['feedrate-upm']))
    root_window.tk.call('.pane.bottom.common.spindle-speed2','configure','-text','%3.0f' % (comp['spindle-speed2']))
    root_window.tk.call('.pane.bottom.common.tool-number2','configure','-text','%3.0f' % (comp['tool-number2']))

    ###coordinate
    W('.pane.bottom.common.ucs','configure','-text','U:' + all_systems[o.last_g5x_index].split()[1])


def user_hal_pins():
    # create new hal pins
    #mycomp = hal.component('feed')
    comp.newpin('feedrate-upm', hal.HAL_FLOAT, hal.HAL_IN)
    comp.newpin('spindle-speed2', hal.HAL_FLOAT, hal.HAL_IN)
    comp.newpin('tool-number2', hal.HAL_U32, hal.HAL_IN)
    comp.ready()
    # create new signals and connect pins
    
    hal.new_sig('feedrate-upm',hal.HAL_FLOAT)
    #hal.connect('feedrate-upm','motion.feed-upm')
    #hal.connect('axisui.feedrate-upm','feedrate-upm')
##### end feed test

i tried to do it like the docs/plasmac for the feedrate pin to make axisui.feedrate-upm , but it would always make to pyvcp and couldnt connect to it, so i just did it in pyvcp hal, what am i missing/did wrong to make these axisui pins, the pins are just connected to basic pins so i was hoping this wouldnt be so bulky , if anyone could help me out that would be great



Attachments:

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

More
20 Oct 2020 06:58 #186654 by Grotius
Hi Cakeslob,

Have you ever tried to program your (side) windows with glade gtk2 (with linuxcnc widgets)?
If i where you, i would invest some time in that way of programming.

If you have questions about installing the glade linuxcnc widgets, i can give you info.

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

More
20 Oct 2020 07:17 - 20 Oct 2020 07:58 #186656 by phillc54
It works fine here.
Warning: Spoiler!


Are you sure there is no reference to PYVCP in your ini file.

Edit: I just tried with a PYVCP panel as well and it seems there is a conflict. If you have a PYVCP panel then the custom axisui hal pins are not created, the pins are created as pyvcp pins. It looks like a relatively simple fix in Axis, I'll test it and put in a PR if if works out.
Attachments:
Last edit: 20 Oct 2020 07:58 by phillc54.

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

More
20 Oct 2020 19:38 #186734 by cakeslob

Are you sure there is no reference to PYVCP in your ini file.

Edit: I just tried with a PYVCP panel as well and it seems there is a conflict. If you have a PYVCP panel then the custom axisui hal pins are not created, the pins are created as pyvcp pins. It looks like a relatively simple fix in Axis, I'll test it and put in a PR if if works out.

Yes, I have a pyvcp, doing almost the same thing as the new side panel, which is causing me issues with the pins created. Interesting, so if i have a pyvcp in my ini it changes them to pyvcp comps, is that this area right here creating axisui pins then changing the comp prefix to pyvcp?
if hal_present == 1 :
    comp = hal.component("axisui")
    comp.newpin("jog.x", hal.HAL_BIT, hal.HAL_OUT)
    comp.newpin("jog.y", hal.HAL_BIT, hal.HAL_OUT)
    comp.newpin("jog.z", hal.HAL_BIT, hal.HAL_OUT)
    comp.newpin("jog.a", hal.HAL_BIT, hal.HAL_OUT)
    comp.newpin("jog.b", hal.HAL_BIT, hal.HAL_OUT)
    comp.newpin("jog.c", hal.HAL_BIT, hal.HAL_OUT)
    comp.newpin("jog.u", hal.HAL_BIT, hal.HAL_OUT)
    comp.newpin("jog.v", hal.HAL_BIT, hal.HAL_OUT)
    comp.newpin("jog.w", hal.HAL_BIT, hal.HAL_OUT)
    comp.newpin("jog.increment", hal.HAL_FLOAT, hal.HAL_OUT)
    comp.newpin("notifications-clear",hal.HAL_BIT,hal.HAL_IN)
    comp.newpin("notifications-clear-info",hal.HAL_BIT,hal.HAL_IN)
    comp.newpin("notifications-clear-error",hal.HAL_BIT,hal.HAL_IN)
    comp.newpin("resume-inhibit",hal.HAL_BIT,hal.HAL_IN)

    vars.has_ladder.set(hal.component_exists('classicladder_rt'))

    if vcp:
        import vcpparse
        comp.setprefix("pyvcp")
        f = Tkinter.Frame(root_window)
        if inifile.find("DISPLAY", "PYVCP_POSITION") == "BOTTOM":
            f.grid(row=4, column=0, columnspan=6, sticky="nw", padx=4, pady=4)
        else:
            f.grid(row=0, column=4, rowspan=6, sticky="nw", padx=4, pady=4)
        vcpparse.filename = vcp
        vcpparse.create_vcp(f, comp)
        vcp_frame = f
        root_window.bind("<Control-e>", commands.toggle_show_pyvcppanel)
        help2 += [("Ctrl-E", _("toggle PYVCP panel visibility"))]
    else:
        widgets.menu_view.delete(_("Show pyVCP pan_el").replace("_", ""))

I just checked, without pyvcp it makes my pins axisui, so aside from all this my code is alright?

Hi Cakeslob,
Have you ever tried to program your (side) windows with glade gtk2 (with linuxcnc widgets)?
If i where you, i would invest some time in that way of programming.
If you have questions about installing the glade linuxcnc widgets, i can give you info.

I do that, for tabs and side panels (not well mind you) but I would have no idea where to start with embedding it into different frames aside from the standard way

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

More
20 Oct 2020 22:20 #186758 by phillc54
Yes, that is where the problem is, if you change the following two lines it appears to work ok.

From:
comp.setprefix("pyvcp")
To:
comp1 = hal.component("pyvcp")

From:
vcpparse.create_vcp(f, comp)
To:
vcpparse.create_vcp(f, comp1)

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

More
22 Oct 2020 04:41 #186874 by cakeslob
Alright, i tried both making it without pyvcp, then making the changes and adding pyvcp, all seems to work well, thank you for the help

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

More
31 Oct 2020 18:47 #187935 by cakeslob
The way the fanuc controller scrolls/searches through gcode and runs from line is something to be desired in linuxcnc, you can use the arrows to go up or down in the gcode, or use the arrows and search bar to to just forward and backwards to the next instance of a gcode, like scrolling through, looking for all the m6 commands. I use this feature every work day on the fanuc, so I though I would try to implement it. I almost have it, but im a bit stuck again, and need some guidance.
#####  search function  #########

def select_g3(event):  
      
    # remove tag 'found' from index 1 to END  
    t.tag_remove('found', '1.0', END)  
      
    # returns to widget currently in focus  
    s = "3"
      
    if (s):  
        idx = '1.0'
        while 1:  
            # searches for desried string from index 1  
            idx = t.search(s, idx, nocase = 1,
                            forwards = 1,
                            stopindex = END) 
              
            if not idx: break
              
            # last index sum of current index and  
            # length of text  
            lastidx = '% s+% dc' % (idx, len(s)) 
              
  
            # overwrite 'Found' at idx  
            t.tag_add('found', idx, lastidx)  
            idx = lastidx 
            t.see(idx) 
  
        # mark located string as red 
          
        t.tag_config('found', foreground ='red') 
    


######  gcode scroll ######
root_window.bind('<Key-1>', select_next)
root_window.bind('<Key-2>', select_prev)
root_window.bind('<Key-3>', rClicker)
root_window.bind('<Key-4>', select_g3)


here is the farthest ive got with the search function. there is no entry widget, im just using key4 to search the file for "3". it works, but it finds them all at once and jumps to the very last found line, instead of one at a time. since that was as far as i could get function wise, i started packing widgets for the other part of it
#######  add search_bar  #########


## add search entry widget ###
W('entry','.pane.bottom.common.srch_bar','-width','15')
W('button','.pane.bottom.common.srch_btn','-text','search')
W('button','.pane.bottom.common.scrl_up','-text','^','-command','select_next')
W('button','.pane.bottom.common.scrl_dwn','-text','V','-command','select_prev')

#W('button','.pane.bottom.common.srch_btn','-text','search','-command','search_gcode')

W('grid','.pane.bottom.common.srch_bar','-column','0','-row','4','-sticky','nw')
W('grid','.pane.bottom.common.scrl_up','-column','3','-row','0','-sticky','ne')
W('grid','.pane.bottom.common.srch_btn','-column','0','-row','5','-sticky','nw')
W('grid','.pane.bottom.common.scrl_dwn','-column','3','-row','5','-sticky','ne')



#####  search function  #########
search = 'Entry','.pane.bottom.common.srch_bar'

def search_gcode(event):  
      
    # remove tag 'found' from index 1 to END  
    t.tag_remove('found', '1.0', END)  
      
    # returns to widget currently in focus  
  
    s = search.get()
      
    if (s):  
        idx = '1.0'
        while 1:  
            # searches for desried string from index 1  
            idx = t.search(s, idx, nocase = 1,
                            stopindex = END) 
              
            if not idx: break
              
            # last index sum of current index and  
            # length of text  
            lastidx = '% s+% dc' % (idx, len(s)) 
              
  
            # overwrite 'Found' at idx  
            t.tag_add('found', idx, lastidx)  
            idx = lastidx 
            t.see(idx) 
  
        # mark located string as red 
          
        t.tag_config('found', foreground ='red') 
    






######  gcode scroll ######
root_window.bind('<Key-1>', select_next)
root_window.bind('<Key-2>', select_prev)
root_window.bind('<Key-3>', rClicker)
#root_window.bind('<Key-4>', select_g3)

W('.pane.bottom.common.srch_btn','configure','-command','search_gcode')



TclCommands.search_gcode = search_gcode
commands = TclCommands(root_window)

#### end search stuff #########

This file is usercommand_search, it has all the layout. But once i added the entry widget I started getting a bunch of errors with the search feature, like tuple and now it says Im not presenting an argument. Im a bit stuck here. Im also having a hard time binding these to buttons. binding them to keyboard commands works fine and easy but to do buttons it made a whole thing of it being events and such. the whole thing is pretty crude, but the main functions and widgets are all there.

so, what Im trying to get it to do in the very end
-put something in search
-search arrow next button jumps/highlights the closest line with that expression
-search arrow prev jumps backwards to the closest line
-hijack the run command to do something similar to fanuc, like, if not line 1 push button again to run from line

the tkinter text widget has a log of unused features. it looks like it has the ability to edit as well, here is my progress so far
Attachments:
The following user(s) said Thank You: phillc54

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

More
31 Oct 2020 19:04 #187938 by cakeslob
g code window line scroll and run from line keyboard keys

This part was much easier. In axis, there is already defined actions to scroll up and down g code as well as run from line. this is very handy for lots of reasons, mostly if you prefer keyboard only type setups. To transfer this to buttons is a bit more work and im not there yet. This was the first part of my test, since it was already included in axis.py, it just needed to be fixed
######  gcode scroll ######
root_window.bind('<Key-1>', select_next)
root_window.bind('<Key-2>', select_prev)
root_window.bind('<Key-3>', rClicker)
crude, but working example of gcode scroll line and run from line using the keyboard.
key 1 moves the highlighted line to the next spot
key 2 moves it to previous line
key 3 is supposed to run from line, but because the righclick dialog is part of it, it opens the dialog and i use arrow key to run from line
this is different from axis because this scrolls with the highlighted line

select_next and select_prev are already defined, but when I went looking, they dont seem to be tied to anything, so i bound them to some keys. select previous worked fine outta the box. select next always jumped back to line 1 and never advanced. so i had to change it a bit
def select_prev(event):
    if o.highlight_line is None:
        i = o.last_line
    else:
        i = max(1, o.highlight_line - 1)
    o.set_highlight_line(i)
    o.tkRedraw()

def select_next(event):
    if o.highlight_line is None:
        i = 1
    else:
        i = min(o.last_line, o.highlight_line + 1)
    o.set_highlight_line(i)
    o.tkRedraw()

def select_next(event):
    if o.highlight_line is None:
        i = 1
    else:
        i = max(o.last_line, o.highlight_line + 1)
    o.set_highlight_line(i)
    o.tkRedraw()

I changed select_next from i = min to i = max and it now scrolls next correctly
The following user(s) said Thank You: phillc54

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

More
05 Nov 2020 19:56 - 05 Nov 2020 23:58 #188432 by cakeslob
I am stuck and need help.
I have the search part working, but I cannot send the text from the search entry to the search command. i just keeps searching for " '.pane.bottom.common.srch_bar.get()' "
ahh i got it, just have to figure out how to clear the entries/highlights
attached file "usercommand_search.py"
def search_gcode(event):  
      
   
    
    # remove tag 'found' from index 1 to END  
    #t.tag_remove('found', '1.0', END)  
      
    
    s = W ('.pane.bottom.common.srch_bar','get')
    #s = "g3"

          
    if (s):         
        line = o.get_highlight_line()
        idx = ("%d.0" % (line+1))
    
            # searches for desried string from index highlighted line  
        idx = t.search(s, idx, nocase = 1,
                            forwards = 1,
                            stopindex = END)
                
              
            # last index sum of current index and  
            # length of text  
        lastidx = '% s+% dc' % (idx, len(s))               
  
  
  
            # overwrite 'Found' at idx  
        t.tag_add('found', idx, lastidx)  
        idx = lastidx 
        t.see(idx)
         
  
        # mark located string as red 
          
    t.tag_config('found', background ='yellow') 
    
      
    idxh = int(idx.split('.')[0])
    o.set_highlight_line(idxh)
    o.tkRedraw()
    '.pane.bottom.common.srch_bar.set(" ")'


this is the working search command. it searches forward and highlights the line containing the search (g3) using key 4. then using key3 you can run from line or pressing 4 again searches for the next line with g3. attached file "usercommand_searchg3.py"

def select_g3(event):  


    
    # remove tag 'found' from index 1 to END  
    t.tag_remove('found', '1.0', END)  
      
    # returns to widget currently in focus  
    s = "G3"
    #lastidx = 1.0  
      
    if (s):  
#       
        line = o.get_highlight_line()
        idx = ("%d.0" % (line+1))
    
            # searches for desried string from index 1  
        idx = t.search(s, idx, nocase = 1,
                            forwards = 1,
                            stopindex = END)
                
              
            # last index sum of current index and  
            # length of text  
        lastidx = '% s+% sc' % (idx, len(s)) 
              
  
            # overwrite 'Found' at idx  
        t.tag_add('found', idx, lastidx)  
            #t.tag_ranges('found') 
        idx = lastidx 
        t.see(idx)
         
  
        # mark located string as red 
          
    t.tag_config('found', background ='yellow') 
    
    idxh = int(idx.split('.')[0])
    o.set_highlight_line(idxh)
    o.tkRedraw()





######  gcode scroll ######
root_window.bind('<Key-1>', select_next)
root_window.bind('<Key-2>', select_prev)
root_window.bind('<Key-3>', rClicker)
root_window.bind('<Key-4>', select_g3)

known issues so far
-it searches the line numbers
-doesnt remove highlight even if you change search query
-it needs cleaning up for when no search entry, or end of search
-buttons dont work yet
Attachments:
Last edit: 05 Nov 2020 23:58 by cakeslob.

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

More
06 Nov 2020 07:42 #188478 by cakeslob



File Attachment:

File Name: usercomman..._tabs.py
File Size:14 KB


-add new tab to left side
not a fancy dynamic tab or glade, but like the manual tab
### ADD NEW TAB TO LEFT SIDE  #######

W('.pane.top.tabs','insert','end', 'user', '-text','user')

###########  add buttons to tab  #########

W('grid','columnconfigure','.pane.top.tabs.fuser','0','-weight','1')
W('button','.pane.top.tabs.fuser.scrl','-text','^','-command','select_next')
W('grid','.pane.top.tabs.fuser.scrl','-column','1','-row','1','-sticky','ne')
W('label','.pane.top.tabs.fuser.ucs','-text','G5x')
W('grid','.pane.top.tabs.fuser.ucs','-column','0','-row','1','-sticky','nw')


-add buttons to preview frame
cant get it to go first, cant figure out how to forget the preview widget or what the name is

###################   add button to preview ##################
W('grid','columnconfigure','.pane.top.right.fpreview','0','-weight','1')
W('button','.pane.top.right.fpreview.scrl','-text','^','-command','select_next')
W('pack','.pane.top.right.fpreview.scrl','-side','left','-anchor','nw')

-expand widgets
press number 5 and 6 to toggle the 2 options
def toggle_show_bottom(*event):
        # need to toggle variable manually for keyboard shortcut
        if len(event) > 0:
            vars.show_pyvcppanel.set(not vars.show_pyvcppanel.get())

        if vars.show_pyvcppanel.get():
            root_window.tk.call('grid','.pane.top','-row','1')
            root_window.tk.call('.pane','paneconfigure','.pane.top',"-stretch","never","-minsize","350");

            root_window.tk.call('grid','.pane.bottom','-row','2')
            root_window.tk.call('.pane','paneconfigure','.pane.bottom',"-stretch","always",'-width','500');

            
        else:
            root_window.tk.call('grid','remove','.pane.top')
            root_window.tk.call('.pane','paneconfigure','.pane.top',"-stretch","always","-minsize","150");
            root_window.tk.call('.pane','paneconfigure','.pane.bottom',"-stretch","never",'-width','500','-height','500');

        o.tkRedraw()

root_window.bind('<Key-5>', toggle_show_bottom)
root_window.bind('<Key-6>', toggle_show_tabs)


TclCommands.toggle_show_bottom = toggle_show_bottom
TclCommands.toggle_show_tabs = toggle_show_tabs
commands = TclCommands(root_window)


Attachments:
The following user(s) said Thank You: phillc54

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

Time to create page: 0.337 seconds
Powered by Kunena Forum