On 8 avr, 06:56, stefan <
stefan.reinsb...@gmail.com> wrote:
> When I try this, it works and I do get calls to func1 and func2 when
> the value changes.
>
> However, it seems to me a bit awkward although my lack of
> understanding of python could be a problem:
> As I understand this, func1 is a function outside of class Example and
> also not at all connected to the DataSetEditGroupBox that makes use of
> it. How would one communicate with the ImageDialog object that this
> parameter set is a part of? I'm trying to update the image display as
> a function of an integer input (similar to simple_dialog.py) but I
> would rather just input the number or, even better, just use a
> slider...
Actually you have a lot of options to implement this link between the
DataSet instance and the ImageDialog instance.
Let's say you have a class named MainWindow deriving from QMainWindow
and containing an ImageDialog instance and other widgets, like this
for example:
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.imagedialog = None
self.widget1 = None
self.widget2 = None
self.setup_layout()
def setup_layout(self):
# setup your mainwindow's layout: constructing widgets,
setting the central widget, ...
pass
Examples:
(1) define a custom DataSet class with an attribute keeping a
reference to MainWindow object (to do this properly, you have to
override the DataSet constructor and implement your own, see below)
class MyDataSet(DataSet):
def __init__(self, title=None, comment=None, icon=''):
super(MyDataSet, self).__init__(title, comment, icon)
self.mainwindow = None
def set_mainwindow(self, mainwindow):
self.mainwindow = mainwindow
# then define your data items as usual:
x = FloatItem("foobar")
First create the DataSet, and then bind it to your main window
instance:
param = MyDataSet()
param.set_mainwindow(mainwindow) # or param.set_mainwindow(self) if
you are in one of the main window methods
Then your callback will be able to do things with your mainwindow
object: you may for example implement another method in your MyDataSet
class to specify actions to do with the mainwindow object.
(2) define a standard DataSet class but within a method of MainWindow:
class MainWindow(QMainWindow):
...
def some_method(self):
class MyDataSet(DataSet):
x = FloatItem("foobar")
# then, your callback functions may be methods of the
mainwindow objects, so they will have access to this object
HTH,
Pierre