objects not loaded or recognized

More
28 Aug 2014 21:02 #50399 by mariusl
Hi
I have written a small Glade panel with six buttons on. I have a python srcript to handle the buttons but for some reason the halcomp and ini objects are not seen. I get no error when loading but when I want to write to the halpin.

how it is loaded in Gmoccapy
EMBED_TAB_NAME = gears
EMBED_TAB_LOCATION = box_vel_info  
EMBED_TAB_COMMAND = gladevcp -u gearselect.py -x {XID} gear_select.glade 


the python script
#!/usr/bin/env python
# -*- coding:UTF-8 -*-
"""
    This file will control some options of the custom panel
    and should be something like a skeleton to begin with
    Please include a smal description of the file, so it is much
    easier for other developers to follow yozr style. there ar many 
    lasy people out there, not taking care of that, please do not become 
    one of them!

    Copyright 2013 Norbert Schechner
    nieson@web.de

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

"""

# Please read also the above text! And if you begin to code some new stuff
# please include comments, so others can follow you!

# Name varialbles so others do now there meaning, see the following example:
# v=f-s+(w.get_value)
# value = first_value - second_value + (widget.get_value)
# it cost no performanca, but is much easier to read!
# for coding style I recfommend to follow PEP8
# see : http://legacy.python.org/dev/peps/pep-0008/


####################################################################
# Watch the terminal output, as the error reports will apear there #
####################################################################

# We will need to import some basic stuff
import hal           # needed to make our own hal pins
import hal_glib      # needed to make our own hal pins and react with handlers
from gladevcp.persistence import IniFile  # we use this one to save the states of the widgets on shut down and restart
from gladevcp.persistence import widget_defaults
from gladevcp.persistence import select_widgets
from gtk.gtkgl.widget import Widget

class GearSelect:

    # __init__ will set the defaults and get all relevant information, before showing the panel
    def __init__(self, halcomp, builder, useropts):
        self.builder = builder
        self.halcomp = halcomp

        self.defaults = {
        # the following names will be saved/restored as method attributes
        # the save/restore mechanism is strongly typed - the variables type will be derived from the type of the
        # initialization value. Currently supported types are: int, float, bool, string
        IniFile.vars : { 'gear_state' : 0},
        # to save/restore all widget's state which might remotely make sense, add this:
        IniFile.widgets: widget_defaults(select_widgets(self.builder.get_objects(),
                                                        hal_only = True, output_only = True))
        # a sensible alternative might be to retain only all HAL output widgets' state:
        # IniFile.widgets: widget_defaults(select_widgets(self.builder.get_objects(), hal_only=True,output_only = True)),
    }

        self.ini_filename = 'gears'+'.var'
        self.ini = IniFile(self.ini_filename, self.defaults, self.builder)
        self.ini.restore_state(self)

        # lets make our hal pins, to find out what pins you can build, please take a look at
        # http://www.linuxcnc.org/docs/devel/html/hal/halmodule.html#_create_pins_and_parameters
        # This way we are able to handle events here
        
        # and this way we just can read or write the pin values, but not react to the changes
        #self.halcomp.newpin("panel-is-hidden", hal.HAL_BIT, hal.HAL_OUT)

        self.frame_main = self.builder.get_object("frame_main")
        
        self.halcomp.newpin("selected-gear", hal.HAL_S32, hal.HAL_IO)

        self.btn_1 = self.builder.get_object("btn-1")
        self.btn_1.connect("clicked", self._btn_1_clicked)

        self.btn_2 = self.builder.get_object("btn-2")
        self.btn_2.connect("clicked", self._btn_2_clicked)

        self.btn_3 = self.builder.get_object("btn-3")
        self.btn_3.connect("clicked", self._btn_3_clicked)

        self.btn_4 = self.builder.get_object("btn-4")
        self.btn_4.connect("clicked", self._btn_4_clicked)

        self.btn_5 = self.builder.get_object("btn-5")
        self.btn_5.connect("clicked", self._btn_5_clicked)

        self.btn_6 = self.builder.get_object("btn-6")
        self.btn_6.connect("clicked", self._btn_6_clicked)



        # if we want to have handlers to our widgets, or we want to modify them, we
        # need to get there instance with the builder
        # we get the needed widgets and connect them like so
        #self.frame_main = self.builder.get_object("frame_main")
        # self.lbl_text = self.builder.get_object("lbl_text")
        # self.lbl_pin_value = self.builder.get_object("lbl_pin_value")

        # Oh there is a button we will connect the pressed event to our own handler
        # self.btn_set_text_to_label = self.builder.get_object("btn_set_text_to_label")
        # self.btn_set_text_to_label.connect("pressed", self._btn_set_text_to_label_pressed)

        # and this one to the clicked event
        #self.btn_hide = self.builder.get_object("btn_hide")
        #self.btn_hide.connect("clicked", self._btn_hide_clicked)

        

# OK here comes our handlers to react to the hal pin changes
  
    # def _on_btn_select_rh_toggled(self, Widget):

    def _btn_1_clicked(self, Widget):
        self.gear_state = 1
        self.ini.save_state(self)
        self.halcomp["selected-gear"] = 1
    
    def _btn_2_clicked(self, Widget):
        self.gear_state = 2
        self.halcomp["selected-gear"] = 2
    
    def _btn_3_clicked(self, Widget):
        self.gear_state = 3
        self.halcomp["selected-gear"] = 3
    
    def _btn_4_clicked(self, Widget):
        self.gear_state = 4
        self.halcomp["selected-gear"] = 4

    def _btn_5_clicked(self, Widget):
        self.gear_state = 5
        self.halcomp["selected-gear"] = 5
    
    def _btn_6_clicked(self, Widget):
        self.gear_state = 6
        self.halcomp["selected-gear"] = 6
        

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

    def on_frame_main_destroy(self, object, data = None):
        self.ini.save_state(self)
        print("State saved on exit")

  # This is the main procedure in this case, please take care that the name within the return value
# is exactly the same as the Class Name, (case senstitive)
def get_handlers(halcomp, builder, useropts):
    return(GearSelect(halcomp, builder, useropts))

the error
Traceback (most recent call last):
  File "./gearselect.py", line 130, in _btn_1_clicked
    self.ini.save_state(self)
AttributeError: GearSelect instance has no attribute 'ini'


File Attachment:

File Name: gear_select.glade
File Size:5 KB

Regards
Marius


www.bluearccnc.com

Attachments:

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

More
28 Aug 2014 21:31 - 28 Aug 2014 21:32 #50402 by ArcEye
Hi Marius

You might have to wait for Chris, or someone who actually knows about glade and python :laugh:

In the meanwhile, the only thing that occurs to me is this
self.ini_filename = 'gears'+'.var'
        self.ini = IniFile(self.ini_filename, self.defaults, self.builder)

You are passing a filename which assumes it is in the PWD, since there is no path.

Does that file exist and is it in the directory the python file is running from?

If not, is self.ini actually being created, or just a variable of that name?

regards
Last edit: 28 Aug 2014 21:32 by ArcEye.

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

More
28 Aug 2014 21:34 #50404 by mariusl
I also caught this error further up. I have no idea what it means.
gladevcp: trouble looking for handlers in 'gearselect': iteration over non-sequence
Traceback (most recent call last):
  File "/home/marius/dev/linuxcnc-dev/bin/gladevcp", line 129, in load_handlers
    for object in objlist:
TypeError: iteration over non-sequence

Regards
Marius


www.bluearccnc.com

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

More
28 Aug 2014 21:57 - 28 Aug 2014 21:58 #50408 by ArcEye
Is that because you called your class GearSelect but are invoking gearselect

EMBED_TAB_COMMAND = gladevcp -u gearselect.py -x {XID} gear_select.glade


The text above the handler states that the name must be exact.
  # This is the main procedure in this case, please take care that the name within the return value
# is exactly the same as the Class Name, (case senstitive)
def get_handlers(halcomp, builder, useropts):
    return(GearSelect(halcomp, builder, useropts))
Last edit: 28 Aug 2014 21:58 by ArcEye.

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

More
28 Aug 2014 22:05 - 28 Aug 2014 22:29 #50409 by mariusl
I dont understand. The file name is gearselect.py. It contains the class GearSelect. I thought that the file name is passed.

Ohh the comment refers to the very last statement in the file. This refers to the class return.

Regards
Marius


www.bluearccnc.com

Last edit: 28 Aug 2014 22:29 by mariusl.

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

More
28 Aug 2014 22:15 #50411 by mariusl

You are passing a filename which assumes it is in the PWD, since there is no path.

Does that file exist and is it in the directory the python file is running from?

If not, is self.ini actually being created, or just a variable of that name?


Yes the ini file is created in the path of where the python script resides.

Regards
Marius


www.bluearccnc.com

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

More
28 Aug 2014 23:40 #50417 by ArcEye
OK

Well that has exhausted any knowledge I might have of parseltongue :laugh:

Hope Chris or Norbert can help you

regards

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

More
28 Aug 2014 23:56 #50420 by mariusl
Hey you have a stack more than me. Parceltongue as you say confuses the crap out of me.

Regards
Marius


www.bluearccnc.com

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

More
29 Aug 2014 00:47 #50423 by newbynobi
Hallo Marius,

I just took a very short look on it. I am pretty sure, that the self.defaults = ...
contains the error.

I do remember, when I wrote your plasma stuff I did fall in the same trap and needed long to get out.

May be tomorow I find some time to check it on detail.

Meanwhile, what happen if you do commend out all the ini stuff?

Norbert

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

More
29 Aug 2014 01:08 #50424 by mariusl
Hi Norbert
Yes this thing is driving me crazy.
I have taken everything out the file. This is even another file and still get the error
gladevcp: trouble looking for handlers in 'tc': iteration over non-sequence
Traceback (most recent call last):
  File "/home/marius/dev/linuxcnc-dev/bin/gladevcp", line 129, in load_handlers
    for object in objlist:
TypeError: iteration over non-sequence

Python script
# We will need to import some basic stuff
import hal           # needed to make our own hal pins
import hal_glib      # needed to make our own hal pins and react with handlers
#from gladevcp.persistence import IniFile  # we use this one to save the states of the widgets on shut down and restart
from gladevcp.persistence import widget_defaults
from gladevcp.persistence import select_widgets
from gtk.gtkgl.widget import Widget

class TwinControl:

    # __init__ will set the defaults and get all relevant information, before showing the panel
    def __init__(self, halcomp, builder, useropts):
        self.builder = builder
        self.halcomp = halcomp

        self.defaults = {
      
    }

#        self.ini_filename = 'control' + '.ini'
#        self.ini = IniFile(self.ini_filename, self.defaults, self.builder)
#        self.ini.restore_state(self)

        # lets make our hal pins, to find out what pins you can build, please take a look at
        # http://www.linuxcnc.org/docs/devel/html/hal/halmodule.html#_create_pins_and_parameters
        # This way we are able to handle events here
      
# This is the main procedure in this case, please take care that the name within the return value
# is exactly the same as the Class Name, (case senstitive)
def get_handlers(halcomp, builder, useropts):
    return(TwinControl(halcomp, builder, useropts))

Regards
Marius


www.bluearccnc.com

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

Moderators: HansU
Time to create page: 0.108 seconds
Powered by Kunena Forum