Brian Clowers
2012-12-18 21:09:14 UTC
First thank you for both spyder and guidata. I find them quite useful and
am trying to expand to a more complex application and am running into a
problem when I embed the datasets into a gui. Specifically, it seems
overly complex to have to click on each apply button to register changes to
the dataset. Granted there is the following thread
(https://groups.google.com/d/topic/guidata_guiqwt/9qk0TPGLMzk/discussion),
however, it is still not clear how to make sure the dataset is updated
using an external button.
I've attached an example in which there are a few parameters that I would
like to change and then move straight to the processing button. You'll
that the following example allows me to connect the button clicks to
events, however, I cannot seem to find a way to accept all changes to a
dataset without explicitly clicking on the "Apply" button. Am I emitting
the wrong SIGNAL?
Any help would be appreciated.
Cheers,
Brian
################
# -*- coding: utf-8 -*-
import os
import tempfile, atexit, shutil
import numpy as np
from guidata.dataset.datatypes import (DataSet, BeginTabGroup, EndTabGroup,
BeginGroup, EndGroup, ObjectItem)
from guidata.dataset.dataitems import (FloatItem, IntItem, BoolItem,
ChoiceItem,
MultipleChoiceItem, ImageChoiceItem,
FilesOpenItem,
StringItem, TextItem, ColorItem, FileSaveItem,
FileOpenItem, DirectoryItem, FloatArrayItem,
ButtonItem)
from guidata.configtools import get_icon
from guidata.qthelpers import create_action, add_actions, get_std_icon
from guidata.qt.QtGui import QMainWindow, QSplitter, QPushButton,
QGridLayout, QGroupBox
from guidata.qt.QtCore import SIGNAL, Qt
from guidata.dataset.qtwidgets import DataSetEditLayout, DataSetShowLayout,
DataSetShowGroupBox, DataSetEditGroupBox
from guidata.dataset.qtitemwidgets import DataSetWidget
def dummyCall(a = None, b = None, c = None, d = None):
print ""
#~ print a
#~ print b
#~ print c
#~ print d
class ProcessParams(DataSet):
'''
Note that the None for the callback MUST be replaced or ignored
'''
#This is position 1
floatArray = FloatArrayItem("Float array", default=np.ones( (5,5),
float),
format=" %.2e ").set_pos(col=0)
#This is position 2
processButton = ButtonItem("Process Data", dummyCall).set_pos(col = 1,
colspan = 1)
btnPos = 2
def __init__(self, title=None, comment=None, icon=''):
super(ProcessParams, self).__init__(title, comment, icon)
self.mainWindow = None
def setMainWindow(self, mainWindow):
self.mainWindow = mainWindow
class ExperimentParams(DataSet):
'''
Experimental Parameters
'''
analyteID = StringItem("Analyte ID", "Biotin").set_pos(col=0, colspan =
1)
analyteConc = FloatItem("Analyte Concentration (ppm)", default = 10.0,
min = 0.000005, max = 100000, step = 0.5).set_pos(col=1, colspan = 1)
humidity = FloatItem("Humidity (ppm)", default = 100.0, min = 1, max =
10000, step = 0.5).set_pos(col=0, colspan = 1)
waterBool = BoolItem("Water Spike?").set_pos(col=1, colspan=1)
def __init__(self, title=None, comment=None, icon=''):
super(ExperimentParams, self).__init__(title, comment, icon)
self.mainWindow = None
def setMainWindow(self, mainWindow):
self.mainWindow = mainWindow
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.setWindowIcon(get_icon('python.png'))
self.setWindowTitle("Application example")
# Instantiate dataset-related widgets:
self.expBox = DataSetEditGroupBox("Experimental Parameters",
ExperimentParams, comment='')
self.expBox.dataset.setMainWindow(self)#link to MainWindow instance
self.processingBox = DataSetEditGroupBox("Processing Parameters",
ProcessParams, comment =
'')
self.processingBox.dataset.setMainWindow(self)#link to MainWindow
instance
self.groupList = []
self.groupList.append(self.expBox)
self.groupList.append(self.processingBox)
btnPos = self.processingBox.dataset.btnPos
self.processBtn = self.processingBox.children()[btnPos]
self.connect(self.processBtn, SIGNAL('clicked()'),
self.processingCallback)
vsplitter = QSplitter(Qt.Vertical, self)
vsplitter.addWidget(self.expBox)
vsplitter.addWidget(self.processingBox)
self.setCentralWidget(vsplitter)
self.setContentsMargins(10, 5, 10, 5)
self.connect(self.expBox, SIGNAL("apply_button_clicked()"),
self.updateExperimentBox)
def emitApply(self):
self.processingBox.emit(SIGNAL("apply_button_clicked()"))#This
updates the variables (you hope)
self.expBox.emit(SIGNAL("apply_button_clicked()"))
def updateExperimentBox(self, extra = None):
print "Exp Box Apply Clicked"
print self.expBox.dataset
def processingCallback(self):
print ""
print "Callback"
print self.emitApply()
print self.expBox.dataset
#~ print self.processingBox.dataset
if __name__ == "__main__":
from guidata.qt.QtGui import QApplication
import sys
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())
am trying to expand to a more complex application and am running into a
problem when I embed the datasets into a gui. Specifically, it seems
overly complex to have to click on each apply button to register changes to
the dataset. Granted there is the following thread
(https://groups.google.com/d/topic/guidata_guiqwt/9qk0TPGLMzk/discussion),
however, it is still not clear how to make sure the dataset is updated
using an external button.
I've attached an example in which there are a few parameters that I would
like to change and then move straight to the processing button. You'll
that the following example allows me to connect the button clicks to
events, however, I cannot seem to find a way to accept all changes to a
dataset without explicitly clicking on the "Apply" button. Am I emitting
the wrong SIGNAL?
Any help would be appreciated.
Cheers,
Brian
################
# -*- coding: utf-8 -*-
import os
import tempfile, atexit, shutil
import numpy as np
from guidata.dataset.datatypes import (DataSet, BeginTabGroup, EndTabGroup,
BeginGroup, EndGroup, ObjectItem)
from guidata.dataset.dataitems import (FloatItem, IntItem, BoolItem,
ChoiceItem,
MultipleChoiceItem, ImageChoiceItem,
FilesOpenItem,
StringItem, TextItem, ColorItem, FileSaveItem,
FileOpenItem, DirectoryItem, FloatArrayItem,
ButtonItem)
from guidata.configtools import get_icon
from guidata.qthelpers import create_action, add_actions, get_std_icon
from guidata.qt.QtGui import QMainWindow, QSplitter, QPushButton,
QGridLayout, QGroupBox
from guidata.qt.QtCore import SIGNAL, Qt
from guidata.dataset.qtwidgets import DataSetEditLayout, DataSetShowLayout,
DataSetShowGroupBox, DataSetEditGroupBox
from guidata.dataset.qtitemwidgets import DataSetWidget
def dummyCall(a = None, b = None, c = None, d = None):
print ""
#~ print a
#~ print b
#~ print c
#~ print d
class ProcessParams(DataSet):
'''
Note that the None for the callback MUST be replaced or ignored
'''
#This is position 1
floatArray = FloatArrayItem("Float array", default=np.ones( (5,5),
float),
format=" %.2e ").set_pos(col=0)
#This is position 2
processButton = ButtonItem("Process Data", dummyCall).set_pos(col = 1,
colspan = 1)
btnPos = 2
def __init__(self, title=None, comment=None, icon=''):
super(ProcessParams, self).__init__(title, comment, icon)
self.mainWindow = None
def setMainWindow(self, mainWindow):
self.mainWindow = mainWindow
class ExperimentParams(DataSet):
'''
Experimental Parameters
'''
analyteID = StringItem("Analyte ID", "Biotin").set_pos(col=0, colspan =
1)
analyteConc = FloatItem("Analyte Concentration (ppm)", default = 10.0,
min = 0.000005, max = 100000, step = 0.5).set_pos(col=1, colspan = 1)
humidity = FloatItem("Humidity (ppm)", default = 100.0, min = 1, max =
10000, step = 0.5).set_pos(col=0, colspan = 1)
waterBool = BoolItem("Water Spike?").set_pos(col=1, colspan=1)
def __init__(self, title=None, comment=None, icon=''):
super(ExperimentParams, self).__init__(title, comment, icon)
self.mainWindow = None
def setMainWindow(self, mainWindow):
self.mainWindow = mainWindow
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.setWindowIcon(get_icon('python.png'))
self.setWindowTitle("Application example")
# Instantiate dataset-related widgets:
self.expBox = DataSetEditGroupBox("Experimental Parameters",
ExperimentParams, comment='')
self.expBox.dataset.setMainWindow(self)#link to MainWindow instance
self.processingBox = DataSetEditGroupBox("Processing Parameters",
ProcessParams, comment =
'')
self.processingBox.dataset.setMainWindow(self)#link to MainWindow
instance
self.groupList = []
self.groupList.append(self.expBox)
self.groupList.append(self.processingBox)
btnPos = self.processingBox.dataset.btnPos
self.processBtn = self.processingBox.children()[btnPos]
self.connect(self.processBtn, SIGNAL('clicked()'),
self.processingCallback)
vsplitter = QSplitter(Qt.Vertical, self)
vsplitter.addWidget(self.expBox)
vsplitter.addWidget(self.processingBox)
self.setCentralWidget(vsplitter)
self.setContentsMargins(10, 5, 10, 5)
self.connect(self.expBox, SIGNAL("apply_button_clicked()"),
self.updateExperimentBox)
def emitApply(self):
self.processingBox.emit(SIGNAL("apply_button_clicked()"))#This
updates the variables (you hope)
self.expBox.emit(SIGNAL("apply_button_clicked()"))
def updateExperimentBox(self, extra = None):
print "Exp Box Apply Clicked"
print self.expBox.dataset
def processingCallback(self):
print ""
print "Callback"
print self.emitApply()
print self.expBox.dataset
#~ print self.processingBox.dataset
if __name__ == "__main__":
from guidata.qt.QtGui import QApplication
import sys
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())