def _isCloseOk(self): doc = self.document if doc.saved: return True else: # current document has unsaved changes if doc.filePath is None: prefix = 'This document' else: fileName = os.path.basename(doc.filePath) prefix = 'The document "{:s}"'.format(fileName) box = QMessageBox() box.setText(prefix + ' has unsaved changes.') box.setInformativeText('Would you like to save them before closing?') box.setStandardButtons(QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel) box.setDefaultButton(QMessageBox.Save) result = box.exec_() if result == QMessageBox.Save: return self._onSave() elif result == QMessageBox.Cancel: return False else: return True
def check_editor_preferences(): # get preference values of external app path photo_dir = cmds.optionVar(exists='PhotoshopDir') image_dir = cmds.optionVar(exists='EditImageDir') # if there is no external app, request for an app path if not photo_dir and not image_dir: pref_warn = QMessageBox() pref_warn.setWindowTitle(WINDOW_TITLE) pref_warn.setIcon(QMessageBox.Warning) pref_warn.setText( '<b>Applications for Editing Image Files</b> ' 'is not set in your preferences.<br>' 'Maya needs it to send image in the right Image Editor ' 'instead of file system association.') pref_warn.setInformativeText('Do you want to select an application ?') pref_warn.setStandardButtons(QMessageBox.Yes | QMessageBox.No) pref_warn.setDefaultButton(QMessageBox.Yes) pref_warn.setEscapeButton(QMessageBox.Cancel) ret = pref_warn.exec_() if ret == QMessageBox.Yes: app_path = cmds.fileDialog2( fileFilter='Image editor application (*.exe)', caption='Select image editor application', startingDirectory=os.path.expandvars('%ProgramFiles%'), fileMode=1) if app_path is not None: cmds.optionVar(sv=('PhotoshopDir', app_path[0])) cmds.optionVar(sv=('EditImageDir', app_path[0]))
def error(self, error): if error == QNetworkSession.UnknownSessionError: msgBox = QMessageBox(self.parent()) msgBox.setText('This application requires network access to function.') msgBox.setInformativeText('Press Cancel to quit the application.') msgBox.setStandardButtons(QMessageBox.Retry | QMessageBox.Cancel) msgBox.setIcon(QMessageBox.Information) msgBox.setDefaultButton(QMessageBox.Retry) ret = msgBox.exec_() if ret == QMessageBox.Retry: QTimer.singleShot(0, self.session.open) elif ret == QMessageBox.Cancel: self.close() elif error == QNetworkSession.SessionAbortedError: msgBox = QMessageBox(self.parent()) msgBox.setText('Out of range of network') msgBox.setInformativeText('Move back into range and press Retry, or press Cancel to quit the application') msgBox.setStandardButtons(QMessageBox.Retry | QMessageBox.Cancel) msgBox.setIcon(QMessageBox.Information) msgBox.setDefaultButton(QMessageBox.Retry) ret = msgBox.exec_() if ret == QMessageBox.Retry: QTimer.singleShot(0, self.session.open) elif ret == QMessageBox.Cancel: self.close()
def error(title, text, buttons=QMessageBox.Ok, default_button=QMessageBox.Ok): msgBox = QMessageBox() msgBox.setWindowTitle(title) msgBox.setText(text) msgBox.setInformativeText(title) msgBox.setStandardButtons(buttons) msgBox.setDefaultButton(default_button) msgBox.setIcon(QMessageBox.Critical) return msgBox.exec_()
def make(title, text, icon=QMessageBox.Critical, buttons=QMessageBox.Ok, default_button=QMessageBox.Ok): ntfctn = QMessageBox() ntfctn.setWindowTitle(title) ntfctn.setText(text) ntfctn.setInformativeText(title) ntfctn.setStandardButtons(buttons) ntfctn.setDefaultButton(default_button) ntfctn.setIcon(icon) return ntfctn.exec_()
def onExit(self): msgBox = QMessageBox(self) msgBox.setIcon(QMessageBox.Question) msgBox.setWindowTitle(_translate("MainWindow", "Pythonthusiast", None)); msgBox.setText(_translate("MainWindow", "Are you sure you want to quit?", None)) msgBox.setStandardButtons(QMessageBox.No|QMessageBox.Yes) msgBox.setDefaultButton(QMessageBox.Yes) msgBox.exec_ if msgBox.exec_() == QMessageBox.Yes: QtGui.qApp.quit()
def new_selected(self): msgBox = QMessageBox() msgBox.setText("Do you want to discard your changes?") msgBox.setStandardButtons(QMessageBox.Discard | QMessageBox.Cancel) msgBox.setDefaultButton(QMessageBox.Cancel) ret = msgBox.exec_() if ret == QMessageBox.Cancel: return self.filename = None self.apply_default()
def updateDialog(self): msgBox = QMessageBox() msgBox.setWindowTitle('Update available') msgBox.setText("There is a new version of AssetJet available.\n" \ "Do you want to download and install?") msgBox.setStandardButtons(QMessageBox.Yes | QtGui.QMessageBox.No) msgBox.setIcon(QMessageBox.Question) msgBox.setDefaultButton(QMessageBox.Yes) msgBox.setWindowIcon(QtGui.QIcon(':/Pie-chart.ico')) reply = msgBox.exec_() return reply
def removeButtonClicked(self): """ Remove the last transformation in the list. """ messageBox = QMessageBox() messageBox.setText("The last transformation is about to be removed.") messageBox.setInformativeText("Do you want to proceed?") messageBox.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel) messageBox.setDefaultButton(QMessageBox.Ok) res = messageBox.exec_() if res == QMessageBox.Ok: self.transformationView.removeLastRow()
def showCancelMessage(self): msgBox = QMessageBox() msgBox.setText("Are You Sure You Want To Cancel %s" % self.mode) msgBox.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel) msgBox.setDefaultButton(QMessageBox.Cancel) ret = msgBox.exec_() if ret == QMessageBox.Ok: self.end_process_early.value = 1 elif ret == QMessageBox.Cancel: self.paused.value = 0 self.pause_requested.value = 0 self.pause_sig_sent.value = 0 self.pause_requested.value = 0
def run(app): # Ask user for AssetJet database location dlgDbLocation = DbLocation() # Hide the 'What's This' question mark dlgDbLocation.setWindowFlags(QtCore.Qt.WindowTitleHint) if dlgDbLocation.exec_(): loc = os.path.join(dlgDbLocation.getText(),'assetjet.db') # create directory if it doesn't exist yet if not os.path.exists(dlgDbLocation.getText()): os.mkdir(dlgDbLocation.getText()) cfg.add_entry('Database', 'DbFileName', loc) # Start download thread if database is not existing yet if not os.path.exists(loc): # Check internet connection from assetjet.util import util if util.test_url('http://finance.yahoo.com'): # Start download thread download = download_data.Downloader(loc) download.daemon = True download.start() # Create download progress dialog dlgProgress = QtGui.QProgressDialog( labelText='Downloading 1 year of daily returns for members of the S&P 500. \n This may take a couple of minutes.\n' , minimum = 0, maximum = 500, flags=Qt.CustomizeWindowHint | Qt.WindowTitleHint) dlgProgress.setWindowTitle('Downloading...') dlgProgress.setCancelButton(None) dlgProgress.setWindowIcon(QtGui.QIcon(':/Pie-chart.ico')) dlgProgress.show() # Update progress bar through signal download.downloaded.connect(dlgProgress.setValue) download.finished.connect(dlgProgress.close) app.exec_() # TODO: let it run in parallel with the local server thread download.wait() else: msgBox = QMessageBox() msgBox.setWindowTitle('No Internet Connection') msgBox.setText("To run AssetJet the first time, you need a working \n" \ "internet connection to download the historical returns.") msgBox.setStandardButtons(QMessageBox.Ok) msgBox.setIcon(QMessageBox.Warning) msgBox.setDefaultButton(QMessageBox.Ok) msgBox.setWindowIcon(QtGui.QIcon(':/Pie-chart.ico')) reply = msgBox.exec_() sys.exit()
def closeEvent(self, event): msgBox = QMessageBox() msgBox.setText("Do you want to save before quitting?") msgBox.setInformativeText("Do you want to save your changes?") msgBox.setStandardButtons(QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel) msgBox.setDefaultButton(QMessageBox.Save) ret = msgBox.exec_() if ret == QMessageBox.Save: self.save_file() event.accept() elif ret == QMessageBox.Discard: event.accept() else: event.ignore()
def exception(parent, ex, buttons=QMessageBox.Ok, defaultButton=QMessageBox.NoButton): title = type(ex).__name__ message = str(ex) tb = StringIO() if hasattr(ex, '__traceback__'): exc_traceback = ex.__traceback__ else: exc_traceback = sys.exc_info()[2] traceback.print_tb(exc_traceback, file=tb) msgbox = QMessageBox(QMessageBox.Icon.Critical, title, message, buttons, parent) msgbox.setDefaultButton(defaultButton) msgbox.setDetailedText(tb.getvalue()) msgbox.exec_()
def on_override_panels(): """ Override HyperShade and NodeEditor creation callback""" override_info_box = QMessageBox() override_info_box.setWindowTitle(WINDOW_TITLE) override_info_box.setIcon(QMessageBox.Information) override_info_box.setText( 'Buttons will be added to HyperShade toolbar and Node Editor toolbar.<br/>' 'Changes will exists during this session.' ) override_info_box.setInformativeText('<i>Read Help to set this settings permanent</i>') override_info_box.setStandardButtons(QMessageBox.Ok) override_info_box.setDefaultButton(QMessageBox.Ok) override_info_box.exec_() mttOverridePanels.override_panels()
def newFile(self): """ Create a blank new file. """ if self.saved is False and self.editor.toPlainText() != '': msgBox = QMessageBox() msgBox.setText("The document has been modified.") msgBox.setInformativeText("really discard current document?") msgBox.setStandardButtons(QMessageBox.Discard | QMessageBox.Cancel) msgBox.setDefaultButton(QMessageBox.Cancel) ret = msgBox.exec_() if ret == QMessageBox.Cancel: return self.editor.clear() self.filename = ''
def ssl_errors(self, reply): try: self.replies.remove(reply) except KeyError: return False ca_cert = reply.sslConfiguration().peerCertificateChain()[-1] if not ca_cert.isValid(): self.message.setText( '<span style="font-size: 10px; color: #aa0000;">' + "Das Zertifikat ist nicht gültig." + "</span>" ) return False domain_list = [] for cert in reply.sslConfiguration().peerCertificateChain(): domain_list.append(cert.subjectInfo(cert.SubjectInfo.CommonName)) for key in cert.alternateSubjectNames().keys(): if type(key) == str and key[:3] == "DNS": domain_list.append(cert.alternateSubjectNames()[key]) print(extract_full_domain(self.url_edit.text())) print(domain_list) if extract_full_domain(self.url_edit.text()) not in domain_list: self.message.setText( '<span style="font-size: 10px; color: #aa0000;">' + "Das Zertifikat wurde für eine andere Domain ausgestellt." + "</span>" ) return False message_box = QMessageBox() message_box.setText("Ein unbekanntes CA-Zertifikat wurde gefunden.") message_box.setInformativeText( "Das Zertifikat hat den Fingerabdruck " + ":".join(re.findall("(.{2})", str(ca_cert.digest(QCryptographicHash.Sha1).toHex().toUpper()))) + ". Möchten Sie diesem Zertifikat vertrauen?" ) message_box.setStandardButtons(QMessageBox.No | QMessageBox.Yes) message_box.setDefaultButton(QMessageBox.Yes) answer = message_box.exec_() if answer != QMessageBox.Yes: self.message.setText( '<span style="font-size: 10px; color: #aa0000;">' + "Sie haben dem Zertifikat nicht vertraut." + "</span>" ) return False if not self.certificate: reply.ignoreSslErrors() self.certificate = ca_cert.toPem() self.save_settings() self.certificate_loaded.emit()
def removeUnusedClips(self) : # Get selected items item = self.selectedItem proj = item.project() # Build a list of Projects SEQS = hiero.core.findItems(proj,"Sequences") # Build a list of Clips CLIPSTOREMOVE = hiero.core.findItems(proj,"Clips") # For each sequence, iterate through each track Item, see if the Clip is in the CLIPS list. # Remaining items in CLIPS will be removed for seq in SEQS: # Loop through selected and make folders... for track in seq: for trackitem in track: if trackitem.source() in CLIPSTOREMOVE: CLIPSTOREMOVE.remove(trackitem.source()) # If there are no Clips to remove, return if len(CLIPSTOREMOVE)==0: return # Present Dialog Asking if User wants to remove Clips msgBox = QMessageBox() msgBox.setWindowTitle("Remove Unused Clips"); msgBox.setText("Remove %i unused Clips from Project %s?" % (len(CLIPSTOREMOVE),proj.name())); msgBox.setDetailedText("Remove:\n %s" % (str(CLIPSTOREMOVE))); msgBox.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel); msgBox.setDefaultButton(QMessageBox.Ok); ret = msgBox.exec_() if ret == QMessageBox.Cancel: return elif ret == QMessageBox.Ok: BINS = [] with proj.beginUndo('Remove Unused Clips'): # Delete the rest of the Clips for clip in CLIPSTOREMOVE: BI = clip.binItem() B = BI.parentBin() BINS+=[B] B.removeItem(BI)
def closeTab(self): if self.tabWidget.currentWidget().getSaved() is True: self.tabWidget.removeTab(self.tabWidget.currentWidget().getIndex()) else: confirmBox = QMessageBox() confirmBox.setText('The document has been modified.') confirmBox.setInformativeText('Do you want to save your changes?') confirmBox.setStandardButtons(QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel) confirmBox.setDefaultButton(QMessageBox.Save) confirm = confirmBox.exec_() if confirm == QMessageBox.Save: self.tabWidget.currentWidget().save() self.closeTab() elif confirm == QMessageBox.Discard: self.tabWidget.removeTab(self.tabWidget.currentWidget().getIndex()) elif confirm == QMessageBox.Cancel: pass else: raise ValueError(confirm)
def closeEvent(self, event): if self.process is not None: msg = QMessageBox() msg.setIcon(QMessageBox.Warning) msg.setWindowTitle('Confirm process interruption') msg.setText( 'Closing the window will terminate the running process. ' 'Do you really want to exit?') msg.setInformativeText('Interrupting the process may leave partly ' 'created files that cannot be used for ' 'further analysis.') close_button = msg.addButton("Stop and close", QMessageBox.YesRole) cancel_button = msg.addButton("Cancel", QMessageBox.NoRole) msg.setDefaultButton(cancel_button) msg.exec_() if msg.clickedButton() == close_button: self.stop(force=True) super(LaunchGUI, self).closeEvent(event) else: event.ignore()
def stop(self, force=False): if self.process is not None: if not force: msg = QMessageBox() msg.setIcon(QMessageBox.Warning) msg.setWindowTitle('Confirm process termination') msg.setText( 'This will terminate the running process. Are you sure ' 'you want to do this?') msg.setInformativeText( 'Interrupting the process may leave partly ' 'created files that cannot be used for ' 'further analysis.') msg.addButton('Stop process', QMessageBox.YesRole) cancel_button = msg.addButton('Cancel', QMessageBox.NoRole) msg.setDefaultButton(cancel_button) msg.exec_() if msg.clickedButton() == cancel_button: # Continue to run return self._interrupted = True # Terminate child processes as well pid = int(self.process.pid()) if sys.platform == 'win32' and pid != 0: # The returned value is not a PID but a pointer lp = ctypes.cast(pid, LPWinProcInfo) pid = lp.contents.dwProcessID if pid != 0: process = psutil.Process(pid) children = process.children(recursive=True) for proc in children: proc.terminate() gone, alive = psutil.wait_procs(children, timeout=3) for proc in alive: proc.kill() self.process.terminate() self.process = None
def download_file(self): """ Takes whatever text the combobox is showing. Either uses the imgur or youtube download methods depending on the file extension """ filename = self.uploaded_combo.currentText() if filename in self.filenameToLink: if filename[-3:] == 'mp4': dv = DownloadVideo(self.filenameToLink[filename]) dv.downloadVideo() elif filename[-3:] == 'mp3': downloadMP3(self.filenameToLink[filename]) else: self.imgur_uploader.download_image( self.filenameToLink[filename], filename) msgBox = QMessageBox() msgBox.setText("File downloaded.") msgBox.setStandardButtons(QMessageBox.Ok) msgBox.setDefaultButton(QMessageBox.Ok) ret = msgBox.exec_()
def openFile(self, filename=None): """ Open a file. """ if self.saved is False and self.editor.toPlainText() != '': msgBox = QMessageBox() msgBox.setText("The document has been modified.") msgBox.setInformativeText("Really discard current document?") msgBox.setStandardButtons(QMessageBox.Discard | QMessageBox.Cancel) msgBox.setDefaultButton(QMessageBox.Cancel) ret = msgBox.exec_() if ret == QMessageBox.Cancel: return self.editor.clear() if not filename: fname, _ = QtGui.QFileDialog.getOpenFileName( self, 'Open file', '', ("Markdown Files (*.txt *.md)")) self.filename = fname else: fname = filename self.filename = filename f = open(fname, 'r') # change working directory os.chdir(os.path.dirname(f.name)) with f: tmp = f.read() tmp = tmp.decode('utf-8') self.editor.insertPlainText(tmp) f.close() self.saved = True self.saveStatus.setText('Document saved: ' + str(self.saved))
def closeEvent(self, event): """ Called when the main window is closing, and meaning that the application is exiting. The application then saves the layout, and then check for unsaved documents. Override from QWidget. """ self.userLayout.saveLayout() # check for unsaved files. for o in PySUMOWidget.IA.ontologies: changed, diff = self.ontologyChanged(o) if changed: msgBox = QMessageBox(self) msgBox.setText("The ontology file \"" + o.name + "\" has been modified.") msgBox.setInformativeText("Do you want to save your changes?") msgBox.setDetailedText(diff) msgBox.setStandardButtons(QMessageBox.Save | QMessageBox.Discard) msgBox.setDefaultButton(QMessageBox.Save) ret = msgBox.exec_() if ret == QMessageBox.Save: o.save() super(MainWindow, self).closeEvent(event)
def __abortComputationBox(self): tit = self.tr("Aborting Batch Computation") txt = self.tr("Reduce is currently evaluating several groups in " "batch. Do you want to interrupt only the current " "computation or all?") diag = QMessageBox(self.model.controller.mainWindow) diag.setWindowTitle(tit) diag.setIcon(QMessageBox.Question) diag.setText(txt) abortAll = diag.addButton("Abort All",QMessageBox.YesRole) abortCurrent = diag.addButton("Abort Current",QMessageBox.YesRole) cancel = diag.addButton(QMessageBox.StandardButton.Cancel) diag.setDefaultButton(abortAll) diag.setEscapeButton(cancel) diag.setWindowModality(Qt.WindowModal) diag.exec_() ans = diag.clickedButton() if ans == abortAll: return 'all' elif ans == abortCurrent: return 'current' elif ans == cancel: return 'cancel' traceLogger.critical("unidentifiable button %s" % ans)
def _closeOntology_(self, ontology, ontologyMenu): """ QT Slot which handles the close ontology action when it is triggered. Parameter : - ontology : The ontology to delete. - ontologyMenu : The QMenu where the ontology could be managed. It should be remove too. """ changed, diff = self.ontologyChanged(ontology) if changed: msgBox = QMessageBox(self) msgBox.setText("The ontology file \"" + ontology.name + "\" has been modified.") msgBox.setInformativeText("Do you want to save your changes?") msgBox.setDetailedText(diff) msgBox.setStandardButtons(QMessageBox.Save | QMessageBox.Discard) msgBox.setDefaultButton(QMessageBox.Save) ret = msgBox.exec_() if ret == QMessageBox.Save: ontology.save() self.removeOntology(ontology) # remove ontology in active ones. ontologyMenu.deleteLater()
def openFile(self, filename = None): """ Open a file. """ if self.saved is False and self.editor.toPlainText() != '': msgBox = QMessageBox() msgBox.setText("The document has been modified.") msgBox.setInformativeText("Really discard current document?") msgBox.setStandardButtons(QMessageBox.Discard | QMessageBox.Cancel) msgBox.setDefaultButton(QMessageBox.Cancel) ret = msgBox.exec_() if ret == QMessageBox.Cancel: return self.editor.clear() if not filename: fname, _ = QtGui.QFileDialog.getOpenFileName(self, 'Open file', '', ("Markdown Files (*.txt *.md)")) self.filename = fname else: fname = filename self.filename = filename f = open(fname, 'r') # change working directory os.chdir(os.path.dirname(f.name)) with f: tmp = f.read() tmp = tmp.decode('utf-8') self.editor.insertPlainText(tmp) f.close() self.saved = True self.saveStatus.setText('Document saved: ' + str(self.saved))
def warningDialogBox(self, title, message, typeButton='ok'): msgBox = QMessageBox() msgBox.setText("<p align='center'>" + title + "</p>") msgBox.setInformativeText("<p align='center'>" + message + "</p>") if typeButton: if typeButton.lower() == "yesno": msgBox.setStandardButtons(QMessageBox.No | QMessageBox.Yes) msgBox.setDefaultButton(QMessageBox.No) elif typeButton.lower() == "yesnoall": msgBox.setStandardButtons(QMessageBox.No | QMessageBox.NoToAll | QMessageBox.Yes | QMessageBox.YesToAll) msgBox.setDefaultButton(QMessageBox.No) elif typeButton.lower() == "savedisccan": msgBox.setStandardButtons(QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel) msgBox.setDefaultButton(QMessageBox.Save) return msgBox.exec_()
def warningDialogBox(title, message, typeButton=Ok): msgBox = QMessageBox() msgBox.setText("<p align='center'>" + title + "</p>") msgBox.setInformativeText("<p align='center'>" + message + "</p>") if typeButton: if typeButton == WarningBox.YesNo: msgBox.setStandardButtons(QMessageBox.No | QMessageBox.Yes) msgBox.setDefaultButton(QMessageBox.No) elif typeButton == WarningBox.YesNoAll: msgBox.setStandardButtons(QMessageBox.No | QMessageBox.NoToAll | QMessageBox.Yes | QMessageBox.YesToAll) msgBox.setDefaultButton(QMessageBox.No) elif typeButton == WarningBox.SaveDiscCan: msgBox.setStandardButtons(QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel) msgBox.setDefaultButton(QMessageBox.Save) return msgBox.exec_()
def load_model(self, filename=None): """ Loads a given SBML file, thereby creating a new subwindow on the main MDI Area. If filename is None, it creates a new model. There are a lot of reference variables, so that the system knows the currently active subwindow, etc. @param filename: The filename of the model. If None, a new model is created. @type filename: str """ if not filename: action = self.sender() if type(action) == QAction: filename = action.data() else: return # note: this has been (temporarily added) to allow only one file to be open at the same time # We will probably change this behaviour again later, once we have decided how to handle # multiple-model results, etc. intelligently if len(self.ModelControllers) > 0: # show warning dialog msgBox = QMessageBox() infoText =\ """<b>Another model is currently loaded.</b><br> """ msgBox.setText(infoText) infoTextShort = "Do you want to save the current model (you will be prompted to enter a new filename)?" msgBox.setInformativeText(infoTextShort) msgBox.setWindowTitle(infoTextShort) msgBox.setStandardButtons(QMessageBox.Save | QMessageBox.Discard) msgBox.setDefaultButton(QMessageBox.Save) msgBox.setIcon(QMessageBox.Warning) # msgBox.setWindowIcon(None) clickedButton = msgBox.exec_() if clickedButton == QMessageBox.Save: self.actionSave_as.trigger() for modelController in self.ModelControllers.values(): # close all models (in theory, there should be only one :) self.modelClosed.emit(modelController) # self.NetworkWindowCount += 1 # self.setStatusTip("Opening file %s..." % filename) self.statusBar().showMessage("Opening file %s..." % filename, 2000) modelController = ModelController(filename=filename, views=self.mainWindowViews) # # create NetworkViewController # networkViewController = NetworkViewController(modelController=modelController) # networkView = networkViewController.createNetworkView(self) # sets networkController.networkView internally # networkView.setMinimumSize(400, 300) # modelController.setViews(networkViewController=networkViewController) # # Create Subwindow to hold the NetworkView # subWindow = QMdiSubWindow(parent=self._mdiArea) # networkViewController.subWindow = subWindow # subWindow.setAttribute(Qt.WA_DeleteOnClose) # subWindow.setWidget(networkView) # subWindow.setOption(QMdiSubWindow.RubberBandResize, True) # self._mdiArea.addSubWindow(subWindow) # subWindow.activateWindow() # # # why do these not work to emit a self._mdiArea.networkWindowActivated Signal? # # self._mdiArea.setActiveSubWindow(subWindow) # # self._mdiArea.activateNextSubWindow() # # self._mdiArea.subWindowActivated() # # subWindow.show() # important! # networkView.show() # handle references filename = modelController.filename # self.SubWindowToModelControllers[subWindow] = modelController # self.networkSubWindows[modelController] = subWindow #networkView self.ModelControllers[filename] = modelController # self.ActiveNetworkWindow = networkWindow self.ActiveModelController = modelController # self.connectNetworkWindowSignals(networkView, subWindow) # emit custom Signal so that e.g. Simulationworkbench are notified of the new subwindow # self.newNetworkWindowCreated.emit() self.activeModelChanged.emit(modelController) # handle recent files list if filename in self.recentFiles: self.recentFiles.remove(filename) self.recentFiles.insert(0, filename) if len(self.recentFiles) > NUM_RECENT_FILES: # cap list at length of NUM_RECENT_FILES self.recentFiles = self.recentFiles[:NUM_RECENT_FILES]
def upload_file(self): """ Takes data from the text boxes. If there is enough info, the video is uploaded. A dialog opens when complete """ fileName = self.filename_text.text() description = self.description_text.text() title = self.title_text.text() if fileName[-3:] == 'png' or fileName[-3:] == 'jpg': smallName = fileName.split('/')[-1] self.uploaded_combo.addItem(smallName) result = self.imgur_uploader.upload_image(fileName) self.filenameToLink[smallName] = result['id'] # print 'Image upload: ', result self.backend.addToDB('Image', smallName, result['id'], self.backend_service) msgBox = QMessageBox() msgBox.setText("File uploaded.") msgBox.setStandardButtons(QMessageBox.Ok) msgBox.setDefaultButton(QMessageBox.Ok) ret = msgBox.exec_() return if not (fileName and description and title): return file_type = 'Video' smallName = fileName.split('/')[-1] if fileName[-3:] == 'mp3': vFileName = smallName[:-3] + 'avi' os.system('ffmpeg -loop 1 -r 1 -i pic.jpg -i ' + fileName + ' -c:a copy -shortest ' + vFileName) fileName = vFileName file_type = 'Audio' category = '22' keywords = 'empty' privacyStatus = 'unlisted' args = { 'fileName': fileName, 'title': title, 'description': description, 'category:': category, 'keywords': keywords, 'privacyStatus': privacyStatus } videoUrl = upload(args) msgBox = QMessageBox() msgBox.setText("File uploaded.") msgBox.setStandardButtons(QMessageBox.Ok) msgBox.setDefaultButton(QMessageBox.Ok) ret = msgBox.exec_() self.uploaded_combo.addItem(smallName) self.filenameToLink[ smallName] = r'https://www.youtube.com/watch?v=' + videoUrl self.backend.addToDB(file_type, smallName, r'https://www.youtube.com/watch?v=' + videoUrl, self.backend_service)
def load_model(self, filename=None): """ Loads a given SBML file, thereby creating a new subwindow on the main MDI Area. If filename is None, it creates a new model. There are a lot of reference variables, so that the system knows the currently active subwindow, etc. @param filename: The filename of the model. If None, a new model is created. @type filename: str """ if not filename: action = self.sender() if type(action) == QAction: filename = action.data() else: return # note: this has been (temporarily added) to allow only one file to be open at the same time # We will probably change this behaviour again later, once we have decided how to handle # multiple-model results, etc. intelligently if len(self.ModelControllers) > 0: # show warning dialog msgBox = QMessageBox() infoText = """<b>Another model is currently loaded.</b><br> """ msgBox.setText(infoText) infoTextShort = "Do you want to save the current model (you will be prompted to enter a new filename)?" msgBox.setInformativeText(infoTextShort) msgBox.setWindowTitle(infoTextShort) msgBox.setStandardButtons(QMessageBox.Save | QMessageBox.Discard) msgBox.setDefaultButton(QMessageBox.Save) msgBox.setIcon(QMessageBox.Warning) clickedButton = msgBox.exec_() if clickedButton == QMessageBox.Save: self.actionSave_as.trigger() for ( modelController ) in self.ModelControllers.values(): # close all models (in theory, there should be only one :) self.modelClosed.emit(modelController) # self.NetworkWindowCount += 1 # self.setStatusTip("Opening file %s..." % filename) self.statusBar().showMessage("Opening file %s..." % filename, 2000) modelController = ModelController(filename=filename, views=self.mainWindowViews) # # create NetworkViewController # networkViewController = NetworkViewController(modelController=modelController) # networkView = networkViewController.createNetworkView(self) # sets networkController.networkView internally # networkView.setMinimumSize(400, 300) # modelController.setViews(networkViewController=networkViewController) # # Create Subwindow to hold the NetworkView # subWindow = QMdiSubWindow(parent=self._mdiArea) # networkViewController.subWindow = subWindow # subWindow.setAttribute(Qt.WA_DeleteOnClose) # subWindow.setWidget(networkView) # subWindow.setOption(QMdiSubWindow.RubberBandResize, True) # self._mdiArea.addSubWindow(subWindow) # subWindow.activateWindow() # subWindow.show() # important! # networkView.show() # handle references filename = modelController.filename # self.SubWindowToModelControllers[subWindow] = modelController # self.networkSubWindows[modelController] = subWindow #networkView self.ModelControllers[filename] = modelController # self.ActiveNetworkWindow = networkWindow self.ActiveModelController = modelController # self.connectNetworkWindowSignals(networkView, subWindow) # emit custom Signal so that e.g. Simulationworkbench are notified of the new subwindow # self.newNetworkWindowCreated.emit() self.activeModelChanged.emit(modelController) # handle recent files list if filename in self.recentFiles: self.recentFiles.remove(filename) self.recentFiles.insert(0, filename) if len(self.recentFiles) > NUM_RECENT_FILES: # cap list at length of NUM_RECENT_FILES self.recentFiles = self.recentFiles[:NUM_RECENT_FILES]