Skip to content

Commit

Permalink
Added ImgMplCanvas to command interpreter
Browse files Browse the repository at this point in the history
  • Loading branch information
tomacorp committed Jun 15, 2015
1 parent 9bddda0 commit 60821a6
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 25 deletions.
25 changes: 22 additions & 3 deletions CommandInterp.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
import imghdr
import ntpath


import re
import numpy as np
import h5py

import EngEvaluate
import ReadSpiceRaw
import SpiceVarExpr
import ImgMplCanvas

# di show available vars from raw file
# show list user-assigned variables
Expand Down Expand Up @@ -223,7 +223,11 @@ def executeLongCommand(self, longCmd, cmdText):
print(message)
self.pyCode= "# " + message
elif cmd == 'img':
if os.path.isfile(arg):
canvasType= str(type(self.sc))
if (canvasType != "<class 'ImgMplCanvas.ImgMplCanvas'>"):
message= "Error: can't draw image except on an image canvas"
print(message)
elif os.path.isfile(arg):
print("Display image: " + str(arg))
fileType= imghdr.what(arg)
fileExtension= '.' + fileType
Expand All @@ -235,6 +239,9 @@ def executeLongCommand(self, longCmd, cmdText):
print("Image is in variable: " + str(varName))
self._globals[varName]= skimage.data.imread(arg)
# self.setPostParameter("graphdev " + str(varName))

self.sc.displayImagePySideFrameButtons(arg, imageName=varName)

# self.sc.plt.imshow(self._globals[varName])
# self.sc.show()
else:
Expand Down Expand Up @@ -434,7 +441,7 @@ def graphExpr(self, arg, cmdText):
return message

def setPostParameter(self, arg):
regexSet= re.match(r'^(xname|title|xl|yl|graphdev) (.*)', arg)
regexSet= re.match(r'^(xname|title|xl|yl|graphdev|imgdev) (.*)', arg)
if regexSet is not None:
setcmd= regexSet.group(1)
setarg= regexSet.group(2)
Expand Down Expand Up @@ -494,6 +501,7 @@ def setPostParameter(self, arg):
self.sc.plt.set_xlim(lo, hi)
self.pyCode = 'graph.set_xlim(' + str(lo) + ',' + str(hi) + ')'
self.sc.draw()

elif setcmd == 'graphdev':
currentCanvasName= self.sc.get_name()
if setarg != currentCanvasName:
Expand All @@ -504,6 +512,17 @@ def setPostParameter(self, arg):
print "Need to set active graph to " + str(setarg)
self.graphs.setActive(setarg)
self.setGraphicsActiveDelegate(self.graphs.getActiveCanvas())

elif setcmd == 'imgdev':
currentCanvasName= self.sc.get_name()
if setarg != currentCanvasName:
if setarg not in self.graphs.cd:
print "Need a new graph called " + str(setarg)
self.graphs.createImg(canvasName=str(setarg))
else:
print "Need to set active graph to " + str(setarg)
self.graphs.setActive(setarg)
self.setGraphicsActiveDelegate(self.graphs.getActiveCanvas())

else:
message = "Unrecognized set command: " + setcmd
Expand Down
13 changes: 9 additions & 4 deletions ImgMplCanvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import sys
import os.path
import numpy as np
from numpy import *
from collections import deque

Expand Down Expand Up @@ -135,7 +136,7 @@ def __init__(self, parent=None, imageName='Image', width=5, height=4, dpi=72):
self.frame= QtGui.QFrame()
self.frame.setFrameShape(QtGui.QFrame.StyledPanel)
self.frame.setParent(self.parent)
self.statusBar= None
self.statusBar= None

def getImageName(self, fn):

Expand Down Expand Up @@ -196,7 +197,6 @@ def displayImagePySideFrame(fn, imageName='image'):
layout = QtGui.QVBoxLayout()
layout.addWidget(canvas)
layout.addWidget(label)

layout.setStretchFactor(canvas, 1.0)

self.frame.setLayout(layout)
Expand Down Expand Up @@ -279,14 +279,19 @@ def displayImagePySideFrameButtons(self, fn, imageName='image'):
def setStatusBar(self, main):
self.statusBar= main

def get_name(self):
return self.name

def get_xvar(self):
return None

# The test starts here
if __name__ == "__main__":
from matplotlib import pyplot as plt
import numpy as np

print("ImgMplCanvas class test")

app = QApplication(sys.argv)

main = QtGui.QMainWindow()

# The file is in a subdirectory of the run directory.
Expand Down
17 changes: 0 additions & 17 deletions MainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,6 @@
# Running in the virtual environment at
# /Users/toma/anaconda/envs/pypostenv/bin/

# conda env list
# source activate pypostenv

# conda install pyside
# conda remove pyqt
# conda install matplotlib
# pip install fysom

# On new machines, configure git:
# git config --global user.name "Tom Anderson"
# git config --global user.email [email protected]

# For git commit:
# git push origin master

# Project->Project Properties

# Previous things I've used:
# Custom python: /Users/toma/Library/Enthought/Canopy_64bit/User/bin/python
# Or: /Users/toma/python278i/bin/python
Expand Down
13 changes: 12 additions & 1 deletion MplCanvasDict.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from matplotlib.figure import Figure
from matplotlib.ticker import EngFormatter
import EngMplCanvas
import ImgMplCanvas

# TODO: Refactor to take more canvas types.

Expand Down Expand Up @@ -57,7 +58,17 @@ def create(self, canvasName='', parent=None, width=5, height=4, dpi=72):
c.name= canvasName
self.cd[canvasName]= c
return canvasName


def createImg(self, canvasName='', parent=None, width=5, height=4, dpi=72):
if canvasName == '':
canvasCount= len(self.cd) + 1
canvasName= "PyPost_" + str(canvasCount)
c= ImgMplCanvas.ImgMplCanvas(parent=parent, width=width, height=height, dpi=dpi)
# c.setWindowTitle(canvasName)
c.name= canvasName
self.cd[canvasName]= c
return canvasName

def delete(self, canvasName):
if self.active == canvasName:
self.active= ''
Expand Down

0 comments on commit 60821a6

Please sign in to comment.