def __init__(self, parent=None): QCellWidget.__init__(self, parent) centralLayout = QtGui.QVBoxLayout() self.setLayout(centralLayout) centralLayout.setMargin(0) centralLayout.setSpacing(0) # self.setAnimationEnabled(True) self.Frame = QtGui.QFrame() self.ui = Ui_Frame() self.ui.setupUi(self.Frame) # #add scenes to our graphicViews # self.gs_prob_map = QtGui.QGraphicsScene() # self.ui.gv_prob_map.setScene(self.gs_prob_map) # self.gs_prob_map.wheelEvent = self.wheel_event_prob self.gs_auc_graph = QtGui.QGraphicsScene() self.ui.gv_auc.setScene(self.gs_auc_graph) self.gs_auc_graph.wheelEvent = self.wheel_event_auc #add in ie browsers for the text and response self.text_browser = QAxContainer.QAxWidget(self) self.text_browser.setFocusPolicy(QtCore.Qt.StrongFocus) self.text_browser.setControl("{8856F961-340A-11D0-A96B-00C04FD705A2}") self.ui.text_output_layout.addWidget(self.text_browser) self.text_urlSrc = None self.response_browser = QAxContainer.QAxWidget(self) self.response_browser.setFocusPolicy(QtCore.Qt.StrongFocus) self.response_browser.setControl( "{8856F961-340A-11D0-A96B-00C04FD705A2}") self.ui.response_curves_layout.addWidget(self.response_browser) self.response_urlSrc = None self.layout().addWidget(self.Frame)
def __init__(self, parent=None): QCellWidget.__init__(self, parent) centralLayout = QtGui.QVBoxLayout() self.setLayout(centralLayout) centralLayout.setMargin(0) centralLayout.setSpacing(0) # self.setAnimationEnabled(True) self.Frame = QtGui.QFrame() self.ui = Ui_Frame() self.ui.setupUi(self.Frame) # #add scenes to our graphicViews # self.gs_prob_map = QtGui.QGraphicsScene() # self.ui.gv_prob_map.setScene(self.gs_prob_map) # self.gs_prob_map.wheelEvent = self.wheel_event_prob self.gs_auc_graph = QtGui.QGraphicsScene() self.ui.gv_auc.setScene(self.gs_auc_graph) self.gs_auc_graph.wheelEvent = self.wheel_event_auc #add in ie browsers for the text and response self.text_browser = QAxContainer.QAxWidget(self) self.text_browser.setFocusPolicy(QtCore.Qt.StrongFocus) self.text_browser.setControl("{8856F961-340A-11D0-A96B-00C04FD705A2}") self.ui.text_output_layout.addWidget(self.text_browser) self.text_urlSrc = None self.response_browser = QAxContainer.QAxWidget(self) self.response_browser.setFocusPolicy(QtCore.Qt.StrongFocus) self.response_browser.setControl("{8856F961-340A-11D0-A96B-00C04FD705A2}") self.ui.response_curves_layout.addWidget(self.response_browser) self.response_urlSrc = None self.layout().addWidget(self.Frame)
class SAHMOutputViewerCellWidget(QCellWidget): """ SAHMOutputViewerCellWidget is the widget that will display the various non spatial outputs from a model run """ def __init__(self, parent=None): QCellWidget.__init__(self, parent) centralLayout = QtGui.QVBoxLayout() self.setLayout(centralLayout) centralLayout.setMargin(0) centralLayout.setSpacing(0) # self.setAnimationEnabled(True) self.Frame = QtGui.QFrame() self.ui = Ui_Frame() self.ui.setupUi(self.Frame) # #add scenes to our graphicViews # self.gs_prob_map = QtGui.QGraphicsScene() # self.ui.gv_prob_map.setScene(self.gs_prob_map) # self.gs_prob_map.wheelEvent = self.wheel_event_prob self.gs_auc_graph = QtGui.QGraphicsScene() self.ui.gv_auc.setScene(self.gs_auc_graph) self.gs_auc_graph.wheelEvent = self.wheel_event_auc #add in ie browsers for the text and response self.text_browser = QAxContainer.QAxWidget(self) self.text_browser.setFocusPolicy(QtCore.Qt.StrongFocus) self.text_browser.setControl("{8856F961-340A-11D0-A96B-00C04FD705A2}") self.ui.text_output_layout.addWidget(self.text_browser) self.text_urlSrc = None self.response_browser = QAxContainer.QAxWidget(self) self.response_browser.setFocusPolicy(QtCore.Qt.StrongFocus) self.response_browser.setControl("{8856F961-340A-11D0-A96B-00C04FD705A2}") self.ui.response_curves_layout.addWidget(self.response_browser) self.response_urlSrc = None self.layout().addWidget(self.Frame) def updateContents(self, inputPorts): """ updateContents(inputPorts: tuple) -> None Update the widget contents based on the input data """ (auc_graph, text_output, response_curves, model_label) = inputPorts self.images = {} # if prob_map: # #Value = (full image, sized image, scene, view, max_height) # pixmap = QtGui.QPixmap(prob_map.name) # max_size = self.getMaxSize(self.ui.gv_prob_map) # scaled_pixmap = pixmap.scaled(max_size, max_size, # QtCore.Qt.KeepAspectRatio, # QtCore.Qt.FastTransformation) # # self.images['prob_map'] = [pixmap, # scaled_pixmap, # self.gs_prob_map, # self.ui.gv_prob_map, # max_size] if auc_graph: pixmap = QtGui.QPixmap(auc_graph.name) max_size = self.getMaxSize(self.ui.gv_auc) scaled_pixmap = pixmap.scaled(max_size, max_size, QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation) self.images['auc_graph'] = [pixmap, scaled_pixmap, self.gs_auc_graph, self.ui.gv_auc, max_size] self.text_urlSrc = QtCore.QUrl.fromLocalFile(text_output.name) if self.text_urlSrc!=None: self.text_browser.dynamicCall('Navigate(const QString&)', self.text_urlSrc.toString()) else: self.text_browser.dynamicCall('Navigate(const QString&)', QtCore.QString('about:blank')) self.response_urlSrc = QtCore.QUrl.fromLocalFile(response_curves.name) if self.response_urlSrc!=None: self.response_browser.dynamicCall('Navigate(const QString&)', self.response_urlSrc.toString()) else: self.response_browser.dynamicCall('Navigate(const QString&)', QtCore.QString('about:blank')) self.view_current() #QCellWidget.updateContents(self, inputPorts) def getMaxSize(self, view): return self.Frame.size().width() - 10 # if view.size().width() <= view.size().height(): # return view.size().width() * 0.95 # else: # return view.size().height() * 0.95 def view_current(self): for k,v in self.images.iteritems(): size_img = v[1].size() wth, hgt = QtCore.QSize.width(size_img), QtCore.QSize.height(size_img) v[2].clear() v[2].setSceneRect(0, 0, wth, hgt) v[2].addPixmap(v[1]) QtCore.QCoreApplication.processEvents() def wheel_event_prob(self, event): self.wheel_event(event, 'prob_map', QtCore.Qt.FastTransformation) def wheel_event_auc(self, event): self.wheel_event(event, 'auc_graph', QtCore.Qt.SmoothTransformation) def wheel_event (self, event, id, transform): numDegrees = event.delta() / 8 numSteps = numDegrees / 15.0 self.zoom(numSteps, self.images[id], transform) event.accept() def zoom(self, step, images, transform): zoom_step = 0.06 images[2].clear() w = images[1].size().width() h = images[1].size().height() w, h = w * (1 + zoom_step*step), h * (1 + zoom_step*step) images[1] = images[0].scaled(w, h, QtCore.Qt.KeepAspectRatio, transform) self.view_current() def saveToPNG(self, filename): """ saveToPNG(filename: str) -> bool Save the current widget contents to an image file """ pixmap = QtGui.QPixmap(self.Frame.size()) painter = QtGui.QPainter(pixmap) self.Frame.render(painter) painter.end() if pixmap and (not pixmap.isNull()): return pixmap.save(filename) return False def saveToPDF(self, filename): """ saveToPDF(filename: str) -> bool Save the current widget contents to a pdf file """ printer = QtGui.QPrinter() printer.setOutputFormat(QtGui.QPrinter.PdfFormat) printer.setOutputFileName(filename) painter = QtGui.QPainter() painter.begin(printer) rect = painter.viewport() pixmap = self.label.pixmap() size = pixmap.size() size.scale(rect.size(), QtCore.Qt.KeepAspectRatio) painter.setViewport(rect.x(), rect.y(), size.width(), size.height()) painter.setWindow(pixmap.rect()) painter.drawPixmap(0, 0, pixmap) painter.end()
class SAHMOutputViewerCellWidget(QCellWidget): """ SAHMOutputViewerCellWidget is the widget that will display the various non spatial outputs from a model run """ def __init__(self, parent=None): QCellWidget.__init__(self, parent) centralLayout = QtGui.QVBoxLayout() self.setLayout(centralLayout) centralLayout.setMargin(0) centralLayout.setSpacing(0) # self.setAnimationEnabled(True) self.Frame = QtGui.QFrame() self.ui = Ui_Frame() self.ui.setupUi(self.Frame) # #add scenes to our graphicViews # self.gs_prob_map = QtGui.QGraphicsScene() # self.ui.gv_prob_map.setScene(self.gs_prob_map) # self.gs_prob_map.wheelEvent = self.wheel_event_prob self.gs_auc_graph = QtGui.QGraphicsScene() self.ui.gv_auc.setScene(self.gs_auc_graph) self.gs_auc_graph.wheelEvent = self.wheel_event_auc #add in ie browsers for the text and response self.text_browser = QAxContainer.QAxWidget(self) self.text_browser.setFocusPolicy(QtCore.Qt.StrongFocus) self.text_browser.setControl("{8856F961-340A-11D0-A96B-00C04FD705A2}") self.ui.text_output_layout.addWidget(self.text_browser) self.text_urlSrc = None self.response_browser = QAxContainer.QAxWidget(self) self.response_browser.setFocusPolicy(QtCore.Qt.StrongFocus) self.response_browser.setControl( "{8856F961-340A-11D0-A96B-00C04FD705A2}") self.ui.response_curves_layout.addWidget(self.response_browser) self.response_urlSrc = None self.layout().addWidget(self.Frame) def updateContents(self, inputPorts): """ updateContents(inputPorts: tuple) -> None Update the widget contents based on the input data """ (auc_graph, text_output, response_curves, model_label) = inputPorts self.images = {} # if prob_map: # #Value = (full image, sized image, scene, view, max_height) # pixmap = QtGui.QPixmap(prob_map.name) # max_size = self.getMaxSize(self.ui.gv_prob_map) # scaled_pixmap = pixmap.scaled(max_size, max_size, # QtCore.Qt.KeepAspectRatio, # QtCore.Qt.FastTransformation) # # self.images['prob_map'] = [pixmap, # scaled_pixmap, # self.gs_prob_map, # self.ui.gv_prob_map, # max_size] if auc_graph: pixmap = QtGui.QPixmap(auc_graph.name) max_size = self.getMaxSize(self.ui.gv_auc) scaled_pixmap = pixmap.scaled(max_size, max_size, QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation) self.images['auc_graph'] = [ pixmap, scaled_pixmap, self.gs_auc_graph, self.ui.gv_auc, max_size ] self.text_urlSrc = QtCore.QUrl.fromLocalFile(text_output.name) if self.text_urlSrc != None: self.text_browser.dynamicCall('Navigate(const QString&)', self.text_urlSrc.toString()) else: self.text_browser.dynamicCall('Navigate(const QString&)', QtCore.QString('about:blank')) self.response_urlSrc = QtCore.QUrl.fromLocalFile(response_curves.name) if self.response_urlSrc != None: self.response_browser.dynamicCall('Navigate(const QString&)', self.response_urlSrc.toString()) else: self.response_browser.dynamicCall('Navigate(const QString&)', QtCore.QString('about:blank')) self.view_current() #QCellWidget.updateContents(self, inputPorts) def getMaxSize(self, view): return self.Frame.size().width() - 10 # if view.size().width() <= view.size().height(): # return view.size().width() * 0.95 # else: # return view.size().height() * 0.95 def view_current(self): for k, v in self.images.iteritems(): size_img = v[1].size() wth, hgt = QtCore.QSize.width(size_img), QtCore.QSize.height( size_img) v[2].clear() v[2].setSceneRect(0, 0, wth, hgt) v[2].addPixmap(v[1]) QtCore.QCoreApplication.processEvents() def wheel_event_prob(self, event): self.wheel_event(event, 'prob_map', QtCore.Qt.FastTransformation) def wheel_event_auc(self, event): self.wheel_event(event, 'auc_graph', QtCore.Qt.SmoothTransformation) def wheel_event(self, event, id, transform): numDegrees = event.delta() / 8 numSteps = numDegrees / 15.0 self.zoom(numSteps, self.images[id], transform) event.accept() def zoom(self, step, images, transform): zoom_step = 0.06 images[2].clear() w = images[1].size().width() h = images[1].size().height() w, h = w * (1 + zoom_step * step), h * (1 + zoom_step * step) images[1] = images[0].scaled(w, h, QtCore.Qt.KeepAspectRatio, transform) self.view_current() def saveToPNG(self, filename): """ saveToPNG(filename: str) -> bool Save the current widget contents to an image file """ pixmap = QtGui.QPixmap(self.Frame.size()) painter = QtGui.QPainter(pixmap) self.Frame.render(painter) painter.end() if pixmap and (not pixmap.isNull()): return pixmap.save(filename) return False def saveToPDF(self, filename): """ saveToPDF(filename: str) -> bool Save the current widget contents to a pdf file """ printer = QtGui.QPrinter() printer.setOutputFormat(QtGui.QPrinter.PdfFormat) printer.setOutputFileName(filename) painter = QtGui.QPainter() painter.begin(printer) rect = painter.viewport() pixmap = self.label.pixmap() size = pixmap.size() size.scale(rect.size(), QtCore.Qt.KeepAspectRatio) painter.setViewport(rect.x(), rect.y(), size.width(), size.height()) painter.setWindow(pixmap.rect()) painter.drawPixmap(0, 0, pixmap) painter.end()