python - Gio SimpleAction to call a function -


i have made menu using gio action in gtk3 app. menu item created as:

#in main file menuelem = menu.menumanager # open menu action = gio.simpleaction(name="open") action.connect("activate", menuelem.file_open_clicked) self.add_action(action) 

the file_open_clicked in menu.py, class menumanager, defined as:

import gi import pybib import view gi.require_version("gtk", "3.0") gi.repository import gtk   class menumanager:     def __init__(self):         self.parsing = pybib.parser()         self.treeview = view.treeview()     #file_open_clicked     #in menu.py     def file_open_clicked(self, widget):         dialog = gtk.filechooserdialog("open existing fine", none,                                        gtk.filechooseraction.open,                                        (gtk.stock_cancel,                                         gtk.responsetype.cancel,                                         gtk.stock_open, gtk.responsetype.ok))         response = dialog.run()         if response == gtk.responsetype.ok:             filename = dialog.get_filename()             dialog.destroy()             self.treeview.bookstore.clear()             self.treeview.viewer(self.parsing.booklist)             # self.treeview.view.set_model()         elif response == gtk.responsetype.cancel:             print("cancel clicked")             dialog.destroy() 

i getting error:

traceback (most recent call last):   file "/home/rudra/devel/mkbib/python/src/menu.py", line 81, in file_open_clicked     self.treeview.bookstore.clear() attributeerror: 'simpleaction' object has no attribute 'treeview' 

i know simpleaction takes 1 more option, , treeview should called. dont know how. kindly help

let me break down code you.

#in main file menuelem = menu.menumanager 

here set menuelem point menu.menumanager class. meant initialize object here such menuelem become instance of menu.menumanagerclass. such __init__ function of menumanager class called. code should be:

#in main file menuelem = menu.menumanager() 

then next part goes wrong in here:

def file_open_clicked(self, widget): 

if check docs activate signal see has 2 parameters. without initializing object self set first parameter namely simpleaction , widget set activation parameter.

but have initialized menumanager object, file_open_clicked function 3 input parameters namely self, simpleaction , parameter. need accept them this:

def file_open_clicked(self, simpleaction, parameter): 

now code work self object attribute treeview. (just information in python variables , attributes written in lowercase)


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -