class MainDialog(QtWidgets.QDialog, AnimaDialogBase): """The ImageFormat Dialog """ def __init__(self, parent=None, image_format=None): super(MainDialog, self).__init__(parent=parent) self.vertical_layout = None self.dialog_label = None self.line = None self.form_layout = None self.name_fields_vertical_layout = None self.name_validator_label = None self.width_height_label = None self.horizontal_layout = None self.width_spin_box = None self.label = None self.height_spin_box = None self.pixel_aspect_label = None self.pixel_aspect_double_spin_box = None self.name_label = None self.button_box = None self.setup_ui() self.image_format = image_format self.mode = 'Create' if self.image_format: self.mode = 'Update' self.dialog_label.setText('%s Image Format' % self.mode) # create name_line_edit from anima.ui.widgets import ValidatedLineEdit self.name_line_edit = ValidatedLineEdit( message_field=self.name_validator_label) self.name_line_edit.setPlaceholderText('Enter Name') self.name_fields_vertical_layout.insertWidget(0, self.name_line_edit) self._setup_signals() self._set_defaults() if self.image_format: self.fill_ui_with_image_format(self.image_format) def setup_ui(self): self.resize(328, 184) self.vertical_layout = QtWidgets.QVBoxLayout(self) self.dialog_label = QtWidgets.QLabel(self) self.dialog_label.setStyleSheet("color: rgb(71, 143, 202);\n" "font: 18pt;") self.vertical_layout.addWidget(self.dialog_label) self.line = QtWidgets.QFrame(self) self.line.setFrameShape(QtWidgets.QFrame.HLine) self.line.setFrameShadow(QtWidgets.QFrame.Sunken) self.vertical_layout.addWidget(self.line) self.form_layout = QtWidgets.QFormLayout() self.form_layout.setLabelAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter) self.name_fields_vertical_layout = QtWidgets.QVBoxLayout() self.name_validator_label = QtWidgets.QLabel(self) self.name_validator_label.setStyleSheet("color: rgb(255, 0, 0);") self.name_fields_vertical_layout.addWidget(self.name_validator_label) self.form_layout.setLayout(0, QtWidgets.QFormLayout.FieldRole, self.name_fields_vertical_layout) self.width_height_label = QtWidgets.QLabel(self) self.form_layout.setWidget(1, QtWidgets.QFormLayout.LabelRole, self.width_height_label) self.horizontal_layout = QtWidgets.QHBoxLayout() self.width_spin_box = QtWidgets.QSpinBox(self) self.width_spin_box.setMaximum(99999) self.horizontal_layout.addWidget(self.width_spin_box) self.label = QtWidgets.QLabel(self) self.horizontal_layout.addWidget(self.label) self.height_spin_box = QtWidgets.QSpinBox(self) self.height_spin_box.setMaximum(99999) self.horizontal_layout.addWidget(self.height_spin_box) self.horizontal_layout.setStretch(0, 1) self.horizontal_layout.setStretch(2, 1) self.form_layout.setLayout(1, QtWidgets.QFormLayout.FieldRole, self.horizontal_layout) self.pixel_aspect_label = QtWidgets.QLabel(self) self.form_layout.setWidget(2, QtWidgets.QFormLayout.LabelRole, self.pixel_aspect_label) self.pixel_aspect_double_spin_box = QtWidgets.QDoubleSpinBox(self) self.pixel_aspect_double_spin_box.setProperty("value", 1.0) self.form_layout.setWidget(2, QtWidgets.QFormLayout.FieldRole, self.pixel_aspect_double_spin_box) self.name_label = QtWidgets.QLabel(self) self.form_layout.setWidget(0, QtWidgets.QFormLayout.LabelRole, self.name_label) self.vertical_layout.addLayout(self.form_layout) self.button_box = QtWidgets.QDialogButtonBox(self) self.button_box.setOrientation(QtCore.Qt.Horizontal) self.button_box.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel | QtWidgets.QDialogButtonBox.Ok) self.vertical_layout.addWidget(self.button_box) self.vertical_layout.setStretch(2, 1) QtCore.QObject.connect(self.button_box, QtCore.SIGNAL("accepted()"), self.accept) QtCore.QObject.connect(self.button_box, QtCore.SIGNAL("rejected()"), self.reject) QtCore.QMetaObject.connectSlotsByName(self) self.setWindowTitle("Image Format Dialog") self.dialog_label.setText("Create Image Format") self.name_validator_label.setText("Validator Message") self.width_height_label.setText("Width x Height") self.label.setText("x") self.pixel_aspect_label.setText("Pixel Aspect") self.name_label.setText("Name") def _setup_signals(self): """create the signals """ # name_line_edit is changed QtCore.QObject.connect(self.name_line_edit, QtCore.SIGNAL('textChanged(QString)'), self.name_line_edit_changed) def _set_defaults(self): """sets the default values """ pass def name_line_edit_changed(self, text): """runs when the name_line_edit text has changed """ if re.findall(r'[^a-zA-Z0-9\-_. ]+', text): self.name_line_edit.set_invalid('Invalid character') else: if text == '': self.name_line_edit.set_invalid('Enter a name') else: self.name_line_edit.set_valid() def fill_ui_with_image_format(self, image_format): """fills the UI with the given image_format :param image_format: A Stalker ImageFormat instance :return: """ if False: from stalker import ImageFormat assert isinstance(image_format, ImageFormat) self.image_format = image_format self.name_line_edit.setText(self.image_format.name) self.name_line_edit.set_valid() self.width_spin_box.setValue(self.image_format.width) self.height_spin_box.setValue(self.image_format.height) self.pixel_aspect_double_spin_box.setValue( self.image_format.pixel_aspect) def accept(self): """overridden accept method """ if not self.name_line_edit.is_valid: QtWidgets.QMessageBox.critical(self, 'Error', 'Please fix <b>name</b> field!') return name = self.name_line_edit.text() width = self.width_spin_box.value() height = self.height_spin_box.value() pixel_aspect = self.pixel_aspect_double_spin_box.value() from stalker import ImageFormat from stalker.db.session import DBSession logged_in_user = self.get_logged_in_user() if self.mode == 'Create': # Create a new Image Format try: imf = ImageFormat(name=name, width=width, height=height, pixel_aspect=pixel_aspect, created_by=logged_in_user) self.image_format = imf DBSession.add(imf) DBSession.commit() except Exception as e: DBSession.rollback() QtWidgets.QMessageBox.critical(self, 'Error', str(e)) return elif self.mode == 'Update': # Update the image format try: self.image_format.name = name self.image_format.width = width self.image_format.height = height self.image_format.pixel_aspect = pixel_aspect self.image_format.updated_by = logged_in_user DBSession.add(self.image_format) DBSession.commit() except Exception as e: DBSession.rollback() QtWidgets.QMessageBox.critical(self, 'Error', str(e)) return super(MainDialog, self).accept()
class MainDialog(QtWidgets.QDialog, AnimaDialogBase): """The Project Dialog """ def __init__(self, parent=None, project=None): logger.debug("initializing the interface") super(MainDialog, self).__init__(parent) # store the logged in user self.logged_in_user = None self.project = project self.mode = 'Create' if self.project: self.mode = 'Update' self.image_format = None self._setup_ui() self._setup_signals() self._set_defaults() if self.project: self.fill_ui_with_project(self.project) def _setup_ui(self): """create UI elements """ self.resize(517, 545) self.verticalLayout = QtWidgets.QVBoxLayout(self) self.setWindowTitle("Project Dialog") # ---------------------- # Dialog Label self.dialog_label = QtWidgets.QLabel(self) self.dialog_label.setText('%s Project' % self.mode) self.dialog_label.setStyleSheet( "color: rgb(71, 143, 202);\nfont: 18pt;") self.verticalLayout.addWidget(self.dialog_label) self.line = QtWidgets.QFrame(self) self.line.setFrameShape(QtWidgets.QFrame.HLine) self.line.setFrameShadow(QtWidgets.QFrame.Sunken) self.verticalLayout.addWidget(self.line) self.project_info_formLayout = QtWidgets.QFormLayout() self.project_info_formLayout.setLabelAlignment( QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter) # ---------------------- # Name Fields self.name_label = QtWidgets.QLabel(self) self.name_label.setText("Name") self.project_info_formLayout.setWidget(0, QtWidgets.QFormLayout.LabelRole, self.name_label) self.name_fields_verticalLayout = QtWidgets.QVBoxLayout() self.name_validator_label = QtWidgets.QLabel(self) self.name_validator_label.setText("Validator Message") self.name_validator_label.setStyleSheet("color: rgb(255, 0, 0);") self.name_fields_verticalLayout.addWidget(self.name_validator_label) self.project_info_formLayout.setLayout(0, QtWidgets.QFormLayout.FieldRole, self.name_fields_verticalLayout) # add name_lineEdit from anima.ui.widgets import ValidatedLineEdit self.name_lineEdit = ValidatedLineEdit( message_field=self.name_validator_label) self.name_fields_verticalLayout.insertWidget(0, self.name_lineEdit) # ---------------------- # Code Fields self.code_label = QtWidgets.QLabel(self) self.code_label.setText("Code") self.project_info_formLayout.setWidget(1, QtWidgets.QFormLayout.LabelRole, self.code_label) self.code_fields_verticalLayout = QtWidgets.QVBoxLayout() self.code_validator_label = QtWidgets.QLabel(self) self.code_validator_label.setText("Validator Message") self.code_validator_label.setStyleSheet("color: rgb(255, 0, 0);") self.code_fields_verticalLayout.addWidget(self.code_validator_label) self.project_info_formLayout.setLayout(1, QtWidgets.QFormLayout.FieldRole, self.code_fields_verticalLayout) # add code_lineEdit self.code_lineEdit = ValidatedLineEdit( message_field=self.code_validator_label) self.code_fields_verticalLayout.insertWidget(0, self.code_lineEdit) # ---------------------- # Type Fields self.type_label = QtWidgets.QLabel(self) self.type_label.setText("Type") self.project_info_formLayout.setWidget(2, QtWidgets.QFormLayout.LabelRole, self.type_label) self.type_comboBox = QtWidgets.QComboBox(self) self.type_comboBox.setEditable(True) self.project_info_formLayout.setWidget(2, QtWidgets.QFormLayout.FieldRole, self.type_comboBox) # ---------------------- # Date Fields self.date_label = QtWidgets.QLabel(self) self.date_label.setText("Date") self.project_info_formLayout.setWidget(3, QtWidgets.QFormLayout.LabelRole, self.date_label) self.date_dateEdit = QtWidgets.QDateEdit(self) self.project_info_formLayout.setWidget(3, QtWidgets.QFormLayout.FieldRole, self.date_dateEdit) # ---------------------- # Image Format Fields from anima.ui.widgets.image_format import ImageFormatWidget self.image_format = ImageFormatWidget( parent=self, parent_form_layout=self.project_info_formLayout, parent_form_layout_index=4) # ---------------------- # FPS Fields self.fps_label = QtWidgets.QLabel(self) self.fps_label.setText("FPS") self.project_info_formLayout.setWidget(5, QtWidgets.QFormLayout.LabelRole, self.fps_label) self.fps_spinBox = QtWidgets.QSpinBox(self) self.fps_spinBox.setMinimum(1) self.fps_spinBox.setProperty("value", 25) self.project_info_formLayout.setWidget(5, QtWidgets.QFormLayout.FieldRole, self.fps_spinBox) # ---------------------- # Repository Fields self.repository_label = QtWidgets.QLabel(self) self.repository_label.setText("Repository") self.project_info_formLayout.setWidget(6, QtWidgets.QFormLayout.LabelRole, self.repository_label) self.repository_horizontalLayout = QtWidgets.QHBoxLayout() self.repository_comboBox = QtWidgets.QComboBox(self) self.repository_horizontalLayout.addWidget(self.repository_comboBox) # Update Repository Push Button self.update_repository_pushButton = QtWidgets.QPushButton(self) self.update_repository_pushButton.setText("Update...") self.repository_horizontalLayout.addWidget( self.update_repository_pushButton) # Create Repository Push Button self.create_repository_pushButton = QtWidgets.QPushButton(self) self.create_repository_pushButton.setText("New...") self.repository_horizontalLayout.addWidget( self.create_repository_pushButton) self.repository_horizontalLayout.setStretch(0, 1) self.project_info_formLayout.setLayout( 6, QtWidgets.QFormLayout.FieldRole, self.repository_horizontalLayout) # ---------------------- self.structure_label = QtWidgets.QLabel(self) self.structure_label.setText("Structure") self.project_info_formLayout.setWidget(7, QtWidgets.QFormLayout.LabelRole, self.structure_label) self.structure_horizontalLayout = QtWidgets.QHBoxLayout() self.structure_comboBox = QtWidgets.QComboBox(self) self.structure_horizontalLayout.addWidget(self.structure_comboBox) # Update Structure Push Button self.update_structure_pushButton = QtWidgets.QPushButton(self) self.update_structure_pushButton.setText("Update...") self.structure_horizontalLayout.addWidget( self.update_structure_pushButton) # Create Structure Push Button self.create_structure_pushButton = QtWidgets.QPushButton(self) self.create_structure_pushButton.setText("New...") self.structure_horizontalLayout.addWidget( self.create_structure_pushButton) self.structure_horizontalLayout.setStretch(0, 1) self.project_info_formLayout.setLayout(7, QtWidgets.QFormLayout.FieldRole, self.structure_horizontalLayout) # ---------------------- # Status Fields self.status_label = QtWidgets.QLabel(self) self.status_label.setText("Status") self.project_info_formLayout.setWidget(8, QtWidgets.QFormLayout.LabelRole, self.status_label) self.status_comboBox = QtWidgets.QComboBox(self) self.project_info_formLayout.setWidget(8, QtWidgets.QFormLayout.FieldRole, self.status_comboBox) self.verticalLayout.addLayout(self.project_info_formLayout) # ---------------------- # Client Fields self.client_info_label = QtWidgets.QLabel(self) self.client_info_label.setText("Client Info") self.client_info_label.setStyleSheet( "color: rgb(71, 143, 202);\nfont: 18pt;") self.verticalLayout.addWidget(self.client_info_label) self.line_2 = QtWidgets.QFrame(self) self.line_2.setFrameShape(QtWidgets.QFrame.HLine) self.line_2.setFrameShadow(QtWidgets.QFrame.Sunken) self.verticalLayout.addWidget(self.line_2) self.client_info_formLayout = QtWidgets.QFormLayout() self.client_info_formLayout.setLabelAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter) # Client Fields self.client_label = QtWidgets.QLabel(self) self.client_label.setText("Client") self.client_info_formLayout.setWidget(0, QtWidgets.QFormLayout.LabelRole, self.client_label) self.client_comboBox = QtWidgets.QComboBox(self) self.client_comboBox.setEditable(True) self.client_info_formLayout.setWidget(0, QtWidgets.QFormLayout.FieldRole, self.client_comboBox) # Agency Fields self.agency_label = QtWidgets.QLabel(self) self.agency_label.setText("Agency") self.client_info_formLayout.setWidget(1, QtWidgets.QFormLayout.LabelRole, self.agency_label) self.agency_comboBox = QtWidgets.QComboBox(self) self.agency_comboBox.setEditable(True) self.client_info_formLayout.setWidget(1, QtWidgets.QFormLayout.FieldRole, self.agency_comboBox) # Production Company Fields self.production_company_label = QtWidgets.QLabel(self) self.production_company_label.setText( "<html><head/><body><p align=\"right\">Production<br/>" "Company</p></body></html>") self.client_info_formLayout.setWidget(2, QtWidgets.QFormLayout.LabelRole, self.production_company_label) self.production_company_comboBox = QtWidgets.QComboBox(self) self.production_company_comboBox.setEditable(True) self.client_info_formLayout.setWidget(2, QtWidgets.QFormLayout.FieldRole, self.production_company_comboBox) self.verticalLayout.addLayout(self.client_info_formLayout) self.buttonBox = QtWidgets.QDialogButtonBox(self) self.buttonBox.setOrientation(QtCore.Qt.Horizontal) self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel | QtWidgets.QDialogButtonBox.Ok) self.verticalLayout.addWidget(self.buttonBox) self.verticalLayout.setStretch(2, 2) self.verticalLayout.setStretch(5, 1) def _setup_signals(self): """creates the signals """ QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("accepted()"), self.accept) QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), self.reject) # name_lineEdit is changed QtCore.QObject.connect(self.name_lineEdit, QtCore.SIGNAL('textChanged(QString)'), self.name_line_edit_changed) # code_lineEdit is changed QtCore.QObject.connect(self.code_lineEdit, QtCore.SIGNAL('textChanged(QString)'), self.code_line_edit_changed) # create_repository_pushButton QtCore.QObject.connect(self.create_repository_pushButton, QtCore.SIGNAL('clicked()'), self.create_repository_push_button_clicked) # update_repository_pushButton QtCore.QObject.connect(self.update_repository_pushButton, QtCore.SIGNAL('clicked()'), self.update_repository_push_button_clicked) # create_structure_pushButton QtCore.QObject.connect(self.create_structure_pushButton, QtCore.SIGNAL('clicked()'), self.create_structure_push_button_clicked) # update_structure_pushButton QtCore.QObject.connect(self.update_structure_pushButton, QtCore.SIGNAL('clicked()'), self.update_structure_push_button_clicked) def _set_defaults(self): """setup the default values """ # set size policies # self.name_lineEdit self.type_comboBox.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed) self.status_comboBox.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed) self.client_comboBox.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed) self.agency_comboBox.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed) self.production_company_comboBox.setSizePolicy( QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed) # invalidate the name and code fields by default self.name_lineEdit.set_invalid('Enter a name') self.code_lineEdit.set_invalid('Enter a code') # update type field from stalker import Type from stalker.db.session import DBSession project_types = \ DBSession.query(Type.id, Type.name)\ .filter(Type.target_entity_type == 'Project')\ .order_by(Type.name)\ .all() self.type_comboBox.clear() self.type_comboBox.addItem('', -1) for type_id, type_name in project_types: self.type_comboBox.addItem(type_name, type_id) self.image_format.fill_combo_box() self.fill_repository_combo_box() self.fill_structure_combo_box() # fill status field sql = """select "SimpleEntities".id, "SimpleEntities".name from "Statuses" join "SimpleEntities" on "Statuses".id = "SimpleEntities".id join "StatusList_Statuses" on "Statuses".id = "StatusList_Statuses".status_id join "StatusLists" on "StatusLists".id = "StatusList_Statuses".status_list_id where "StatusLists".target_entity_type = 'Project'""" all_project_statuses = \ DBSession.connection().execute(sql).fetchall() for st_id, st_name in all_project_statuses: self.status_comboBox.addItem(st_name, st_id) def show(self): """overridden show method """ logger.debug('MainDialog.show is started') self.logged_in_user = self.get_logged_in_user() if not self.logged_in_user: self.reject() return_val = None else: return_val = super(MainDialog, self).show() logger.debug('MainDialog.show is finished') return return_val def fill_repository_combo_box(self): """fills the repository_comboBox with Repository instances """ # fill the repository field from stalker import Repository from stalker.db.session import DBSession all_repos = DBSession \ .query(Repository.id, Repository.name) \ .order_by(Repository.name) \ .all() self.repository_comboBox.clear() for repo_id, repo_name in all_repos: self.repository_comboBox.addItem(repo_name, repo_id) def fill_structure_combo_box(self): """fills the structure_comboBox with Structure instances """ # fill the structure field from stalker import Structure from stalker.db.session import DBSession all_structures = DBSession \ .query(Structure.id, Structure.name) \ .order_by(Structure.name) \ .all() self.structure_comboBox.clear() for st_id, st_name in all_structures: self.structure_comboBox.addItem(st_name, st_id) def name_line_edit_changed(self, text): """runs when the name_lineEdit text has changed """ if re.findall(r'[^a-zA-Z0-9\-_ ]+', text): self.name_lineEdit.set_invalid('Invalid character') else: if text == '': self.name_lineEdit.set_invalid('Enter a name') else: self.name_lineEdit.set_valid() # update code field also formatted_text = re.sub(r'[^A-Z0-9_]+', '', text) self.code_lineEdit.setText(formatted_text) def code_line_edit_changed(self, text): """runs when the code_lineEdit text has changed """ if re.findall(r'[^a-zA-Z0-9_]+', text): self.code_lineEdit.set_invalid('Invalid character') else: if text == '': self.code_lineEdit.set_invalid('Enter a code') else: if len(text) > 16: self.code_lineEdit.set_invalid('Code is too long (>16)') else: self.code_lineEdit.set_valid() def fill_ui_with_project(self, project): """fills the UI fields with the given project :param project: A Stalker Project instance :return: """ if not project: return self.project = project self.name_lineEdit.setText(project.name) self.name_lineEdit.set_valid() self.code_lineEdit.setText(project.code) self.code_lineEdit.set_valid() if project.type: index = self.type_comboBox.findData(project.type.id) if index: self.type_comboBox.setCurrentIndex(index) if project.image_format: index = self.image_format.combo_box.findData( project.image_format.id) if index: self.image_format.combo_box.setCurrentIndex(index) self.fps_spinBox.setValue(project.fps) if project.repository: # TODO: allow multiple repositories index = self.repository_comboBox.findText(project.repository.name, QtCore.Qt.MatchExactly) if index: self.repository_comboBox.setCurrentIndex(index) if project.structure: index = self.structure_comboBox.findText(project.structure.name, QtCore.Qt.MatchExactly) if index: self.repository_comboBox.setCurrentIndex(index) if project.status: index = self.status_comboBox.findText(project.status.name, QtCore.Qt.MatchExactly) if index: self.status_comboBox.setCurrentIndex(index) def create_repository_push_button_clicked(self): """runs when create_repository_pushButton is clicked """ try: # PySide accepted = QtWidgets.QDialog.DialogCode.Accepted except AttributeError: # PyQt4 accepted = QtWidgets.QDialog.Accepted from anima.ui import repository_dialog create_repository_dialog = \ repository_dialog.MainDialog(parent=self) create_repository_dialog.exec_() result = create_repository_dialog.result() if result == accepted: repository = create_repository_dialog.repository # select the created repository self.fill_repository_combo_box() index = self.repository_comboBox.findData(repository.id) if index: self.repository_comboBox.setCurrentIndex(index) create_repository_dialog.deleteLater() def update_repository_push_button_clicked(self): """runs when update_repository_pushButton is clicked """ try: # PySide accepted = QtWidgets.QDialog.DialogCode.Accepted except AttributeError: # PyQt4 accepted = QtWidgets.QDialog.Accepted repo = self.get_current_repository() if not repo: return from anima.ui import repository_dialog update_repository_dialog = \ repository_dialog.MainDialog(parent=self, repository=repo) update_repository_dialog.exec_() result = update_repository_dialog.result() if result == accepted: repository = update_repository_dialog.repository # select the created repository self.fill_repository_combo_box() index = self.repository_comboBox.findData(repository.id) if index: self.repository_comboBox.setCurrentIndex(index) update_repository_dialog.deleteLater() def create_structure_push_button_clicked(self): """runs when create_structure_pushButton is clicked """ try: # PySide accepted = QtWidgets.QDialog.DialogCode.Accepted except AttributeError: # PyQt4 accepted = QtWidgets.QDialog.Accepted from anima.ui import structure_dialog create_structure_dialog = \ structure_dialog.MainDialog(parent=self) create_structure_dialog.exec_() result = create_structure_dialog.result() if result == accepted: structure = create_structure_dialog.structure # select the created repository self.fill_structure_combo_box() index = self.structure_comboBox.findData(structure.id) if index: self.structure_comboBox.setCurrentIndex(index) create_structure_dialog.deleteLater() def update_structure_push_button_clicked(self): """runs when update_structure_pushButton is clicked """ try: # PySide accepted = QtWidgets.QDialog.DialogCode.Accepted except AttributeError: # PyQt4 accepted = QtWidgets.QDialog.Accepted structure = self.get_current_structure() if not structure: return from anima.ui import structure_dialog update_structure_dialog = \ structure_dialog.MainDialog(parent=self, structure=structure) update_structure_dialog.exec_() result = update_structure_dialog.result() if result == accepted: structure = update_structure_dialog.structure # select the created repository self.fill_structure_combo_box() index = self.structure_comboBox.findData(structure.id) if index: self.structure_comboBox.setCurrentIndex(index) update_structure_dialog.deleteLater() def get_current_repository(self): """returns the currently selected repository instance from the UI """ from stalker import Repository index = self.repository_comboBox.currentIndex() repo_id = self.repository_comboBox.itemData(index) repo = Repository.query.get(repo_id) return repo def get_current_structure(self): """returns the currently selected structure instance from the UI """ from stalker import Structure index = self.structure_comboBox.currentIndex() structure_id = self.structure_comboBox.itemData(index) structure = Structure.query.get(structure_id) return structure def accept(self): """create/update the project """ # Name if not self.name_lineEdit.is_valid: QtWidgets.QMessageBox.critical(self, 'Error', 'Please fix <b>name</b> field!') return name = self.name_lineEdit.text() # Code if not self.code_lineEdit.is_valid: QtWidgets.QMessageBox.critical(self, 'Error', 'Please fix <b>code</b> field!') return code = self.code_lineEdit.text() # Type from stalker import Type index = self.type_comboBox.currentIndex() type_id = self.type_comboBox.itemData(index) type_ = Type.query.get(type_id) # None type is ok # Image Format image_format = self.image_format.get_current_image_format() if not image_format: QtWidgets.QMessageBox.critical( self, 'Error', 'Please select an valid <b>Image Format</b>!') return # FPS fps = self.fps_spinBox.value() # Repository repo = self.get_current_repository() if not repo: QtWidgets.QMessageBox.critical( self, 'Error', 'Please select an valid <b>Repository</b>!') return # Structure structure = self.get_current_structure() if not structure: QtWidgets.QMessageBox.critical( self, 'Error', 'Please select an valid <b>Structure</b>!') return # Status from stalker import Status index = self.status_comboBox.currentIndex() status_id = self.status_comboBox.itemData(index) status = Status.query.get(status_id) if not status: QtWidgets.QMessageBox.critical( self, 'Error', 'Please select an valid <b>Status</b>!') return # TODO: Add Client Data fields (which I don't care for now) logged_in_user = self.get_logged_in_user() # create or update project from stalker.db.session import DBSession if self.mode == 'Create': # create a new project from stalker import Project new_project = Project(name=name, code=code, type=type_, repositories=[repo], structure=structure, image_format=image_format, fps=fps, created_by=logged_in_user) DBSession.add(new_project) try: DBSession.commit() except Exception as e: DBSession.rollback() QtWidgets.QMessageBox.critical(self, 'Error', str(e)) return else: # update the project self.project.updated_by = logged_in_user self.project.name = name self.project.code = code self.project.type = type_ self.project.repositories = [repo] self.project.structure = structure self.project.image_format = image_format self.project.fps = fps self.project.status = status DBSession.add(self.project) try: DBSession.commit() except Exception as e: DBSession.rollback() QtWidgets.QMessageBox.critical(self, 'Error', str(e)) return super(MainDialog, self).accept()
class MainDialog(QtWidgets.QDialog, AnimaDialogBase): """The FilenameTemplate Dialog """ def __init__(self, parent=None, filename_template=None): super(MainDialog, self).__init__(parent=parent) self.filename_template = filename_template self.mode = 'Create' if self.filename_template: self.mode = 'Update' self._setup_ui() if self.filename_template: self._fill_ui_with_filename_template(self.filename_template) def _setup_ui(self): """setup the ui elements """ self.resize(750, 180) self.vertical_layout = QtWidgets.QVBoxLayout(self) # Dialog Label self.dialog_label = QtWidgets.QLabel(self) self.dialog_label.setText('%s Filename Template' % self.mode) self.dialog_label.setStyleSheet("color: rgb(71, 143, 202);font: 18pt;") self.vertical_layout.addWidget(self.dialog_label) # Title Line line = QtWidgets.QFrame(self) line.setFrameShape(QtWidgets.QFrame.HLine) line.setFrameShadow(QtWidgets.QFrame.Sunken) self.vertical_layout.addWidget(line) # Form Layout self.form_layout = QtWidgets.QFormLayout() self.form_layout.setLabelAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter) self.vertical_layout.addLayout(self.form_layout) # ------------------------------------------------ # Target Entity Type Field # label self.target_entity_type_label = \ QtWidgets.QLabel('Target Entity Type', self) self.form_layout.setWidget(0, QtWidgets.QFormLayout.LabelRole, self.target_entity_type_label) # field self.target_entity_type_combo_box = QtWidgets.QComboBox(self) self.form_layout.setWidget(0, QtWidgets.QFormLayout.FieldRole, self.target_entity_type_combo_box) # ------------------------------------------------ # Name Field self.name_label = QtWidgets.QLabel('Name', self) self.form_layout.setWidget(1, QtWidgets.QFormLayout.LabelRole, self.name_label) self.name_fields_vertical_layout = QtWidgets.QVBoxLayout() self.name_validator_label = QtWidgets.QLabel(self) self.name_validator_label.setStyleSheet('color: rgb(255, 0, 0);') from anima.ui.widgets import ValidatedLineEdit self.name_line_edit = ValidatedLineEdit( self, message_field=self.name_validator_label) self.name_fields_vertical_layout.addWidget(self.name_line_edit) self.name_fields_vertical_layout.addWidget(self.name_validator_label) self.form_layout.setLayout(1, QtWidgets.QFormLayout.FieldRole, self.name_fields_vertical_layout) # ------------------------------------------------ # Path Code Field self.path_label = QtWidgets.QLabel('Path', self) self.form_layout.setWidget(2, QtWidgets.QFormLayout.LabelRole, self.path_label) self.path_line_edit = QtWidgets.QLineEdit(self) # set the default value to something useful self.form_layout.setWidget(2, QtWidgets.QFormLayout.FieldRole, self.path_line_edit) # ------------------------------------------------ # Filename Code Field self.filename_label = QtWidgets.QLabel('Filename', self) self.form_layout.setWidget(3, QtWidgets.QFormLayout.LabelRole, self.filename_label) self.filename_line_edit = QtWidgets.QLineEdit(self) self.form_layout.setWidget(3, QtWidgets.QFormLayout.FieldRole, self.filename_line_edit) # ------------------------------------------------ # Button Box self.button_box = QtWidgets.QDialogButtonBox(self) self.button_box.setOrientation(QtCore.Qt.Horizontal) self.button_box.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel | QtWidgets.QDialogButtonBox.Ok) self.vertical_layout.addWidget(self.button_box) self.vertical_layout.setStretch(2, 1) # ------------------------------------------------ # Default values self.target_entity_type_combo_box.addItems( ['Task', 'Asset', 'Shot', 'Sequence']) self.name_line_edit.set_invalid() # Empty field is not valid self.path_line_edit.setText( '$REPO{{project.repository.code}}/{{project.code}}/' '{%- for parent_task in parent_tasks -%}{{parent_task.nice_name}}' '/{%- endfor -%}') self.filename_line_edit.setText( '{{version.nice_name}}_v{{"%03d"|format(version.version_number)}}') # ------------------------------------------------ # Disable Fields if self.mode == 'Update': self.target_entity_type_combo_box.setEnabled(False) # ------------------------------------------------ # Signals # Name QtCore.QObject.connect(self.name_line_edit, QtCore.SIGNAL('textChanged(QString)'), self.name_line_edit_changed) # Button box QtCore.QObject.connect(self.button_box, QtCore.SIGNAL("accepted()"), self.accept) QtCore.QObject.connect(self.button_box, QtCore.SIGNAL("rejected()"), self.reject) def name_line_edit_changed(self, text): """runs when the name_line_edit text has changed """ if re.findall(r'[^a-zA-Z0-9\-_ ]+', text): self.name_line_edit.set_invalid('Invalid character') else: if text == '': self.name_line_edit.set_invalid('Enter a name') else: self.name_line_edit.set_valid() def _fill_ui_with_filename_template(self, filename_template): """Fills the UI with the given filename template :param filename_template: A Stalker FilenameTemplate instance :return: """ if False: from stalker import FilenameTemplate assert isinstance(filename_template, FilenameTemplate) self.name_line_edit.setText(filename_template.name) self.path_line_edit.setText(filename_template.path) self.filename_line_edit.setText(filename_template.filename) def accept(self): """the overridden accept method """ target_entity_type = self.target_entity_type_combo_box.currentText() if not self.name_line_edit.is_valid: QtWidgets.QMessageBox.critical(self, 'Error', 'Please fix <b>name</b> field!') return name = self.name_line_edit.text() path = self.path_line_edit.text() if path == '': QtWidgets.QMessageBox.critical(self, 'Error', 'Please fix <b>path</b> field!') return filename = self.filename_line_edit.text() if path == '': QtWidgets.QMessageBox.critical( self, 'Error', 'Please fix <b>filename</b> field!') return logged_in_user = self.get_logged_in_user() from stalker.db.session import DBSession if self.mode == 'Create': try: from stalker import FilenameTemplate # create a new FilenameTemplate ft = FilenameTemplate(name=name, path=path, filename=filename, target_entity_type=target_entity_type, created_by=logged_in_user) self.filename_template = ft DBSession.add(ft) DBSession.commit() except Exception as e: DBSession.rollback() QtWidgets.QMessageBox.critical(self, 'Error', str(e)) return elif self.mode == 'Update': try: self.filename_template.name = name self.filename_template.path = path self.filename_template.filename = filename self.filename_template.updated_by = logged_in_user DBSession.add(self.filename_template) DBSession.commit() except Exception as e: DBSession.rollback() QtWidgets.QMessageBox.critical(self, 'Error', str(e)) return super(MainDialog, self).accept()
class MainDialog(QtWidgets.QDialog, project_dialog_UI.Ui_Dialog, AnimaDialogBase): """The Project Dialog """ def __init__(self, parent=None, project=None): logger.debug("initializing the interface") super(MainDialog, self).__init__(parent) self.setupUi(self) # store the logged in user self.logged_in_user = None self.project = project self.mode = 'Create' if self.project: self.mode = 'Update' self.dialog_label.setText('%s Project' % self.mode) from anima.ui.widgets import ValidatedLineEdit # add name_lineEdit self.name_lineEdit = ValidatedLineEdit( message_field=self.name_validator_label) self.name_fields_verticalLayout.insertWidget(0, self.name_lineEdit) # add code_lineEdit self.code_lineEdit = ValidatedLineEdit( message_field=self.code_validator_label) self.code_fields_verticalLayout.insertWidget(0, self.code_lineEdit) self._setup_signals() self._set_defaults() if self.project: self.fill_ui_with_project(self.project) def show(self): """overridden show method """ logger.debug('MainDialog.show is started') self.logged_in_user = self.get_logged_in_user() if not self.logged_in_user: self.reject() return_val = None else: return_val = super(MainDialog, self).show() logger.debug('MainDialog.show is finished') return return_val def _setup_signals(self): """creates the signals """ # name_lineEdit is changed QtCore.QObject.connect(self.name_lineEdit, QtCore.SIGNAL('textChanged(QString)'), self.name_line_edit_changed) # code_lineEdit is changed QtCore.QObject.connect(self.code_lineEdit, QtCore.SIGNAL('textChanged(QString)'), self.code_line_edit_changed) # create_image_format_pushButton QtCore.QObject.connect(self.create_image_format_pushButton, QtCore.SIGNAL('clicked()'), self.create_image_format_push_button_clicked) # update_image_format_pushButton QtCore.QObject.connect(self.update_image_format_pushButton, QtCore.SIGNAL('clicked()'), self.update_image_format_push_button_clicked) # create_repository_pushButton QtCore.QObject.connect(self.create_repository_pushButton, QtCore.SIGNAL('clicked()'), self.create_repository_push_button_clicked) # update_repository_pushButton QtCore.QObject.connect(self.update_repository_pushButton, QtCore.SIGNAL('clicked()'), self.update_repository_push_button_clicked) # create_structure_pushButton QtCore.QObject.connect(self.create_structure_pushButton, QtCore.SIGNAL('clicked()'), self.create_structure_push_button_clicked) # update_structure_pushButton QtCore.QObject.connect(self.update_structure_pushButton, QtCore.SIGNAL('clicked()'), self.update_structure_push_button_clicked) def _set_defaults(self): """setup the default values """ # set size policies # self.name_lineEdit self.type_comboBox.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed) self.status_comboBox.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed) self.client_comboBox.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed) self.agency_comboBox.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed) self.production_company_comboBox.setSizePolicy( QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed) # invalidate the name and code fields by default self.name_lineEdit.set_invalid('Enter a name') self.code_lineEdit.set_invalid('Enter a code') # update type field from stalker import Type from stalker.db.session import DBSession project_types = \ DBSession.query(Type.id, Type.name)\ .filter(Type.target_entity_type == 'Project')\ .order_by(Type.name)\ .all() self.type_comboBox.clear() self.type_comboBox.addItem('', -1) for type_id, type_name in project_types: self.type_comboBox.addItem(type_name, type_id) self.fill_image_format_combo_box() self.fill_repository_combo_box() self.fill_structure_combo_box() # fill status field sql = """select "SimpleEntities".id, "SimpleEntities".name from "Statuses" join "SimpleEntities" on "Statuses".id = "SimpleEntities".id join "StatusList_Statuses" on "Statuses".id = "StatusList_Statuses".status_id join "StatusLists" on "StatusLists".id = "StatusList_Statuses".status_list_id where "StatusLists".target_entity_type = 'Project'""" all_project_statuses = \ DBSession.connection().execute(sql).fetchall() for st_id, st_name in all_project_statuses: self.status_comboBox.addItem(st_name, st_id) def fill_repository_combo_box(self): """fills the repository_comboBox with Repository instances """ # fill the repository field from stalker import Repository from stalker.db.session import DBSession all_repos = DBSession \ .query(Repository.id, Repository.name) \ .order_by(Repository.name) \ .all() self.repository_comboBox.clear() for repo_id, repo_name in all_repos: self.repository_comboBox.addItem(repo_name, repo_id) def fill_structure_combo_box(self): """fills the structure_comboBox with Structure instances """ # fill the structure field from stalker import Structure from stalker.db.session import DBSession all_structures = DBSession \ .query(Structure.id, Structure.name) \ .order_by(Structure.name) \ .all() self.structure_comboBox.clear() for st_id, st_name in all_structures: self.structure_comboBox.addItem(st_name, st_id) def fill_image_format_combo_box(self): """fills the image_format_comboBox """ # fill the image format field from stalker import ImageFormat from stalker.db.session import DBSession all_image_formats = DBSession \ .query(ImageFormat.id, ImageFormat.name, ImageFormat.width, ImageFormat.height) \ .order_by(ImageFormat.name) \ .all() self.image_format_comboBox.clear() for imf_id, imf_name, imf_width, imf_height in all_image_formats: imf_text = '%s (%s x %s)' % (imf_name, imf_width, imf_height) self.image_format_comboBox.addItem(imf_text, imf_id) def name_line_edit_changed(self, text): """runs when the name_lineEdit text has changed """ if re.findall(r'[^a-zA-Z0-9\-_ ]+', text): self.name_lineEdit.set_invalid('Invalid character') else: if text == '': self.name_lineEdit.set_invalid('Enter a name') else: self.name_lineEdit.set_valid() # update code field also formatted_text = re.sub(r'[^A-Z0-9_]+', '', text) self.code_lineEdit.setText(formatted_text) def code_line_edit_changed(self, text): """runs when the code_lineEdit text has changed """ if re.findall(r'[^a-zA-Z0-9_]+', text): self.code_lineEdit.set_invalid('Invalid character') else: if text == '': self.code_lineEdit.set_invalid('Enter a code') else: if len(text) > 16: self.code_lineEdit.set_invalid('Code is too long (>16)') else: self.code_lineEdit.set_valid() def fill_ui_with_project(self, project): """fills the UI fields with the given project :param project: A Stalker Project instance :return: """ if not project: return self.project = project self.name_lineEdit.setText(project.name) self.name_lineEdit.set_valid() self.code_lineEdit.setText(project.code) self.code_lineEdit.set_valid() if project.type: index = self.type_comboBox.findData(project.type.id) if index: self.type_comboBox.setCurrentIndex(index) if project.image_format: index = self.image_format_comboBox.findData( project.image_format.id) if index: self.image_format_comboBox.setCurrentIndex(index) self.fps_spinBox.setValue(project.fps) if project.repository: # TODO: allow multiple repositories index = self.repository_comboBox.findText(project.repository.name, QtCore.Qt.MatchExactly) if index: self.repository_comboBox.setCurrentIndex(index) if project.structure: index = self.structure_comboBox.findText(project.structure.name, QtCore.Qt.MatchExactly) if index: self.repository_comboBox.setCurrentIndex(index) if project.status: index = self.status_comboBox.findText(project.status.name, QtCore.Qt.MatchExactly) if index: self.status_comboBox.setCurrentIndex(index) def create_image_format_push_button_clicked(self): """runs when create_image_format_pushButton is clicked """ try: # PySide accepted = QtWidgets.QDialog.DialogCode.Accepted except AttributeError: # PyQt4 accepted = QtWidgets.QDialog.Accepted from anima.ui import image_format_dialog create_image_format_dialog = \ image_format_dialog.MainDialog(parent=self) create_image_format_dialog.exec_() result = create_image_format_dialog.result() if result == accepted: image_format = create_image_format_dialog.image_format # select the created image format self.fill_image_format_combo_box() index = self.image_format_comboBox.findData(image_format.id) if index: self.image_format_comboBox.setCurrentIndex(index) create_image_format_dialog.deleteLater() def update_image_format_push_button_clicked(self): """runs when update_image_format_pushButton is clicked """ try: # PySide accepted = QtWidgets.QDialog.DialogCode.Accepted except AttributeError: # PyQt4 accepted = QtWidgets.QDialog.Accepted image_format = self.get_current_image_format() from anima.ui import image_format_dialog update_image_format_dialog = \ image_format_dialog.MainDialog(parent=self, image_format=image_format) update_image_format_dialog.exec_() result = update_image_format_dialog.result() if result == accepted: image_format = update_image_format_dialog.image_format # select the created image format self.fill_image_format_combo_box() index = self.image_format_comboBox.findData(image_format.id) if index: self.image_format_comboBox.setCurrentIndex(index) update_image_format_dialog.deleteLater() def create_repository_push_button_clicked(self): """runs when create_repository_pushButton is clicked """ try: # PySide accepted = QtWidgets.QDialog.DialogCode.Accepted except AttributeError: # PyQt4 accepted = QtWidgets.QDialog.Accepted from anima.ui import repository_dialog create_repository_dialog = \ repository_dialog.MainDialog(parent=self) create_repository_dialog.exec_() result = create_repository_dialog.result() if result == accepted: repository = create_repository_dialog.repository # select the created repository self.fill_repository_combo_box() index = self.repository_comboBox.findData(repository.id) if index: self.repository_comboBox.setCurrentIndex(index) create_repository_dialog.deleteLater() def update_repository_push_button_clicked(self): """runs when update_repository_pushButton is clicked """ try: # PySide accepted = QtWidgets.QDialog.DialogCode.Accepted except AttributeError: # PyQt4 accepted = QtWidgets.QDialog.Accepted repo = self.get_current_repository() if not repo: return from anima.ui import repository_dialog update_repository_dialog = \ repository_dialog.MainDialog(parent=self, repository=repo) update_repository_dialog.exec_() result = update_repository_dialog.result() if result == accepted: repository = update_repository_dialog.repository # select the created repository self.fill_repository_combo_box() index = self.repository_comboBox.findData(repository.id) if index: self.repository_comboBox.setCurrentIndex(index) update_repository_dialog.deleteLater() def create_structure_push_button_clicked(self): """runs when create_structure_pushButton is clicked """ try: # PySide accepted = QtWidgets.QDialog.DialogCode.Accepted except AttributeError: # PyQt4 accepted = QtWidgets.QDialog.Accepted from anima.ui import structure_dialog create_structure_dialog = \ structure_dialog.MainDialog(parent=self) create_structure_dialog.exec_() result = create_structure_dialog.result() if result == accepted: structure = create_structure_dialog.structure # select the created repository self.fill_structure_combo_box() index = self.structure_comboBox.findData(structure.id) if index: self.structure_comboBox.setCurrentIndex(index) create_structure_dialog.deleteLater() def update_structure_push_button_clicked(self): """runs when update_structure_pushButton is clicked """ try: # PySide accepted = QtWidgets.QDialog.DialogCode.Accepted except AttributeError: # PyQt4 accepted = QtWidgets.QDialog.Accepted structure = self.get_current_structure() if not structure: return from anima.ui import structure_dialog update_structure_dialog = \ structure_dialog.MainDialog(parent=self, structure=structure) update_structure_dialog.exec_() result = update_structure_dialog.result() if result == accepted: structure = update_structure_dialog.structure # select the created repository self.fill_structure_combo_box() index = self.structure_comboBox.findData(structure.id) if index: self.structure_comboBox.setCurrentIndex(index) update_structure_dialog.deleteLater() def get_current_image_format(self): """returns the currently selected image format instance from the UI """ from stalker import ImageFormat index = self.image_format_comboBox.currentIndex() image_format_id = self.image_format_comboBox.itemData(index) image_format = ImageFormat.query.get(image_format_id) return image_format def get_current_repository(self): """returns the currently selected repository instance from the UI """ from stalker import Repository index = self.repository_comboBox.currentIndex() repo_id = self.repository_comboBox.itemData(index) repo = Repository.query.get(repo_id) return repo def get_current_structure(self): """returns the currently selected structure instance from the UI """ from stalker import Structure index = self.structure_comboBox.currentIndex() structure_id = self.structure_comboBox.itemData(index) structure = Structure.query.get(structure_id) return structure def accept(self): """create/update the project """ # Name if not self.name_lineEdit.is_valid: QtWidgets.QMessageBox.critical(self, 'Error', 'Please fix <b>name</b> field!') return name = self.name_lineEdit.text() # Code if not self.code_lineEdit.is_valid: QtWidgets.QMessageBox.critical(self, 'Error', 'Please fix <b>code</b> field!') return code = self.code_lineEdit.text() # Type from stalker import Type index = self.type_comboBox.currentIndex() type_id = self.type_comboBox.itemData(index) type = Type.query.get(type_id) # None type is ok # Image Format image_format = self.get_current_image_format() if not image_format: QtWidgets.QMessageBox.critical( self, 'Error', 'Please select an valid <b>Image Format</b>!') return # FPS fps = self.fps_spinBox.value() # Repository repo = self.get_current_repository() if not repo: QtWidgets.QMessageBox.critical( self, 'Error', 'Please select an valid <b>Repository</b>!') return # Structure structure = self.get_current_structure() if not structure: QtWidgets.QMessageBox.critical( self, 'Error', 'Please select an valid <b>Structure</b>!') return # Status from stalker import Status index = self.status_comboBox.currentIndex() status_id = self.status_comboBox.itemData(index) status = Status.query.get(status_id) if not status: QtWidgets.QMessageBox.critical( self, 'Error', 'Please select an valid <b>Status</b>!') return # TODO: Add Client Data fields (which I don't care for now) logged_in_user = self.get_logged_in_user() # create or update project from stalker.db.session import DBSession if self.mode == 'Create': # create a new project from stalker import Project new_project = Project(name=name, code=code, type=type, repositories=[repo], structure=structure, image_format=image_format, fps=fps, created_by=logged_in_user) DBSession.add(new_project) try: DBSession.commit() except Exception as e: DBSession.rollback() QtWidgets.QMessageBox.critical(self, 'Error', str(e)) return else: # update the project self.project.updated_by = logged_in_user self.project.name = name self.project.code = code self.project.type = type self.project.repositories = [repo] self.project.structure = structure self.project.image_format = image_format self.project.fps = fps DBSession.add(self.project) try: DBSession.commit() except Exception as e: DBSession.rollback() QtWidgets.QMessageBox.critical(self, 'Error', str(e)) return super(MainDialog, self).accept()
class MainDialog(QtWidgets.QDialog, AnimaDialogBase): """The ImageFormat Dialog """ def __init__(self, parent=None, image_format=None): super(MainDialog, self).__init__(parent=parent) self.vertical_layout = None self.dialog_label = None self.line = None self.form_layout = None self.name_fields_vertical_layout = None self.name_validator_label = None self.width_height_label = None self.horizontal_layout = None self.width_spin_box = None self.label = None self.height_spin_box = None self.pixel_aspect_label = None self.pixel_aspect_double_spin_box = None self.name_label = None self.button_box = None self.setup_ui() self.image_format = image_format self.mode = 'Create' if self.image_format: self.mode = 'Update' self.dialog_label.setText('%s Image Format' % self.mode) # create name_lineEdit from anima.ui.widgets import ValidatedLineEdit self.name_line_edit = ValidatedLineEdit( message_field=self.name_validator_label ) self.name_line_edit.setPlaceholderText('Enter Name') self.name_fields_vertical_layout.insertWidget( 0, self.name_line_edit ) self._setup_signals() self._set_defaults() if self.image_format: self.fill_ui_with_image_format(self.image_format) def setup_ui(self): self.resize(328, 184) self.vertical_layout = QtWidgets.QVBoxLayout(self) self.dialog_label = QtWidgets.QLabel(self) self.dialog_label.setStyleSheet("color: rgb(71, 143, 202);\n" "font: 18pt;") self.vertical_layout.addWidget(self.dialog_label) self.line = QtWidgets.QFrame(self) self.line.setFrameShape(QtWidgets.QFrame.HLine) self.line.setFrameShadow(QtWidgets.QFrame.Sunken) self.vertical_layout.addWidget(self.line) self.form_layout = QtWidgets.QFormLayout() self.form_layout.setLabelAlignment( QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter ) self.name_fields_vertical_layout = QtWidgets.QVBoxLayout() self.name_validator_label = QtWidgets.QLabel(self) self.name_validator_label.setStyleSheet("color: rgb(255, 0, 0);") self.name_fields_vertical_layout.addWidget( self.name_validator_label) self.form_layout.setLayout( 0, QtWidgets.QFormLayout.FieldRole, self.name_fields_vertical_layout ) self.width_height_label = QtWidgets.QLabel(self) self.form_layout.setWidget( 1, QtWidgets.QFormLayout.LabelRole, self.width_height_label ) self.horizontal_layout = QtWidgets.QHBoxLayout() self.width_spin_box = QtWidgets.QSpinBox(self) self.width_spin_box.setMaximum(99999) self.horizontal_layout.addWidget(self.width_spin_box) self.label = QtWidgets.QLabel(self) self.horizontal_layout.addWidget(self.label) self.height_spin_box = QtWidgets.QSpinBox(self) self.height_spin_box.setMaximum(99999) self.horizontal_layout.addWidget(self.height_spin_box) self.horizontal_layout.setStretch(0, 1) self.horizontal_layout.setStretch(2, 1) self.form_layout.setLayout( 1, QtWidgets.QFormLayout.FieldRole, self.horizontal_layout ) self.pixel_aspect_label = QtWidgets.QLabel(self) self.form_layout.setWidget( 2, QtWidgets.QFormLayout.LabelRole, self.pixel_aspect_label ) self.pixel_aspect_double_spin_box = QtWidgets.QDoubleSpinBox(self) self.pixel_aspect_double_spin_box.setProperty("value", 1.0) self.form_layout.setWidget( 2, QtWidgets.QFormLayout.FieldRole, self.pixel_aspect_double_spin_box ) self.name_label = QtWidgets.QLabel(self) self.form_layout.setWidget( 0, QtWidgets.QFormLayout.LabelRole, self.name_label ) self.vertical_layout.addLayout(self.form_layout) self.button_box = QtWidgets.QDialogButtonBox(self) self.button_box.setOrientation(QtCore.Qt.Horizontal) self.button_box.setStandardButtons( QtWidgets.QDialogButtonBox.Cancel | QtWidgets.QDialogButtonBox.Ok) self.vertical_layout.addWidget(self.button_box) self.vertical_layout.setStretch(2, 1) QtCore.QObject.connect( self.button_box, QtCore.SIGNAL("accepted()"), self.accept ) QtCore.QObject.connect( self.button_box, QtCore.SIGNAL("rejected()"), self.reject ) QtCore.QMetaObject.connectSlotsByName(self) self.setWindowTitle("Image Format Dialog") self.dialog_label.setText("Create Image Format") self.name_validator_label.setText("Validator Message") self.width_height_label.setText("Width x Height") self.label.setText("x") self.pixel_aspect_label.setText("Pixel Aspect") self.name_label.setText("Name") def _setup_signals(self): """create the signals """ # name_lineEdit is changed QtCore.QObject.connect( self.name_line_edit, QtCore.SIGNAL('textChanged(QString)'), self.name_line_edit_changed ) def _set_defaults(self): """sets the default values """ pass def name_line_edit_changed(self, text): """runs when the name_lineEdit text has changed """ if re.findall(r'[^a-zA-Z0-9\-_ ]+', text): self.name_line_edit.set_invalid('Invalid character') else: if text == '': self.name_line_edit.set_invalid('Enter a name') else: self.name_line_edit.set_valid() def fill_ui_with_image_format(self, image_format): """fills the UI with the given image_format :param image_format: A Stalker ImageFormat instance :return: """ if False: from stalker import ImageFormat assert isinstance(image_format, ImageFormat) self.image_format = image_format self.name_line_edit.setText(self.image_format.name) self.name_line_edit.set_valid() self.width_spin_box.setValue(self.image_format.width) self.height_spin_box.setValue(self.image_format.height) self.pixel_aspect_double_spin_box.setValue( self.image_format.pixel_aspect ) def accept(self): """overridden accept method """ if not self.name_line_edit.is_valid: QtWidgets.QMessageBox.critical( self, 'Error', 'Please fix <b>name</b> field!' ) return name = self.name_line_edit.text() width = self.width_spin_box.value() height = self.height_spin_box.value() pixel_aspect = self.pixel_aspect_double_spin_box.value() from stalker import ImageFormat from stalker.db.session import DBSession logged_in_user = self.get_logged_in_user() if self.mode == 'Create': # Create a new Image Format try: imf = ImageFormat( name=name, width=width, height=height, pixel_aspect=pixel_aspect, created_by=logged_in_user ) self.image_format = imf DBSession.add(imf) DBSession.commit() except Exception as e: DBSession.rollback() QtWidgets.QMessageBox.critical( self, 'Error', str(e) ) return elif self.mode == 'Update': # Update the image format try: self.image_format.name = name self.image_format.width = width self.image_format.height = height self.image_format.pixel_aspect = pixel_aspect self.image_format.updated_by = logged_in_user DBSession.add(self.image_format) DBSession.commit() except Exception as e: DBSession.rollback() QtWidgets.QMessageBox.critical( self, 'Error', str(e) ) return super(MainDialog, self).accept()
class MainDialog(QtWidgets.QDialog, structure_dialog_UI.Ui_Dialog, AnimaDialogBase): """The structure Dialog """ def __init__(self, parent=None, structure=None): super(MainDialog, self).__init__(parent=parent) self.setupUi(self) self.structure = structure self.mode = 'Create' if self.structure: self.mode = 'Update' self.dialog_label.setText('%s Structure' % self.mode) # create name_line_edit from anima.ui.widgets import ValidatedLineEdit self.name_line_edit = ValidatedLineEdit( message_field=self.name_validator_label ) self.name_line_edit.setPlaceholderText('Enter Name') self.name_fields_verticalLayout.insertWidget( 0, self.name_line_edit ) # create DoubleListWidget from anima.ui.widgets import DoubleListWidget self.filename_templates_double_list_widget = DoubleListWidget( dialog=self, parent_layout=self.filename_template_fields_verticalLayout, primary_label_text='Templates From DB', secondary_label_text='Selected Templates' ) # set the tooltip self.filename_templates_double_list_widget\ .primary_list_widget.setToolTip( "Right Click to Create/Update FilenameTemplates" ) self.filename_templates_double_list_widget\ .secondary_list_widget.setToolTip( "Right Click to Create/Update FilenameTemplates" ) self._setup_signals() self._set_defaults() if self.structure: self.fill_ui_with_structure(self.structure) def _setup_signals(self): """create the signals """ # name_line_edit is changed QtCore.QObject.connect( self.name_line_edit, QtCore.SIGNAL('textChanged(QString)'), self.name_line_edit_changed ) # add context menu for primary items in DoubleListWidget self.filename_templates_double_list_widget\ .primary_list_widget\ .setContextMenuPolicy(QtCore.Qt.CustomContextMenu) QtCore.QObject.connect( self.filename_templates_double_list_widget.primary_list_widget, QtCore.SIGNAL("customContextMenuRequested(const QPoint&)"), self.show_primary_filename_template_context_menu ) # add context menu for secondary items in DoubleListWidget self.filename_templates_double_list_widget\ .secondary_list_widget\ .setContextMenuPolicy(QtCore.Qt.CustomContextMenu) QtCore.QObject.connect( self.filename_templates_double_list_widget.secondary_list_widget, QtCore.SIGNAL("customContextMenuRequested(const QPoint&)"), self.show_secondary_filename_template_context_menu ) def _set_defaults(self): """sets the default values """ # fill filename_templates_from_db_listWidget # add all the other filename templates from the database from stalker import FilenameTemplate fts = FilenameTemplate.query.all() self.filename_templates_double_list_widget.clear() self.filename_templates_double_list_widget.add_primary_items( map( lambda x: '%s (%s) (%s)' % (x.name, x.target_entity_type, x.id), fts ) ) def name_line_edit_changed(self, text): """runs when the name_line_edit text has changed """ if re.findall(r'[^a-zA-Z0-9\-_ ]+', text): self.name_line_edit.set_invalid('Invalid character') else: if text == '': self.name_line_edit.set_invalid('Enter a name') else: self.name_line_edit.set_valid() def fill_ui_with_structure(self, structure): """fills the UI with the given structure :param structure: A Stalker ImageFormat instance :return: """ if False: from stalker import Structure assert isinstance(structure, Structure) self.structure = structure self.name_line_edit.setText(self.structure.name) self.name_line_edit.set_valid() self.custom_template_plainTextEdit.setPlainText( self.structure.custom_template ) # add the structure templates to the secondary list of the double list self.filename_templates_double_list_widget.clear() self.filename_templates_double_list_widget.add_secondary_items( map( lambda x: '%s (%s) (%s)' % (x.name, x.target_entity_type, x.id), self.structure.templates ) ) # add all the other filename templates from the database from stalker import FilenameTemplate fts = FilenameTemplate.query\ .filter( ~FilenameTemplate.id.in_( map(lambda x: x.id, self.structure.templates) ) )\ .all() self.filename_templates_double_list_widget.add_primary_items( map( lambda x: '%s (%s) (%s)' % (x.name, x.target_entity_type, x.id), fts ) ) def show_primary_filename_template_context_menu(self, position): """shows the custom context menu for primary list widget :param position: :return: """ self.show_filename_template_context_menu( self.filename_templates_double_list_widget.primary_list_widget, position ) def show_secondary_filename_template_context_menu(self, position): """shows the custom context menu for secondary list widget :param position: :return: """ self.show_filename_template_context_menu( self.filename_templates_double_list_widget.secondary_list_widget, position ) def show_filename_template_context_menu(self, list_widget, position): """shows a context menu for the given list_widget :param list_widget: QListWidget instance :param position: the mouse click position :return: """ item = list_widget.itemAt(position) menu = QtWidgets.QMenu() menu.addAction('Create FilenameTemplate...') if item: menu.addAction('Update FilenameTemplate...') global_position = list_widget.mapToGlobal(position) selected_item = menu.exec_(global_position) try: # PySide accepted = QtWidgets.QDialog.DialogCode.Accepted except AttributeError: # PyQt4 accepted = QtWidgets.QDialog.Accepted if selected_item: choice = selected_item.text() if choice == 'Create FilenameTemplate...': from anima.ui import filename_template_dialog create_filename_template_dialog = \ filename_template_dialog.MainDialog(parent=self) create_filename_template_dialog.exec_() if create_filename_template_dialog.result() == accepted: ft = create_filename_template_dialog.filename_template list_widget.addItem( '%s (%s) (%s)' % (ft.name, ft.target_entity_type, ft.id) ) create_filename_template_dialog.deleteLater() elif choice == 'Update FilenameTemplate...': ft_id = int(item.text().split('(')[-1].split(')')[0]) if not ft_id: return from stalker import FilenameTemplate ft = FilenameTemplate.query.get(ft_id) from anima.ui import filename_template_dialog update_filename_template_dialog = \ filename_template_dialog.MainDialog( parent=self, filename_template=ft ) try: update_filename_template_dialog.exec_() if update_filename_template_dialog.result() == accepted: # update the text of the item ft = update_filename_template_dialog.filename_template item.setText( '%s (%s) (%s)' % (ft.name, ft.target_entity_type, ft.id) ) update_filename_template_dialog.deleteLater() except Exception as e: QtWidgets.QMessageBox.warning( self, "Error", str(e) ) return def accept(self): """overridden accept method """ if not self.name_line_edit.is_valid: QtWidgets.QMessageBox.critical( self, 'Error', 'Please fix <b>name</b> field!' ) return name = self.name_line_edit.text() custom_template = self.custom_template_plainTextEdit.toPlainText() filename_template_items = \ self.filename_templates_double_list_widget.secondary_items() filename_template_ids = [] for item in filename_template_items: filename_template_id = \ int(item.text().split('(')[-1].split(')')[0]) filename_template_ids.append(filename_template_id) from stalker import FilenameTemplate filename_templates = FilenameTemplate.query\ .filter(FilenameTemplate.id.in_(filename_template_ids)).all() from stalker import Structure from stalker.db.session import DBSession logged_in_user = self.get_logged_in_user() if self.mode == 'Create': # Create a new Structure try: structure = Structure( name=name, templates=filename_templates, custom_template=custom_template, created_by=logged_in_user ) self.structure = structure DBSession.add(structure) DBSession.commit() except Exception as e: DBSession.rollback() QtWidgets.QMessageBox.critical( self, 'Error', str(e) ) return elif self.mode == 'Update': # Update the structure try: self.structure.name = name self.structure.templates = filename_templates self.structure.custom_template = custom_template self.structure.updated_by = logged_in_user DBSession.add(self.structure) DBSession.commit() except Exception as e: DBSession.rollback() QtWidgets.QMessageBox.critical( self, 'Error', str(e) ) return super(MainDialog, self).accept()
class MainDialog(QtWidgets.QDialog, AnimaDialogBase): """The Repository Dialog """ def __init__(self, parent=None, repository=None): super(MainDialog, self).__init__(parent=parent) self._setup_ui() self.repository = repository self.mode = 'Create' if self.repository: self.mode = 'Update' self.dialog_label.setText('%s Repository' % self.mode) self._setup_signals() self._set_defaults() if self.repository: self.fill_ui_with_repository(self.repository) def _setup_ui(self): self.setObjectName("Dialog") self.resize(502, 220) self.vertical_layout = QtWidgets.QVBoxLayout(self) self.vertical_layout.setObjectName("verticalLayout") self.dialog_label = QtWidgets.QLabel(self) self.dialog_label.setStyleSheet( "color: rgb(71, 143, 202);\n" "font: 18pt;" ) self.dialog_label.setObjectName("dialog_label") self.dialog_label.setText("Create Repository") self.vertical_layout.addWidget(self.dialog_label) self.line = QtWidgets.QFrame(self) self.line.setFrameShape(QtWidgets.QFrame.HLine) self.line.setFrameShadow(QtWidgets.QFrame.Sunken) self.line.setObjectName("line") self.vertical_layout.addWidget(self.line) self.form_layout = QtWidgets.QFormLayout() self.form_layout.setLabelAlignment( QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter ) self.form_layout.setObjectName("form_layout") row_number = 0 # ------------- # Name # Label self.name_label = QtWidgets.QLabel(self) self.name_label.setObjectName("name_label") self.name_label.setText("Name") self.form_layout.setWidget(0, QtWidgets.QFormLayout.LabelRole, self.name_label) # Field self.name_fields_vertical_layout = QtWidgets.QVBoxLayout() self.name_fields_vertical_layout.setObjectName("name_fields_verticalLayout") self.name_validator_label = QtWidgets.QLabel(self) self.name_validator_label.setStyleSheet("color: rgb(255, 0, 0);") self.name_validator_label.setObjectName("name_validator_label") self.name_fields_vertical_layout.addWidget(self.name_validator_label) self.form_layout.setLayout( row_number, QtWidgets.QFormLayout.FieldRole, self.name_fields_vertical_layout ) self.name_validator_label.setText("Validator Message") # create name_line_edit from anima.ui.widgets import ValidatedLineEdit self.name_line_edit = ValidatedLineEdit( message_field=self.name_validator_label ) self.name_line_edit.setPlaceholderText('Enter Name') self.name_fields_vertical_layout.insertWidget( 0, self.name_line_edit ) row_number += 1 # ------------- # Code # Label self.code_label = QtWidgets.QLabel(self) self.code_label.setText("Code") self.code_label.setObjectName("code_label") self.form_layout.setWidget( row_number, QtWidgets.QFormLayout.LabelRole, self.code_label ) # Field self.code_fields_vertical_layout = QtWidgets.QVBoxLayout() self.code_fields_vertical_layout.setObjectName("code_fields_verticalLayout") self.code_validator_label = QtWidgets.QLabel(self) self.code_validator_label.setStyleSheet("color: rgb(255, 0, 0);") self.code_validator_label.setObjectName("code_validator_label") self.code_fields_vertical_layout.addWidget(self.code_validator_label) self.form_layout.setLayout( row_number, QtWidgets.QFormLayout.FieldRole, self.code_fields_vertical_layout ) # create code_line_edit from anima.ui.widgets import ValidatedLineEdit self.code_line_edit = ValidatedLineEdit( message_field=self.code_validator_label ) self.code_line_edit.setPlaceholderText('Enter Code') self.code_fields_vertical_layout.insertWidget( 0, self.code_line_edit ) row_number += 1 # ------------- # Windows Path # Label self.windows_path_label = QtWidgets.QLabel(self) self.windows_path_label.setObjectName("windows_path_label") self.form_layout.setWidget( row_number, QtWidgets.QFormLayout.LabelRole, self.windows_path_label ) self.windows_path_label.setText("Windows Path") # Field self.windows_path_line_edit = QtWidgets.QLineEdit(self) self.windows_path_line_edit.setObjectName("windows_path_lineEdit") self.form_layout.setWidget( row_number, QtWidgets.QFormLayout.FieldRole, self.windows_path_line_edit ) row_number += 1 # ------------- # Linux Path # Label self.linux_label = QtWidgets.QLabel(self) self.linux_label.setObjectName("linux_label") self.linux_label.setText("Linux Path") self.form_layout.setWidget( row_number, QtWidgets.QFormLayout.LabelRole, self.linux_label ) # Field self.linux_path_line_edit = QtWidgets.QLineEdit(self) self.linux_path_line_edit.setObjectName("linux_path_lineEdit") self.form_layout.setWidget( row_number, QtWidgets.QFormLayout.FieldRole, self.linux_path_line_edit ) row_number += 1 # ------------- # OSX Path # Label self.osx_path_label = QtWidgets.QLabel(self) self.osx_path_label.setObjectName("osx_path_label") self.osx_path_label.setText("OSX Path") self.form_layout.setWidget( row_number, QtWidgets.QFormLayout.LabelRole, self.osx_path_label ) # Field self.osx_path_line_edit = QtWidgets.QLineEdit(self) self.osx_path_line_edit.setObjectName("osx_path_lineEdit") self.form_layout.setWidget( row_number, QtWidgets.QFormLayout.FieldRole, self.osx_path_line_edit ) self.vertical_layout.addLayout(self.form_layout) # Button Box self.button_box = QtWidgets.QDialogButtonBox(self) self.button_box.setOrientation(QtCore.Qt.Horizontal) self.button_box.setStandardButtons( QtWidgets.QDialogButtonBox.Cancel | QtWidgets.QDialogButtonBox.Ok ) self.button_box.setObjectName("button_box") self.vertical_layout.addWidget(self.button_box) self.vertical_layout.setStretch(2, 1) QtCore.QObject.connect( self.button_box, QtCore.SIGNAL("accepted()"), self.accept ) QtCore.QObject.connect( self.button_box, QtCore.SIGNAL("rejected()"), self.reject ) QtCore.QMetaObject.connectSlotsByName(self) def _setup_signals(self): """create the signals """ # name_line_edit is changed QtCore.QObject.connect( self.name_line_edit, QtCore.SIGNAL('textChanged(QString)'), self.name_line_edit_changed ) def _set_defaults(self): """sets the default values """ pass def name_line_edit_changed(self, text): """runs when the name_line_edit text has changed """ if re.findall(r'[^a-zA-Z0-9\-_ ]+', text): self.name_line_edit.set_invalid('Invalid character') else: if text == '': self.name_line_edit.set_invalid('Enter a name') else: self.name_line_edit.set_valid() def fill_ui_with_repository(self, repository): """fills the UI with the given repository :param repository: A Stalker ImageFormat instance :return: """ if False: from stalker import Repository assert isinstance(repository, Repository) self.repository = repository self.name_line_edit.setText(self.repository.name) self.name_line_edit.set_valid() self.code_line_edit.setText(self.repository.code) self.code_line_edit.set_valid() self.windows_path_line_edit.setText(self.repository.windows_path) self.linux_path_line_edit.setText(self.repository.linux_path) self.osx_path_line_edit.setText(self.repository.osx_path) def accept(self): """overridden accept method """ if not self.name_line_edit.is_valid: QtWidgets.QMessageBox.critical( self, 'Error', 'Please fix <b>name</b> field!' ) return name = self.name_line_edit.text() code = self.code_line_edit.text() windows_path = self.windows_path_line_edit.text() linux_path = self.linux_path_line_edit.text() osx_path = self.osx_path_line_edit.text() from stalker import Repository from stalker.db.session import DBSession logged_in_user = self.get_logged_in_user() if self.mode == 'Create': # Create a new Repository try: repo = Repository( name=name, code=code, windows_path=windows_path, linux_path=linux_path, osx_path=osx_path ) self.repository = repo DBSession.add(repo) DBSession.commit() except Exception as e: DBSession.rollback() QtWidgets.QMessageBox.critical( self, 'Error', str(e) ) return elif self.mode == 'Update': # Update the repository try: self.repository.name = name self.repository.code = code self.repository.windows_path = windows_path self.repository.linux_path = linux_path self.repository.osx_path = osx_path self.repository.updated_by = logged_in_user DBSession.add(self.repository) DBSession.commit() except Exception as e: DBSession.rollback() QtWidgets.QMessageBox.critical( self, 'Error', str(e) ) return super(MainDialog, self).accept()
class MainDialog(QtWidgets.QDialog, repository_dialog_UI.Ui_Dialog, AnimaDialogBase): """The Repository Dialog """ def __init__(self, parent=None, repository=None): super(MainDialog, self).__init__(parent=parent) self.setupUi(self) self.repository = repository self.mode = 'Create' if self.repository: self.mode = 'Update' self.dialog_label.setText('%s Repository' % self.mode) # create name_lineEdit from anima.ui.widgets import ValidatedLineEdit self.name_lineEdit = ValidatedLineEdit( message_field=self.name_validator_label) self.name_lineEdit.setPlaceholderText('Enter Name') self.name_fields_verticalLayout.insertWidget(0, self.name_lineEdit) self._setup_signals() self._set_defaults() if self.repository: self.fill_ui_with_repository(self.repository) def _setup_signals(self): """create the signals """ # name_lineEdit is changed QtCore.QObject.connect(self.name_lineEdit, QtCore.SIGNAL('textChanged(QString)'), self.name_line_edit_changed) def _set_defaults(self): """sets the default values """ pass def name_line_edit_changed(self, text): """runs when the name_lineEdit text has changed """ if re.findall(r'[^a-zA-Z0-9\-_ ]+', text): self.name_lineEdit.set_invalid('Invalid character') else: if text == '': self.name_lineEdit.set_invalid('Enter a name') else: self.name_lineEdit.set_valid() def fill_ui_with_repository(self, repository): """fills the UI with the given repository :param repository: A Stalker ImageFormat instance :return: """ if False: from stalker import Repository assert isinstance(repository, Repository) self.repository = repository self.name_lineEdit.setText(self.repository.name) self.name_lineEdit.set_valid() self.windows_path_lineEdit.setText(self.repository.windows_path) self.linux_path_lineEdit.setText(self.repository.linux_path) self.osx_path_lineEdit.setText(self.repository.osx_path) def accept(self): """overridden accept method """ if not self.name_lineEdit.is_valid: QtWidgets.QMessageBox.critical(self, 'Error', 'Please fix <b>name</b> field!') return name = self.name_lineEdit.text() windows_path = self.windows_path_lineEdit.text() linux_path = self.linux_path_lineEdit.text() osx_path = self.osx_path_lineEdit.text() from stalker import Repository from stalker.db.session import DBSession logged_in_user = self.get_logged_in_user() if self.mode == 'Create': # Create a new Repository try: repo = Repository(name=name, windows_path=windows_path, linux_path=linux_path, osx_path=osx_path) self.repository = repo DBSession.add(repo) DBSession.commit() except Exception as e: DBSession.rollback() QtWidgets.QMessageBox.critical(self, 'Error', str(e)) return elif self.mode == 'Update': # Update the repository try: self.repository.name = name self.repository.windows_path = windows_path self.repository.linux_path = linux_path self.repository.osx_path = osx_path self.repository.updated_by = logged_in_user DBSession.add(self.repository) DBSession.commit() except Exception as e: DBSession.rollback() QtWidgets.QMessageBox.critical(self, 'Error', str(e)) return super(MainDialog, self).accept()
class MainDialog(QtWidgets.QDialog, repository_dialog_UI.Ui_Dialog, AnimaDialogBase): """The Repository Dialog """ def __init__(self, parent=None, repository=None): super(MainDialog, self).__init__(parent=parent) self.setupUi(self) self.repository = repository self.mode = 'Create' if self.repository: self.mode = 'Update' self.dialog_label.setText('%s Repository' % self.mode) # create name_lineEdit from anima.ui.widgets import ValidatedLineEdit self.name_lineEdit = ValidatedLineEdit( message_field=self.name_validator_label ) self.name_lineEdit.setPlaceholderText('Enter Name') self.name_fields_verticalLayout.insertWidget( 0, self.name_lineEdit ) self._setup_signals() self._set_defaults() if self.repository: self.fill_ui_with_repository(self.repository) def _setup_signals(self): """create the signals """ # name_lineEdit is changed QtCore.QObject.connect( self.name_lineEdit, QtCore.SIGNAL('textChanged(QString)'), self.name_line_edit_changed ) def _set_defaults(self): """sets the default values """ pass def name_line_edit_changed(self, text): """runs when the name_lineEdit text has changed """ if re.findall(r'[^a-zA-Z0-9\-_ ]+', text): self.name_lineEdit.set_invalid('Invalid character') else: if text == '': self.name_lineEdit.set_invalid('Enter a name') else: self.name_lineEdit.set_valid() def fill_ui_with_repository(self, repository): """fills the UI with the given repository :param repository: A Stalker ImageFormat instance :return: """ if False: from stalker import Repository assert isinstance(repository, Repository) self.repository = repository self.name_lineEdit.setText(self.repository.name) self.name_lineEdit.set_valid() self.windows_path_lineEdit.setText(self.repository.windows_path) self.linux_path_lineEdit.setText(self.repository.linux_path) self.osx_path_lineEdit.setText(self.repository.osx_path) def accept(self): """overridden accept method """ if not self.name_lineEdit.is_valid: QtWidgets.QMessageBox.critical( self, 'Error', 'Please fix <b>name</b> field!' ) return name = self.name_lineEdit.text() windows_path = self.windows_path_lineEdit.text() linux_path = self.linux_path_lineEdit.text() osx_path = self.osx_path_lineEdit.text() from stalker import Repository from stalker.db.session import DBSession logged_in_user = self.get_logged_in_user() if self.mode == 'Create': # Create a new Repository try: repo = Repository( name=name, windows_path=windows_path, linux_path=linux_path, osx_path=osx_path ) self.repository = repo DBSession.add(repo) DBSession.commit() except Exception as e: DBSession.rollback() QtWidgets.QMessageBox.critical( self, 'Error', str(e) ) return elif self.mode == 'Update': # Update the repository try: self.repository.name = name self.repository.windows_path = windows_path self.repository.linux_path = linux_path self.repository.osx_path = osx_path self.repository.updated_by = logged_in_user DBSession.add(self.repository) DBSession.commit() except Exception as e: DBSession.rollback() QtWidgets.QMessageBox.critical( self, 'Error', str(e) ) return super(MainDialog, self).accept()
class MainDialog(QtWidgets.QDialog, structure_dialog_UI.Ui_Dialog, AnimaDialogBase): """The structure Dialog """ def __init__(self, parent=None, structure=None): super(MainDialog, self).__init__(parent=parent) self.setupUi(self) self.structure = structure self.mode = 'Create' if self.structure: self.mode = 'Update' self.dialog_label.setText('%s Structure' % self.mode) # create name_lineEdit from anima.ui.widgets import ValidatedLineEdit self.name_lineEdit = ValidatedLineEdit( message_field=self.name_validator_label ) self.name_lineEdit.setPlaceholderText('Enter Name') self.name_fields_verticalLayout.insertWidget( 0, self.name_lineEdit ) # create DoubleListWidget from anima.ui.widgets import DoubleListWidget self.filename_templates_double_list_widget = DoubleListWidget( dialog=self, parent_layout=self.filename_template_fields_verticalLayout, primary_label_text='Templates From DB', secondary_label_text='Selected Templates' ) # set the tooltip self.filename_templates_double_list_widget\ .primary_list_widget.setToolTip( "Right Click to Create/Update FilenameTemplates" ) self.filename_templates_double_list_widget\ .secondary_list_widget.setToolTip( "Right Click to Create/Update FilenameTemplates" ) self._setup_signals() self._set_defaults() if self.structure: self.fill_ui_with_structure(self.structure) def _setup_signals(self): """create the signals """ # name_lineEdit is changed QtCore.QObject.connect( self.name_lineEdit, QtCore.SIGNAL('textChanged(QString)'), self.name_line_edit_changed ) # add context menu for primary items in DoubleListWidget self.filename_templates_double_list_widget\ .primary_list_widget\ .setContextMenuPolicy(QtCore.Qt.CustomContextMenu) QtCore.QObject.connect( self.filename_templates_double_list_widget.primary_list_widget, QtCore.SIGNAL("customContextMenuRequested(const QPoint&)"), self.show_primary_filename_template_context_menu ) # add context menu for secondary items in DoubleListWidget self.filename_templates_double_list_widget\ .secondary_list_widget\ .setContextMenuPolicy(QtCore.Qt.CustomContextMenu) QtCore.QObject.connect( self.filename_templates_double_list_widget.secondary_list_widget, QtCore.SIGNAL("customContextMenuRequested(const QPoint&)"), self.show_secondary_filename_template_context_menu ) def _set_defaults(self): """sets the default values """ # fill filename_templates_from_db_listWidget # add all the other filename templates from the database from stalker import FilenameTemplate fts = FilenameTemplate.query.all() self.filename_templates_double_list_widget.clear() self.filename_templates_double_list_widget.add_primary_items( map( lambda x: '%s (%s) (%s)' % (x.name, x.target_entity_type, x.id), fts ) ) def name_line_edit_changed(self, text): """runs when the name_lineEdit text has changed """ if re.findall(r'[^a-zA-Z0-9\-_ ]+', text): self.name_lineEdit.set_invalid('Invalid character') else: if text == '': self.name_lineEdit.set_invalid('Enter a name') else: self.name_lineEdit.set_valid() def fill_ui_with_structure(self, structure): """fills the UI with the given structure :param structure: A Stalker ImageFormat instance :return: """ if False: from stalker import Structure assert isinstance(structure, Structure) self.structure = structure self.name_lineEdit.setText(self.structure.name) self.name_lineEdit.set_valid() self.custom_template_plainTextEdit.setPlainText( self.structure.custom_template ) # add the structure templates to the secondary list of the double list self.filename_templates_double_list_widget.clear() self.filename_templates_double_list_widget.add_secondary_items( map( lambda x: '%s (%s) (%s)' % (x.name, x.target_entity_type, x.id), self.structure.templates ) ) # add all the other filename templates from the database from stalker import FilenameTemplate fts = FilenameTemplate.query\ .filter( ~FilenameTemplate.id.in_( map(lambda x: x.id, self.structure.templates) ) )\ .all() self.filename_templates_double_list_widget.add_primary_items( map( lambda x: '%s (%s) (%s)' % (x.name, x.target_entity_type, x.id), fts ) ) def show_primary_filename_template_context_menu(self, position): """shows the custom context menu for primary list widget :param position: :return: """ self.show_filename_template_context_menu( self.filename_templates_double_list_widget.primary_list_widget, position ) def show_secondary_filename_template_context_menu(self, position): """shows the custom context menu for secondary list widget :param position: :return: """ self.show_filename_template_context_menu( self.filename_templates_double_list_widget.secondary_list_widget, position ) def show_filename_template_context_menu(self, list_widget, position): """shows a context menu for the given list_widget :param list_widget: QListWidget instance :param position: the mouse click position :return: """ item = list_widget.itemAt(position) menu = QtWidgets.QMenu() menu.addAction('Create FilenameTemplate...') if item: menu.addAction('Update FilenameTemplate...') global_position = list_widget.mapToGlobal(position) selected_item = menu.exec_(global_position) try: # PySide accepted = QtWidgets.QDialog.DialogCode.Accepted except AttributeError: # PyQt4 accepted = QtWidgets.QDialog.Accepted if selected_item: choice = selected_item.text() if choice == 'Create FilenameTemplate...': from anima.ui import filename_template_dialog create_filename_template_dialog = \ filename_template_dialog.MainDialog(parent=self) create_filename_template_dialog.exec_() if create_filename_template_dialog.result() == accepted: ft = create_filename_template_dialog.filename_template list_widget.addItem( '%s (%s) (%s)' % (ft.name, ft.target_entity_type, ft.id) ) create_filename_template_dialog.deleteLater() elif choice == 'Update FilenameTemplate...': ft_id = int(item.text().split('(')[-1].split(')')[0]) if not ft_id: return from stalker import FilenameTemplate ft = FilenameTemplate.query.get(ft_id) from anima.ui import filename_template_dialog update_filename_template_dialog = \ filename_template_dialog.MainDialog( parent=self, filename_template=ft ) try: update_filename_template_dialog.exec_() if update_filename_template_dialog.result() == accepted: # update the text of the item ft = update_filename_template_dialog.filename_template item.setText( '%s (%s) (%s)' % (ft.name, ft.target_entity_type, ft.id) ) update_filename_template_dialog.deleteLater() except Exception as e: QtWidgets.QMessageBox.warning( self, "Error", str(e) ) return def accept(self): """overridden accept method """ if not self.name_lineEdit.is_valid: QtWidgets.QMessageBox.critical( self, 'Error', 'Please fix <b>name</b> field!' ) return name = self.name_lineEdit.text() custom_template = self.custom_template_plainTextEdit.toPlainText() filename_template_items = \ self.filename_templates_double_list_widget.secondary_items() filename_template_ids = [] for item in filename_template_items: filename_template_id = \ int(item.text().split('(')[-1].split(')')[0]) filename_template_ids.append(filename_template_id) from stalker import FilenameTemplate filename_templates = FilenameTemplate.query\ .filter(FilenameTemplate.id.in_(filename_template_ids)).all() from stalker import Structure from stalker.db.session import DBSession logged_in_user = self.get_logged_in_user() if self.mode == 'Create': # Create a new Structure try: structure = Structure( name=name, templates=filename_templates, custom_template=custom_template, created_by=logged_in_user ) self.structure = structure DBSession.add(structure) DBSession.commit() except Exception as e: DBSession.rollback() QtWidgets.QMessageBox.critical( self, 'Error', str(e) ) return elif self.mode == 'Update': # Update the structure try: self.structure.name = name self.structure.templates = filename_templates self.structure.custom_template = custom_template self.structure.updated_by = logged_in_user DBSession.add(self.structure) DBSession.commit() except Exception as e: DBSession.rollback() QtWidgets.QMessageBox.critical( self, 'Error', str(e) ) return super(MainDialog, self).accept()
class MainDialog(QtWidgets.QDialog, AnimaDialogBase): """The FilenameTemplate Dialog """ def __init__(self, parent=None, filename_template=None): super(MainDialog, self).__init__(parent=parent) self.filename_template = filename_template self.mode = 'Create' if self.filename_template: self.mode = 'Update' self._setup_ui() if self.filename_template: self._fill_ui_with_filename_template(self.filename_template) def _setup_ui(self): """setup the ui elements """ self.resize(750, 180) self.vertical_layout = QtWidgets.QVBoxLayout(self) # Dialog Label self.dialog_label = QtWidgets.QLabel(self) self.dialog_label.setText('%s Filename Template' % self.mode) self.dialog_label.setStyleSheet("color: rgb(71, 143, 202);font: 18pt;") self.vertical_layout.addWidget(self.dialog_label) # Title Line line = QtWidgets.QFrame(self) line.setFrameShape(QtWidgets.QFrame.HLine) line.setFrameShadow(QtWidgets.QFrame.Sunken) self.vertical_layout.addWidget(line) # Form Layout self.form_layout = QtWidgets.QFormLayout() self.form_layout.setLabelAlignment( QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter ) self.vertical_layout.addLayout(self.form_layout) # ------------------------------------------------ # Target Entity Type Field # label self.target_entity_type_label = \ QtWidgets.QLabel('Target Entity Type', self) self.form_layout.setWidget( 0, QtWidgets.QFormLayout.LabelRole, self.target_entity_type_label ) # field self.target_entity_type_combo_box = QtWidgets.QComboBox(self) self.form_layout.setWidget( 0, QtWidgets.QFormLayout.FieldRole, self.target_entity_type_combo_box ) # ------------------------------------------------ # Name Field self.name_label = QtWidgets.QLabel('Name', self) self.form_layout.setWidget( 1, QtWidgets.QFormLayout.LabelRole, self.name_label ) self.name_fields_vertical_layout = QtWidgets.QVBoxLayout() self.name_validator_label = QtWidgets.QLabel(self) self.name_validator_label.setStyleSheet('color: rgb(255, 0, 0);') from anima.ui.widgets import ValidatedLineEdit self.name_line_edit = ValidatedLineEdit( self, message_field=self.name_validator_label ) self.name_fields_vertical_layout.addWidget(self.name_line_edit) self.name_fields_vertical_layout.addWidget(self.name_validator_label) self.form_layout.setLayout( 1, QtWidgets.QFormLayout.FieldRole, self.name_fields_vertical_layout ) # ------------------------------------------------ # Path Code Field self.path_label = QtWidgets.QLabel('Path', self) self.form_layout.setWidget( 2, QtWidgets.QFormLayout.LabelRole, self.path_label ) self.path_line_edit = QtWidgets.QLineEdit(self) # set the default value to something useful self.form_layout.setWidget( 2, QtWidgets.QFormLayout.FieldRole, self.path_line_edit ) # ------------------------------------------------ # Filename Code Field self.filename_label = QtWidgets.QLabel('Filename', self) self.form_layout.setWidget( 3, QtWidgets.QFormLayout.LabelRole, self.filename_label ) self.filename_line_edit = QtWidgets.QLineEdit(self) self.form_layout.setWidget( 3, QtWidgets.QFormLayout.FieldRole, self.filename_line_edit ) # ------------------------------------------------ # Button Box self.button_box = QtWidgets.QDialogButtonBox(self) self.button_box.setOrientation(QtCore.Qt.Horizontal) self.button_box.setStandardButtons( QtWidgets.QDialogButtonBox.Cancel | QtWidgets.QDialogButtonBox.Ok ) self.vertical_layout.addWidget(self.button_box) self.vertical_layout.setStretch(2, 1) # ------------------------------------------------ # Default values self.target_entity_type_combo_box.addItems( ['Task', 'Asset', 'Shot', 'Sequence'] ) self.name_line_edit.set_invalid() # Empty field is not valid self.path_line_edit.setText( '$REPO{{project.repository.id}}/{{project.code}}/' '{%- for parent_task in parent_tasks -%}{{parent_task.nice_name}}' '/{%- endfor -%}' ) self.filename_line_edit.setText( '{{version.nice_name}}_v{{"%03d"|format(version.version_number)}}' ) # ------------------------------------------------ # Disable Fields if self.mode == 'Update': self.target_entity_type_combo_box.setEnabled(False) # ------------------------------------------------ # Signals # Name QtCore.QObject.connect( self.name_line_edit, QtCore.SIGNAL('textChanged(QString)'), self.name_line_edit_changed ) # Button box QtCore.QObject.connect( self.button_box, QtCore.SIGNAL("accepted()"), self.accept ) QtCore.QObject.connect( self.button_box, QtCore.SIGNAL("rejected()"), self.reject ) def name_line_edit_changed(self, text): """runs when the name_line_edit text has changed """ if re.findall(r'[^a-zA-Z0-9\-_ ]+', text): self.name_line_edit.set_invalid('Invalid character') else: if text == '': self.name_line_edit.set_invalid('Enter a name') else: self.name_line_edit.set_valid() def _fill_ui_with_filename_template(self, filename_template): """Fills the UI with the given filename template :param filename_template: A Stalker FilenameTemplate instance :return: """ if False: from stalker import FilenameTemplate assert isinstance(filename_template, FilenameTemplate) self.name_line_edit.setText(filename_template.name) self.path_line_edit.setText(filename_template.path) self.filename_line_edit.setText(filename_template.filename) def accept(self): """the overridden accept method """ target_entity_type = self.target_entity_type_combo_box.currentText() if not self.name_line_edit.is_valid: QtWidgets.QMessageBox.critical( self, 'Error', 'Please fix <b>name</b> field!' ) return name = self.name_line_edit.text() path = self.path_line_edit.text() if path == '': QtWidgets.QMessageBox.critical( self, 'Error', 'Please fix <b>path</b> field!' ) return filename = self.filename_line_edit.text() if path == '': QtWidgets.QMessageBox.critical( self, 'Error', 'Please fix <b>filename</b> field!' ) return logged_in_user = self.get_logged_in_user() from stalker.db.session import DBSession if self.mode == 'Create': try: from stalker import FilenameTemplate # create a new FilenameTemplate ft = FilenameTemplate( name=name, path=path, filename=filename, target_entity_type=target_entity_type, created_by=logged_in_user ) self.filename_template = ft DBSession.add(ft) DBSession.commit() except Exception as e: DBSession.rollback() QtWidgets.QMessageBox.critical( self, 'Error', str(e) ) return elif self.mode == 'Update': try: self.filename_template.name = name self.filename_template.path = path self.filename_template.filename = filename self.filename_template.updated_by = logged_in_user DBSession.add(self.filename_template) DBSession.commit() except Exception as e: DBSession.rollback() QtWidgets.QMessageBox.critical( self, 'Error', str(e) ) return super(MainDialog, self).accept()
class MainDialog(QtWidgets.QDialog, AnimaDialogBase): """The Project Dialog """ max_project_name_length = 32 def __init__(self, parent=None, project=None): logger.debug("initializing the interface") super(MainDialog, self).__init__(parent) # store the logged in user self.logged_in_user = None self.project = project self.mode = 'Create' if self.project: self.mode = 'Update' self.image_format = None self._setup_ui() self._setup_signals() self._set_defaults() if self.project: self.fill_ui_with_project(self.project) def _setup_ui(self): """create UI elements """ self.resize(517, 545) self.verticalLayout = QtWidgets.QVBoxLayout(self) self.setWindowTitle("Project Dialog") # ---------------------- # Dialog Label self.dialog_label = QtWidgets.QLabel(self) self.dialog_label.setText('%s Project' % self.mode) self.dialog_label.setStyleSheet( "color: rgb(71, 143, 202);\nfont: 18pt;" ) self.verticalLayout.addWidget(self.dialog_label) self.line = QtWidgets.QFrame(self) self.line.setFrameShape(QtWidgets.QFrame.HLine) self.line.setFrameShadow(QtWidgets.QFrame.Sunken) self.verticalLayout.addWidget(self.line) self.project_info_formLayout = QtWidgets.QFormLayout() self.project_info_formLayout.setLabelAlignment( QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter ) # ---------------------- # Name Fields self.name_label = QtWidgets.QLabel(self) self.name_label.setText("Name") self.project_info_formLayout.setWidget( 0, QtWidgets.QFormLayout.LabelRole, self.name_label ) self.name_fields_verticalLayout = QtWidgets.QVBoxLayout() self.name_validator_label = QtWidgets.QLabel(self) self.name_validator_label.setText("Validator Message") self.name_validator_label.setStyleSheet("color: rgb(255, 0, 0);") self.name_fields_verticalLayout.addWidget(self.name_validator_label) self.project_info_formLayout.setLayout( 0, QtWidgets.QFormLayout.FieldRole, self.name_fields_verticalLayout ) # add name_lineEdit from anima.ui.widgets import ValidatedLineEdit self.name_lineEdit = ValidatedLineEdit( message_field=self.name_validator_label ) self.name_fields_verticalLayout.insertWidget( 0, self.name_lineEdit ) # ---------------------- # Code Fields self.code_label = QtWidgets.QLabel(self) self.code_label.setText("Code") self.project_info_formLayout.setWidget( 1, QtWidgets.QFormLayout.LabelRole, self.code_label ) self.code_fields_verticalLayout = QtWidgets.QVBoxLayout() self.code_validator_label = QtWidgets.QLabel(self) self.code_validator_label.setText("Validator Message") self.code_validator_label.setStyleSheet("color: rgb(255, 0, 0);") self.code_fields_verticalLayout.addWidget(self.code_validator_label) self.project_info_formLayout.setLayout( 1, QtWidgets.QFormLayout.FieldRole, self.code_fields_verticalLayout ) # add code_lineEdit self.code_lineEdit = ValidatedLineEdit( message_field=self.code_validator_label ) self.code_fields_verticalLayout.insertWidget( 0, self.code_lineEdit ) # ---------------------- # Type Fields self.type_label = QtWidgets.QLabel(self) self.type_label.setText("Type") self.project_info_formLayout.setWidget( 2, QtWidgets.QFormLayout.LabelRole, self.type_label ) self.type_comboBox = QtWidgets.QComboBox(self) self.type_comboBox.setEditable(True) self.project_info_formLayout.setWidget( 2, QtWidgets.QFormLayout.FieldRole, self.type_comboBox ) # ---------------------- # Date Fields self.date_label = QtWidgets.QLabel(self) self.date_label.setText("Date") self.project_info_formLayout.setWidget( 3, QtWidgets.QFormLayout.LabelRole, self.date_label ) self.date_dateEdit = QtWidgets.QDateEdit(self) self.project_info_formLayout.setWidget( 3, QtWidgets.QFormLayout.FieldRole, self.date_dateEdit ) # ---------------------- # Image Format Fields from anima.ui.widgets.image_format import ImageFormatWidget self.image_format = ImageFormatWidget( parent=self, parent_form_layout=self.project_info_formLayout, parent_form_layout_index=4 ) # ---------------------- # FPS Fields self.fps_label = QtWidgets.QLabel(self) self.fps_label.setText("FPS") self.project_info_formLayout.setWidget( 5, QtWidgets.QFormLayout.LabelRole, self.fps_label ) self.fps_spinBox = QtWidgets.QSpinBox(self) self.fps_spinBox.setMinimum(1) self.fps_spinBox.setProperty("value", 25) self.project_info_formLayout.setWidget( 5, QtWidgets.QFormLayout.FieldRole, self.fps_spinBox ) # ---------------------- # Repository Fields self.repository_label = QtWidgets.QLabel(self) self.repository_label.setText("Repository") self.project_info_formLayout.setWidget( 6, QtWidgets.QFormLayout.LabelRole, self.repository_label ) self.repository_horizontalLayout = QtWidgets.QHBoxLayout() self.repository_comboBox = QtWidgets.QComboBox(self) self.repository_horizontalLayout.addWidget( self.repository_comboBox) # Update Repository Push Button self.update_repository_pushButton = QtWidgets.QPushButton(self) self.update_repository_pushButton.setText("Update...") self.repository_horizontalLayout.addWidget( self.update_repository_pushButton ) # Create Repository Push Button self.create_repository_pushButton = QtWidgets.QPushButton(self) self.create_repository_pushButton.setText("New...") self.repository_horizontalLayout.addWidget( self.create_repository_pushButton ) self.repository_horizontalLayout.setStretch(0, 1) self.project_info_formLayout.setLayout( 6, QtWidgets.QFormLayout.FieldRole, self.repository_horizontalLayout ) # ---------------------- self.structure_label = QtWidgets.QLabel(self) self.structure_label.setText("Structure") self.project_info_formLayout.setWidget( 7, QtWidgets.QFormLayout.LabelRole, self.structure_label ) self.structure_horizontalLayout = QtWidgets.QHBoxLayout() self.structure_comboBox = QtWidgets.QComboBox(self) self.structure_horizontalLayout.addWidget(self.structure_comboBox) # Update Structure Push Button self.update_structure_pushButton = QtWidgets.QPushButton(self) self.update_structure_pushButton.setText("Update...") self.structure_horizontalLayout.addWidget( self.update_structure_pushButton ) # Create Structure Push Button self.create_structure_pushButton = QtWidgets.QPushButton(self) self.create_structure_pushButton.setText("New...") self.structure_horizontalLayout.addWidget( self.create_structure_pushButton ) self.structure_horizontalLayout.setStretch(0, 1) self.project_info_formLayout.setLayout( 7, QtWidgets.QFormLayout.FieldRole, self.structure_horizontalLayout ) # ---------------------- # Status Fields self.status_label = QtWidgets.QLabel(self) self.status_label.setText("Status") self.project_info_formLayout.setWidget( 8, QtWidgets.QFormLayout.LabelRole, self.status_label ) self.status_comboBox = QtWidgets.QComboBox(self) self.project_info_formLayout.setWidget( 8, QtWidgets.QFormLayout.FieldRole, self.status_comboBox ) self.verticalLayout.addLayout(self.project_info_formLayout) # ---------------------- # Client Fields self.client_info_label = QtWidgets.QLabel(self) self.client_info_label.setText("Client Info") self.client_info_label.setStyleSheet( "color: rgb(71, 143, 202);\nfont: 18pt;" ) self.verticalLayout.addWidget(self.client_info_label) self.line_2 = QtWidgets.QFrame(self) self.line_2.setFrameShape(QtWidgets.QFrame.HLine) self.line_2.setFrameShadow(QtWidgets.QFrame.Sunken) self.verticalLayout.addWidget(self.line_2) self.client_info_formLayout = QtWidgets.QFormLayout() self.client_info_formLayout.setLabelAlignment( QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter ) # Client Fields self.client_label = QtWidgets.QLabel(self) self.client_label.setText("Client") self.client_info_formLayout.setWidget( 0, QtWidgets.QFormLayout.LabelRole, self.client_label ) self.client_comboBox = QtWidgets.QComboBox(self) self.client_comboBox.setEditable(True) self.client_info_formLayout.setWidget( 0, QtWidgets.QFormLayout.FieldRole, self.client_comboBox ) # Agency Fields self.agency_label = QtWidgets.QLabel(self) self.agency_label.setText("Agency") self.client_info_formLayout.setWidget( 1, QtWidgets.QFormLayout.LabelRole, self.agency_label ) self.agency_comboBox = QtWidgets.QComboBox(self) self.agency_comboBox.setEditable(True) self.client_info_formLayout.setWidget( 1, QtWidgets.QFormLayout.FieldRole, self.agency_comboBox ) # Production Company Fields self.production_company_label = QtWidgets.QLabel(self) self.production_company_label.setText( "<html><head/><body><p align=\"right\">Production<br/>" "Company</p></body></html>" ) self.client_info_formLayout.setWidget( 2, QtWidgets.QFormLayout.LabelRole, self.production_company_label ) self.production_company_comboBox = QtWidgets.QComboBox(self) self.production_company_comboBox.setEditable(True) self.client_info_formLayout.setWidget( 2, QtWidgets.QFormLayout.FieldRole, self.production_company_comboBox ) self.verticalLayout.addLayout(self.client_info_formLayout) self.buttonBox = QtWidgets.QDialogButtonBox(self) self.buttonBox.setOrientation(QtCore.Qt.Horizontal) self.buttonBox.setStandardButtons( QtWidgets.QDialogButtonBox.Cancel | QtWidgets.QDialogButtonBox.Ok) self.verticalLayout.addWidget(self.buttonBox) self.verticalLayout.setStretch(2, 2) self.verticalLayout.setStretch(5, 1) def _setup_signals(self): """creates the signals """ QtCore.QObject.connect( self.buttonBox, QtCore.SIGNAL("accepted()"), self.accept ) QtCore.QObject.connect( self.buttonBox, QtCore.SIGNAL("rejected()"), self.reject ) # name_lineEdit is changed QtCore.QObject.connect( self.name_lineEdit, QtCore.SIGNAL('textChanged(QString)'), self.name_line_edit_changed ) # code_lineEdit is changed QtCore.QObject.connect( self.code_lineEdit, QtCore.SIGNAL('textChanged(QString)'), self.code_line_edit_changed ) # create_repository_pushButton QtCore.QObject.connect( self.create_repository_pushButton, QtCore.SIGNAL('clicked()'), self.create_repository_push_button_clicked ) # update_repository_pushButton QtCore.QObject.connect( self.update_repository_pushButton, QtCore.SIGNAL('clicked()'), self.update_repository_push_button_clicked ) # create_structure_pushButton QtCore.QObject.connect( self.create_structure_pushButton, QtCore.SIGNAL('clicked()'), self.create_structure_push_button_clicked ) # update_structure_pushButton QtCore.QObject.connect( self.update_structure_pushButton, QtCore.SIGNAL('clicked()'), self.update_structure_push_button_clicked ) def _set_defaults(self): """setup the default values """ # set size policies # self.name_lineEdit self.type_comboBox.setSizePolicy( QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed ) self.status_comboBox.setSizePolicy( QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed ) self.client_comboBox.setSizePolicy( QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed ) self.agency_comboBox.setSizePolicy( QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed ) self.production_company_comboBox.setSizePolicy( QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed ) # invalidate the name and code fields by default self.name_lineEdit.set_invalid('Enter a name') self.code_lineEdit.set_invalid('Enter a code') # update type field from stalker import Type from stalker.db.session import DBSession project_types = \ DBSession.query(Type.id, Type.name)\ .filter(Type.target_entity_type == 'Project')\ .order_by(Type.name)\ .all() self.type_comboBox.clear() self.type_comboBox.addItem('', -1) for type_id, type_name in project_types: self.type_comboBox.addItem(type_name, type_id) self.image_format.fill_combo_box() self.fill_repository_combo_box() self.fill_structure_combo_box() # fill status field sql = """select "SimpleEntities".id, "SimpleEntities".name from "Statuses" join "SimpleEntities" on "Statuses".id = "SimpleEntities".id join "StatusList_Statuses" on "Statuses".id = "StatusList_Statuses".status_id join "StatusLists" on "StatusLists".id = "StatusList_Statuses".status_list_id where "StatusLists".target_entity_type = 'Project'""" all_project_statuses = \ DBSession.connection().execute(sql).fetchall() for st_id, st_name in all_project_statuses: self.status_comboBox.addItem(st_name, st_id) def show(self): """overridden show method """ logger.debug('MainDialog.show is started') self.logged_in_user = self.get_logged_in_user() if not self.logged_in_user: self.reject() return_val = None else: return_val = super(MainDialog, self).show() logger.debug('MainDialog.show is finished') return return_val def fill_repository_combo_box(self): """fills the repository_comboBox with Repository instances """ # fill the repository field from stalker import Repository from stalker.db.session import DBSession all_repos = DBSession \ .query(Repository.id, Repository.name) \ .order_by(Repository.name) \ .all() self.repository_comboBox.clear() for repo_id, repo_name in all_repos: self.repository_comboBox.addItem(repo_name, repo_id) def fill_structure_combo_box(self): """fills the structure_comboBox with Structure instances """ # fill the structure field from stalker import Structure from stalker.db.session import DBSession all_structures = DBSession \ .query(Structure.id, Structure.name) \ .order_by(Structure.name) \ .all() self.structure_comboBox.clear() for st_id, st_name in all_structures: self.structure_comboBox.addItem(st_name, st_id) def name_line_edit_changed(self, text): """runs when the name_lineEdit text has changed """ if re.findall(r'[^a-zA-Z0-9\-_ ]+', text): self.name_lineEdit.set_invalid('Invalid character') else: if text == '': self.name_lineEdit.set_invalid('Enter a name') else: self.name_lineEdit.set_valid() # update code field also formatted_text = re.sub(r'[^A-Z0-9_]+', '', text) self.code_lineEdit.setText(formatted_text) def code_line_edit_changed(self, text): """runs when the code_lineEdit text has changed """ if re.findall(r'[^a-zA-Z0-9_]+', text): self.code_lineEdit.set_invalid('Invalid character') else: if text == '': self.code_lineEdit.set_invalid('Enter a code') else: if len(text) > self.max_project_name_length: self.code_lineEdit.set_invalid( 'Code is too long (>%s)' % self.max_project_name_length ) else: self.code_lineEdit.set_valid() def fill_ui_with_project(self, project): """fills the UI fields with the given project :param project: A Stalker Project instance :return: """ if not project: return self.project = project self.name_lineEdit.setText(project.name) self.name_lineEdit.set_valid() self.code_lineEdit.setText(project.code) self.code_lineEdit.set_valid() if project.type: index = self.type_comboBox.findData(project.type.id) if index: self.type_comboBox.setCurrentIndex(index) if project.image_format: index = self.image_format.combo_box.findData( project.image_format.id ) if index: self.image_format.combo_box.setCurrentIndex(index) self.fps_spinBox.setValue(project.fps) if project.repository: # TODO: allow multiple repositories index = self.repository_comboBox.findText( project.repository.name, QtCore.Qt.MatchExactly ) if index: self.repository_comboBox.setCurrentIndex(index) if project.structure: index = self.structure_comboBox.findText( project.structure.name, QtCore.Qt.MatchExactly ) if index: self.structure_comboBox.setCurrentIndex(index) if project.status: index = self.status_comboBox.findText( project.status.name, QtCore.Qt.MatchExactly ) if index: self.status_comboBox.setCurrentIndex(index) def create_repository_push_button_clicked(self): """runs when create_repository_pushButton is clicked """ try: # PySide accepted = QtWidgets.QDialog.DialogCode.Accepted except AttributeError: # PyQt4 accepted = QtWidgets.QDialog.Accepted from anima.ui import repository_dialog create_repository_dialog = \ repository_dialog.MainDialog(parent=self) create_repository_dialog.exec_() result = create_repository_dialog.result() if result == accepted: repository = create_repository_dialog.repository # select the created repository self.fill_repository_combo_box() index = self.repository_comboBox.findData(repository.id) if index: self.repository_comboBox.setCurrentIndex(index) create_repository_dialog.deleteLater() def update_repository_push_button_clicked(self): """runs when update_repository_pushButton is clicked """ try: # PySide accepted = QtWidgets.QDialog.DialogCode.Accepted except AttributeError: # PyQt4 accepted = QtWidgets.QDialog.Accepted repo = self.get_current_repository() if not repo: return from anima.ui import repository_dialog update_repository_dialog = \ repository_dialog.MainDialog(parent=self, repository=repo) update_repository_dialog.exec_() result = update_repository_dialog.result() if result == accepted: repository = update_repository_dialog.repository # select the created repository self.fill_repository_combo_box() index = self.repository_comboBox.findData(repository.id) if index: self.repository_comboBox.setCurrentIndex(index) update_repository_dialog.deleteLater() def create_structure_push_button_clicked(self): """runs when create_structure_pushButton is clicked """ try: # PySide accepted = QtWidgets.QDialog.DialogCode.Accepted except AttributeError: # PyQt4 accepted = QtWidgets.QDialog.Accepted from anima.ui import structure_dialog create_structure_dialog = \ structure_dialog.MainDialog(parent=self) create_structure_dialog.exec_() result = create_structure_dialog.result() if result == accepted: structure = create_structure_dialog.structure # select the created repository self.fill_structure_combo_box() index = self.structure_comboBox.findData(structure.id) if index: self.structure_comboBox.setCurrentIndex(index) create_structure_dialog.deleteLater() def update_structure_push_button_clicked(self): """runs when update_structure_pushButton is clicked """ try: # PySide accepted = QtWidgets.QDialog.DialogCode.Accepted except AttributeError: # PyQt4 accepted = QtWidgets.QDialog.Accepted structure = self.get_current_structure() if not structure: return from anima.ui import structure_dialog update_structure_dialog = \ structure_dialog.MainDialog(parent=self, structure=structure) update_structure_dialog.exec_() result = update_structure_dialog.result() if result == accepted: structure = update_structure_dialog.structure # select the created repository self.fill_structure_combo_box() index = self.structure_comboBox.findData(structure.id) if index: self.structure_comboBox.setCurrentIndex(index) update_structure_dialog.deleteLater() def get_current_repository(self): """returns the currently selected repository instance from the UI """ from stalker import Repository index = self.repository_comboBox.currentIndex() repo_id = self.repository_comboBox.itemData(index) repo = Repository.query.get(repo_id) return repo def get_current_structure(self): """returns the currently selected structure instance from the UI """ from stalker import Structure index = self.structure_comboBox.currentIndex() structure_id = self.structure_comboBox.itemData(index) structure = Structure.query.get(structure_id) return structure def accept(self): """create/update the project """ # Name if not self.name_lineEdit.is_valid: QtWidgets.QMessageBox.critical( self, 'Error', 'Please fix <b>name</b> field!' ) return name = self.name_lineEdit.text() # Code if not self.code_lineEdit.is_valid: QtWidgets.QMessageBox.critical( self, 'Error', 'Please fix <b>code</b> field!' ) return code = self.code_lineEdit.text() # Type from stalker import Type index = self.type_comboBox.currentIndex() type_id = self.type_comboBox.itemData(index) type_ = Type.query.get(type_id) # None type is ok # Image Format image_format = self.image_format.get_current_image_format() if not image_format: QtWidgets.QMessageBox.critical( self, 'Error', 'Please select a valid <b>Image Format</b>!' ) return # FPS fps = self.fps_spinBox.value() # Repository repo = self.get_current_repository() if not repo: QtWidgets.QMessageBox.critical( self, 'Error', 'Please select a valid <b>Repository</b>!' ) return # Structure structure = self.get_current_structure() if not structure: QtWidgets.QMessageBox.critical( self, 'Error', 'Please select a valid <b>Structure</b>!' ) return # Status from stalker import Status index = self.status_comboBox.currentIndex() status_id = self.status_comboBox.itemData(index) status = Status.query.get(status_id) if not status: QtWidgets.QMessageBox.critical( self, 'Error', 'Please select a valid <b>Status</b>!' ) return # TODO: Add Client Data fields (which I don't care for now) logged_in_user = self.get_logged_in_user() # create or update project from stalker.db.session import DBSession if self.mode == 'Create': # create a new project from stalker import Project new_project = Project( name=name, code=code, type=type_, repositories=[repo], structure=structure, image_format=image_format, fps=fps, created_by=logged_in_user ) DBSession.add(new_project) try: DBSession.commit() except Exception as e: DBSession.rollback() QtWidgets.QMessageBox.critical( self, 'Error', str(e) ) return else: # update the project self.project.updated_by = logged_in_user self.project.name = name self.project.code = code self.project.type = type_ self.project.repositories = [repo] self.project.structure = structure self.project.image_format = image_format self.project.fps = fps self.project.status = status DBSession.add(self.project) try: DBSession.commit() except Exception as e: DBSession.rollback() QtWidgets.QMessageBox.critical( self, 'Error', str(e) ) return super(MainDialog, self).accept()
class MainDialog(QtWidgets.QDialog, image_format_dialog_UI.Ui_Dialog, AnimaDialogBase): """The ImageFormat Dialog """ def __init__(self, parent=None, image_format=None): super(MainDialog, self).__init__(parent=parent) self.setupUi(self) self.image_format = image_format self.mode = 'Create' if self.image_format: self.mode = 'Update' self.dialog_label.setText('%s Image Format' % self.mode) # create name_lineEdit from anima.ui.widgets import ValidatedLineEdit self.name_lineEdit = ValidatedLineEdit( message_field=self.name_validator_label) self.name_lineEdit.setPlaceholderText('Enter Name') self.name_fields_verticalLayout.insertWidget(0, self.name_lineEdit) self._setup_signals() self._set_defaults() if self.image_format: self.fill_ui_with_image_format(self.image_format) def _setup_signals(self): """create the signals """ # name_lineEdit is changed QtCore.QObject.connect(self.name_lineEdit, QtCore.SIGNAL('textChanged(QString)'), self.name_line_edit_changed) def _set_defaults(self): """sets the default values """ pass def name_line_edit_changed(self, text): """runs when the name_lineEdit text has changed """ if re.findall(r'[^a-zA-Z0-9\-_ ]+', text): self.name_lineEdit.set_invalid('Invalid character') else: if text == '': self.name_lineEdit.set_invalid('Enter a name') else: self.name_lineEdit.set_valid() def fill_ui_with_image_format(self, image_format): """fills the UI with the given image_format :param image_format: A Stalker ImageFormat instance :return: """ if False: from stalker import ImageFormat assert isinstance(image_format, ImageFormat) self.image_format = image_format self.name_lineEdit.setText(self.image_format.name) self.name_lineEdit.set_valid() self.width_spinBox.setValue(self.image_format.width) self.height_spinBox.setValue(self.image_format.height) self.pixel_aspect_doubleSpinBox.setValue( self.image_format.pixel_aspect) def accept(self): """overridden accept method """ if not self.name_lineEdit.is_valid: QtWidgets.QMessageBox.critical(self, 'Error', 'Please fix <b>name</b> field!') return name = self.name_lineEdit.text() width = self.width_spinBox.value() height = self.height_spinBox.value() pixel_aspect = self.pixel_aspect_doubleSpinBox.value() from stalker import ImageFormat from stalker.db.session import DBSession logged_in_user = self.get_logged_in_user() if self.mode == 'Create': # Create a new Image Format try: imf = ImageFormat(name=name, width=width, height=height, pixel_aspect=pixel_aspect, created_by=logged_in_user) self.image_format = imf DBSession.add(imf) DBSession.commit() except Exception as e: DBSession.rollback() QtWidgets.QMessageBox.critical(self, 'Error', str(e)) return elif self.mode == 'Update': # Update the image format try: self.image_format.name = name self.image_format.width = width self.image_format.height = height self.image_format.pixel_aspect = pixel_aspect self.image_format.updated_by = logged_in_user DBSession.add(self.image_format) DBSession.commit() except Exception as e: DBSession.rollback() QtWidgets.QMessageBox.critical(self, 'Error', str(e)) return super(MainDialog, self).accept()