Skip to content

Commit 4d96b4f

Browse files
committed
Merge pull request #101 from will-moore/unicode_support
Unicode support
2 parents dc0a28f + fbe427e commit 4d96b4f

File tree

5 files changed

+32
-17
lines changed

5 files changed

+32
-17
lines changed

omero/export_scripts/Batch_Image_Export.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ def log(text):
5959
"""
6060
Adds the text to a list of logs. Compiled into text file at the end.
6161
"""
62+
# Handle unicode
63+
try:
64+
text = text.encode('utf8')
65+
except:
66+
pass
6267
print text
6368
logStrings.append(str(text))
6469

omero/figure_scripts/ROI_Split_Figure.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
import omero.util.figureUtil as figUtil
4646
import omero.util.script_utils as scriptUtil
4747
from omero.gateway import BlitzGateway
48-
from omero.rtypes import rlong, robject, rstring, wrap
48+
from omero.rtypes import rlong, robject, rstring, wrap, unwrap
4949
import os
5050
from omero.constants.namespaces import NSCREATED
5151
from omero.constants.projection import ProjectionType
@@ -332,8 +332,8 @@ def getRectangle(roiService, imageId, roiLabel):
332332
# go through all the shapes of the ROI
333333
for shape in roi.copyShapes():
334334
if type(shape) == omero.model.RectI:
335-
t = shape.getTheT().getValue()
336-
z = shape.getTheZ().getValue()
335+
t = unwrap(shape.getTheT())
336+
z = unwrap(shape.getTheZ())
337337
x = shape.getX().getValue()
338338
y = shape.getY().getValue()
339339
tv = shape.getTextValue()

omero/figure_scripts/Split_View_Figure.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ def log(text):
6868
"""
6969
Adds the text to a list of logs. Compiled into figure legend at the end.
7070
"""
71+
# Handle unicode
72+
try:
73+
text = text.encode('utf8')
74+
except:
75+
pass
7176
print text
7277
logStrings.append(text)
7378

@@ -474,7 +479,7 @@ def makeSplitViewFigure(conn, pixelIds, zStart, zEnd, splitIndexes,
474479
rgba = (0, 0, 0, 255)
475480
if index in mergedColours:
476481
rgba = tuple(mergedColours[index])
477-
print index, channelNames[index], rgba
482+
log("%s %s %s" % (index, channelNames[index], rgba))
478483
if rgba == (255, 255, 255, 255): # if white (unreadable),
479484
# needs to be black!
480485
rgba = (0, 0, 0, 255)
@@ -515,16 +520,16 @@ def splitViewFigure(conn, scriptParams):
515520
# function for getting image labels.
516521
def getImageNames(fullName, tagsList, pdList):
517522
name = fullName.split("/")[-1]
518-
return [name]
523+
return [name.decode('utf8')]
519524

520525
# default function for getting labels is getName (or use datasets / tags)
521526
if scriptParams["Image_Labels"] == "Datasets":
522527
def getDatasets(name, tagsList, pdList):
523-
return [dataset for project, dataset in pdList]
528+
return [dataset.decode('utf8') for project, dataset in pdList]
524529
getLabels = getDatasets
525530
elif scriptParams["Image_Labels"] == "Tags":
526531
def getTags(name, tagsList, pdList):
527-
return tagsList
532+
return [t.decode('utf8') for t in tagsList]
528533
getLabels = getTags
529534
else:
530535
getLabels = getImageNames
@@ -603,7 +608,7 @@ def getTags(name, tagsList, pdList):
603608
cNameMap = scriptParams["Channel_Names"]
604609
for c in cNameMap:
605610
index = int(c)
606-
channelNames[index] = cNameMap[c]
611+
channelNames[index] = cNameMap[c].decode('utf8')
607612

608613
mergedIndexes = [] # the channels in the combined image,
609614
mergedColours = {}

omero/figure_scripts/Thumbnail_Figure.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ def log(text):
6363
Adds lines of text to the logLines list, so they can be collected into a
6464
figure legend.
6565
"""
66+
try:
67+
text = text.encode('utf8')
68+
except:
69+
pass
6670
print text
6771
logLines.append(text)
6872

@@ -179,7 +183,7 @@ def paintDatasetCanvas(conn, images, title, tagIds=None, showUntagged=False,
179183
for tag in tags:
180184
tagId = tag.getId().getValue()
181185
# make a dict of tag-names
182-
tagNames[tagId] = tag.getTextValue().getValue()
186+
tagNames[tagId] = tag.getTextValue().getValue().decode('utf8')
183187
print " Tag:", tagId, tagId in tagIds
184188
imgTagIds.append(tagId)
185189
imgTags[imageId] = imgTagIds
@@ -403,8 +407,9 @@ def makeThumbnailFigure(conn, scriptParams):
403407
log("Dataset: %s ID: %d"
404408
% (dataset.getName(), dataset.getId()))
405409
images = list(dataset.listChildren())
410+
title = dataset.getName().decode('utf8')
406411
dsCanvas = paintDatasetCanvas(
407-
conn, images, dataset.getName(), tagIds, showUntagged,
412+
conn, images, title, tagIds, showUntagged,
408413
length=thumbSize, colCount=maxColumns)
409414
if dsCanvas is None:
410415
continue

omero/util_scripts/Dataset_To_Plate.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ def addImageToPlate(conn, image, plateId, column, row, removeFrom=None):
6868
# remove from Datast
6969
if removeFrom is not None:
7070
links = list(image.getParentLinks(removeFrom.id))
71-
print " Removing image from %d Dataset: %s" \
72-
% (len(links), removeFrom.name)
71+
print " Removing image from Dataset: %s" \
72+
% removeFrom.id
7373
for l in links:
7474
conn.deleteObjectDirect(l._obj)
7575
return True
@@ -86,7 +86,7 @@ def dataset_to_plate(conn, scriptParams, datasetId, screen):
8686

8787
# create Plate
8888
plate = omero.model.PlateI()
89-
plate.name = rstring(str(dataset.name))
89+
plate.name = omero.rtypes.RStringI(dataset.name)
9090
plate.columnNamingConvention = rstring(str(scriptParams["Column_Names"]))
9191
# 'letter' or 'number'
9292
plate.rowNamingConvention = rstring(str(scriptParams["Row_Names"]))
@@ -100,8 +100,8 @@ def dataset_to_plate(conn, scriptParams, datasetId, screen):
100100
else:
101101
link = None
102102

103-
print "Moving images from Dataset: %d %s to Plate: %d %s" \
104-
% (dataset.id, dataset.name, plate.id.val, plate.name.val)
103+
print "Moving images from Dataset: %d to Plate: %d" \
104+
% (dataset.id, plate.id.val)
105105

106106
row = 0
107107
col = 0
@@ -126,8 +126,8 @@ def dataset_to_plate(conn, scriptParams, datasetId, screen):
126126
removeFrom = dataset
127127

128128
for image in images:
129-
print " moving image: %d %s to row: %d, column: %d" \
130-
% (image.id, image.name, row, col)
129+
print " moving image: %d to row: %d, column: %d" \
130+
% (image.id, row, col)
131131
addedCount = addImageToPlate(conn, image, plate.id.val, col, row,
132132
removeFrom)
133133
# update row and column index

0 commit comments

Comments
 (0)