def add_data(self, header, data): """Add information which needs to be displayed""" if header in self.data_table: print("Cannot add similar header, please use `update` in stead") return data_widget = QtWidgets.QWidget() data_widget.setFixedHeight(self._tile_height) layout = QtWidgets.QVBoxLayout() title = QtWidgets.QLabel(header.upper()) title.setStyleSheet(style.overview_tile_title) formlayout = QtWidgets.QFormLayout() for label, value in data.items(): value_label = QtWidgets.QLabel(value) formlayout.addRow("%s :" % label, value_label) layout.addWidget(title) layout.addLayout(formlayout) layout.addStretch() data_widget.setLayout(layout) self.data_table[header] = {"widget": data_widget, "data": data} position = self.layout.count() + 1 self.layout.insertWidget(position, data_widget)
def __init__(self, parent=None, context=None): super(Window, self).__init__(parent) self.context = context project_name = io.active_project() self.setWindowTitle("Asset creator ({0})".format(project_name)) self.setFocusPolicy(QtCore.Qt.StrongFocus) self.setAttribute(QtCore.Qt.WA_DeleteOnClose) # Validators self.valid_parent = False self.session = None # assets widget assets_widget = QtWidgets.QWidget() assets_widget.setContentsMargins(0, 0, 0, 0) assets_layout = QtWidgets.QVBoxLayout(assets_widget) assets = widget.AssetWidget() assets.view.setSelectionMode(assets.view.ExtendedSelection) assets_layout.addWidget(assets) # Outlink label_outlink = QtWidgets.QLabel("Outlink:") input_outlink = QtWidgets.QLineEdit() input_outlink.setReadOnly(True) input_outlink.setStyleSheet("background-color: #333333;") checkbox_outlink = QtWidgets.QCheckBox("Use outlink") # Parent label_parent = QtWidgets.QLabel("*Parent:") input_parent = QtWidgets.QLineEdit() input_parent.setReadOnly(True) input_parent.setStyleSheet("background-color: #333333;") # Name label_name = QtWidgets.QLabel("*Name:") input_name = QtWidgets.QLineEdit() input_name.setPlaceholderText("<asset name>") # Asset Build label_assetbuild = QtWidgets.QLabel("Asset Build:") combo_assetbuilt = QtWidgets.QComboBox() # Task template label_task_template = QtWidgets.QLabel("Task template:") combo_task_template = QtWidgets.QComboBox() # Info widget info_widget = QtWidgets.QWidget() info_widget.setContentsMargins(10, 10, 10, 10) info_layout = QtWidgets.QVBoxLayout(info_widget) # Inputs widget inputs_widget = QtWidgets.QWidget() inputs_widget.setContentsMargins(0, 0, 0, 0) inputs_layout = QtWidgets.QFormLayout(inputs_widget) inputs_layout.addRow(label_outlink, input_outlink) inputs_layout.addRow(None, checkbox_outlink) inputs_layout.addRow(label_parent, input_parent) inputs_layout.addRow(label_name, input_name) inputs_layout.addRow(label_assetbuild, combo_assetbuilt) inputs_layout.addRow(label_task_template, combo_task_template) # Add button btns_widget = QtWidgets.QWidget() btns_widget.setContentsMargins(0, 0, 0, 0) btn_layout = QtWidgets.QHBoxLayout(btns_widget) btn_create_asset = QtWidgets.QPushButton("Create asset") btn_create_asset.setToolTip( "Creates all neccessary components for asset" ) checkbox_app = None if self.context is not None: checkbox_app = QtWidgets.QCheckBox("Open {}".format( self.context.capitalize()) ) btn_layout.addWidget(checkbox_app) btn_layout.addWidget(btn_create_asset) task_view = QtWidgets.QTreeView() task_view.setIndentation(0) task_model = model.TasksModel() task_view.setModel(task_model) info_layout.addWidget(inputs_widget) info_layout.addWidget(task_view) info_layout.addWidget(btns_widget) # Body body = QtWidgets.QSplitter() body.setContentsMargins(0, 0, 0, 0) body.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding) body.setOrientation(QtCore.Qt.Horizontal) body.addWidget(assets_widget) body.addWidget(info_widget) body.setStretchFactor(0, 100) body.setStretchFactor(1, 150) # statusbar message = QtWidgets.QLabel() message.setFixedHeight(20) statusbar = QtWidgets.QWidget() layout = QtWidgets.QHBoxLayout(statusbar) layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(message) layout = QtWidgets.QVBoxLayout(self) layout.addWidget(body) layout.addWidget(statusbar) self.data = { "label": { "message": message, }, "view": { "tasks": task_view }, "model": { "assets": assets, "tasks": task_model }, "inputs": { "outlink": input_outlink, "outlink_cb": checkbox_outlink, "parent": input_parent, "name": input_name, "assetbuild": combo_assetbuilt, "tasktemplate": combo_task_template, "open_app": checkbox_app }, "buttons": { "create_asset": btn_create_asset } } # signals btn_create_asset.clicked.connect(self.create_asset) assets.selection_changed.connect(self.on_asset_changed) input_name.textChanged.connect(self.on_asset_name_change) checkbox_outlink.toggled.connect(self.on_outlink_checkbox_change) combo_task_template.currentTextChanged.connect( self.on_task_template_changed ) if self.context is not None: checkbox_app.toggled.connect(self.on_app_checkbox_change) # on start self.on_start() self.resize(600, 500) self.echo("Connected to project: {0}".format(project_name))