Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/zoom frame #98

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions ultratrace/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def afterstartup(self):
self.getWinSize()
self.alignBottomRight(self.oldwidth-self.leftwidth)
if self.Dicom.zframe.image:
self.Dicom.zframe.setImage(self.Dicom.zframe.image)
self.Dicom.zframe.set_image(self.Dicom.zframe.image)

def alignBottomLeftWrapper(self, event=None):
if self.isResizing: return
Expand All @@ -246,7 +246,7 @@ def alignBottomLeft(self, event=None):
if event == None or event.widget == self:
self.alignBottomRight(self.winfo_width() - self.leftwidth)
if self.Dicom.zframe.image:
self.Dicom.zframe.setImage(self.Dicom.zframe.image)
self.Dicom.zframe.set_image(self.Dicom.zframe.image)
self.isResizing = False
def alignBottomRight(self,x):
''' '''
Expand Down Expand Up @@ -416,7 +416,7 @@ def onRelease(self,event):
#resize dicom image
png_loc = self.Data.getPreprocessedDicom(self.frame)
image = PIL.Image.open( png_loc )
self.Dicom.zframe.setImage(image)
self.Dicom.zframe.set_image(image)
# x = self.Dicom.zframe.width
x = self.winfo_width() - self.LEFT.winfo_width()
# y = self.Dicom.zframe.height
Expand Down Expand Up @@ -455,8 +455,8 @@ def onMotion(self, event):
lastClick = self.click
thisClick = (event.x, event.y)
# enforce minimum distance b/w new crosshairs
dx = abs(thisClick[0] - lastClick[0]) / self.Dicom.zframe.imgscale
dy = abs(thisClick[1] - lastClick[1]) / self.Dicom.zframe.imgscale
dx = abs(thisClick[0] - lastClick[0]) / self.Dicom.zframe.get_zoom_scale()
dy = abs(thisClick[1] - lastClick[1]) / self.Dicom.zframe.get_zoom_scale()
if dx > util.CROSSHAIR_DRAG_BUFFER or dy > util.CROSSHAIR_DRAG_BUFFER:
self.click = thisClick
ch = self.Trace.add( *self.click )
Expand Down
10 changes: 5 additions & 5 deletions ultratrace/modules/dicom.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self, app):
self.reader = None

# zoom frame (contains our tracing canvas)
self.zframe = ZoomFrame(self.app.RIGHT, 1.3, app)
self.zframe = ZoomFrame(self.app.RIGHT, app)

# reset zoom button
self.zoomResetBtn = Button(self.app.LEFT, text='Reset image', command=self.zoomReset, takefocus=0)#, pady=7 )
Expand All @@ -54,9 +54,6 @@ def zoomReset(self, fromButton=False):
if self.isLoaded():
# creates a new canvas object and we redraw everything to it
self.zframe.resetCanvas()
# self.zframe.canvas.bind('<Button-1>', self.app.onClickZoom )
# self.zframe.canvas.bind('<ButtonRelease-1>', self.app.onRelease )
# self.zframe.canvas.bind('<Motion>', self.app.onMotion )

# we want to go here only after a button press
if fromButton: self.app.framesUpdate()
Expand All @@ -66,7 +63,7 @@ def update(self, _frame=None):
change the image on the zoom frame
'''
if self.reader and self.reader.loaded:
self.zframe.setImage(self.reader.getFrame(_frame or self.app.frame))
self.zframe.set_image(self.reader.getFrame(_frame or self.app.frame))

def load(self, event=None):
'''
Expand Down Expand Up @@ -163,6 +160,7 @@ def grid(self):
self.app.framesNextBtn.grid( row=0, column=3 )
self.zoomResetBtn.grid( row=7 )
self.app.Control.grid()
self.zframe.grid()

def grid_remove(self):
'''
Expand All @@ -175,3 +173,5 @@ def grid_remove(self):
self.app.framesNextBtn.grid_remove()
self.zoomResetBtn.grid_remove()
self.app.Control.grid_remove()
self.zframe.grid_remove()

2 changes: 2 additions & 0 deletions ultratrace/modules/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ def loadIntervals(self):
tg = self.app.Data.checkFileLevel('.TextGrid', f)
if tg:
grid = self.app.TextGrid.fromFile(tg)
if grid is None:
return
keggsmurph21 marked this conversation as resolved.
Show resolved Hide resolved
for tier in grid:
if TextGrid.isIntervalTier(tier):
for el in tier:
Expand Down
18 changes: 12 additions & 6 deletions ultratrace/modules/textgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

try:
from textgrid import TextGrid as TextGridFile, IntervalTier, PointTier, Point # textgrid
from textgrid.exceptions import TextGridError
LIBS_INSTALLED = True
except ImportError as e:
warn(e)
Expand Down Expand Up @@ -180,7 +181,8 @@ def fromFile(self, filename):
if LIBS_INSTALLED:
try:
return TextGridFile.fromFile(filename)
except UnicodeDecodeError:
except (TextGridError, UnicodeDecodeError) as e:
error(e)
f = open(filename, 'rb')
bytes = f.read()
f.close()
Expand All @@ -198,9 +200,13 @@ def fromFile(self, filename):
if not found:
raise
else:
ret = TextGridFile.fromFile(tmp.name)
tmp.close()
return ret
try:
ret = TextGridFile.fromFile(tmp.name)
tmp.close()
return ret
except TextGridError as e:
error(e)
return None
else:
error("can't load from file: textgrid lib not installed")
return None
Expand All @@ -218,7 +224,7 @@ def loadOrGenerate(self):
sentenceTier = IntervalTier("text")
sentenceTier.add(minTime, maxTime, "text")
self.TextGrid.tiers.append(sentenceTier)
fname = self.app.Data.unrelativize(self.app.Data.getCurrentFileName() + '.TextGrid')
fname = self.app.Data.unrelativize(self.app.Data.getCurrentFilename() + '.TextGrid')
self.app.Data.setFileLevel('.TextGrid', fname)
names = self.TextGrid.getNames()
for i, n in enumerate(names):
Expand Down Expand Up @@ -656,7 +662,7 @@ def fillCanvases(self):
else:
fill = 'gray50'
frame = frames.create_line(x_coord, 0, x_coord, self.canvas_height, tags="frame"+tier[i].mark, fill=fill)
if first_frame_found == False:
if first_frame_found == False and i + 1 < len(tier):
self.firstFrame = int(tier[i].mark) + 1
first_frame_found = True
self.frame_len = tier[i+1].time - tier[i].time
Expand Down
22 changes: 11 additions & 11 deletions ultratrace/widgets/crosshairs.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ def transformCoordsToTrue(self, x, y):
canvas coords -> absolute coords
absolute coords are % along each axis (e.g. center of image = [.5,.5])
'''
# x = (self.trueX - self.zframe.panX) / self.zframe.imgscale
# y = (self.trueY - self.zframe.panY) / self.zframe.imgscale
# x = (self.trueX - self.zframe.panX) / self.zframe.get_zoom_scale()
keggsmurph21 marked this conversation as resolved.
Show resolved Hide resolved
# y = (self.trueY - self.zframe.panY) / self.zframe.get_zoom_scale()
# return x,y
truex = (x-self.zframe.panX)/(self.zframe.width*self.zframe.imgscale)
truey = (y-self.zframe.panY)/(self.zframe.height*self.zframe.imgscale)
# truex = (x-self.zframe.panX)/self.zframe.imgscale
# truey = (y-self.zframe.panY)/self.zframe.imgscale
truex = (x-self.zframe.panX)/(self.zframe.width*self.zframe.get_zoom_scale())
truey = (y-self.zframe.panY)/(self.zframe.height*self.zframe.get_zoom_scale())
# truex = (x-self.zframe.panX)/self.zframe.get_zoom_scale()
# truey = (y-self.zframe.panY)/self.zframe.get_zoom_scale()
debug(truex, truey)
return truex, truey

Expand All @@ -77,10 +77,10 @@ def transformTrueToCoords(self, truex, truey):
absolute coords -> canvas coords
absolute coords are % along each axis (e.g. center of image = [.5,.5])
'''
# x = (_x * self.zframe.imgscale) + self.zframe.panX
# y = (_y * self.zframe.imgscale) + self.zframe.panY
x = truex * self.zframe.width * self.zframe.imgscale + self.zframe.panX
y = truey * self.zframe.height * self.zframe.imgscale + self.zframe.panY
# x = (_x * self.zframe.get_zoom_scale()) + self.zframe.panX
# y = (_y * self.zframe.get_zoom_scale()) + self.zframe.panY
x = truex * self.zframe.width * self.zframe.get_zoom_scale() + self.zframe.panX
y = truey * self.zframe.height * self.zframe.get_zoom_scale() + self.zframe.panY
return x, y

def transformCoords(self, x, y):
Expand All @@ -91,7 +91,7 @@ def transformCoords(self, x, y):

def transformLength(self, l):
''' transforms a length by our current zoom-amount '''
return l * self.zframe.imgscale
return l * self.zframe.get_zoom_scale()

def getDistance(self, click):
''' calculates the distance from centerpoint to a click event '''
Expand Down
Loading