Choose a file from folder using "file chooser button" or other widget

More
10 Sep 2018 04:43 #117277 by cmorley
You can ignore the X protocol error - it's related to embedding GTK into another window and unimportant.

In Glade did you select a 'destroy' signal and set the handler name to 'on_notebook1_destroy' in the signal tab for any widget besides the top window?

Otherwise your 'on_notebook1_destroy' function will never be called.

linuxcnc.org/docs/2.7/html/gui/gladevcp...._on_gladvcp_shutdown
Chris M
The following user(s) said Thank You: bkt

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

More
10 Sep 2018 05:58 #117281 by bkt
no .... I select the destroy signal, on Glade graphical interface, only for notebook1 ..... I must select it for every button, label, table etc etc?? really? a rather boring thing to do, but if it should be done ....

thanks
Giorgio

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

More
11 Sep 2018 02:43 #117318 by cmorley
I sent a message from my phone but maybe it didn't go through...
You only need to do one widget - just can't be the top window.
Can you confirm if the on_notbook1_destroy() is being called?
maybe with a print statement?

Chris M
The following user(s) said Thank You: bkt

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

More
13 Sep 2018 11:51 #117453 by bkt
The error output ....
/home/pc/linuxcnc-dev/bin/gladevcp:298: GtkWarning: gtk_widget_size_allocate(): attempt to allocate widget with width -5 and height 17
  gtk.main()
/home/pc/linuxcnc-dev/bin/gladevcp:298: GtkWarning: GdkWindow 0x4e00003 unexpectedly destroyed
  gtk.main()
Traceback (most recent call last):
  File "./hitcounter-modifyed.py", line 31, in on_notebook1_destroy
    self.ini.save_state(self)
AttributeError: HandlerClass instance has no attribute 'ini'
task: main loop took 0.012469 seconds
**** GLADE VCP ERROR:    X Protocol Error: 3
Shutting down and cleaning up LinuxCNC...
task: 13845 cycles, min=0.000005, max=0.012469, avg=0.001055, 1 latency excursions (> 10x expected cycle time of 0.001000s)
Note: Using POSIX realtime


the code: ....
import hal
import glib
import time
import gtk
import gtk.glade
import gobject
import os



class HandlerClass:
    '''
    class with gladevcp callback handlers
    '''

    def on_button_press(widget,data=None):

        '''
        a callback method
        parameters are:
            the generating object instance, likte a GtkButton instance
            user data passed if any - this is currently unused but
            the convention should be retained just in case
        '''
        print "on_button_press called"
        self.nhits += 1
        self.builder.get_object('hits').set_label("Hits: %d" % (self.nhits))


    def on_notebook1_destroy(self,obj,data=None):
        self.ini.save_state(self)



    def __init__(self, halcomp,builder,useropts):

        '''
        Handler classes are instantiated in the following state:
        - the widget tree is created, but not yet realized (no toplevel window.show() executed yet)
        - the halcomp HAL component is set up and the widhget tree's HAL pins have already been added to it
        - it is safe to add more hal pins because halcomp.ready() has not yet been called at this point.

        after all handlers are instantiated in command line and get_handlers() order, callbacks will be
        connected with connect_signals()/signal_autoconnect()

        The builder may be either of libglade or GtkBuilder type depending on the glade file format.
        '''

        self.halcomp = halcomp
        self.builder = builder
        self.nhits = 0

        builder.get_object('vcp_filechooserbutton1').set_current_folder(os.path.expanduser('/home/pc/F1/'))
        builder.get_object('vcp_filechooserbutton2').set_current_folder(os.path.expanduser('/home/sara/pc/F2/'))


def get_handlers(halcomp,builder,useropts):
    '''
    this function is called by gladevcp at import time (when this module is passed with '-u <modname>.py')

    return a list of object instances whose methods should be connected as callback handlers
    any method whose name does not begin with an underscore ('_') is a  callback candidate

    the 'get_handlers' name is reserved - gladevcp expects it, so do not change
    '''


    return [HandlerClass(halcomp,builder,useropts)]


as you see there are these gladevcp callback:

def on_notebook1_destroy(self,obj,data=None):
self.ini.save_state(self)

regards
Giorgio

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

More
14 Sep 2018 04:03 #117500 by cmorley
read this part:
linuxcnc.org/docs/2.7/html/gui/gladevcp....ariables_in_gladevcp

You are missing an import of gladevcp.persistance
and initialization code.

It explains it in the link i added.

Chris M
The following user(s) said Thank You: bkt

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

More
15 Sep 2018 07:07 #117569 by bkt
@ cmorley .... thanks a lot ... SOLVED.

regards
Giorgio

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

Moderators: mhaberlerHansU
Time to create page: 0.073 seconds
Powered by Kunena Forum