Orange Forum • View topic - Erratic UI behaviour at ows loading

Erratic UI behaviour at ows loading

Report bugs (or imagined bugs).
(Archived/read-only, please use our ticketing system for reporting bugs and their discussion.)
Forum rules
Archived/read-only, please use our ticketing system for reporting bugs and their discussion.

Erratic UI behaviour at ows loading

Postby assela » Fri Feb 22, 2008 20:59

Hi all,

Look at the following code for a simple Orange Widget. I observe the following behavior. (First guess is I have done something wrong..)

--To reproduce--
a. Create a new widget folder and copy the code into a file in it.
b. Run Orange canvas and create two instances of the component.
c. change the lineedit content of each instance to a distinct value (say x1 and x2)
c. Save the 'model' as ows
d. Quit
e. Open orange again and load ows file
--(imagined?) bug--
f. the value in both lineedits would be same!!
g. now click on button (test value), it will show that pickled instances has loaded (myWSComponent.name) correctly. But the UI (lineedit) values are not updated.
h. The moment the values in the lineedit are edited, that edit will be reflected in the myWSComponent.name value (do it and check after that by clicking the button).

--Conclusion--
When OWGUI is given a value in a constituent object, at loading of ows file the communication from value->UI is broken, but UI->value works!!



"""
<name>Default WSS Component</name>
<description>Use this only when there is no specific component available.</description>
<icon>foo.png</icon>
<priority>2000</priority>
"""
from OWWidget import *
from orange import *
import OWGUI

class OWWSComponent(OWWidget):
settingsList = ['myWSComponent']
def __init__(self, parent=None, signalManager=None,_myWSComponent=None):
OWWidget.__init__(self,parent, signalManager, 'WSComponent-generic')

if _myWSComponent==None :
self.myWSComponent=WSComponent("Empty",0)
else:
self.myWSComponent=_myWSComponent
self.loadSettings()

# GUI
self.box = QVGroupBox("", self.controlArea)
self.tmp=OWGUI.lineEdit(self.box,self,"myWSComponent.name")
self.tmp2=OWGUI.button(self.box,self,"test value",callback=self.click)

def click(self):
print self.myWSComponent.name


def process_data(self,data):
pass

class WSComponent:
"""Parent class for all WS compoents"""
def __init__(self, name, dumb):
self.name = name


def __getstate__(self):
print "saving my state : ", self.name
return [self.name]
def __setstate__(self,state):
[self.name]=state
print "loading my state : ", self.name

A work around?

Postby assela » Fri Feb 22, 2008 22:57

If you add the following to the widget class, then things are ok. But is this the intended behavior:

def activateLoadedSettings(self):
#don't know why, but this is necessary to get GUI sync with value object
#after loading ows file.
self.tmp.setText(self.myWSComponent.name)
OWWidget.activateLoadedSettings(self)

Postby Gregor Leban » Mon Feb 25, 2008 14:22

Hi Assela,

the behaviour that you get is not a bug. In the settingsList you specified myWSComponent, which is actually a class instance. If you want to make you widget work as desired, simply change:

settingsList = ['myWSComponent']

into

settingsList = ['myWSComponent.name']

Best,
Gregor


Return to Bugs



cron