def save( self ): """ Saves the current shortuct settings to the current item. :return <bool> success """ aitem = self.uiActionTREE.currentItem() if ( not aitem ): return True scut = self.uiShortcutTXT.text() if ( not scut ): aitem.setText(1, '') return True for i in range(self.uiActionTREE.topLevelItemCount()): item = self.uiActionTREE.topLevelItem(i) if (item != aitem and item.text(1) == scut): msg = '%s already is using the %s shortcut.' % (item.text(0), scut) QMessageBox.critical( self, 'Duplicate Shortcut', msg ) return False # update the item aitem.setText(1, scut) return True
def edit( cls, record, parent = None, uifile = '', commit = True ): """ Prompts the user to edit the inputed record. :param record | <orb.Table> parent | <QWidget> :return <bool> | accepted """ # create the dialog dlg = QDialog(parent) dlg.setWindowTitle('Edit %s' % record.schema().name()) # create the widget cls = record.schema().property('widgetClass', cls) widget = cls(dlg) if ( uifile ): widget.setUiFile(uifile) widget.setRecord(record) widget.layout().setContentsMargins(0, 0, 0, 0) # create buttons opts = QDialogButtonBox.Save | QDialogButtonBox.Cancel btns = QDialogButtonBox(opts, Qt.Horizontal, dlg) # create layout layout = QVBoxLayout() layout.addWidget(widget) layout.addWidget(btns) dlg.setLayout(layout) dlg.adjustSize() # create connections #btns.accepted.connect(widget.save) btns.rejected.connect(dlg.reject) widget.saved.connect(dlg.accept) if ( dlg.exec_() ): if commit: result = widget.record().commit() if 'errored' in result: QMessageBox.information(self.window(), 'Error Committing to Database', result['errored']) return False return True return False
def checkForSave( self ): """ Checks to see if the current document has been modified and should \ be saved. :return <bool> """ # if the file is not modified, then save is not needed if ( not self.isModified() ): return True options = QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel question = 'Would you like to save your changes to %s?' % \ self.windowTitle() answer = QMessageBox.question( None, 'Save Changes', question, options ) if ( answer == QMessageBox.Yes ): return self.save() elif ( answer == QMessageBox.Cancel ): return False return True
def saveProfileLayout(self, profile): """ Saves the profile layout to the inputed profile. :param profile | <projexui.widgets.xviewwidget.XViewProfile> """ if not self.viewWidget(): text = self.profileText() QMessageBox.information(self.window(), 'Could Not Save {0}'.format(text), 'Error saving layout, '\ 'No View Widget Assigned') return # save the profile from the view widget prof = self.viewWidget().saveProfile() profile.setXmlElement(prof.xmlElement()) if not self.signalsBlocked(): self.profileChanged.emit(profile)
def accept( self ): """ Saves the data to the profile before closing. """ if ( not self.uiNameTXT.text() ): QMessageBox.information(self, 'Invalid Name', 'You need to supply a name for your layout.') return prof = self.profile() if ( not prof ): prof = XViewProfile() prof.setName(nativestring(self.uiNameTXT.text())) prof.setVersion(self.uiVersionSPN.value()) prof.setDescription(nativestring(self.uiDescriptionTXT.toPlainText())) prof.setIcon(self.uiIconBTN.filepath()) super(XViewProfileDialog, self).accept()
def accept(self): """ Saves the data to the profile before closing. """ if (not self.uiNameTXT.text()): QMessageBox.information( self, 'Invalid Name', 'You need to supply a name for your layout.') return prof = self.profile() if (not prof): prof = XViewProfile() prof.setName(nativestring(self.uiNameTXT.text())) prof.setVersion(self.uiVersionSPN.value()) prof.setDescription(nativestring(self.uiDescriptionTXT.toPlainText())) prof.setIcon(self.uiIconBTN.filepath()) super(XViewProfileDialog, self).accept()
def removeProfile( self ): """ Removes the current profile from the system. """ manager = self.parent() prof = manager.currentProfile() opts = QMessageBox.Yes | QMessageBox.No question = 'Are you sure you want to remove "%s"?' % prof.name() answer = QMessageBox.question( self, 'Remove Profile', question, opts) if ( answer == QMessageBox.Yes ): manager.removeProfile(prof)
def removeProfile(self): """ Removes the current profile from the system. """ manager = self.parent() prof = manager.currentProfile() opts = QMessageBox.Yes | QMessageBox.No question = 'Are you sure you want to remove "%s"?' % prof.name() answer = QMessageBox.question(self, 'Remove Profile', question, opts) if (answer == QMessageBox.Yes): manager.removeProfile(prof)
def removeProfile(self, profile, silent=False): """ Removes the given profile from the toolbar. :param profile | <projexui.widgets.xviewwidget.XViewProfile> """ if not profile: return if not silent: title = 'Remove {0}'.format(self.profileText()) opts = QMessageBox.Yes | QMessageBox.No quest = 'Are you sure you want to remove "%s" from the toolbar?' quest %= profile.name() if isinstance(profile, XViewProfile) else profile answer = QMessageBox.question(self.window(), title, quest, opts) else: answer = QMessageBox.Yes if answer == QMessageBox.Yes: reset = profile == self.currentProfile() if not reset: try: reset = profile == self.currentProfile().name() except AttributeError: reset = False if reset and self.viewWidget(): self.viewWidget().reset(True) # remove the actions from this toolbar removed = [] for act in self.actions(): if not isinstance(act, XViewProfileAction): continue if not profile in (act.profile(), act.text()): continue removed.append(act.profile()) self.removeAction(act) self._profileGroup.removeAction(act) act.deleteLater() if not self.signalsBlocked() and removed: for prof in removed: self.profileRemoved.emit(prof) self.profilesChanged.emit()
def checkForSave(self): """ Checks to see if the current document has been modified and should \ be saved. :return <bool> """ # if the file is not modified, then save is not needed if (not self.isModified()): return True options = QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel question = 'Would you like to save your changes to %s?' % \ self.windowTitle() answer = QMessageBox.question(None, 'Save Changes', question, options) if (answer == QMessageBox.Yes): return self.save() elif (answer == QMessageBox.Cancel): return False return True
def removeItem(self): """ Removes the item from the menu. """ item = self.uiMenuTREE.currentItem() if (not item): return opts = QMessageBox.Yes | QMessageBox.No answer = QMessageBox.question( self, 'Remove Item', 'Are you sure you want to remove this '\ ' item?', opts ) if (answer == QMessageBox.Yes): parent = item.parent() if (parent): parent.takeChild(parent.indexOfChild(item)) else: tree = self.uiMenuTREE tree.takeTopLevelItem(tree.indexOfTopLevelItem(item))
def removeItem( self ): """ Removes the item from the menu. """ item = self.uiMenuTREE.currentItem() if ( not item ): return opts = QMessageBox.Yes | QMessageBox.No answer = QMessageBox.question( self, 'Remove Item', 'Are you sure you want to remove this '\ ' item?', opts ) if ( answer == QMessageBox.Yes ): parent = item.parent() if ( parent ): parent.takeChild(parent.indexOfChild(item)) else: tree = self.uiMenuTREE tree.takeTopLevelItem(tree.indexOfTopLevelItem(item))
def save(self): """ Saves the changes from the ui to this widgets record instance. """ record = self.record() if not record: logger.warning('No record has been defined for %s.' % self) return False if not self.signalsBlocked(): self.aboutToSaveRecord.emit(record) self.aboutToSave.emit() values = self.saveValues() # ignore columns that are the same (fixes bugs in encrypted columns) check = values.copy() for column_name, value in check.items(): try: equals = value == record.recordValue(column_name) except UnicodeWarning: equals = False if equals: check.pop(column_name) # check to see if nothing has changed if not check and record.isRecord(): if not self.signalsBlocked(): self.recordSaved.emit(record) self.saved.emit() self._saveSignalBlocked = False else: self._saveSignalBlocked = True if self.autoCommitOnSave(): status, result = record.commit() if status == 'errored': if 'db_error' in result: msg = nativestring(result['db_error']) else: msg = 'An unknown database error has occurred.' QMessageBox.information(self, 'Commit Error', msg) return False return True # validate the modified values success, msg = record.validateValues(check) if ( not success ): QMessageBox.information(None, 'Could Not Save', msg) return False record.setRecordValues(**values) success, msg = record.validateRecord() if not success: QMessageBox.information(None, 'Could Not Save', msg) return False if ( self.autoCommitOnSave() ): result = record.commit() if 'errored' in result: QMessageBox.information(None, 'Could Not Save', msg) return False if ( not self.signalsBlocked() ): self.recordSaved.emit(record) self.saved.emit() self._saveSignalBlocked = False else: self._saveSignalBlocked = True return True
def save( self ): """ Saves the values from the editor to the system. """ schema = self.schema() if ( not schema ): self.saved.emit() return record = self.record() if not record: record = self._model() # validate the information save_data = [] column_edits = self.findChildren(XOrbColumnEdit) for widget in column_edits: columnName = widget.columnName() column = schema.column(columnName) if ( not column ): logger.warning('%s is not a valid column of %s.' % \ (columnName, schema.name())) continue value = widget.value() if ( value == IGNORED ): continue # check for required columns if ( column.required() and not value ): name = column.displayName() QMessageBox.information(self, 'Missing Required Field', '%s is a required field.' % name) return # check for unique columns elif ( column.unique() ): # check for uniqueness query = Q(column.name()) == value if ( record.isRecord() ): query &= Q(self._model) != record columns = self._model.schema().primaryColumns() result = self._model.select(columns = columns, where = query) if ( result.total() ): QMessageBox.information(self, 'Duplicate Entry', '%s already exists.' % value) return save_data.append((column, value)) # record the properties for the record for column, value in save_data: record.setRecordValue(column.name(), value) self._record = record self.saved.emit()
def showProfileMenu(self, point): """ Prompts the user for profile menu options. Editing needs to be enabled for this to work. """ if not self.isEditingEnabled(): return trigger = self.actionAt(point) if (isinstance(trigger, XViewProfileAction)): prof = trigger.profile() else: prof = None # define the menu menu = QMenu(self) acts = {} text = self.profileText() # user right clicked on a profile if prof: acts['edit'] = menu.addAction('Edit {0}...'.format(text)) acts['save'] = menu.addAction('Save Layout') menu.addSeparator() acts['copy'] = menu.addAction('Copy {0}'.format(text)) acts['export'] = menu.addAction('Export {0}...'.format(text)) menu.addSeparator() acts['remove'] = menu.addAction('Delete {0}'.format(text)) # show toolbar options else: acts['new'] = menu.addAction('New Layout'.format(text)) menu.addSeparator() acts['save_as'] = menu.addAction('Save Layout as...') if QApplication.clipboard().text(): acts['paste'] = menu.addAction('Paste {0}'.format(text)) acts['import'] = menu.addAction('Import {0}...'.format(text)) for key, act in acts.items(): act.setIcon(QIcon(resources.find('img/{0}.png'.format(key)))) # run the menu act = menu.exec_(QCursor.pos()) # create a new profile if act is None: return elif act == acts.get('new'): self.clearActive() # create a new clear profile elif act == acts.get('save_as'): self.saveProfileAs() # edit an existing profile elif act == acts.get('edit'): self.editProfile(prof) # save or create a new profile elif act == acts.get('save'): self.saveProfileLayout(prof) # copy profile elif act == acts.get('copy'): QApplication.clipboard().setText(prof.toString()) # export elif act == acts.get('export'): self.exportProfile(prof) # export elif act == acts.get('import'): self.importProfile() # paste profile elif act == acts.get('paste'): text = QApplication.clipboard().text() try: prof = XViewProfile.fromString(text) except: prof = None QMessageBox.information(self.window(), 'Invalid {0}'.format(text), 'The clipboard text does not contain '\ 'a properly formated {0}'.format(text)) if prof and not prof.isEmpty(): self.createProfile(profile=prof) # paste as profile elif act == acts.get('paste_as'): text = QApplication.clipboard().text() prof = XViewProfile.fromString(text) if not prof.isEmpty(): if XViewProfileDialog.edit(self, prof): self.createProfile(profile=prof) # remove the profile elif act == acts.get('remove'): self.removeProfile(prof)