def createIconGroupBox(self): """ dummy icongroupbox (to be removed from here -- reference only) """ icons = { 'disconnected': ':/images/conn_error.png', 'connecting': ':/images/conn_connecting.png', 'connected': ':/images/conn_connected.png' } con_widgets = { 'disconnected': QLabel(), 'connecting': QLabel(), 'connected': QLabel(), } con_widgets['disconnected'].setPixmap( QPixmap(icons['disconnected'])) con_widgets['connecting'].setPixmap( QPixmap(icons['connecting'])) con_widgets['connected'].setPixmap( QPixmap(icons['connected'])), self.ConnectionWidgets = con_widgets con_icons = { 'disconnected': QIcon(icons['disconnected']), 'connecting': QIcon(icons['connecting']), 'connected': QIcon(icons['connected']) } self.Icons = con_icons self.statusIconBox = QGroupBox("Connection Status") statusIconLayout = QHBoxLayout() statusIconLayout.addWidget(self.ConnectionWidgets['disconnected']) statusIconLayout.addWidget(self.ConnectionWidgets['connecting']) statusIconLayout.addWidget(self.ConnectionWidgets['connected']) statusIconLayout.itemAt(1).widget().hide() statusIconLayout.itemAt(2).widget().hide() self.statusIconBox.setLayout(statusIconLayout)
class ParameterContainer(QWidget, object): """Container to hold Parameter Widgets.""" def __init__( self, parameters=None, description_text='', extra_parameters=None, parent=None, vertical=True): """Constructor .. versionadded:: 2.2 :param parameters: List of Parameter Widget :type parameters: list :param description_text: Text for description of the parameter container. :type description_text: str """ QWidget.__init__(self, parent) # attributes if not parameters: self.parameters = [] else: self.parameters = parameters self.description_text = description_text self.extra_parameters = extra_parameters self.parent = parent self.validators = [] self.validators_kwargs = [] # UI if vertical: self.vertical_layout = QVBoxLayout() else: self.vertical_layout = QHBoxLayout() self.widget = QWidget() self.description_label = QLabel() self.description_label.setWordWrap(True) self.scroll_area = QScrollArea() self.group_frame = QFrame() self.qt4_parameter_factory = Qt4ParameterFactory() self.main_layout = QGridLayout() # NOTES(IS) : These functions are commented since the architecture is not # ready yet. # def register_widget(self, parameter, parameter_widget): # """Register new custom widget. # # :param parameter: # :type parameter: GenericParameter # # :param parameter_widget: # :type parameter_widget: GenericParameterWidget # """ # self.qt4_parameter_factory.register_widget( # parameter, parameter_widget) # # def remove_widget(self, parameter): # """Register new custom widget. # # :param parameter: # :type parameter: GenericParameter # """ # if parameter.__name__ in self.dict_widget.keys(): # self.dict_widget.pop(parameter.__name__) def get_parameters(self, validate=True): """Return list of parameters from the current state of widget. :param validate: If true, run validator, else no. :type validate: bool :returns: List of parameter :rtype: list """ if validate: validation_result = self.validate() if not validation_result['valid']: raise InvalidValidationException(validation_result['message']) parameter_widgets = self.get_parameter_widgets() parameters = [] for widget_item in parameter_widgets: parameter_widget = widget_item.widget() parameter = parameter_widget.get_parameter() parameters.append(parameter) # returns based on the object type of self.parameters if isinstance(self.parameters, list): return parameters else: # just return single parameter return parameters[0] def get_parameter_widgets(self): """Return list of parameter widgets from the current state of widget. :returns: List of parameter widget :rtype: list """ parameter_widgets = [self.vertical_layout.itemAt(i) for i in range( self.vertical_layout.count())] return parameter_widgets def setup_ui(self, must_scroll=True): """Setup the UI of this parameter container. """ # Vertical layout to place the parameter widgets self.vertical_layout.setContentsMargins(0, 0, 0, 0) self.vertical_layout.setSpacing(0) # Widget to hold the vertical layout self.widget = QWidget() self.widget.setLayout(self.vertical_layout) # Label for description self.description_label.setText(self.description_text) self.group_frame.setLineWidth(0) self.group_frame.setFrameStyle(QFrame.NoFrame) vlayout = QVBoxLayout() vlayout.setContentsMargins(0, 0, 0, 0) vlayout.setSpacing(0) self.group_frame.setLayout(vlayout) if must_scroll: vlayout.addWidget(self.scroll_area) self.scroll_area.setWidgetResizable(True) self.scroll_area.setWidget(self.widget) else: vlayout.addWidget(self.widget) # Main layout of the container if self.description_text: self.main_layout.addWidget(self.description_label) self.main_layout.setContentsMargins(0, 0, 0, 0) self.setLayout(self.main_layout) self.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.MinimumExpanding) if not isinstance(self.parameters, list): parameters = [self.parameters] else: parameters = self.parameters if len(parameters) == 0: self.set_empty_parameters() return self.main_layout.addWidget(self.group_frame) self.qt4_parameter_factory = Qt4ParameterFactory() if self.extra_parameters is not None: for extra_parameter in self.extra_parameters: if (type(extra_parameter) == tuple and len(extra_parameter) == 2): self.qt4_parameter_factory.register_widget( extra_parameter[0], extra_parameter[1]) color_odd = QColor(220, 220, 220) color_even = QColor(192, 192, 192) i = 0 for parameter in parameters: parameter_widget = self.qt4_parameter_factory.get_widget(parameter) if i % 2: color = color_even else: color = color_odd i += 1 parameter_widget.setAutoFillBackground(True) # palette = parameter_widget.palette() # palette.setColor(parameter_widget.backgroundRole(), color) # parameter_widget.setPalette(palette) self.vertical_layout.addWidget(parameter_widget) self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) def set_description(self, description): """Set description of the parameter container. :param description: A new description fot the parameter container. :type description: str """ self.description_text = description self.description_label.setText(self.description_text) def set_empty_parameters(self): """Update UI if there is no parameters in the container. """ new_description = self.description_text new_description += '\n' new_description += 'But, currently there is no parameters available.' self.description_label.setText(new_description) def add_validator(self, validator, **kwargs): """Add validator for this parameter container. :param validator: validator function for this parameter container. :type validator: function """ validator.parent = self self.validators.append(validator) if kwargs: self.validators_kwargs.append(kwargs) else: self.validators_kwargs.append({}) def validate(self): """Validate of all rule for all parameter in this container. :return: True if all valid, False :rtype: dict """ for i in range(len(self.validators)): validator = self.validators[i] validator_kwargs = self.validators_kwargs[i] validation_result = validator(self, **validator_kwargs) if not validation_result['valid']: return validation_result return { 'valid': True, 'message': '' } def get_parameter_by_guid(self, parameter_guid): """Return a parameter based on its uuid :param parameter_guid: The parameter uuid :type parameter_guid: str :returns: The parameter or None if not exist :rtype: GenericParameter, None """ parameters = self.get_parameters(validate=False) for parameter in parameters: if parameter.guid == parameter_guid: return parameter return None def get_parameter_widget_by_guid(self, parameter_guid): """Return a parameter widget based on its uuid :param parameter_guid: The parameter uuid :type parameter_guid: str :returns: The parameter widget or None if not exist :rtype: GenericParameterWidget, None """ parameter_widgets = self.get_parameter_widgets() for parameter_widget in parameter_widgets: if (parameter_widget.widget().get_parameter().guid == parameter_guid): return parameter_widget.widget() return None
class ParameterContainer(QWidget, object): """Container to hold Parameter Widgets.""" def __init__(self, parameters=None, description_text='', extra_parameters=None, parent=None, vertical=True): """Constructor .. versionadded:: 2.2 :param parameters: List of Parameter Widget :type parameters: list :param description_text: Text for description of the parameter container. :type description_text: str """ QWidget.__init__(self, parent) # attributes if not parameters: self.parameters = [] else: self.parameters = parameters self.description_text = description_text self.extra_parameters = extra_parameters self.parent = parent self.validators = [] self.validators_kwargs = [] # UI if vertical: self.vertical_layout = QVBoxLayout() else: self.vertical_layout = QHBoxLayout() self.widget = QWidget() self.description_label = QLabel() self.description_label.setWordWrap(True) self.scroll_area = QScrollArea() self.group_frame = QFrame() self.qt4_parameter_factory = Qt4ParameterFactory() self.main_layout = QGridLayout() # NOTES(IS) : These functions are commented since the architecture is not # ready yet. # def register_widget(self, parameter, parameter_widget): # """Register new custom widget. # # :param parameter: # :type parameter: GenericParameter # # :param parameter_widget: # :type parameter_widget: GenericParameterWidget # """ # self.qt4_parameter_factory.register_widget( # parameter, parameter_widget) # # def remove_widget(self, parameter): # """Register new custom widget. # # :param parameter: # :type parameter: GenericParameter # """ # if parameter.__name__ in self.dict_widget.keys(): # self.dict_widget.pop(parameter.__name__) def get_parameters(self, validate=True): """Return list of parameters from the current state of widget. :param validate: If true, run validator, else no. :type validate: bool :returns: List of parameter :rtype: list """ if validate: validation_result = self.validate() if not validation_result['valid']: raise InvalidValidationException(validation_result['message']) parameter_widgets = self.get_parameter_widgets() parameters = [] for widget_item in parameter_widgets: parameter_widget = widget_item.widget() parameter = parameter_widget.get_parameter() parameters.append(parameter) # returns based on the object type of self.parameters if isinstance(self.parameters, list): return parameters else: # just return single parameter return parameters[0] def get_parameter_widgets(self): """Return list of parameter widgets from the current state of widget. :returns: List of parameter widget :rtype: list """ parameter_widgets = [ self.vertical_layout.itemAt(i) for i in range(self.vertical_layout.count()) ] return parameter_widgets def setup_ui(self, must_scroll=True): """Setup the UI of this parameter container. """ # Vertical layout to place the parameter widgets self.vertical_layout.setContentsMargins(0, 0, 0, 0) self.vertical_layout.setSpacing(0) # Widget to hold the vertical layout self.widget = QWidget() self.widget.setLayout(self.vertical_layout) # Label for description self.description_label.setText(self.description_text) self.group_frame.setLineWidth(0) self.group_frame.setFrameStyle(QFrame.NoFrame) vlayout = QVBoxLayout() vlayout.setContentsMargins(0, 0, 0, 0) vlayout.setSpacing(0) self.group_frame.setLayout(vlayout) if must_scroll: vlayout.addWidget(self.scroll_area) self.scroll_area.setWidgetResizable(True) self.scroll_area.setWidget(self.widget) else: vlayout.addWidget(self.widget) # Main layout of the container if self.description_text: self.main_layout.addWidget(self.description_label) self.main_layout.setContentsMargins(0, 0, 0, 0) self.setLayout(self.main_layout) self.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.MinimumExpanding) if not isinstance(self.parameters, list): parameters = [self.parameters] else: parameters = self.parameters if len(parameters) == 0: self.set_empty_parameters() return self.main_layout.addWidget(self.group_frame) self.qt4_parameter_factory = Qt4ParameterFactory() if self.extra_parameters is not None: for extra_parameter in self.extra_parameters: if (type(extra_parameter) == tuple and len(extra_parameter) == 2): self.qt4_parameter_factory.register_widget( extra_parameter[0], extra_parameter[1]) color_odd = QColor(220, 220, 220) color_even = QColor(192, 192, 192) i = 0 for parameter in parameters: parameter_widget = self.qt4_parameter_factory.get_widget(parameter) if i % 2: color = color_even else: color = color_odd i += 1 parameter_widget.setAutoFillBackground(True) # palette = parameter_widget.palette() # palette.setColor(parameter_widget.backgroundRole(), color) # parameter_widget.setPalette(palette) self.vertical_layout.addWidget(parameter_widget) self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) def set_description(self, description): """Set description of the parameter container. :param description: A new description fot the parameter container. :type description: str """ self.description_text = description self.description_label.setText(self.description_text) def set_empty_parameters(self): """Update UI if there is no parameters in the container. """ new_description = self.description_text new_description += '\n' new_description += 'But, currently there is no parameters available.' self.description_label.setText(new_description) def add_validator(self, validator, **kwargs): """Add validator for this parameter container. :param validator: validator function for this parameter container. :type validator: function """ validator.parent = self self.validators.append(validator) if kwargs: self.validators_kwargs.append(kwargs) else: self.validators_kwargs.append({}) def validate(self): """Validate of all rule for all parameter in this container. :return: True if all valid, False :rtype: dict """ for i in range(len(self.validators)): validator = self.validators[i] validator_kwargs = self.validators_kwargs[i] validation_result = validator(self, **validator_kwargs) if not validation_result['valid']: return validation_result return {'valid': True, 'message': ''} def get_parameter_by_guid(self, parameter_guid): """Return a parameter based on its uuid :param parameter_guid: The parameter uuid :type parameter_guid: str :returns: The parameter or None if not exist :rtype: GenericParameter, None """ parameters = self.get_parameters(validate=False) for parameter in parameters: if parameter.guid == parameter_guid: return parameter return None def get_parameter_widget_by_guid(self, parameter_guid): """Return a parameter widget based on its uuid :param parameter_guid: The parameter uuid :type parameter_guid: str :returns: The parameter widget or None if not exist :rtype: GenericParameterWidget, None """ parameter_widgets = self.get_parameter_widgets() for parameter_widget in parameter_widgets: if (parameter_widget.widget().get_parameter().guid == parameter_guid): return parameter_widget.widget() return None
class TaskGeneratorDialog(QDialog): def __init__(self, nbprocessors): QDialog.__init__(self) self.layout = QVBoxLayout(self) self.taskset = None # Utilizations: vbox_utilizations = QVBoxLayout() group = QGroupBox("Task Utilizations:") hbox = QHBoxLayout() hbox.addWidget(QLabel("Generator:", self)) self.comboGenerator = QComboBox() self.comboGenerator.addItem("RandFixedSum") self.comboGenerator.addItem("UUniFast-Discard") self.comboGenerator.addItem("Kato's method") self.comboGenerator.currentIndexChanged.connect(self.generator_changed) hbox.addWidget(self.comboGenerator) vbox_utilizations.addLayout(hbox) # Load slider + spinner: hbox_load = QHBoxLayout() sld = _DoubleSlider(QtCore.Qt.Horizontal, self) sld.setMinimum(0) sld.setMaximum(32) self.spin_load = QDoubleSpinBox(self) self.spin_load.setMinimum(0) self.spin_load.setMaximum(32) self.spin_load.setSingleStep(0.1) hbox_load.addWidget(QLabel("Total utilization: ", self)) hbox_load.addWidget(sld) hbox_load.addWidget(self.spin_load) sld.doubleValueChanged.connect(self.spin_load.setValue) self.spin_load.valueChanged.connect(sld.setValue) self.spin_load.setValue(nbprocessors / 2.) vbox_utilizations.addLayout(hbox_load) # Number of periodic tasks: self.hbox_tasks = QHBoxLayout() self.spin_tasks = QSpinBox(self) self.spin_tasks.setMinimum(0) self.spin_tasks.setMaximum(999) # That's arbitrary. self.hbox_tasks.addWidget(QLabel("Number of periodic tasks: ", self)) self.hbox_tasks.addStretch(1) self.hbox_tasks.addWidget(self.spin_tasks) vbox_utilizations.addLayout(self.hbox_tasks) # Number of sporadic tasks: self.hbox_sporadic_tasks = QHBoxLayout() self.spin_sporadic_tasks = QSpinBox(self) self.spin_sporadic_tasks.setMinimum(0) self.spin_sporadic_tasks.setMaximum(999) # That's arbitrary. self.hbox_sporadic_tasks.addWidget( QLabel("Number of sporadic tasks: ", self)) self.hbox_sporadic_tasks.addStretch(1) self.hbox_sporadic_tasks.addWidget(self.spin_sporadic_tasks) vbox_utilizations.addLayout(self.hbox_sporadic_tasks) # Min / Max utilizations self.hbox_utilizations = QHBoxLayout() self.hbox_utilizations.addWidget(QLabel("Min/Max utilizations: ", self)) self.interval_utilization = IntervalSpinner(self, min_=0, max_=1, step=.01, round_option=False) self.hbox_utilizations.addWidget(self.interval_utilization) vbox_utilizations.addLayout(self.hbox_utilizations) group.setLayout(vbox_utilizations) self.layout.addWidget(group) # Periods: vbox_periods = QVBoxLayout() group = QGroupBox("Task Periods:") # Log uniform self.lunif = QRadioButton("log-uniform distribution between:") vbox_periods.addWidget(self.lunif) self.lunif.setChecked(True) self.lunif_interval = IntervalSpinner(self) self.lunif_interval.setEnabled(self.lunif.isChecked()) self.lunif.toggled.connect(self.lunif_interval.setEnabled) vbox_periods.addWidget(self.lunif_interval) # Uniform self.unif = QRadioButton("uniform distribution between:") vbox_periods.addWidget(self.unif) self.unif_interval = IntervalSpinner(self) self.unif_interval.setEnabled(self.unif.isChecked()) self.unif.toggled.connect(self.unif_interval.setEnabled) vbox_periods.addWidget(self.unif_interval) # Discrete discrete = QRadioButton("chosen among these (space separated) values:") vbox_periods.addWidget(discrete) self.periods = QLineEdit(self) self.periods.setValidator( QRegExpValidator(QRegExp("^\\d*(\.\\d*)?( \\d*(\.\\d*)?)*$"))) vbox_periods.addWidget(self.periods) self.periods.setEnabled(discrete.isChecked()) discrete.toggled.connect(self.periods.setEnabled) vbox_periods.addStretch(1) group.setLayout(vbox_periods) self.layout.addWidget(group) buttonBox = QDialogButtonBox() cancel = buttonBox.addButton(QDialogButtonBox.Cancel) generate = buttonBox.addButton("Generate", QDialogButtonBox.AcceptRole) cancel.clicked.connect(self.reject) generate.clicked.connect(self.generate) self.layout.addWidget(buttonBox) self.show_randfixedsum_options() def generator_changed(self, value): if value == 2: self.show_kato_options() else: self.show_randfixedsum_options() def show_randfixedsum_options(self): for i in range(self.hbox_utilizations.count()): self.hbox_utilizations.itemAt(i).widget().hide() for i in range(self.hbox_tasks.count()): if self.hbox_tasks.itemAt(i).widget(): self.hbox_tasks.itemAt(i).widget().show() for i in range(self.hbox_sporadic_tasks.count()): if self.hbox_sporadic_tasks.itemAt(i).widget(): self.hbox_sporadic_tasks.itemAt(i).widget().show() def show_kato_options(self): for i in range(self.hbox_utilizations.count()): if self.hbox_utilizations.itemAt(i).widget(): self.hbox_utilizations.itemAt(i).widget().show() for i in range(self.hbox_tasks.count()): if self.hbox_tasks.itemAt(i).widget(): self.hbox_tasks.itemAt(i).widget().hide() for i in range(self.hbox_sporadic_tasks.count()): if self.hbox_sporadic_tasks.itemAt(i).widget(): self.hbox_sporadic_tasks.itemAt(i).widget().hide() def get_min_utilization(self): return self.interval_utilization.getMin() def get_max_utilization(self): return self.interval_utilization.getMax() def generate(self): if self.comboGenerator.currentIndex() == 0: n = self.get_nb_tasks() u = StaffordRandFixedSum(n, self.get_utilization(), 1) elif self.comboGenerator.currentIndex() == 1: n = self.get_nb_tasks() u = UUniFastDiscard(n, self.get_utilization(), 1) else: u = gen_kato_utilizations(1, self.get_min_utilization(), self.get_max_utilization(), self.get_utilization()) n = len(u[0]) p_types = self.get_periods() if p_types[0] == "unif": p = gen_periods_uniform(n, 1, p_types[1], p_types[2], p_types[3]) elif p_types[0] == "lunif": p = gen_periods_loguniform(n, 1, p_types[1], p_types[2], p_types[3]) else: p = gen_periods_discrete(n, 1, p_types[1]) if u and p: self.taskset = gen_tasksets(u, p)[0] self.accept() elif not u: QMessageBox.warning( self, "Generation failed", "Please check the utilization and the number of tasks.") else: QMessageBox.warning(self, "Generation failed", "Pleache check the periods.") def get_nb_tasks(self): return self.spin_tasks.value() + self.spin_sporadic_tasks.value() def get_nb_periodic_tasks(self): return self.spin_tasks.value() def get_nb_sporadic_tasks(self): return self.spin_sporadic_tasks.value() def get_utilization(self): return self.spin_load.value() def get_periods(self): if self.unif.isChecked(): return ("unif", self.unif_interval.getMin(), self.unif_interval.getMax(), self.unif_interval.getRound()) elif self.lunif.isChecked(): return ("lunif", self.lunif_interval.getMin(), self.lunif_interval.getMax(), self.lunif_interval.getRound()) else: return ("discrete", map(float, str(self.periods.text()).split()))
class TerminalWidget(QWidget): def __init__(self, mainloop, addr, title, parent=None): QWidget.__init__(self, parent) self.mainloop = mainloop self.addr = addr self.title = QLabel(title) self.title.setFont(QFont('Monospace', 16)) self.message = QLabel('') self.message.setFont(QFont('Monospace', 13)) self.bt_open = self.init_button('arrow-up-icon.png', QSize(50, 50)) self.bt_close = self.init_button('arrow-down-icon.png', QSize(50, 50)) info_layout = QVBoxLayout() info_layout.addWidget(self.title) layout = QHBoxLayout() layout.addLayout(info_layout) layout.addSpacerItem(QSpacerItem(0, 0, QSizePolicy.Expanding)) self.options_layout = QHBoxLayout() layout.addLayout(self.options_layout) layout.addWidget(self.bt_open) layout.addWidget(self.bt_close) self.setLayout(layout) self.bt_open.clicked.connect(self.open) self.bt_close.clicked.connect(self.close) self.grabGesture(Qt.TapAndHoldGesture) def update_config(self): self.mainloop.update_config(self.addr) self.clear_config_layout() def init_config_layout(self): if self.options_layout.isEmpty(): config_bt = self.init_button('settings-icon.png', QSize(50, 50)) config_bt.clicked.connect(self.update_config) self.options_layout.addWidget(config_bt) def clear_config_layout(self): for i in reversed(range(self.options_layout.count())): self.options_layout.itemAt(i).widget().setParent(None) def gesture_event(self, event): #if event.gestureType() == self.tap_and_hold_type: # self.init_config_layout() # return True if event.gestureType() == Qt.TapAndHoldGesture: self.init_config_layout() return True return False def event(self, event): if event.type() == QEvent.Gesture: print self.addr, event for g in event.gestures(): if g.state() != Qt.GestureFinished: continue if self.gesture_event(g): return event.setAccepted(g, True) return QWidget.event(self, event) def init_button(self, icon_filename, size): button = QPushButton(self) button.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum) button.setAutoFillBackground(True) button.setMinimumSize(size) button.setIcon(QIcon(icon_filename)) button.setIconSize(size) return button def show_message(self, msg): print unicode(msg).encode('utf8') self.message.setText(msg) def set_style_color(self, color): return self.setStyleSheet(""" TerminalWidget { background-color: qradialgradient(cx:0.5, cy:0.5, radius: 0.5, fx:0.7, fy:0.7, stop:0 %s, stop:1 white); }""" % (color,)) def set_state(self, state): if not self.isEnabled(): return if state == 'active': self.set_style_color('green') elif state == 'inactive': self.set_style_color('red') elif state == 'disabled': self.set_style_color('gray') else: self.set_style_color('white') self.setAutoFillBackground(True) def open(self): self.mainloop.terminal_open(self.addr) def close(self): self.mainloop.terminal_close(self.addr)
class Step(QObject): def __init__(self, params): super(Step, self).__init__() self.parse_properties(params) self.initUI() print "Step {0} initialized".format(self.name) self.data_dict = {"name": self.name} def parse_properties(self, props): self.data_widgets = {} props.setdefault('name', "") props.setdefault('duration', "") props.setdefault('next_button', "true") props.setdefault('show_timer', "true") props.setdefault('record', "true") self.name = props['name'] self.record = props['record'] self.show_timer = (props['show_timer'] == 'true') self.duration = self.parse_duration(props['duration']) self.has_next_button = (props['next_button'] == 'true') if 'graph' in props: self.graph = True plot_params = props['graph'] self.plot = EEGPlot(plot_params) self.data_widgets['plot'] = self.plot else: self.graph = False def initUI(self): self.widget = QWidget() self.grid = QHBoxLayout() if self.duration: self.timer_widget = TimerWidget(self.duration, self.endStep) if self.show_timer: self.grid.addWidget(self.timer_widget) if self.graph: self.grid.addWidget(self.plot.pw) self.horseshoe = HorseshoeWidget(self.plot.pw) else: self.horseshoe = HorseshoeWidget(self.widget) self.widget.setLayout(self.grid) def startStep(self, callback): print "starting a step" if self.duration: self.timer_widget.start() self.horseshoe.start() if self.graph: self.plot.start() self.callback = callback def endStep(self): for i in range(self.grid.count()): self.grid.itemAt(i).widget().close() # clear the layout if self.graph: self.plot.stop() if self.record: for name, widget in self.data_widgets.iteritems(): self.data_dict[name] = widget.serialize() if self.has_next_button: self.next_button = QPushButton() self.next_button.setText("Press to Continue") self.next_button.clicked.connect(lambda: self.callback(self.data_dict)) self.grid.addWidget(self.next_button) else: self.callback(self.data_dict) def parse_duration(self, time_string): if len(time_string) == 0: return None else: times = [int(x) for x in time_string.split(":")] times.reverse() # Now we have ss:mm:hh:dd multipliers = [1, 60, 3600, 3600*24] time_in_secs = sum([unit* multiplier for unit, multiplier in zip(times, multipliers)]) return time_in_secs
class TaskGeneratorDialog(QDialog): def __init__(self, nbprocessors): QDialog.__init__(self) self.layout = QVBoxLayout(self) self.taskset = None # Utilizations: vbox_utilizations = QVBoxLayout() group = QGroupBox("Task Utilizations:") hbox = QHBoxLayout() hbox.addWidget(QLabel("Generator:", self)) self.comboGenerator = QComboBox() self.comboGenerator.addItem("RandFixedSum") self.comboGenerator.addItem("UUniFast-Discard") self.comboGenerator.addItem("Kato's method") self.comboGenerator.currentIndexChanged.connect(self.generator_changed) hbox.addWidget(self.comboGenerator) vbox_utilizations.addLayout(hbox) # Load slider + spinner: hbox_load = QHBoxLayout() sld = _DoubleSlider(QtCore.Qt.Horizontal, self) sld.setMinimum(0) sld.setMaximum(32) self.spin_load = QDoubleSpinBox(self) self.spin_load.setMinimum(0) self.spin_load.setMaximum(32) self.spin_load.setSingleStep(0.1) hbox_load.addWidget(QLabel("Total utilization: ", self)) hbox_load.addWidget(sld) hbox_load.addWidget(self.spin_load) sld.doubleValueChanged.connect(self.spin_load.setValue) self.spin_load.valueChanged.connect(sld.setValue) self.spin_load.setValue(nbprocessors / 2.) vbox_utilizations.addLayout(hbox_load) # Number of periodic tasks: self.hbox_tasks = QHBoxLayout() self.spin_tasks = QSpinBox(self) self.spin_tasks.setMinimum(0) self.spin_tasks.setMaximum(999) # That's arbitrary. self.hbox_tasks.addWidget(QLabel("Number of periodic tasks: ", self)) self.hbox_tasks.addStretch(1) self.hbox_tasks.addWidget(self.spin_tasks) vbox_utilizations.addLayout(self.hbox_tasks) # Number of sporadic tasks: self.hbox_sporadic_tasks = QHBoxLayout() self.spin_sporadic_tasks = QSpinBox(self) self.spin_sporadic_tasks.setMinimum(0) self.spin_sporadic_tasks.setMaximum(999) # That's arbitrary. self.hbox_sporadic_tasks.addWidget( QLabel("Number of sporadic tasks: ", self)) self.hbox_sporadic_tasks.addStretch(1) self.hbox_sporadic_tasks.addWidget(self.spin_sporadic_tasks) vbox_utilizations.addLayout(self.hbox_sporadic_tasks) # Min / Max utilizations self.hbox_utilizations = QHBoxLayout() self.hbox_utilizations.addWidget(QLabel("Min/Max utilizations: ", self)) self.interval_utilization = IntervalSpinner( self, min_=0, max_=1, step=.01, round_option=False) self.hbox_utilizations.addWidget(self.interval_utilization) vbox_utilizations.addLayout(self.hbox_utilizations) group.setLayout(vbox_utilizations) self.layout.addWidget(group) # Periods: vbox_periods = QVBoxLayout() group = QGroupBox("Task Periods:") # Log uniform self.lunif = QRadioButton("log-uniform distribution between:") vbox_periods.addWidget(self.lunif) self.lunif.setChecked(True) self.lunif_interval = IntervalSpinner(self) self.lunif_interval.setEnabled(self.lunif.isChecked()) self.lunif.toggled.connect(self.lunif_interval.setEnabled) vbox_periods.addWidget(self.lunif_interval) # Uniform self.unif = QRadioButton("uniform distribution between:") vbox_periods.addWidget(self.unif) self.unif_interval = IntervalSpinner(self) self.unif_interval.setEnabled(self.unif.isChecked()) self.unif.toggled.connect(self.unif_interval.setEnabled) vbox_periods.addWidget(self.unif_interval) # Discrete discrete = QRadioButton("chosen among these (space separated) values:") vbox_periods.addWidget(discrete) self.periods = QLineEdit(self) self.periods.setValidator(QRegExpValidator( QRegExp("^\\d*(\.\\d*)?( \\d*(\.\\d*)?)*$"))) vbox_periods.addWidget(self.periods) self.periods.setEnabled(discrete.isChecked()) discrete.toggled.connect(self.periods.setEnabled) vbox_periods.addStretch(1) group.setLayout(vbox_periods) self.layout.addWidget(group) buttonBox = QDialogButtonBox() cancel = buttonBox.addButton(QDialogButtonBox.Cancel) generate = buttonBox.addButton("Generate", QDialogButtonBox.AcceptRole) cancel.clicked.connect(self.reject) generate.clicked.connect(self.generate) self.layout.addWidget(buttonBox) self.show_randfixedsum_options() def generator_changed(self, value): if value == 2: self.show_kato_options() else: self.show_randfixedsum_options() def show_randfixedsum_options(self): for i in range(self.hbox_utilizations.count()): self.hbox_utilizations.itemAt(i).widget().hide() for i in range(self.hbox_tasks.count()): if self.hbox_tasks.itemAt(i).widget(): self.hbox_tasks.itemAt(i).widget().show() for i in range(self.hbox_sporadic_tasks.count()): if self.hbox_sporadic_tasks.itemAt(i).widget(): self.hbox_sporadic_tasks.itemAt(i).widget().show() def show_kato_options(self): for i in range(self.hbox_utilizations.count()): if self.hbox_utilizations.itemAt(i).widget(): self.hbox_utilizations.itemAt(i).widget().show() for i in range(self.hbox_tasks.count()): if self.hbox_tasks.itemAt(i).widget(): self.hbox_tasks.itemAt(i).widget().hide() for i in range(self.hbox_sporadic_tasks.count()): if self.hbox_sporadic_tasks.itemAt(i).widget(): self.hbox_sporadic_tasks.itemAt(i).widget().hide() def get_min_utilization(self): return self.interval_utilization.getMin() def get_max_utilization(self): return self.interval_utilization.getMax() def generate(self): if self.comboGenerator.currentIndex() == 0: n = self.get_nb_tasks() u = StaffordRandFixedSum(n, self.get_utilization(), 1) elif self.comboGenerator.currentIndex() == 1: n = self.get_nb_tasks() u = UUniFastDiscard(n, self.get_utilization(), 1) else: u = gen_kato_utilizations(1, self.get_min_utilization(), self.get_max_utilization(), self.get_utilization()) n = len(u[0]) p_types = self.get_periods() if p_types[0] == "unif": p = gen_periods_uniform(n, 1, p_types[1], p_types[2], p_types[3]) elif p_types[0] == "lunif": p = gen_periods_loguniform(n, 1, p_types[1], p_types[2], p_types[3]) else: p = gen_periods_discrete(n, 1, p_types[1]) if u and p: self.taskset = gen_tasksets(u, p)[0] self.accept() elif not u: QMessageBox.warning( self, "Generation failed", "Please check the utilization and the number of tasks.") else: QMessageBox.warning( self, "Generation failed", "Pleache check the periods.") def get_nb_tasks(self): return self.spin_tasks.value() + self.spin_sporadic_tasks.value() def get_nb_periodic_tasks(self): return self.spin_tasks.value() def get_nb_sporadic_tasks(self): return self.spin_sporadic_tasks.value() def get_utilization(self): return self.spin_load.value() def get_periods(self): if self.unif.isChecked(): return ("unif", self.unif_interval.getMin(), self.unif_interval.getMax(), self.unif_interval.getRound()) elif self.lunif.isChecked(): return ("lunif", self.lunif_interval.getMin(), self.lunif_interval.getMax(), self.lunif_interval.getRound()) else: return ("discrete", map(float, str(self.periods.text()).split()))