class LayerTagsWidget(QtWidgets.QWidget): """ A widget for editing tags. """ def __init__(self, layers, parent=None): QtWidgets.QWidget.__init__(self, parent) self.__layers = layers currentTags = set() for layer in self.__layers: for tag in layer.data.tags: currentTags.add(tag) layout = QtWidgets.QVBoxLayout(self) custom_layout = QtWidgets.QHBoxLayout() self._tags_widget = TagsWidget(allowed_tags=Constants.ALLOWED_TAGS) self._tags_widget.set_tags(currentTags) custom_layout.addWidget(self._tags_widget) layout.addLayout(custom_layout) def apply(self): """ Apply values to layers. """ tags = self._tags_widget.get_tags() if not tags: return try: for layer in self.__layers: layer.setTags(tags) except opencue.CueException, e: warning = QtWidgets.QMessageBox(self) warning.setText("Error applying layer tags.") warning.setDetailedText("%s" % e) warning.exec_()
def __init__(self, parent=None): QtWidgets.QWidget.__init__(self, parent) self.__service = None self.gpu_max_mb = 2 * 1024 self.gpu_min_mb = 0 self.gpu_tick_mb = 256 self.name = QtWidgets.QLineEdit(self) self.threadable = QtWidgets.QCheckBox(self) self.min_cores = QtWidgets.QSpinBox(self) self.min_cores.setRange(50, int(self._cfg().get('max_cores', 16)) * 100) self.min_cores.setSingleStep(50) self.min_cores.setValue(100) self.max_cores = QtWidgets.QSpinBox(self) self.max_cores.setRange(0, int(self._cfg().get('max_cores', 16)) * 100) self.max_cores.setSingleStep(100) self.max_cores.setValue(100) self.min_memory = QtWidgets.QSpinBox(self) self.min_memory.setRange(512, int(self._cfg().get('max_memory', 48)) * 1024) self.min_memory.setValue(3276) self.min_gpu = QtWidgets.QSpinBox(self) self.min_gpu.setRange(self.gpu_min_mb, self.gpu_max_mb) self.min_gpu.setValue(0) self.min_gpu.setSingleStep(self.gpu_tick_mb) self.min_gpu.setSuffix(" MB") layout = QtWidgets.QGridLayout(self) layout.addWidget(QtWidgets.QLabel("Name:", self), 0, 0) layout.addWidget(self.name, 0, 1) layout.addWidget(QtWidgets.QLabel("Threadable:", self), 1, 0) layout.addWidget(self.threadable, 1, 1) layout.addWidget( QtWidgets.QLabel("Min Threads (100 = 1 thread):", self), 2, 0) layout.addWidget(self.min_cores, 2, 1) layout.addWidget( QtWidgets.QLabel("Max Threads (100 = 1 thread):", self), 3, 0) layout.addWidget(self.max_cores, 3, 1) layout.addWidget(QtWidgets.QLabel("Min Memory MB:", self), 4, 0) layout.addWidget(self.min_memory, 4, 1) layout.addWidget(QtWidgets.QLabel("Min Gpu Memory MB:", self), 5, 0) layout.addWidget(self.min_gpu, 5, 1) self.__buttons = QtWidgets.QDialogButtonBox( QtWidgets.QDialogButtonBox.Save, QtCore.Qt.Horizontal, self) self.__buttons.setDisabled(True) layout.addWidget(self.__buttons, 8, 1) self.__buttons.accepted.connect(self.save) self._tags_w = TagsWidget(allowed_tags=Constants.ALLOWED_TAGS) layout.addWidget(self._tags_w, 6, 0, 1, 2)
def __init__(self, layers, parent=None): QtWidgets.QWidget.__init__(self, parent) self.__layers = layers currentTags = set() for layer in self.__layers: for tag in layer.data.tags: currentTags.add(tag) layout = QtWidgets.QVBoxLayout(self) custom_layout = QtWidgets.QHBoxLayout() self._tags_widget = TagsWidget(allowed_tags=Constants.ALLOWED_TAGS) self._tags_widget.set_tags(currentTags) custom_layout.addWidget(self._tags_widget) layout.addLayout(custom_layout)
class ServiceForm(QtWidgets.QWidget): """ An Widget for displaying and editing a service. """ saved = QtCore.Signal(object) def __init__(self, parent=None): QtWidgets.QWidget.__init__(self, parent) self.__service = None self.gpu_max_mb = 2 * 1024 self.gpu_min_mb = 0 self.gpu_tick_mb = 256 self.name = QtWidgets.QLineEdit(self) self.threadable = QtWidgets.QCheckBox(self) self.min_cores = QtWidgets.QSpinBox(self) self.min_cores.setRange(50, int(self._cfg().get('max_cores', 16)) * 100) self.min_cores.setSingleStep(50) self.min_cores.setValue(100) self.max_cores = QtWidgets.QSpinBox(self) self.max_cores.setRange(0, int(self._cfg().get('max_cores', 16)) * 100) self.max_cores.setSingleStep(100) self.max_cores.setValue(100) self.min_memory = QtWidgets.QSpinBox(self) self.min_memory.setRange(512, int(self._cfg().get('max_memory', 48)) * 1024) self.min_memory.setValue(3276) self.min_gpu = QtWidgets.QSpinBox(self) self.min_gpu.setRange(self.gpu_min_mb, self.gpu_max_mb) self.min_gpu.setValue(0) self.min_gpu.setSingleStep(self.gpu_tick_mb) self.min_gpu.setSuffix(" MB") layout = QtWidgets.QGridLayout(self) layout.addWidget(QtWidgets.QLabel("Name:", self), 0, 0) layout.addWidget(self.name, 0, 1) layout.addWidget(QtWidgets.QLabel("Threadable:", self), 1, 0) layout.addWidget(self.threadable, 1, 1) layout.addWidget( QtWidgets.QLabel("Min Threads (100 = 1 thread):", self), 2, 0) layout.addWidget(self.min_cores, 2, 1) layout.addWidget( QtWidgets.QLabel("Max Threads (100 = 1 thread):", self), 3, 0) layout.addWidget(self.max_cores, 3, 1) layout.addWidget(QtWidgets.QLabel("Min Memory MB:", self), 4, 0) layout.addWidget(self.min_memory, 4, 1) layout.addWidget(QtWidgets.QLabel("Min Gpu Memory MB:", self), 5, 0) layout.addWidget(self.min_gpu, 5, 1) self.__buttons = QtWidgets.QDialogButtonBox( QtWidgets.QDialogButtonBox.Save, QtCore.Qt.Horizontal, self) self.__buttons.setDisabled(True) layout.addWidget(self.__buttons, 8, 1) self.__buttons.accepted.connect(self.save) self._tags_w = TagsWidget(allowed_tags=Constants.ALLOWED_TAGS) layout.addWidget(self._tags_w, 6, 0, 1, 2) def _cfg(self): """ Loads (if necessary) and returns the config values. Warns and returns an empty dict if there's a problem reading the config @return: The keys & values stored in the config file @rtype: dict<str:str> """ if not hasattr(self, '__config'): self.__config = Utils.getResourceConfig() return self.__config def setService(self, service): """ Update the form with data from the given service. """ self.__buttons.setDisabled(False) self.__service = service.data self.name.setText(self.__service.name) self.threadable.setChecked(self.__service.threadable) self.min_cores.setValue(self.__service.min_cores) self.max_cores.setValue(self.__service.max_cores) self.min_memory.setValue(self.__service.min_memory / 1024) self.min_gpu.setValue(self.__service.min_gpu / 1024) self._tags_w.set_tags(self.__service.tags) def new(self): """ Clear the form for a new service. """ self.__buttons.setDisabled(False) self.__service = None self.name.setFocus() self.name.setText("") self.threadable.setChecked(False) self.min_cores.setValue(100) self.max_cores.setValue(100) self.min_memory.setValue(3276) self.min_gpu.setValue(0) self._tags_w.set_tags(['general']) def save(self): """ Create and emit a ServiceData object based on the contents of the form. """ if len(str(self.name.text())) < 3: QtWidgets.QMessageBox.critical( self, "Error", "The service name must be at least 3 characters.") return if not str(self.name.text()).isalnum(): QtWidgets.QMessageBox.critical( self, "Error", "The service name must alphanumeric.") return data = opencue.api.service_pb2.Service() data.name = str(self.name.text()) data.threadable = self.threadable.isChecked() data.min_cores = self.min_cores.value() data.max_cores = self.max_cores.value() data.min_memory = self.min_memory.value() * 1024 data.min_gpu = self.min_gpu.value() * 1024 data.tags.extend(self._tags_w.get_tags()) self.saved.emit(data)