Invert keyboard jog button's in running program, how to example.

More
25 Dec 2018 00:27 - 25 Dec 2018 00:30 #122851 by Grotius
For the coming up generation of linuxcnc interfaces it is handy to invert keyboard jog buttons at any time.
Mach3 has such a keyboard configuration option in their config directory.

Frequently users have different console position's related to their machine position. Keyboard jog button's (button arrows)
are more understandable if they are aligned with machine movement's.

This example is intended for more experienced linuxcnc users that have some experience with custum gui programming.

How to implement :

In the keycall function for each axis in user gui i added a inverse direction :
def on_keycall_XNEG(self,state,SHIFT,CNTRL,ALT):
	  
        if state == 1 and self.widgets.inverse_x.get_active():
            self.on_x_min_pressed(state)
            return True
        if state == 0 and self.widgets.inverse_x.get_active():
            self.on_x_min_released(state)
            return True        
        #inverse direction :      
        if state == 1 and not self.widgets.inverse_x.get_active():
            self.on_x_plus_pressed(state)
            return True
        if state == 0 and not self.widgets.inverse_x.get_active():
            self.on_x_plus_released(state)
            return True

I added for each axis checkboxes in glade, named "inverse_x" checkbox for x axis.
It writes a configuration text file, and it load's the configuration file also on startup in a slow periodic thread.
def on_save_settings_as_pressed(self, widget, data=None):
      value_x = self.widgets.inverse_x.get_active()
      value_y = self.widgets.inverse_y.get_active()
      value_z = self.widgets.inverse_z.get_active()
      value_a = self.widgets.inverse_a.get_active()
      value_b = self.widgets.inverse_b.get_active()

      x = self.widgets.filename_entry.get_text()
      f=open(x, "w+")
      
      f.write("inverse_x\r\n")
      f.write("%d\r\n" % (value_x))
      
      f.write("inverse_y\r\n")
      f.write("%d\r\n" % (value_y))    
      
      f.write("inverse_z\r\n")
      f.write("%d\r\n" % (value_z))    

      f.write("inverse_a\r\n")
      f.write("%d\r\n" % (value_a))  

      f.write("inverse_b\r\n")
      f.write("%d\r\n" % (value_b))  
      
      f.close() 

  def on_load_settings_pressed(self, widget, data=None):
     x = self.widgets.filename_entry.get_text()
     f=open(x, "r")
     if f.mode == 'r':
        content =f.readlines()

        value_x = int(content[1])       
        self.widgets.inverse_x.set_active(value_x)
        #content[1] # actual line 2 in file.
        
        value_y = int(content[3])       
        self.widgets.inverse_y.set_active(value_y)      
        
        value_z = int(content[5])       
        self.widgets.inverse_z.set_active(value_z) 
        
        value_a = int(content[7])       
        self.widgets.inverse_a.set_active(value_a) 
        
        value_b = int(content[9])       
        self.widgets.inverse_b.set_active(value_b)

It works fantastic !!



For checking the keyboard config file i added a slow thread every 2 second's.

gobject.timeout_add(2000, self.slow_periodic)

code slow thread :
def slow_periodic(self):
     x = self.widgets.filename_entry.get_text()
     f=open(x, "r")
     if f.mode == 'r':
        content =f.readlines()

        value_x = int(content[1])       
        self.widgets.inverse_x.set_active(value_x)
        #content[1] # actual line 2 in file.
        
        value_y = int(content[3])       
        self.widgets.inverse_y.set_active(value_y)      
        
        value_z = int(content[5])       
        self.widgets.inverse_z.set_active(value_z) 
        
        value_a = int(content[7])       
        self.widgets.inverse_a.set_active(value_a) 
        
        value_b = int(content[9])       
        self.widgets.inverse_b.set_active(value_b)
Attachments:
Last edit: 25 Dec 2018 00:30 by Grotius.

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

More
25 Dec 2018 22:09 #122891 by newbynobi
Way too complicated!
Why not place a user tab over the normal button and place on that ones the inverted button. This button can be connected in hal to the corresondig halui pin.

For GUI coder who want to supply that on the fly, just use a notebook and switch pages.

Just my 2 cents.

Norbert

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

Time to create page: 0.182 seconds
Powered by Kunena Forum