def getScreenShots(self): pixmaps = [] for rect in self.getRegionRectangles(): pixmap = qt.QPixmap(rect.size()) self.ui.render(pixmap, qt.QPoint(), qt.QRegion(rect)) pixmaps.append(pixmap) return pixmaps
def __init__(self, *args): BlissWidget.__init__(self, *args) self.__widgetTree = self.loadUIFile("Centering.ui") self.__widgetTree.reparent(self, qt.QPoint(0, 0)) layout = qt.QHBoxLayout(self, 11, 6, "layout") layout.addWidget(self.__widgetTree) self.__centeringPlug = None self.__currentXSize, self.__currentYSize = 0, 0 # current pixel size self.__verticalPhi = True self.pxclient = None self.beam_pos = (None, None) self.addProperty("mnemonic", "string", "") self.addProperty("clockwise", "boolean", False) self.addProperty("table_y_inverted", "boolean", False) self.addProperty("table_z_inverted", "boolean", False) ####### SIGNAL ####### self.defineSignal("getView", ()) self.defineSignal("getBeamPosition", ()) ####### SLOTS ####### self.defineSlot("changePixelScale", ())
def __init__(self, parent=None, name="Grid Dialog", canvas=None, matrix=None, event_mgr=None, drawing_object_layer=None): super(GridDialog, self).__init__(parent, name) self.__cell_width = 30 self.__cell_height = 30 self.__list_items = {} self.__item_counter = 0 self.__grid_list = [] self.__main_layout = qt.QVBoxLayout(self, 10, 11, 'main_layout') self.__canvas = canvas self.__matrix = matrix self.__event_mgr = event_mgr self.__drawing_object_layer = drawing_object_layer self.__drawing_mgr = None ui_file = 'ui_files/grid_row_widget.ui' current_dir = os.path.dirname(__file__) widget = qtui.QWidgetFactory.create(os.path.join(current_dir, ui_file)) widget.reparent(self, qt.QPoint(0, 0)) self.__main_layout.add(widget) self.__list_view = widget.child("list_view") qt.QObject.connect(widget.child("add_button"), qt.SIGNAL("clicked()"), self.__add_drawing) qt.QObject.connect(widget.child("remove_button"), qt.SIGNAL("clicked()"), self.__delete_drawing)
def __init__( self, canvas, num ): if DEBUG: print 'FigureManagerQT.%s' % fn_name() FigureManagerBase.__init__( self, canvas, num ) self.canvas = canvas self.window = qt.QMainWindow() self.canvas.reparent( self.window, qt.QPoint( 0, 0 ) ) # Give the keyboard focus to the figure instead of the manager self.canvas.grabKeyboard() self.window.setCaption( "Figure %d" % num ) self.window.setCentralWidget( self.canvas ) if matplotlib.rcParams['toolbar'] == 'classic': print "Classic toolbar is not yet supported" #self.toolbar = NavigationToolbar( canvas, self.window ) self.toolbar = None elif matplotlib.rcParams['toolbar'] == 'toolbar2': self.toolbar = NavigationToolbar2QT( canvas, self.window ) else: self.toolbar = None self.window.resize( self.canvas.size() ) if matplotlib.is_interactive(): self.window.show() def notify_axes_change( fig ): # This will be called whenever the current axes is changed if self.toolbar != None: self.toolbar.update() self.canvas.figure.add_axobserver( notify_axes_change )
def cursorForEffect(self, effectName): """Return an instance of QCursor customized for the given effectName. TODO: this could be moved to the EffectTool class so that effects can manage per-widget cursors, possibly turning them off or making them dynamic """ if not effectName in self.effectCursors: baseImage = qt.QImage(":/Icons/AnnotationPointWithArrow.png") effectImage = qt.QImage(self.effectIconFiles[effectName]) width = max(baseImage.width(), effectImage.width()) pad = -9 height = pad + baseImage.height() + effectImage.height() width = height = max(width, height) center = int(width / 2) cursorImage = qt.QImage(width, height, qt.QImage().Format_ARGB32) painter = qt.QPainter() cursorImage.fill(0) painter.begin(cursorImage) point = qt.QPoint(center - (baseImage.width() / 2), 0) painter.drawImage(point, baseImage) point.setX(center - (effectImage.width() / 2)) point.setY(cursorImage.height() - effectImage.height()) painter.drawImage(point, effectImage) painter.end() cursorPixmap = qt.QPixmap() cursorPixmap = cursorPixmap.fromImage(cursorImage) self.effectCursors[effectName] = qt.QCursor( cursorPixmap, center, 0) return self.effectCursors[effectName]
def open(self, username="", password=""): """Open the MorphoSource page and fill in or capture the url """ if username != "": self.setLogin(username, password) webWidget = slicer.qSlicerWebWidget() slicerGeometry = slicer.util.mainWindow().geometry webWidget.size = qt.QSize(slicerGeometry.width(), slicerGeometry.height()) webWidget.pos = qt.QPoint(slicerGeometry.x() + 256, slicerGeometry.y() + 128) webWidget.url = "https://www.morphosource.org/LoginReg/form" webWidget.show() self.webWidget = webWidget # TODO: need to expose loadFinished signal from QWebEngine via qSlicerWebWidget # so that we will know when to send this (current 2 second delay is a hack # that may not always work). onFinishLoading = lambda: self.onFinishLoading(username, password) connected = self.webWidget.connect('loadFinished(bool)', onFinishLoading) if not connected: qt.QTimer.singleShot( 3000, lambda: self.onFinishLoading(username, password)) return self.webWidget
def showTableMenu(self, qpoint): # Start from zero. self.tableMenu.clear() """ If we do this in setup, when we first enter the module, a weird background rectangle is seen from the left of the module window. Just workaround it. """ self.tableMenu.setParent(self.parent) # Simple menu item to remove a single row. actionRemoveRow = self.tableMenu.addAction("Remove row") actionRemoveRow.setData(OUTPUT_TABLE_MENU_REMOVE_ROW) actionRemoveRow.connect("triggered()", self.onTableMenuItem) # Simple menu item to remove all rows. actionEmptyTable = self.tableMenu.addAction("Empty table") actionEmptyTable.setData(OUTPUT_TABLE_MENU_EMPTY_TABLE) actionEmptyTable.connect("triggered()", self.onTableMenuItem) self.tableMenu.addSeparator() # Clicking anywhere does not hide menu. actionCancel = self.tableMenu.addAction("Dismiss menu") actionCancel.connect("triggered()", self.onTableMenuItem) """ Set menu position. In developer mode, the height of the additional collapsible button is not taken into account, and influences the menu position. """ outputTableWidget = self.ui.outputTableWidget menuPosition = qt.QPoint() menuPosition.setX(qpoint.x() + outputTableWidget.x) menuPosition.setY(qpoint.y() + outputTableWidget.y) self.tableMenu.popup(menuPosition)
def __init__(self, *args): BlissWidget.__init__(self, *args) self.__widgetTree = self.loadUIFile('Centering.ui') self.__widgetTree.reparent(self, qt.QPoint(0, 0)) layout = qt.QHBoxLayout(self, 11, 6, 'layout') layout.addWidget(self.__widgetTree) self.__centeringPlug = None self.__currentXSize, self.__currentYSize = 0, 0 # current pixel size self.__verticalPhi = True self.pxclient = None self.beam_pos = (None, None) self.addProperty('mnemonic', 'string', '') self.addProperty('clockwise', 'boolean', False) self.addProperty('table_y_inverted', 'boolean', False) self.addProperty('table_z_inverted', 'boolean', False) ####### SIGNAL ####### self.defineSignal('getView', ()) self.defineSignal('getBeamPosition', ()) ####### SLOTS ####### self.defineSlot("changePixelScale", ())
def __init__(self, canvas, num): if DEBUG: print 'FigureManagerQT.%s' % fn_name() FigureManagerBase.__init__(self, canvas, num) self.canvas = canvas self.window = qt.QMainWindow(None, None, qt.Qt.WDestructiveClose) self.canvas.reparent(self.window, qt.QPoint(0, 0)) # Give the keyboard focus to the figure instead of the manager self.canvas.setFocusPolicy(qt.QWidget.ClickFocus) self.canvas.setFocus() self.window.setCaption("Figure %d" % num) self.window.setCentralWidget(self.canvas) qt.QObject.connect(self.window, qt.SIGNAL('destroyed()'), self._widgetclosed) self.window._destroying = False if matplotlib.rcParams['toolbar'] == 'classic': print "Classic toolbar is not yet supported" #self.toolbar = NavigationToolbar( canvas, self.window ) self.toolbar = None elif matplotlib.rcParams['toolbar'] == 'toolbar2': self.toolbar = NavigationToolbar2QT(canvas, self.window) else: self.toolbar = None self.window.resize(self.canvas.size()) if matplotlib.is_interactive(): self.window.show() def notify_axes_change(fig): # This will be called whenever the current axes is changed if self.toolbar != None: self.toolbar.update() self.canvas.figure.add_axobserver(notify_axes_change)
def onSiteButtonClicked(self, site): webWidget = slicer.qSlicerWebWidget() slicerGeometry = slicer.util.mainWindow().geometry webWidget.size = qt.QSize(1536,1024) webWidget.pos = qt.QPoint(slicerGeometry.x() + 256, slicerGeometry.y() + 128) webWidget.url = site["url"] webWidget.show() self.webWidgets.append(webWidget)
def getPointIn(self, point, rect): """ Change point coordinates to stay inside rect """ pointin = qt.QPoint(point.x(), point.y()) if point.x() < rect.left(): pointin.setX(rect.left()) if point.x() > rect.right(): pointin.setX(rect.right()) if point.y() < rect.top(): pointin.setY(rect.top()) if point.y() > rect.bottom(): pointin.setY(rect.bottom()) return pointin
def _onMeasurementItemRightClicked(self, point): if not self._measurementsListWidget.currentIndex() or not self._measurementsListWidget.model().rowCount(): return self.listMenu = qt.QMenu() menu_item = self.listMenu.addAction("Remove Item") menu_item.triggered.connect(self._onRemoveFindingRequested) parentPosition = self._measurementsListWidget.mapToGlobal(qt.QPoint(0, 0)) self.listMenu.move(parentPosition + point) self.listMenu.show()
def __init__( self, canvas, num ): if DEBUG: print 'FigureManagerQT.%s' % fn_name() FigureManagerBase.__init__( self, canvas, num ) self.canvas = canvas self.window = qt.QMainWindow( None, None, qt.Qt.WDestructiveClose ) centralWidget = qt.QWidget( self.window ) self.canvas.reparent( centralWidget, qt.QPoint( 0, 0 ) ) # Give the keyboard focus to the figure instead of the manager self.canvas.setFocusPolicy( qt.QWidget.ClickFocus ) self.canvas.setFocus() self.window.setCaption( "Figure %d" % num ) qt.QObject.connect( self.window, qt.SIGNAL( 'destroyed()' ), self._widgetclosed ) self.window._destroying = False if matplotlib.rcParams['toolbar'] == 'classic': print "Classic toolbar is not yet supported" #self.toolbar = NavigationToolbarQT( centralWidget, canvas ) self.toolbar = None elif matplotlib.rcParams['toolbar'] == 'toolbar2': self.toolbar = NavigationToolbar2QT( centralWidget, canvas ) else: self.toolbar = None # Use a vertical layout for the plot and the toolbar. Set the # stretch to all be in the plot so the toolbar doesn't resize. layout = qt.QVBoxLayout( centralWidget ) layout.addWidget( self.canvas, 1 ) if self.toolbar: layout.addWidget( self.toolbar, 0 ) self.window.setCentralWidget( centralWidget ) # Reset the window height so the canvas will be the right # size. This ALMOST works right. The first issue is that the # height w/ a toolbar seems to be off by just a little bit (so # we add 4 pixels). The second is that the total width/height # is slightly smaller that we actually want. It seems like # the border of the window is being included in the size but # AFAIK there is no way to get that size. w = self.canvas.width() h = self.canvas.height() if self.toolbar: h += self.toolbar.height() + 4 self.window.resize( w, h ) if matplotlib.is_interactive(): self.window.show() def notify_axes_change( fig ): # This will be called whenever the current axes is changed if self.toolbar != None: self.toolbar.update() self.canvas.figure.add_axobserver( notify_axes_change )
def __init__( self, parent=None, name=None, fl=0, acq_params=None, path_template=None, layout=None, ): qt.QWidget.__init__(self, parent, name, fl) # # Attributes # if acq_params is None: self._acquisition_parameters = queue_model_objects.AcquisitionParameters( ) else: self._acquisition_parameters = acq_params if path_template is None: self._path_template = queue_model_objects.PathTemplate() else: self._path_template = path_template self._acquisition_mib = DataModelInputBinder( self._acquisition_parameters) # # Layout # h_layout = qt.QHBoxLayout(self) current_dir = os.path.dirname(__file__) ui_file = "ui_files/acquisition_widget_vertical_simple_layout.ui" widget = qtui.QWidgetFactory.create(os.path.join(current_dir, ui_file)) widget.reparent(self, qt.QPoint(0, 0)) h_layout.addWidget(widget) self.acq_widget_layout = widget # # Logic # self.acq_widget_layout.child("kappa_ledit").setEnabled(False) self.acq_widget_layout.child("kappa_phi_ledit").setEnabled(False) self.acq_widget_layout.child("osc_start_ledit").setEnabled(False) # Default to 2-images self.acq_widget_layout.child("num_images_cbox").setCurrentItem(1) qt.QObject.connect( self.acq_widget_layout.child("num_images_cbox"), qt.SIGNAL("activated(int)"), self.update_num_images, )
def createWebWidget(): webWidget = slicer.qSlicerWebWidget() slicerGeometry = slicer.util.mainWindow().geometry webWidget.size = qt.QSize(slicerGeometry.width(), slicerGeometry.height()) webWidget.pos = qt.QPoint(slicerGeometry.x() + 256, slicerGeometry.y() + 128) webWidget.url = "http://localhost:8000" webWidget.show() return webWidget
def resizeIn(self, rect): """ """ rect = self.__getInRect(rect) left = min( max( self.left(), rect.left() ), rect.right() ) top = min( max( self.top(), rect.top( ) ), rect.bottom() ) self.moveTopLeft(qt.QPoint(left, top)) if self.right() > rect.right(): self.setRight(rect.right()) if self.bottom() > rect.bottom(): self.setBottom(rect.bottom())
def enterFloatingMode(self): self.mainFrame.setParent(None) cursorPosition = qt.QCursor().pos() w = self.mainFrame.width h = self.mainFrame.height self.mainFrame.pos = qt.QPoint(cursorPosition.x() - int(w/2), cursorPosition.y() - int(h/2)) self.mainFrame.show() self.mainFrame.raise_() Key_Space = 0x20 # not in PythonQt self.toggleShortcut = qt.QShortcut(self.mainFrame) self.toggleShortcut.setKey( qt.QKeySequence(Key_Space) ) self.toggleShortcut.connect( 'activated()', self.toggleFloatingMode )
def __init__(self, canvas, num): if DEBUG: print 'FigureManagerQT.%s' % fn_name() FigureManagerBase.__init__(self, canvas, num) self.canvas = canvas self.window = qt.QMainWindow(None, None, qt.Qt.WDestructiveClose) self.window.closeEvent = self._widgetCloseEvent centralWidget = qt.QWidget(self.window) self.canvas.reparent(centralWidget, qt.QPoint(0, 0)) # Give the keyboard focus to the figure instead of the manager self.canvas.setFocusPolicy(qt.QWidget.ClickFocus) self.canvas.setFocus() self.window.setCaption("Figure %d" % num) self.window._destroying = False self.toolbar = self._get_toolbar(self.canvas, centralWidget) # Use a vertical layout for the plot and the toolbar. Set the # stretch to all be in the plot so the toolbar doesn't resize. self.layout = qt.QVBoxLayout(centralWidget) self.layout.addWidget(self.canvas, 1) if self.toolbar: self.layout.addWidget(self.toolbar, 0) self.window.setCentralWidget(centralWidget) # Reset the window height so the canvas will be the right # size. This ALMOST works right. The first issue is that the # height w/ a toolbar seems to be off by just a little bit (so # we add 4 pixels). The second is that the total width/height # is slightly smaller that we actually want. It seems like # the border of the window is being included in the size but # AFAIK there is no way to get that size. w = self.canvas.width() h = self.canvas.height() if self.toolbar: h += self.toolbar.height() + 4 self.window.resize(w, h) if matplotlib.is_interactive(): self.window.show() # attach a show method to the figure for pylab ease of use self.canvas.figure.show = lambda *args: self.window.show() def notify_axes_change(fig): # This will be called whenever the current axes is changed if self.toolbar != None: self.toolbar.update() self.canvas.figure.add_axobserver(notify_axes_change)
def __init__(self, parent, name, uifile='', cmd_name=None): BlissWidget.__init__(self, parent, name) self._widgetTree = self.loadUIFile(uifile) self._widgetTree.reparent(self, qt.QPoint(0, 0)) layout = qt.QHBoxLayout(self) layout.addWidget(self._widgetTree) self.addProperty('horizontal', 'string', '') self.addProperty('vertical', 'string', '') self.addProperty('command', 'string', '') self.addProperty("formatString", "formatString", "###.##") ####### SIGNAL ####### self.defineSignal('getView', ()) self.defineSignal('scanFinished', ()) ####### SLOT ####### self.defineSlot("ChangePixelCalibration", ()) self.defineSlot("ChangeBeamPosition", ()) self._view = None self._beamx, self._beamy = 0, 0 self._XSize, self._YSize = 1, 1 self._horizontalMotors = [] self._verticalMotors = [] self._graphicSelection = None self._SpecCmd = None self.__commandName = cmd_name self._logArgs = {} self._formatString = '%f' ####### GUI INIT ####### gButton = self._widgetTree.child('__grabButton') gButton.hide() showgButton = self._widgetTree.child('__showGrab') showgButton.hide() try: mvButton = self._widgetTree.child('__movetoStart') qt.QObject.connect(mvButton, qt.SIGNAL('clicked()'), self._movetoStart) mvButton.hide() except: pass startButton = self._widgetTree.child('__startScan') qt.QObject.connect(startButton, qt.SIGNAL('clicked()'), self._startScan) startButton.setEnabled(False) stopButton = self._widgetTree.child('__stopScan') qt.QObject.connect(stopButton, qt.SIGNAL('clicked()'), self._stopScan) stopButton.setEnabled(False)
def drawContents(self, painter): x0 = 10 x1 = 218 y0 = 109 y1 = 109 + painter.fontMetrics().height() pxsize = 14 painter.font().setPixelSize(pxsize) painter.setPen(qt.QPen(qt.Qt.white)) painter.drawText( qt.QRect(qt.QPoint(x0, y0), qt.QPoint(x1, y1)), qt.Qt.AlignLeft | qt.Qt.AlignTop, "Loading", ) painter.font().setPixelSize(pxsize * 2.5) y0 = y1 y1 += 3 + painter.fontMetrics().height() painter.drawText( qt.QRect(qt.QPoint(x0, y0), qt.QPoint(x1, y1)), qt.Qt.AlignCenter, self.guiName, ) painter.font().setPixelSize(pxsize) y0 = y1 y1 += 3 + painter.fontMetrics().height() painter.drawText( qt.QRect(qt.QPoint(x0, y0), qt.QPoint(x1, y1)), qt.Qt.AlignLeft | qt.Qt.AlignBottom, "Please wait...", )
def timeimage(self, request=''): """ For timing and debugging - return an image with the current time rendered as text down to the hundredth of a second :param color: hex encoded RGB of dashed border (default 333 for dark gray) :return: png image """ # check arguments p = urllib.parse.urlparse(request.decode()) q = urllib.parse.parse_qs(p.query) try: color = "#" + q['color'][0].strip().lower() except KeyError: color = "#330" # # make a generally transparent image, # imageWidth = 128 imageHeight = 32 timeImage = qt.QImage(imageWidth, imageHeight, qt.QImage().Format_ARGB32) timeImage.fill(0) # a painter to use for various jobs painter = qt.QPainter() # draw a border around the pixmap painter.begin(timeImage) pen = qt.QPen() color = qt.QColor(color) color.setAlphaF(0.8) pen.setColor(color) pen.setWidth(5) pen.setStyle(3) # dotted line (Qt::DotLine) painter.setPen(pen) rect = qt.QRect(1, 1, imageWidth - 2, imageHeight - 2) painter.drawRect(rect) color = qt.QColor("#333") pen.setColor(color) painter.setPen(pen) position = qt.QPoint(10, 20) text = str(time.time()) # text to draw painter.drawText(position, text) painter.end() # convert the image to vtk, then to png from there vtkTimeImage = vtk.vtkImageData() slicer.qMRMLUtils().qImageToVtkImageData(timeImage, vtkTimeImage) pngData = self.vtkImageDataToPNG(vtkTimeImage) return pngData, b'image/png'
def __init__(self, parent=None, name=None, fl=0, data_model=None): qt.QWidget.__init__(self, parent, name, fl) if data_model is None: self._model = queue_model_objects.ProcessingParameters() else: self._model = data_model self._model_mib = DataModelInputBinder(self._model) h_layout = qt.QHBoxLayout(self) widget = self.acq_widget_layout = qtui.QWidgetFactory.\ create(os.path.join(os.path.dirname(__file__), 'ui_files/processing_widget_vertical_layout.ui')) widget.reparent(self, qt.QPoint(0, 0)) self.layout_widget = widget h_layout.addWidget(self.layout_widget) self.layout_widget.child('space_group_ledit').\ insertStrList(queue_model_enumerables.XTAL_SPACEGROUPS) self._model_mib.bind_value_update('cell_a', self.layout_widget.child('a_ledit'), float, None) self._model_mib.bind_value_update( 'cell_alpha', self.layout_widget.child('alpha_ledit'), float, None) self._model_mib.bind_value_update('cell_b', self.layout_widget.child('b_ledit'), float, None) self._model_mib.bind_value_update( 'cell_beta', self.layout_widget.child('beta_ledit'), float, None) self._model_mib.bind_value_update('cell_c', self.layout_widget.child('c_ledit'), float, None) self._model_mib.bind_value_update( 'cell_gamma', self.layout_widget.child('gamma_ledit'), float, None) self._model_mib.bind_value_update( 'num_residues', self.layout_widget.child('num_residues_ledit'), float, None) self.connect(self.layout_widget.child('space_group_ledit'), qt.SIGNAL("activated(int)"), self._space_group_change)
def open(self): if not self.window.isVisible(): self.window.show() if self.popupGeometry.isValid(): self.window.setGeometry(self.popupGeometry) self.popupPositioned = True if not self.popupPositioned: mainWindow = slicer.util.mainWindow() screenMainPos = mainWindow.pos x = screenMainPos.x() + 100 y = screenMainPos.y() + 100 self.window.move(qt.QPoint(x,y)) self.popupPositioned = True self.window.raise_()
def configure_subplots(self): self.adj_window = qt.QMainWindow(None, None, qt.Qt.WDestructiveClose) win = self.adj_window win.setCaption("Subplot Configuration Tool") toolfig = Figure(figsize=(6, 3)) toolfig.subplots_adjust(top=0.9) w = int(toolfig.bbox.width) h = int(toolfig.bbox.height) canvas = self._get_canvas(toolfig) tool = SubplotTool(self.canvas.figure, toolfig) centralWidget = qt.QWidget(win) canvas.reparent(centralWidget, qt.QPoint(0, 0)) win.setCentralWidget(centralWidget) layout = qt.QVBoxLayout(centralWidget) layout.addWidget(canvas, 1) win.resize(w, h) canvas.setFocus() win.show()
def eventFilter(self, o, e): if o is not None and e is not None: if e.type() == qt.QEvent.MouseButtonPress and e.button() == qt.Qt.LeftButton: p = qt.QPoint(e.pos()) if self.itemAt(p): self._presspos = e.pos() self._mousePressed = True elif e.type() == qt.QEvent.MouseButtonRelease: self._mousePressed = False if e.button() == qt.Qt.RightButton: item = self.itemAt(e.pos()) self.emit(qt.PYSIGNAL('contextMenuRequested'), (item, )) elif e.type() == qt.QEvent.MouseMove: if self._mousePressed: self._mousePressed = False item = self.itemAt(self._presspos) if item and item.dragEnabled(): td = qt.QTextDrag(str(item.text(0)), self) td.dragCopy() self.startDrag() return qt.QListView.eventFilter(self, o, e)
def onListSelected(self): item = self.list.selectedItem() pixmap = None if item is None: pass elif item == self.root: pass else: element = self.device.getComponentByAddress(item.text(0)) if element is not None: if element.isLeaf(): img_str = element.fetchImage() if img_str is not None: pixmap = qt.QPixmap() pixmap.loadFromData(img_str) if self.inversed_image: m = qt.QWMatrix() m.scale(1.0, -1.0) pixmap = pixmap.xForm(m) x = element.getImageX() y = element.getImageY() if (x is not None) and (y is not None): # Overlays p = qt.QPainter() p.begin(pixmap) p.setPen(qt.QPen(qt.QColor(0xE0, 0xE0, 0), 2)) size = 8 center = qt.QPoint( int(x / 100.0 * pixmap.width()), int(y / 100.0 * pixmap.height()), ) if self.inversed_image: center.setY( int((100.0 - y) / 100.0 * pixmap.height())) p.drawLine( qt.QPoint(center.x(), center.y() - size), qt.QPoint(center.x(), center.y() + size), ) p.drawLine( qt.QPoint(center.x() - size, center.y()), qt.QPoint(center.x() + size, center.y()), ) p.setPen(qt.QPen(qt.QColor(0, 0xC0, 0), 2)) size = 20 center = qt.QPoint( int(x / 100.0 * pixmap.width()), int(y / 100.0 * pixmap.height()), ) if self.inversed_image: center.setY( int((100.0 - y) / 100.0 * pixmap.height())) p.drawLine( qt.QPoint(center.x(), center.y() - size), qt.QPoint(center.x(), center.y() + size), ) p.drawLine( qt.QPoint(center.x() - size, center.y()), qt.QPoint(center.x() + size, center.y()), ) p.end() self.widget.lbImage.setPixmap(pixmap) # This check because don't know how to clear QLabel but assigniong an empty pixmap, what prints a warning message # if pixmap!=self._empty_image_pixmap or self.widget.lbImage.pixmap() is None or self.widget.lbImage.pixmap().width()>0: # self.widget.lbImage.setPixmap(pixmap) # self.widget.lbImage.setVisible(pixmap != self._empty_image_pixmap) if pixmap is not None: self.widget.lbImage.setPixmap(pixmap) self.widget.lbImage.show() else: self.widget.lbImage.clear() self.widget.lbImage.hide()
def __init__( self, parent=None, name=None, fl=0, acq_params=None, path_template=None, layout="horizontal", ): qt.QWidget.__init__(self, parent, name, fl) # # Attributes # self._beamline_setup = None self.previous_energy = 0 self.layout_type = layout if acq_params is None: self._acquisition_parameters = queue_model_objects.AcquisitionParameters() else: self._acquisition_parameters = acq_params if path_template is None: self._path_template = queue_model_objects.PathTemplate() else: self._path_template = path_template self._acquisition_mib = DataModelInputBinder(self._acquisition_parameters) # self._path_template_mib = DataModelInputBinder(self._path_template) # # Layout # h_layout = qt.QHBoxLayout(self) if layout == "vertical": widget = qtui.QWidgetFactory.create( os.path.join( os.path.dirname(__file__), "ui_files/acquisition_widget_vertical_layout.ui", ) ) elif layout == "horizontal": widget = qtui.QWidgetFactory.create( os.path.join( os.path.dirname(__file__), "ui_files/acquisition_widget_horizontal_layout.ui", ) ) widget.child("inverse_beam_cbx").hide() widget.child("subwedge_size_label").hide() widget.child("subwedge_size_ledit").hide() else: widget = qtui.QWidgetFactory.create( os.path.join( os.path.dirname(__file__), "ui_files/acquisition_widget_vertical_layout.ui", ) ) widget.reparent(self, qt.QPoint(0, 0)) self.acq_widget_layout = widget h_layout.addWidget(self.acq_widget_layout) # # Logic # qt.QObject.connect( self.acq_widget_layout.child("energies_combo"), qt.SIGNAL("activated(int)"), self.energy_selected, ) qt.QObject.connect( self.acq_widget_layout.child("mad_cbox"), qt.SIGNAL("toggled(bool)"), self.use_mad, ) qt.QObject.connect( self.acq_widget_layout.child("inverse_beam_cbx"), qt.SIGNAL("toggled(bool)"), self.set_use_inverse_beam, ) qt.QObject.connect( self.acq_widget_layout.child("first_image_ledit"), qt.SIGNAL("textChanged(const QString &)"), self.first_image_ledit_change, ) qt.QObject.connect( self.acq_widget_layout.child("num_images_ledit"), qt.SIGNAL("textChanged(const QString &)"), self.num_images_ledit_change, ) overlap_ledit = self.acq_widget_layout.child("overlap_ledit") if overlap_ledit: qt.QObject.connect( self.acq_widget_layout.child("overlap_ledit"), qt.SIGNAL("textChanged(const QString &)"), self.overlap_changed, ) qt.QObject.connect( self.acq_widget_layout.child("subwedge_size_ledit"), qt.SIGNAL("textChanged(const QString &)"), self.subwedge_size_ledit_change, ) qt.QObject.connect( self.acq_widget_layout.child("osc_start_cbox"), qt.SIGNAL("toggled(bool)"), self.osc_start_cbox_click, ) self.acq_widget_layout.child("subwedge_size_ledit").setDisabled(True) self.acq_widget_layout.child("energies_combo").setDisabled(True) self.acq_widget_layout.child("energies_combo").insertStrList( ["ip: -", "pk: -", "rm1: -", "rm2: -"] ) self.acq_widget_layout.child("osc_start_ledit").setEnabled(False) self.acq_widget_layout.child("kappa_ledit").setEnabled(False) self.acq_widget_layout.child("kappa_phi_ledit").setEnabled(False) self.acq_widget_layout.child("detector_mode_label").setEnabled(False) self.acq_widget_layout.child("detector_mode_combo").setEnabled(False)
def __init__(self, parent=None, name="xrf_spectrum_tab_widget"): qt.QWidget.__init__(self, parent, name) # Data Attributes self.xrf_spectrum_hwobj = None self.xrf_spectrum = queue_model_objects.XRFSpectrum() self._tree_view_item = None self.data_path_widget = DataPathWidget(self) self.other_parameters_gbox = qt.QHGroupBox("Other parameters", self) self.count_time_label = qt.QLabel("Count time:", self.other_parameters_gbox) self.count_time_ledit = qt.QLineEdit( self.other_parameters_gbox, "count_time_ledit" ) self.count_time_ledit.setFixedWidth(50) spacer = qt.QWidget(self.other_parameters_gbox) spacer.setSizePolicy(qt.QSizePolicy.Expanding, qt.QSizePolicy.Fixed) widget_ui = os.path.join( os.path.dirname(__file__), "ui_files/snapshot_widget_layout.ui" ) widget = qtui.QWidgetFactory.create(widget_ui) widget.reparent(self, qt.QPoint(0, 0)) self.position_widget = widget self.position_widget.setFixedSize(457, 350) # self.position_widget.setSizePolicy(qt.QSizePolicy.Fixed, qt.QSizePolicy.Fixed) self.mca_spectrum = McaSpectrumBrick(self) self.mca_spectrum.setSizePolicy( qt.QSizePolicy.Expanding, qt.QSizePolicy.Expanding ) self.mca_spectrum.setMinimumHeight(700) v_layout = qt.QVBoxLayout(self) rone_hlayout = qt.QHBoxLayout(v_layout) rone_vlayout = qt.QVBoxLayout(rone_hlayout) rone_sv_layout = qt.QVBoxLayout(rone_hlayout) rone_vlayout.addWidget(self.data_path_widget) rone_vlayout.addWidget(self.other_parameters_gbox) rone_vlayout.addStretch() rone_sv_layout.addWidget(self.position_widget) rone_sv_layout.addStretch() v_layout.addWidget(self.mca_spectrum) v_layout.addStretch() qt.QObject.connect( self.data_path_widget.data_path_widget_layout.child("prefix_ledit"), qt.SIGNAL("textChanged(const QString &)"), self._prefix_ledit_change, ) qt.QObject.connect( self.data_path_widget.data_path_widget_layout.child("run_number_ledit"), qt.SIGNAL("textChanged(const QString &)"), self._run_number_ledit_change, ) qt.QObject.connect( self.count_time_ledit, qt.SIGNAL("textChanged(const QString &)"), self._count_time_ledit_change, ) qt.QObject.connect(qt.qApp, qt.PYSIGNAL("tab_changed"), self.tab_changed)
def test_Part1DICOM(self): """ Test the DICOM part of the test using the head atlas """ import os self.delayDisplay("Starting the DICOM test") # # first, get the data - a zip file of dicom data # import urllib downloads = (('http://slicer.kitware.com/midas3/download?items=18822', 'Dcmtk-db.zip'), ) self.delayDisplay("Downloading") for url, name in downloads: filePath = slicer.app.temporaryPath + '/' + name if not os.path.exists(filePath) or os.stat(filePath).st_size == 0: self.delayDisplay('Requesting download %s from %s...\n' % (name, url)) urllib.urlretrieve(url, filePath) self.delayDisplay('Finished with download\n') self.delayDisplay("Unzipping") dicomFilesDirectory = slicer.app.temporaryPath + '/dicomFiles' qt.QDir().mkpath(dicomFilesDirectory) slicer.app.applicationLogic().Unzip(filePath, dicomFilesDirectory) try: self.delayDisplay("Switching to temp database directory") originalDatabaseDirectory = DICOMUtils.openTemporaryDatabase( 'tempDICOMDatbase') self.delayDisplay('Start Local DICOM Q/R SCP') import subprocess import os configFilePath = dicomFilesDirectory + '/Dcmtk-db/dcmqrscp.cfg' processCurrentPath = dicomFilesDirectory + '/Dcmtk-db/' dcmqrscpExeOptions = ( '/bin', '/../CTK-build/CMakeExternals/Install/bin', '/../DCMTK-install/bin', '/../DCMTK-build/bin', ) dcmqrscpExePath = None dcmqrscpExeName = '/dcmqrscp' if slicer.app.os == 'win': dcmqrscpExeName = dcmqrscpExeName + '.exe' for path in dcmqrscpExeOptions: testPath = slicer.app.slicerHome + path + dcmqrscpExeName if os.path.exists(testPath): dcmqrscpExePath = testPath break if not dcmqrscpExePath: raise (UserWarning("Could not find dcmqrscp executable")) args = (dcmqrscpExePath, '-c', configFilePath) popen = subprocess.Popen(args, stdout=subprocess.PIPE, cwd=processCurrentPath) self.delayDisplay('Retrieve DICOM') mainWindow = slicer.util.mainWindow() mainWindow.moduleSelector().selectModule('DICOM') dicomRetrieve = ctk.ctkDICOMRetrieve() dicomRetrieve.setKeepAssociationOpen(True) dicomRetrieve.setDatabase(slicer.dicomDatabase) dicomRetrieve.setCallingAETitle('SlicerAE') dicomRetrieve.setCalledAETitle('DCMTK') dicomRetrieve.setPort(12345) dicomRetrieve.setHost('localhost') dicomRetrieve.getStudy( '1.2.124.113932.1.170.223.162.178.20050502.160340.12640015') popen.kill() dicomWidget.detailsPopup.open() # click on the first row of the tree index = dicomWidget.tree.indexAt(qt.QPoint(0, 0)) dicomWidget.onTreeClicked(index) self.delayDisplay('Loading Selection') dicomWidget.detailsPopup.loadCheckedLoadables() self.delayDisplay('Change Level') layoutManager = slicer.app.layoutManager() redWidget = layoutManager.sliceWidget('Red') self.clickAndDrag(redWidget, start=(10, 10), end=(10, 40)) self.delayDisplay('Change Window') self.clickAndDrag(redWidget, start=(10, 10), end=(40, 10)) self.delayDisplay('Change Layout') layoutManager = slicer.app.layoutManager() layoutManager.setLayout( slicer.vtkMRMLLayoutNode.SlicerLayoutOneUpRedSliceView) self.delayDisplay('Zoom') self.clickAndDrag(redWidget, button='Right', start=(10, 10), end=(10, 40)) self.delayDisplay('Pan') self.clickAndDrag(redWidget, button='Middle', start=(10, 10), end=(40, 40)) self.delayDisplay('Center') redWidget.sliceController().fitSliceToBackground() self.delayDisplay('Lightbox') redWidget.sliceController().setLightboxTo6x6() self.delayDisplay('Conventional Layout') layoutManager.setLayout( slicer.vtkMRMLLayoutNode.SlicerLayoutConventionalView) self.delayDisplay('No Lightbox') redWidget.sliceController().setLightboxTo1x1() self.delayDisplay('Four Up Layout') layoutManager.setLayout( slicer.vtkMRMLLayoutNode.SlicerLayoutFourUpView) self.delayDisplay('Shift Mouse') self.clickAndDrag(redWidget, button='None', start=(100, 100), end=(140, 140), modifiers=['Shift']) self.delayDisplay('Conventional, Link, Slice Model') layoutManager.setLayout( slicer.vtkMRMLLayoutNode.SlicerLayoutConventionalView) redWidget.sliceController().setSliceLink(True) redWidget.sliceController().setSliceVisible(True) self.delayDisplay('Rotate') threeDView = layoutManager.threeDWidget(0).threeDView() self.clickAndDrag(threeDView) self.delayDisplay('Zoom') threeDView = layoutManager.threeDWidget(0).threeDView() self.clickAndDrag(threeDView, button='Right') self.delayDisplay('Test passed!') except Exception, e: import traceback traceback.print_exc() self.delayDisplay('Test caused exception!\n' + str(e))
def xyToIjk(self, xy, viewWidget, image): import vtkSegmentationCorePython as vtkSegmentationCore xyPoint = qt.QPoint(xy[0], xy[1]) ijkVector = self.scriptedEffect.xyToIjk(xyPoint, viewWidget, image) return [int(ijkVector.x()), int(ijkVector.y()), int(ijkVector.z())]