gtk ComboBoxEntry.get_child() returns none - python

I have a problem with the gtk ComboBoxEntry. My program crashes when I try to change the text in the combobox. I use this code:
gui.combo_txt_script.get_child().set_text(fshort)
It crashes with the error:
AttributeError: 'NoneType' object has no attribute 'set_text'
The results of the following prints:
print "combo:",gui.combo_txt_script
print "entry:",gui.combo_txt_script.get_child()
is
combo: <gtk.ComboBoxEntry object at ... >
entry: None

UPDATED
The get and set current value of Gtk.ComboBox objects is related to model attribute of these objects and you can set and/or get items similar below code:
model = combo.get_model()
value = model[combo.get_activate()][0]
# first index refers to row of list
# second index refers to cell in the row. by default an combo/combo-entry have one cell
combo.set_activate(list(model).index(value))

I found the problem. The program I use has different user levels. Every tab and thus every widget is not visible for every user level. Somehow, it happened that the user level could change by itself, which made the combo non existent.

Related

QlineEdit and Findchild() in python

When the following line of codes executes in Python QT it creates a new object and puts it over the original object (Yellow area in the picture).
for (section_name,section_object) in self.settings.items():
for (setting, value) in self.settings.items(section_name):
target = self.tabWidget.findChild(QLineEdit,setting)
if(isinstance(target,QLineEdit)):
obj = QLineEdit(target)
obj.setText(self.settings.get(section_name,setting))
Wrong state
If I do this instead the same above happens
for (section_name,section_object) in self.settings.items():
for (setting, value) in self.settings.items(section_name):
target = self.tabWidget.findChild(QLineEdit,setting)
if(isinstance(target,QLineEdit)):
QLineEdit(target).setText(self.settings.get(section_name,setting))
When the expected outcome would be something like this where object is set directly and no new object gets created
Correct state
Could someone help my identify where the problem is or is it even possible to do so.

python checkbutton appearance does not update after setting to 1

I have a class with a member self.checkbutton (using the TkInter CheckButton), created in the init function with:
self.checkbutton = Checkbutton(self.frame, variable=self.value, command=self.get_entry_and_execute, onvalue="1", offvalue="0")
Now, instead of clicking on the checkbutton in my frame, I want to set it in my code. So, from somewhere in my code, I call setvalue("1") calling this function:
def setvalue(self, value):
if (value == "1"):
print "SELECTING CHECKBUTTON"
self.checkbutton.select()
# self.checkbutton.set(value=1)
Now, when I do this, actually, I can see that the associated "self.get_entry_and_execute" function is called and it even changes some background color. But, the checkbutton remains unchecked (i.e. an empty field without the "V" symbol).
Weirly, when I add the command
self.checkbutton.set(value=1)
, the code complains: AttributeError: Checkbutton instance has no attribute 'set'
but now the checkbutton does get checked!
I am assuming that because of this error, python puts the checkbutton in the correct state (=1) even though the "set" function does not exist. My question is: how can I correctly make python put the "V" inside the checkbutton box? (I.e, something like a "redraw" function).
According to your code, self.value is an instance of a variable class, so all what you need to do is to replace self.checkbutton.set(value=1) by self.value.set(value=1)

GtkComboBox invoking a warning about get_active_iter?

I have a GtkComboBox's changed signal connected to the following function:
def changeCombo(self, widget):
selected = self.ui['comboBox'].get_active_iter()
...
This sort-of-works. However, when the combo's associated model -- a ListStore -- is emptied (and rebuilt), I get this error when the function is invoked:
AttributeError: 'gtk.TreeView' object has no attribute 'get_active_iter'
Thereafter, the code destabilises and stops working properly. (If you select a valid entry, before getting this warning, it works fine.)
What's going on here? I realise the combobox is probably implemented as a TreeView by GTK, but get_active_iter is definitely a member of ComboBox... Does this error imply that the availability of this function is contingent on the model containing items? The documentation, however, implies that a combobox without a selection (or an empty model) should return None for get_active_iter.

Getting attributeError: type object 'Level_2_Headings' has no attribute 'ancestor' (GAE datastore)

I'm using GAE, Datastore, Python 2.7 and am creating/updating entries in the datastore using ancestors for the first time. Here I'm trying to see if there are any entries/rows in Level_2_Headings datastore and if there are not, then creating a new one. If one does exist, updating the description. I'm getting this error -- the datastore for Level_2_Headings is empty so it should be bringing back empty so that I can add the new entry, but instead, I get an error in the query for the q2 object where I use the ancestor attribute - any ideas on why this would be when I'm expecting just an empty object to be returned since it doesn't exist in the datastore??? Help is appreciated as usual.
if q:
q2 = Level_2_Headings.ancestor(q.key()).filter("name2 =",heading2).get()
if q2:
q2.description2 = description2
q2.put()
else:
#new level 2 being added to ds
new_2 = Level_2_Headings(parent=q2, name2=name2, description2=description2, heading_type=heading_type)
new_2.put()
message="Added NEW category entry to level 2"
You are referencing the Level_2_Heading model directly, without calling all() to retrieve the records. Level_2_Headings.all() will return an object that has the ancestor attribute, so try changing your first q2 to:
q2 = Level_2_Headings.all().ancestor(q.key()).filter("name2 =",heading2).get()

return value from listWidget in pyqt4

Whenever I attempt to store the selected value from a listWidget using
foo=self.listWidget.currentItem()
this is what I get as a value for foo:
<PyQt4.QtGui.QListWidgetItem object at 0x023BDD68>
This sort of makes sense, but is clearly not what I was asking it for. I'm aware of round about ways to get the actual item selected but is there not some one line method for doing this, like there is for every other input widget?
From the PyQt4 QListWidgetItem docs, you could use:
item = self.listWidget.currentItem()
value = item.text()
Or on one line:
value = self.listWidget.currentItem().text()

Categories

Resources