def _openDialog(self): ''' Opens selected files containing test results in tabs. ''' log.debug("Opening result file") readableChannels = {} for c in [c for c in channels.get() if isinstance(c, channels.TestResultFileChannel)]: desc = "%s (*.%s)" % (c.name, c.fileExt().strip(".")) readableChannels[desc] = c if not readableChannels: dialogs.runWarning("There are no readable channels available") return dialog = QtGui.QFileDialog(self.view) dialog.setFileMode(QtGui.QFileDialog.ExistingFiles) dialog.setFilter(";;".join(readableChannels)) if not dialog.exec_(): log.debug("Opening result file was cancelled") return channel = readableChannels[dialog.selectedFilter()] for path in dialog.selectedFiles(): try: self.addTab(channel.read(path), os.path.split(path)[1], tooltip=path) self._updateRecentFiles(path) except Exception, ex: dialogs.runError("Error occurred while loading result file " "'%s':\n%s" % (path, ex))
def _responseSave(self, response, filePath): ''' Expands an accessible tree item from the response recursively. ''' try: log.debug("Saving response to file '%s'" % filePath) element = response.accessible.marshal() utils.saveXml(element, filePath) self._view.updateRecentFiles(filePath) except: dialogs.runError("Error occurred while saving dump to file '%s'" % filePath)
def _errorOccurred(self): ''' Disconnects a device in case of a ConnectionLostError. ''' dev = self.sender() err = dev.getError() log.error("Error occurred in '%s' device: %s" % (dev.name, err)) if isinstance(err, client.ConnectionLostError): try: dialogs.runError("'%s' device disconnected:\n%s" % (dev.name, err)) self._errors[dev] = err self._updateConnectionState(False, dev) except ConnectionError, ex: log.error("Connection Error (%s): %s" % (dev, ex))
def _saveOutput(self): ''' Saves console output to a selected file. ''' log.debug("Saving console output") path = dialogs.runSaveFile("Text files (*.txt);;All files (*)") if path is None: return try: summary = open(path, "w") summary.write(self._textEdit.toPlainText()) summary.close() except EnvironmentError, ex: dialogs.runError("Error occurred while writing to file %s:\n%s" % (path, ex[1]))
def _updateConnectionState(self, state, dev): ''' Connects or disconnects a device. :param state: Desired connection state :type state: boolean :param dev: A device :type dev: Device ''' log.debug("%s '%s' device" % ("Connecting" if state else "Disconnecting", dev)) try: if state: dev.connectDevice() else: dev.disconnectDevice() except ConnectionError, err: dialogs.runError("Error occurred in connection to '%s' device:\n%s" % (dev.name, str(err)))
def _open(self, path): ''' Opens a dump in a new tab and returns True on success or False on failure. ''' if path in self._offlineDevs: self._offlineDevs[path].disconnectDevice() try: dev = OfflineDevice(os.path.split(path)[1], file=path) dev.responseReceived.connect(lambda id: self._deviceResponseReceived(dev, id)) dev.connected.connect(lambda: self._deviceConnected(dev)) dev.disconnected.connect(lambda: self._deviceDisconnected(dev, False)) log.debug("Connecting off-line device: %s" % dev.name) dev.connectDevice() self._offlineDevs[path] = dev return True except Exception, ex: dialogs.runError("Error occurred while loading dump:\n%s" % str(ex)) return False
def _accept(self): ''' Accepts provided device data. ''' log.debug("Accepting device data") # Test provided name name = self._name.text() if not name: dialogs.runError("'name' field is required") return # Test provided address address = self._address.currentText() if not address: dialogs.runError("'address' field is required") return if ((not self._device or self._device.name != name) and devices.get(name) is not None): dialogs.runError("'%s' name already in use" % name) return self.params = { "name": name, "description": self._desc.text() or '', "address": address, "port": self._port.value(), "connect": self._connect.isChecked(), "autoconnect": self._autoconnect.isChecked() } self._lastAddresses.add(address) self.dialog.accept()
def _open(self, path): ''' Opens a dump in a new tab and returns True on success or False on failure. ''' if path in self._offlineDevs: self._offlineDevs[path].disconnectDevice() try: dev = OfflineDevice(os.path.split(path)[1], file=path) dev.responseReceived.connect( lambda id: self._deviceResponseReceived(dev, id)) dev.connected.connect(lambda: self._deviceConnected(dev)) dev.disconnected.connect( lambda: self._deviceDisconnected(dev, False)) log.debug("Connecting off-line device: %s" % dev.name) dev.connectDevice() self._offlineDevs[path] = dev return True except Exception, ex: dialogs.runError("Error occurred while loading dump:\n%s" % str(ex)) return False
def _openRecent(self): ''' Opens a recent file containing test results in tabs. ''' log.debug("Opening recent result file") path = self.sender().data() ext = os.path.splitext(path)[1] channel = None for c in channels.get(): if (isinstance(c, channels.TestResultFileChannel) and c.fileExt() == ext): channel = c break if not channel: dialogs.runWarning("There are no readable channels accepting " "'%s' files" % ext) return try: self.addTab(channel.read(path), os.path.split(path)[1], tooltip=path) except Exception, ex: dialogs.runError("Error occurred while loading result file:\n%s" % str(ex))