def __init__ (self) : QMainWindow.__init__(self) # points self._points = [] self._id_gen = IdSetGenerator() #X self.version = 2 self._view = PixmapStackView() #QGraphicsScene self._scene = QGraphicsScene() #QGraphicsPixmapItem self._item = QGraphicsPixmapItem() self._item.setTransformationMode(Qt.SmoothTransformation) self._item.setFlag(self._item.ItemIsSelectable,False) self._scene.addItem(self._item) #QGraphicsView self._widget = ScalableGraphicsView(self._scene) self.setCentralWidget(self._widget) ################### mouse handling ################### self._widget.setMouseTracking(True) self._last_mouse_x = 0 self._last_mouse_y = 0 self._last_slice = 0 QObject.connect(self._widget, SIGNAL("mouse_press"), self.mouse_pressed) QObject.connect(self._widget, SIGNAL("mouse_move"), self.mouse_moved) QObject.connect(self, SIGNAL("mouse_moved"), self.coordinates) ################### menubar ################### self.menu = self.menuBar() self.menu_file = self.menu.addMenu('File') # Import Points self._load_points = self.menu_file.addAction('Import Points') QObject.connect(self._load_points, SIGNAL("triggered(bool)"), self.load_points) # Save points self._save_points = self.menu_file.addAction('Save Points') QObject.connect(self._save_points, SIGNAL("triggered(bool)"), self.save_points) ################### toolbar ################### self._toolbar = self.addToolBar("tools") self._toolgroup = QActionGroup(self) # QWidgetAction : "Rotation Left" self._action_left = self._toolbar.addAction("left rotation") self._action_left.setIcon(QIcon(":/image/rotate_left.png") ) QObject.connect(self._action_left, SIGNAL("triggered(bool)"), self.rotate_left) # QWidgetAction : "Rotation Right" self._action_right = self._toolbar.addAction("right rotation") self._action_right.setIcon(QIcon(":/image/rotate_right.png") ) QObject.connect(self._action_right, SIGNAL("triggered(bool)"), self.rotate_right) # QWidgetAction : "Add point" self._action_add = self._toolbar.addAction("Add point") self._action_add.setCheckable(True) self._toolgroup.addAction(self._action_add) self._action_add.setIcon(QIcon(":/image/add.png") ) # QWidgetAction : "Delete point" self._action_delete = self._toolbar.addAction("Delete point") self._action_delete.setCheckable(True) self._toolgroup.addAction(self._action_delete) self._action_delete.setIcon(QIcon(":/image/delete.png") ) ################### palette ################### self._palette_select = QComboBox() self._toolbar.addWidget(self._palette_select) for palname in palette_names : self._palette_select.addItem(palname) QObject.connect(self._palette_select, SIGNAL("currentIndexChanged(int)"), self.palette_name_changed) ################### slider ################### self._bot_toolbar = QToolBar("slider") self._img_slider = QSlider(Qt.Horizontal) self._img_slider.setRange(0,self._view.nb_slices() - 1) QObject.connect(self._img_slider, SIGNAL("valueChanged(int)"), self.slice_changed) self._bot_toolbar.addWidget(self._img_slider) self.addToolBar(Qt.BottomToolBarArea,self._bot_toolbar) ################### statusbar ################### self._lab_coord = QLabel("coords:") self._lab_xcoord = QLabel("% 4d" % 0) self._lab_ycoord = QLabel("% 4d" % 0) self._lab_zcoord = QLabel("% 4d" % 0) self._lab_intens = QLabel("intens: None") self.statusbar = self.statusBar() self.statusbar.addPermanentWidget(self._lab_coord) self.statusbar.addPermanentWidget(self._lab_xcoord) self.statusbar.addPermanentWidget(self._lab_ycoord) self.statusbar.addPermanentWidget(self._lab_zcoord) self.statusbar.addPermanentWidget(self._lab_intens)
def __init__(self): QMainWindow.__init__(self) # points self._points = [] self._id_gen = IdSetGenerator() #X self.version = 2 self._view = PixmapStackView() #QGraphicsScene self._scene = QGraphicsScene() #QGraphicsPixmapItem self._item = QGraphicsPixmapItem() self._item.setTransformationMode(Qt.SmoothTransformation) self._item.setFlag(self._item.ItemIsSelectable, False) self._scene.addItem(self._item) #QGraphicsView self._widget = ScalableGraphicsView(self._scene) self.setCentralWidget(self._widget) ################### mouse handling ################### self._widget.setMouseTracking(True) self._last_mouse_x = 0 self._last_mouse_y = 0 self._last_slice = 0 QObject.connect(self._widget, SIGNAL("mouse_press"), self.mouse_pressed) QObject.connect(self._widget, SIGNAL("mouse_move"), self.mouse_moved) QObject.connect(self, SIGNAL("mouse_moved"), self.coordinates) ################### menubar ################### self.menu = self.menuBar() self.menu_file = self.menu.addMenu('File') # Import Points self._load_points = self.menu_file.addAction('Import Points') QObject.connect(self._load_points, SIGNAL("triggered(bool)"), self.load_points) # Save points self._save_points = self.menu_file.addAction('Save Points') QObject.connect(self._save_points, SIGNAL("triggered(bool)"), self.save_points) ################### toolbar ################### self._toolbar = self.addToolBar("tools") self._toolgroup = QActionGroup(self) # QWidgetAction : "Rotation Left" self._action_left = self._toolbar.addAction("left rotation") self._action_left.setIcon(QIcon(":/image/rotate_left.png")) QObject.connect(self._action_left, SIGNAL("triggered(bool)"), self.rotate_left) # QWidgetAction : "Rotation Right" self._action_right = self._toolbar.addAction("right rotation") self._action_right.setIcon(QIcon(":/image/rotate_right.png")) QObject.connect(self._action_right, SIGNAL("triggered(bool)"), self.rotate_right) # QWidgetAction : "Add point" self._action_add = self._toolbar.addAction("Add point") self._action_add.setCheckable(True) self._toolgroup.addAction(self._action_add) self._action_add.setIcon(QIcon(":/image/add.png")) # QWidgetAction : "Delete point" self._action_delete = self._toolbar.addAction("Delete point") self._action_delete.setCheckable(True) self._toolgroup.addAction(self._action_delete) self._action_delete.setIcon(QIcon(":/image/delete.png")) ################### palette ################### self._palette_select = QComboBox() self._toolbar.addWidget(self._palette_select) for palname in palette_names: self._palette_select.addItem(palname) QObject.connect(self._palette_select, SIGNAL("currentIndexChanged(int)"), self.palette_name_changed) ################### slider ################### self._bot_toolbar = QToolBar("slider") self._img_slider = QSlider(Qt.Horizontal) self._img_slider.setRange(0, self._view.nb_slices() - 1) QObject.connect(self._img_slider, SIGNAL("valueChanged(int)"), self.slice_changed) self._bot_toolbar.addWidget(self._img_slider) self.addToolBar(Qt.BottomToolBarArea, self._bot_toolbar) ################### statusbar ################### self._lab_coord = QLabel("coords:") self._lab_xcoord = QLabel("% 4d" % 0) self._lab_ycoord = QLabel("% 4d" % 0) self._lab_zcoord = QLabel("% 4d" % 0) self._lab_intens = QLabel("intens: None") self.statusbar = self.statusBar() self.statusbar.addPermanentWidget(self._lab_coord) self.statusbar.addPermanentWidget(self._lab_xcoord) self.statusbar.addPermanentWidget(self._lab_ycoord) self.statusbar.addPermanentWidget(self._lab_zcoord) self.statusbar.addPermanentWidget(self._lab_intens)
class PointSelection (QMainWindow) : def __init__ (self) : QMainWindow.__init__(self) # points self._points = [] self._id_gen = IdSetGenerator() #X self.version = 2 self._view = PixmapStackView() #QGraphicsScene self._scene = QGraphicsScene() #QGraphicsPixmapItem self._item = QGraphicsPixmapItem() self._item.setTransformationMode(Qt.SmoothTransformation) self._item.setFlag(self._item.ItemIsSelectable,False) self._scene.addItem(self._item) #QGraphicsView self._widget = ScalableGraphicsView(self._scene) self.setCentralWidget(self._widget) ################### mouse handling ################### self._widget.setMouseTracking(True) self._last_mouse_x = 0 self._last_mouse_y = 0 self._last_slice = 0 QObject.connect(self._widget, SIGNAL("mouse_press"), self.mouse_pressed) QObject.connect(self._widget, SIGNAL("mouse_move"), self.mouse_moved) QObject.connect(self, SIGNAL("mouse_moved"), self.coordinates) ################### menubar ################### self.menu = self.menuBar() self.menu_file = self.menu.addMenu('File') # Import Points self._load_points = self.menu_file.addAction('Import Points') QObject.connect(self._load_points, SIGNAL("triggered(bool)"), self.load_points) # Save points self._save_points = self.menu_file.addAction('Save Points') QObject.connect(self._save_points, SIGNAL("triggered(bool)"), self.save_points) ################### toolbar ################### self._toolbar = self.addToolBar("tools") self._toolgroup = QActionGroup(self) # QWidgetAction : "Rotation Left" self._action_left = self._toolbar.addAction("left rotation") self._action_left.setIcon(QIcon(":/image/rotate_left.png") ) QObject.connect(self._action_left, SIGNAL("triggered(bool)"), self.rotate_left) # QWidgetAction : "Rotation Right" self._action_right = self._toolbar.addAction("right rotation") self._action_right.setIcon(QIcon(":/image/rotate_right.png") ) QObject.connect(self._action_right, SIGNAL("triggered(bool)"), self.rotate_right) # QWidgetAction : "Add point" self._action_add = self._toolbar.addAction("Add point") self._action_add.setCheckable(True) self._toolgroup.addAction(self._action_add) self._action_add.setIcon(QIcon(":/image/add.png") ) # QWidgetAction : "Delete point" self._action_delete = self._toolbar.addAction("Delete point") self._action_delete.setCheckable(True) self._toolgroup.addAction(self._action_delete) self._action_delete.setIcon(QIcon(":/image/delete.png") ) ################### palette ################### self._palette_select = QComboBox() self._toolbar.addWidget(self._palette_select) for palname in palette_names : self._palette_select.addItem(palname) QObject.connect(self._palette_select, SIGNAL("currentIndexChanged(int)"), self.palette_name_changed) ################### slider ################### self._bot_toolbar = QToolBar("slider") self._img_slider = QSlider(Qt.Horizontal) self._img_slider.setRange(0,self._view.nb_slices() - 1) QObject.connect(self._img_slider, SIGNAL("valueChanged(int)"), self.slice_changed) self._bot_toolbar.addWidget(self._img_slider) self.addToolBar(Qt.BottomToolBarArea,self._bot_toolbar) ################### statusbar ################### self._lab_coord = QLabel("coords:") self._lab_xcoord = QLabel("% 4d" % 0) self._lab_ycoord = QLabel("% 4d" % 0) self._lab_zcoord = QLabel("% 4d" % 0) self._lab_intens = QLabel("intens: None") self.statusbar = self.statusBar() self.statusbar.addPermanentWidget(self._lab_coord) self.statusbar.addPermanentWidget(self._lab_xcoord) self.statusbar.addPermanentWidget(self._lab_ycoord) self.statusbar.addPermanentWidget(self._lab_zcoord) self.statusbar.addPermanentWidget(self._lab_intens) ############################################## # # update GUI # ############################################## def update_pix (self) : """ """ pix = self._view.pixmap() if pix is not None : self._item.setPixmap(pix) else: print 'None pixmap' #update points ind = self._view.current_slice() for point in self._points : if point is not None: pid,item, x,y,z,textid = point visible = abs(z - ind) < 5 item.setVisible(visible) col = QColor.fromHsv( (pid * 10) % 360,255,255) if visible : sca = max(0.,(5 - abs(z - ind) ) / 5.) if z == ind : pen = QPen(QColor(255,255,255) ) pen.setWidthF(2.) item.setPen(pen) textid.setVisible(True) else : pen = QPen(QColor(0,0,0) ) pen.setWidthF(2.) item.setPen(pen) textid.setVisible(False) else : sca = 1. tr = QTransform() tr.scale(sca,sca) item.setTransform(tr) item.update() def coordinates (self,(i,j,k)) : self._last_mouse_x,self._last_mouse_y, self._last_slice = i,j,k self.fill_infos()
class PointSelection(QMainWindow): def __init__(self): QMainWindow.__init__(self) # points self._points = [] self._id_gen = IdSetGenerator() #X self.version = 2 self._view = PixmapStackView() #QGraphicsScene self._scene = QGraphicsScene() #QGraphicsPixmapItem self._item = QGraphicsPixmapItem() self._item.setTransformationMode(Qt.SmoothTransformation) self._item.setFlag(self._item.ItemIsSelectable, False) self._scene.addItem(self._item) #QGraphicsView self._widget = ScalableGraphicsView(self._scene) self.setCentralWidget(self._widget) ################### mouse handling ################### self._widget.setMouseTracking(True) self._last_mouse_x = 0 self._last_mouse_y = 0 self._last_slice = 0 QObject.connect(self._widget, SIGNAL("mouse_press"), self.mouse_pressed) QObject.connect(self._widget, SIGNAL("mouse_move"), self.mouse_moved) QObject.connect(self, SIGNAL("mouse_moved"), self.coordinates) ################### menubar ################### self.menu = self.menuBar() self.menu_file = self.menu.addMenu('File') # Import Points self._load_points = self.menu_file.addAction('Import Points') QObject.connect(self._load_points, SIGNAL("triggered(bool)"), self.load_points) # Save points self._save_points = self.menu_file.addAction('Save Points') QObject.connect(self._save_points, SIGNAL("triggered(bool)"), self.save_points) ################### toolbar ################### self._toolbar = self.addToolBar("tools") self._toolgroup = QActionGroup(self) # QWidgetAction : "Rotation Left" self._action_left = self._toolbar.addAction("left rotation") self._action_left.setIcon(QIcon(":/image/rotate_left.png")) QObject.connect(self._action_left, SIGNAL("triggered(bool)"), self.rotate_left) # QWidgetAction : "Rotation Right" self._action_right = self._toolbar.addAction("right rotation") self._action_right.setIcon(QIcon(":/image/rotate_right.png")) QObject.connect(self._action_right, SIGNAL("triggered(bool)"), self.rotate_right) # QWidgetAction : "Add point" self._action_add = self._toolbar.addAction("Add point") self._action_add.setCheckable(True) self._toolgroup.addAction(self._action_add) self._action_add.setIcon(QIcon(":/image/add.png")) # QWidgetAction : "Delete point" self._action_delete = self._toolbar.addAction("Delete point") self._action_delete.setCheckable(True) self._toolgroup.addAction(self._action_delete) self._action_delete.setIcon(QIcon(":/image/delete.png")) ################### palette ################### self._palette_select = QComboBox() self._toolbar.addWidget(self._palette_select) for palname in palette_names: self._palette_select.addItem(palname) QObject.connect(self._palette_select, SIGNAL("currentIndexChanged(int)"), self.palette_name_changed) ################### slider ################### self._bot_toolbar = QToolBar("slider") self._img_slider = QSlider(Qt.Horizontal) self._img_slider.setRange(0, self._view.nb_slices() - 1) QObject.connect(self._img_slider, SIGNAL("valueChanged(int)"), self.slice_changed) self._bot_toolbar.addWidget(self._img_slider) self.addToolBar(Qt.BottomToolBarArea, self._bot_toolbar) ################### statusbar ################### self._lab_coord = QLabel("coords:") self._lab_xcoord = QLabel("% 4d" % 0) self._lab_ycoord = QLabel("% 4d" % 0) self._lab_zcoord = QLabel("% 4d" % 0) self._lab_intens = QLabel("intens: None") self.statusbar = self.statusBar() self.statusbar.addPermanentWidget(self._lab_coord) self.statusbar.addPermanentWidget(self._lab_xcoord) self.statusbar.addPermanentWidget(self._lab_ycoord) self.statusbar.addPermanentWidget(self._lab_zcoord) self.statusbar.addPermanentWidget(self._lab_intens) ############################################## # # update GUI # ############################################## def update_pix(self): """ """ pix = self._view.pixmap() if pix is not None: self._item.setPixmap(pix) else: print 'None pixmap' #update points ind = self._view.current_slice() for point in self._points: if point is not None: pid, item, x, y, z, textid = point visible = abs(z - ind) < 5 item.setVisible(visible) col = QColor.fromHsv((pid * 10) % 360, 255, 255) if visible: sca = max(0., (5 - abs(z - ind)) / 5.) if z == ind: pen = QPen(QColor(255, 255, 255)) pen.setWidthF(2.) item.setPen(pen) textid.setVisible(True) else: pen = QPen(QColor(0, 0, 0)) pen.setWidthF(2.) item.setPen(pen) textid.setVisible(False) else: sca = 1. tr = QTransform() tr.scale(sca, sca) item.setTransform(tr) item.update() def coordinates(self, (i, j, k)): self._last_mouse_x, self._last_mouse_y, self._last_slice = i, j, k self.fill_infos()