#just make my qt app call functions like this for web plotting from bokeh.models import ColumnDataSource from bokeh.plotting import figure, gridplot, output_file, show from bMapManager import bMap from bMapManager import bStack from bMapManager import bStackPlot #use MapManager class library to open one timepoint in a map mapName = 'a5n' myMap = bMap(mapName) spines = myMap.stackList[1].getSpines() spinesInt = myMap.stackList[1].getSpinesInt() # !!!!! REMEMBER TO MERGE STACK DB AND INT1/INT2 #append spine intensity to spine stack db (tood: put this into main mapmanager class library) for col in spinesInt.columns: spines[col] = spinesInt[col] output_file(mapName + '_bokeh.html') # create a column data source for the plots to share source = ColumnDataSource(data=spines) TOOLS = "box_select,lasso_select,box_zoom,pan,reset,resize,wheel_zoom,help" # create a new plot and add a renderer left = figure(tools=TOOLS, width=300, height=300, title=None, x_axis_label='x (um)', y_axis_label='y (um)') left.circle('x', 'y', source=source) # create another new plot and add a renderer
def __init__(self): QMainWindow.__init__(self) self.map = bMap('a5n') self.map.stackList[1].loadtiff() a = self.map.stackList[1].getSlice(0) #Format_RGB666 image = QImage(a.tostring(), a.shape[0], a.shape[1], QImage.Format_Indexed8) image = image.convertToFormat(QImage.Format_RGB16) #image = QImage(a.tostring(), a.shape[0], a.shape[1], a.shape[0], QImage.Format_RGB666) self.COLORTABLE=[] #for i in range(256): self.COLORTABLE.append(QtGui.qRgb(i/4,i,i/2)) for i in range(256): self.COLORTABLE.append(qRgb(i/4,i,i/2)) self.x = 0 self.imageX = 0 self.imageY = 0 self.imageWidth = 200 self.imageHeight = 200 self.currentImageWidth = 512 self.currentImageHeight = 512 #this is required here AND in self.centralWidget() self.setMouseTracking(True) #see: http://stackoverflow.com/questions/10477075/pyqt4-jpeg-jpg-unsupported-image-format #print 'cwd: ',os.getcwd() localImagePath = os.getcwd() + '/images/pigeon.png' if not os.path.isfile(localImagePath): print '*** ERROR: did not find file:', localImagePath self.image = QImage(localImagePath) if self.image.isNull(): print '*** ERROR: loading image' self.image = image print self.image.width(), self.image.height() self.dirty = False self.filename = 'pigeon xxx' self.mirroredvertically = False self.mirroredhorizontally = False self.move(100,100) self.imageLabel = QLabel() #for some reason, QLabel is used to display images (in general) self.imageLabel.setMinimumSize(450, 450) self.imageLabel.setAlignment(Qt.AlignCenter) self.imageLabel.setContextMenuPolicy(Qt.ActionsContextMenu) #self.setCentralWidget(self.imageLabel) mainWidget = QWidget() vbox = QVBoxLayout() #button = QPushButton("Hello") #vbox.addWidget( button ) self.points = DrawingPointsWidget(self.image, self.map) #self.points.resize(400,400) vbox.addWidget(self.points) vbox.addWidget(self.imageLabel) mainWidget.setLayout(vbox) self.setCentralWidget(mainWidget) #set background color of window palette = QPalette() palette.setColor(QPalette.Background,Qt.gray) self.setPalette(palette) self.centralWidget().setMouseTracking(True) #i want to turn on mouse tracking #see: http://stackoverflow.com/questions/25368295/qwidgetmousemoveevent-not-firing-when-cursor-over-child-widget #self.imageLabel.setMouseTracking(True) self.sizeLabel = QLabel() self.sizeLabel.setFrameStyle(QFrame.StyledPanel|QFrame.Sunken) status = self.statusBar() status.setSizeGripEnabled(False) status.addPermanentWidget(self.sizeLabel) status.showMessage("Ready", 5000) editInvertAction = self.createAction("&Invert", self.editInvert, "Ctrl+I", "editinvert", "Invert the image's colors", True, "toggled(bool)") editSwapRedAndBlueAction = self.createAction("Sw&ap Red and Blue", self.editSwapRedAndBlue, "Ctrl+A", "editswap", "Swap the image's red and blue color components", True, "toggled(bool)") editZoomAction = self.createAction("&Zoom...", self.editZoom, "Alt+Z", "editzoom", "Zoom the image") mirrorGroup = QActionGroup(self) editUnMirrorAction = self.createAction("&Unmirror", self.editUnMirror, "Ctrl+U", "editunmirror", "Unmirror the image", True, "toggled(bool)") mirrorGroup.addAction(editUnMirrorAction) editMirrorHorizontalAction = self.createAction( "Mirror &Horizontally", self.editMirrorHorizontal, "Ctrl+H", "editmirrorhoriz", "Horizontally mirror the image", True, "toggled(bool)") mirrorGroup.addAction(editMirrorHorizontalAction) editMirrorVerticalAction = self.createAction( "Mirror &Vertically", self.editMirrorVertical, "Ctrl+V", "editmirrorvert", "Vertically mirror the image", True, "toggled(bool)") mirrorGroup.addAction(editMirrorVerticalAction) editUnMirrorAction.setChecked(True) editMenu = self.menuBar().addMenu("&Edit") self.addActions(editMenu, (editInvertAction, editSwapRedAndBlueAction, editZoomAction)) editToolbar = self.addToolBar("Edit") editToolbar.setObjectName("EditToolBar") self.addActions(editToolbar, (editInvertAction, editSwapRedAndBlueAction, editUnMirrorAction, editMirrorVerticalAction, editMirrorHorizontalAction)) #remove this #editToolbar.setMouseTracking(True) self.zoomSpinBox = QSpinBox() self.zoomSpinBox.setRange(1, 400) self.zoomSpinBox.setSuffix(" %") self.zoomSpinBox.setValue(100) self.zoomSpinBox.setToolTip("Zoom the image") self.zoomSpinBox.setStatusTip(self.zoomSpinBox.toolTip()) self.zoomSpinBox.setFocusPolicy(Qt.NoFocus) self.connect(self.zoomSpinBox, SIGNAL("valueChanged(int)"), self.showImage) editToolbar.addWidget(self.zoomSpinBox) self.addActions(self.imageLabel, (editInvertAction, editSwapRedAndBlueAction, editUnMirrorAction, editMirrorVerticalAction, editMirrorHorizontalAction)) self.label = QLabel("No data") #self.label.setGeometry(100, 200, 100, 100) #self.setCentralWidget(self.label) #self.setWindowTitle("QMainWindow WheelEvent") editToolbar.addWidget(self.label)
#testing from bMapManager import bMap from bMapManager import bStack from bMapManager import bStackPlot m = bMap('a5n') print m.stackList[1].getMask(z=10) #m.stackList[1].loadtiff()
def __init__(self): QMainWindow.__init__(self) self.setWindowTitle('Stack Browser 2') #a second window (works) #self.secondWindow = MyWindow2(self) #self.secondWindow.show() self.COLORTABLE=[] #for i in range(256): self.COLORTABLE.append(QtGui.qRgb(i/4,i,i/2)) for i in range(256): self.COLORTABLE.append(qRgb(i/4,i,i/2)) self.map = bMap('a5n') self.map.stackList[1].loadtiff() a = self.map.stackList[1].getSlice(0) self.image = QImage(a.tostring(), a.shape[0], a.shape[1], QImage.Format_Indexed8) self.image.setColorTable(self.COLORTABLE) print self.image.width(), self.image.height() self.z = 0 # self.setGeometry(100,100,600,600) #set the main window size self.scene = QGraphicsScene() #self.view = QGraphicsView(self.scene) self.view = MyGraphicsView(self.scene) self.view.fitInView(self.scene.sceneRect(), Qt.KeepAspectRatio) ''' self.setMouseTracking(True) self.installEventFilter(self) ''' self.view.setMouseTracking(True) self.view.viewport().installEventFilter(self) #this is required otherwise QGraphicsView eats arrow keys (does not eat other keys) self.view.installEventFilter(self) #turn of scrollbar self.view.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.view.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.imageLabel = QLabel() self.imageLabel.setGeometry(0, 0, 1024, 1024) #position and size of image #self.imageLabel.setPixmap(QPixmap(os.getcwd() + "/images/pigeon.png")) self.imageLabel.setPixmap(QPixmap.fromImage(self.image)) #this will translate QWidget with image #self.imageLabel.move(200,200) self.scene.addWidget(self.imageLabel) #bug in qt, does not work #self.view.translate(10,10) vbox = QVBoxLayout() vbox.addWidget(self.view) mainWidget = QWidget() mainWidget.setLayout(vbox) self.setCentralWidget(mainWidget) self.points = DrawingPointsWidget(self.map) self.scene.addWidget(self.points) self.view.scale(0.5,0.5) self.points.update() #triggers drawEvent #self.view.show(); #self.view.resize(512,512); #set background color of window palette = QPalette() palette.setColor(QPalette.Background,Qt.gray) self.setPalette(palette) self.sizeLabel = QLabel() self.sizeLabel.setFrameStyle(QFrame.StyledPanel|QFrame.Sunken) status = self.statusBar() status.setSizeGripEnabled(False) status.addPermanentWidget(self.sizeLabel) status.showMessage("Ready", 5000) editToolbar = self.addToolBar("Edit") editToolbar.setObjectName("EditToolBar") ''' self.addActions(editToolbar, (editInvertAction, editSwapRedAndBlueAction, editUnMirrorAction, editMirrorVerticalAction, editMirrorHorizontalAction)) ''' self.zoomSpinBox = QSpinBox() self.zoomSpinBox.setRange(1, 400) self.zoomSpinBox.setSuffix(" %") self.zoomSpinBox.setValue(100) self.zoomSpinBox.setToolTip("Zoom the image") self.zoomSpinBox.setStatusTip(self.zoomSpinBox.toolTip()) self.zoomSpinBox.setFocusPolicy(Qt.NoFocus) self.connect(self.zoomSpinBox, SIGNAL("valueChanged(int)"), self.showImage) #not sure if self.update() is good idea here? editToolbar.addWidget(self.zoomSpinBox) #button to show/hide left toolbar self.myButtonID1 = QPushButton('Left Toolbar') self.myButtonID1.clicked.connect(lambda:self.myButtonPress(self.myButtonID1)) editToolbar.addWidget(self.myButtonID1) #ch1 button self.myCh1ButtonID = QPushButton('Channel 1') self.myCh1ButtonID.clicked.connect(lambda:self.myButtonPress(self.myCh1ButtonID)) editToolbar.addWidget(self.myCh1ButtonID) #ch2 button self.myCh2ButtonID = QPushButton('Channel 2') self.myCh2ButtonID.clicked.connect(lambda:self.myButtonPress(self.myCh2ButtonID)) editToolbar.addWidget(self.myCh2ButtonID) #button to plot self.myButtonID2 = QPushButton('Plot 1') self.myButtonID2.clicked.connect(lambda:self.myButtonPress(self.myButtonID2)) editToolbar.addWidget(self.myButtonID2) #checkbox to show/hide tracong self.checkbox1 = QCheckBox('Show Tracing') self.checkbox1.stateChanged.connect(lambda:self.myButtonPress(self.checkbox1)) editToolbar.addWidget(self.checkbox1) #todo: put this into Qt.LeftToolBarArea self.leftToolbar = QToolBar('left_tb') self.addToolBar(Qt.LeftToolBarArea, self.leftToolbar) #list for stack db self.list = QTableView(self) #uses model/view spinesModel = PandasModel(self.map.stackList[1].getSpines()) self.list.setModel(spinesModel) self.list.setFont(QFont("Arial", 10)) self.leftToolbar.addWidget(self.list)