def __createActions(self): self._addTemplateAction = CommonWidgets.TestermanAction(self, "New template...", self._addTemplate) self.addAction(self._addTemplateAction) self._removeTemplateAction = CommonWidgets.TestermanAction(self, "Remove template...", self._removeTemplate) self.addAction(self._removeTemplateAction) self._modifyTemplateAction = CommonWidgets.TestermanAction(self, "Modify template...", self._modifyTemplate) self.addAction(self._modifyTemplateAction)
def openUrl(self, url): """ Universal opener. Url is either: testerman://<server:port><absolute path> for a remote file on the current testerman server, file://<absolute path> for a local file @type url: QUrl @param url: the URL to open Returns True if OK. """ log("Opening url: %s" % url.toString()) fileTimestamp = None contents = None if url.scheme() == 'file': log("Opening local file: %s" % url.toString()) try: path = url.toLocalFile() f = open(unicode(path), 'r') contents = f.read() f.close() fileTimestamp = os.stat(unicode(path)).st_mtime except Exception, e: CommonWidgets.systemError( self, 'Unable to open %s: %s' % (unicode(path), str(e))) return False
def saveTeAs(self): """ Open a save dialog box to save the TE egg file locally. """ teRemoteFilename = self._details.get("te-filename") # Open a browser settings = QSettings() directory = settings.value('lastVisitedDirectory', QVariant("")).toString() filename = QFileDialog.getSaveFileName( self, "Save Test Executable as...", directory, "Testerman Test Executable (*.egg)") if filename.isEmpty(): return False directory = os.path.dirname(unicode(filename)) settings.setValue('lastVisitedDirectory', QVariant(directory)) try: te = self._client.getFile(teRemoteFilename) f = open(unicode(filename), 'w') # Store files as utf8 f.write(te) f.close() QMessageBox.information(self, getClientName(), "Test Executable successfully saved.", QMessageBox.Ok) except Exception as e: CommonWidgets.systemError( self, "Unable to save file as %s: %s" % (filename, str(e))) return False
def _showContentDocumentation(self, content, key): settings = QSettings() path = "plugins/%s" % PLUGIN_ID defaultDocumentationCache = os.path.normpath( unicode(QDir.homePath()) + "/.testerman/") documentationCache = os.path.normpath( unicode( settings.value('%s/cacheDir' % path, QVariant(QString( defaultDocumentationCache))).toString()) + "/docCache") cache = DocumentationCacheManager(documentationCache) transient = CommonWidgets.WTransientWindow("Doc Generator", self.parent()) transient.showTextLabel("Generating documentation...") path = cache.generateDocumentation(content, key) transient.hide() transient.setParent(None) if path: view = WDocumentationView(path, "Documentation for %s" % key, self.parent()) view.setWindowFlags(Qt.Window) view.resize(QSize(800, 600)) view.show() else: CommonWidgets.systemError( parent, "Unable to generate documentation, please check stderr output.\nPlease check epydoc syntax and indentation" )
def openTab(self, documentModel): """ Opens a new tab with an editor editing the document model. """ # Find an editor to edit the model documentEditorClasses = getDocumentEditorClass(documentModel) if not documentEditorClasses: CommonWidgets.systemError(self, 'Unable to find a suitable editor to edit %s' % documentModel.getName()) return False elif len(documentEditorClasses) > 1: log("Multiple editors found to edit %s. Selecting the first one." % documentModel.getName()) documentEditorClass = documentEditorClasses[0] documentEditor = documentEditorClass(documentModel, self.tab) name = documentModel.getShortName() tabIndex = self.tab.addTab(documentEditor, documentEditor.getIcon(), name) self.tab.setTabToolTip(tabIndex, documentModel.getUrl().toString()) documentEditor.setTabWidget(self.tab) #We should not do this but it doesn't work without for the first tab. self.tab.emit(SIGNAL('currentChanged(int)'), tabIndex) # Set the focus on this tab self.tab.setCurrentIndex(tabIndex) self.connect(documentModel, SIGNAL('urlUpdated()'), self.documentUrlsUpdated) self.documentUrlsUpdated() return True
def openUrl(self, url): """ Universal opener. Url is either: testerman://<server:port><absolute path> for a remote file on the current testerman server, file://<absolute path> for a local file @type url: QUrl @param url: the URL to open Returns True if OK. """ log("Opening url: %s" % url.toString()) fileTimestamp = None contents = None if url.scheme() == 'file': log("Opening local file: %s" % url.toString()) try: path = url.toLocalFile() f = open(unicode(path), 'r') contents = f.read() f.close() fileTimestamp = os.stat(unicode(path)).st_mtime except Exception, e: CommonWidgets.systemError(self, 'Unable to open %s: %s' % (unicode(path), str(e))) return False
def openTab(self, documentModel): """ Opens a new tab with an editor editing the document model. """ # Find an editor to edit the model documentEditorClasses = getDocumentEditorClass(documentModel) if not documentEditorClasses: CommonWidgets.systemError( self, 'Unable to find a suitable editor to edit %s' % documentModel.getName()) return False elif len(documentEditorClasses) > 1: log("Multiple editors found to edit %s. Selecting the first one." % documentModel.getName()) documentEditorClass = documentEditorClasses[0] documentEditor = documentEditorClass(documentModel, self.tab) name = documentModel.getShortName() tabIndex = self.tab.addTab(documentEditor, documentEditor.getIcon(), name) self.tab.setTabToolTip(tabIndex, documentModel.getUrl().toString()) documentEditor.setTabWidget(self.tab) #We should not do this but it doesn't work without for the first tab. self.tab.emit(SIGNAL('currentChanged(int)'), tabIndex) # Set the focus on this tab self.tab.setCurrentIndex(tabIndex) self.connect(documentModel, SIGNAL('urlUpdated()'), self.documentUrlsUpdated) self.documentUrlsUpdated() return True
def reloadCurrent(self, force=False): """ Ask for a confirmation, then reload current document in current tab. """ model = self.tab.currentWidget().model # If the model has never been saved, discard if model.getUrl() is None: return # If the model has been modified, ask for a confirmation if not force and model.isModified(): ret = QMessageBox.warning( self, getClientName(), "Are you sure you want to reload this file and discard your changes?", QMessageBox.Yes, QMessageBox.No) if ret != QMessageBox.Yes: return # OK, now we can reload it. contents = None fileTimestamp = None if model.isRemote(): log("Reloading remote file...") path = model.getUrl().path() contents = getProxy().getFile(unicode(path)) info = getProxy().getFileInfo(unicode(path)) if contents and info: fileTimestamp = info['timestamp'] else: CommonWidgets.systemError( self, "Unable to reload file from the repository: the file does not seem to exist anymore" ) else: log("Reloading local file...") try: path = model.getUrl().toLocalFile() f = open(unicode(path), 'r') contents = f.read() f.close() fileTimestamp = os.stat(unicode(path)).st_mtime except Exception, e: CommonWidgets.systemError( self, 'Unable to open %s: %s' % (model.getUrl().toString(), unicode(e)))
def _saveAs(self): path = "plugins/%s/" % self._pluginId settings = QSettings() directory = settings.value(path + 'lastVisitedDirectory', QVariant("")).toString() filename = QFileDialog.getSaveFileName(self, "Save as...", directory) if filename.isEmpty(): return False filename = unicode(filename) directory = os.path.dirname(filename) settings.setValue(path + 'lastVisitedDirectory', QVariant(directory)) try: f = open(filename, 'w') f.write(unicode(self._source).encode('utf-8')) f.close() QMessageBox.information(self, getClientName(), "File saved successfully.", QMessageBox.Ok) return True except Exception, e: CommonWidgets.systemError(self, "Unable to save file as %s: %s" % (filename, unicode(e))) return False
def _saveAs(self): path = "plugins/%s/" % self._pluginId settings = QSettings() directory = settings.value(path + 'lastVisitedDirectory', QVariant("")).toString() filename = QFileDialog.getSaveFileName(self, "Save as...", directory) if filename.isEmpty(): return False filename = unicode(filename) directory = os.path.dirname(filename) settings.setValue(path + 'lastVisitedDirectory', QVariant(directory)) try: f = open(filename, 'w') f.write(unicode(self._source).encode('utf-8')) f.close() QMessageBox.information(self, getClientName(), "File saved successfully.", QMessageBox.Ok) return True except Exception as e: CommonWidgets.systemError(self, "Unable to save file as %s: %s" % (filename, unicode(e))) return False
def reloadCurrent(self, force = False): """ Ask for a confirmation, then reload current document in current tab. """ model = self.tab.currentWidget().model # If the model has never been saved, discard if model.getUrl() is None: return # If the model has been modified, ask for a confirmation if not force and model.isModified(): ret = QMessageBox.warning(self, getClientName(), "Are you sure you want to reload this file and discard your changes?", QMessageBox.Yes, QMessageBox.No) if ret != QMessageBox.Yes: return # OK, now we can reload it. contents = None fileTimestamp = None if model.isRemote(): log("Reloading remote file...") path = model.getUrl().path() contents = getProxy().getFile(unicode(path)) info = getProxy().getFileInfo(unicode(path)) if contents and info: fileTimestamp = info['timestamp'] else: CommonWidgets.systemError(self, "Unable to reload file from the repository: the file does not seem to exist anymore") else: log("Reloading local file...") try: path = model.getUrl().toLocalFile() f = open(unicode(path), 'r') contents = f.read() f.close() fileTimestamp = os.stat(unicode(path)).st_mtime except Exception, e: CommonWidgets.systemError(self, 'Unable to open %s: %s' % (model.getUrl().toString(), unicode(e)))
def __init__(self, parent = None): QTextEdit.__init__(self, parent) self.setWindowTitle("%s logs" % getClientName()) self.setWindowIcon(icon(':/icons/log')) self.setReadOnly(True) self.setWordWrapMode(QTextOption.NoWrap) self.resize(QSize(800, 600)) self._clearAction = CommonWidgets.TestermanAction(self, "Clear", self.clear) self.connect(getLoggingStream(), SIGNAL('loggingEvent(const QString &)'), self.append) logging.getLogger().info("Logger initialized.")
def _showContentDocumentation(self, content, key): settings = QSettings() path = "plugins/%s" % PLUGIN_ID defaultDocumentationCache = os.path.normpath(unicode(QDir.homePath()) + "/.testerman/") documentationCache = os.path.normpath( unicode(settings.value("%s/cacheDir" % path, QVariant(QString(defaultDocumentationCache))).toString()) + "/docCache" ) cache = DocumentationCacheManager(documentationCache) transient = CommonWidgets.WTransientWindow("Doc Generator", self.parent()) transient.showTextLabel("Generating documentation...") path = cache.generateDocumentation(content, key) transient.hide() transient.setParent(None) if path: view = WDocumentationView(path, "Documentation for %s" % key, self.parent()) view.setWindowFlags(Qt.Window) view.resize(QSize(800, 600)) view.show() else: CommonWidgets.systemError( parent, "Unable to generate documentation, please check stderr output.\nPlease check epydoc syntax and indentation", )
def __createWidgets(self, dateTime): self.setWindowTitle("Reschedule a run") self.setWindowIcon(icon(':icons/testerman.png')) layout = QVBoxLayout() # Date picker self._dateTimePicker = CommonWidgets.WDateTimePicker() layout.addWidget(self._dateTimePicker) buttonLayout = QHBoxLayout() buttonLayout.addStretch() self._okButton = QPushButton("Reschedule", self) self.connect(self._okButton, SIGNAL("clicked()"), self.accept) buttonLayout.addWidget(self._okButton) self._cancelButton = QPushButton("Cancel", self) self.connect(self._cancelButton, SIGNAL("clicked()"), self.reject) buttonLayout.addWidget(self._cancelButton) layout.addLayout(buttonLayout) self.setLayout(layout)
def openUrl(self, url): """ Universal opener. Url is either: testerman://<server:port><absolute path> for a remote file on the current testerman server, file://<absolute path> for a local file @type url: QUrl @param url: the URL to open Returns True if OK. """ log("Opening url: %s" % url.toString()) fileTimestamp = None contents = None if url.scheme() == 'file': log("Opening local file: %s" % url.toString()) try: path = url.toLocalFile() f = open(unicode(path), 'r') contents = f.read() f.close() fileTimestamp = os.stat(unicode(path)).st_mtime except Exception as e: CommonWidgets.systemError( self, 'Unable to open %s: %s' % (unicode(path), str(e))) return False elif url.scheme() == 'testerman': log("Opening remote file: %s" % url.toString()) try: path = url.path() # ignore the server contents = getProxy().getFile(unicode(path)) info = getProxy().getFileInfo(unicode(path)) except: contents = None info = None if (contents is None) or not info: log("Unable to open remote file due to a transport or Ws error" ) return False fileTimestamp = info['timestamp'] else: log("Unknown URL scheme. Not opening.") return False # Now, creates a model based on the file to open filename = os.path.split(unicode(path))[1] documentModelClass = DocumentModels.getDocumentModelClass(filename) if not documentModelClass: CommonWidgets.systemError( self, 'Unable to detect file type. Not opening %s' % unicode(path)) return False model = documentModelClass() model.setDocumentSource(contents) model.setSavedAttributes(url=url, timestamp=fileTimestamp) return self.openTab(model)
if (contents is None) or not info: log("Unable to open remote file due to a transport or Ws error") return False fileTimestamp = info['timestamp'] else: log("Unknown URL scheme. Not opening.") return False # Now, creates a model based on the file to open filename = os.path.split(unicode(path))[1] documentModelClass = DocumentModels.getDocumentModelClass(filename) if not documentModelClass: CommonWidgets.systemError(self, 'Unable to detect file type. Not opening %s' % unicode(path)) return False model = documentModelClass() model.setDocumentSource(contents) model.setSavedAttributes(url = url, timestamp = fileTimestamp) return self.openTab(model) def openTab(self, documentModel): """ Opens a new tab with an editor editing the document model. """ # Find an editor to edit the model documentEditorClasses = getDocumentEditorClass(documentModel) if not documentEditorClasses: CommonWidgets.systemError(self, 'Unable to find a suitable editor to edit %s' % documentModel.getName())
log("Unable to open remote file due to a transport or Ws error" ) return False fileTimestamp = info['timestamp'] else: log("Unknown URL scheme. Not opening.") return False # Now, creates a model based on the file to open filename = os.path.split(unicode(path))[1] documentModelClass = DocumentModels.getDocumentModelClass(filename) if not documentModelClass: CommonWidgets.systemError( self, 'Unable to detect file type. Not opening %s' % unicode(path)) return False model = documentModelClass() model.setDocumentSource(contents) model.setSavedAttributes(url=url, timestamp=fileTimestamp) return self.openTab(model) def openTab(self, documentModel): """ Opens a new tab with an editor editing the document model. """ # Find an editor to edit the model documentEditorClasses = getDocumentEditorClass(documentModel) if not documentEditorClasses:
def __init__(self, parent=None): QTextEdit.__init__(self, parent) self._clearAction = CommonWidgets.TestermanAction( self, "Clear", self.clear)