Skip to content
This repository was archived by the owner on Nov 8, 2021. It is now read-only.

Commit 20563fa

Browse files
Sean Huhuxuan
Sean Hu
authored andcommitted
Merged PR 3543: Python 2/3 Compatible Support in Sample.
1 parent a07dcc0 commit 20563fa

File tree

5 files changed

+18
-16
lines changed

5 files changed

+18
-16
lines changed

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ pillow
33
pyflakes
44
pylint
55
requests
6+
wxpython

sample/util.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77

88
from threading import Thread
9+
import io
910
import operator
1011
import os.path
1112

@@ -51,7 +52,7 @@ def get(cls):
5152
cls.key = ''
5253
if not cls.key:
5354
if os.path.isfile(SUBSCRIPTION_KEY_FILENAME):
54-
with file(SUBSCRIPTION_KEY_FILENAME) as fin:
55+
with io.open(SUBSCRIPTION_KEY_FILENAME, encoding='utf-8') as fin:
5556
cls.key = fin.read().strip()
5657
else:
5758
cls.key = ''
@@ -62,8 +63,8 @@ def get(cls):
6263
def set(cls, key):
6364
"""Set the subscription key."""
6465
cls.key = key
65-
with file(SUBSCRIPTION_KEY_FILENAME, 'w') as fout:
66-
print >> fout, key
66+
with io.open(SUBSCRIPTION_KEY_FILENAME, 'w', encoding='utf-8') as fout:
67+
fout.write(key)
6768
CF.Key.set(cls.key)
6869

6970
@classmethod
@@ -85,7 +86,7 @@ def get(cls):
8586
cls.endpoint = ''
8687
if not cls.endpoint:
8788
if os.path.isfile(ENDPOINT_FILENAME):
88-
with file(ENDPOINT_FILENAME) as fin:
89+
with io.open(ENDPOINT_FILENAME, encoding='utf-8') as fin:
8990
cls.endpoint = fin.read().strip()
9091
else:
9192
cls.endpoint = CF.BaseUrl.get()
@@ -96,8 +97,8 @@ def get(cls):
9697
def set(cls, endpoint):
9798
"""Set the endpoint."""
9899
cls.endpoint = endpoint
99-
with file(ENDPOINT_FILENAME, 'w') as fout:
100-
print >> fout, endpoint
100+
with io.open(ENDPOINT_FILENAME, 'w', encoding='utf-8') as fout:
101+
fout.write(endpoint)
101102
CF.BaseUrl.set(cls.endpoint)
102103

103104
@classmethod
@@ -164,14 +165,14 @@ def draw_bitmap_rectangle(bitmap, faces):
164165

165166
def pil_image_to_wx_image(pil_image):
166167
"""Convert from PIL image to wx image."""
167-
wx_image = wx.EmptyImage(pil_image.width, pil_image.height)
168+
wx_image = wx.Image(pil_image.width, pil_image.height)
168169
wx_image.SetData(pil_image.convert("RGB").tobytes())
169170
return wx_image
170171

171172

172173
def key_with_max_value(item):
173174
"""Get the key with maximum value in a dict."""
174-
return max(item.iteritems(), key=operator.itemgetter(1))[0]
175+
return max(item.items(), key=operator.itemgetter(1))[0]
175176

176177

177178
def async(func):

sample/view/base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def set_data(self, faces, res_tot, size=util.MAX_THUMBNAIL_SIZE):
124124
self, label='{} Mode:'.format(mode))
125125
self.sizer.Add(static_text_caption, 0, wx.EXPAND)
126126

127-
for face_id, face in faces.iteritems():
127+
for face_id, face in faces.items():
128128

129129
static_line = wx.StaticLine(self)
130130
self.sizer.Add(static_line, 0, wx.EXPAND)
@@ -167,7 +167,7 @@ def set_data(self, caption_faces_list, size=util.MAX_THUMBNAIL_SIZE):
167167
"""Set the data."""
168168
self.sizer.Clear(True)
169169

170-
for caption, faces in caption_faces_list.iteritems():
170+
for caption, faces in caption_faces_list.items():
171171
static_text = wx.StaticText(self, label=caption)
172172
self.sizer.Add(static_text, 0, wx.ALIGN_LEFT)
173173
wrap_face_list = WrapFaceList(self, faces, size)

sample/view/panel_find_similar.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ def OnChooseFolder(self, evt):
110110
'Request: List {} will be used to build a person database. '
111111
'Checking whether the list exists.').format(
112112
self.large_face_list_id))
113-
print dir(util.CF)
114-
print util.CF.__file__
113+
print(dir(util.CF))
114+
print(util.CF.__file__)
115115
util.CF.large_face_list.get(self.large_face_list_id)
116116
large_face_list_exists = True
117117
self.log.log(

sample/view/panel_subscription.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def __init__(self, parent):
4747
subgridsizer.Add(self.subscription_key_label, flag=flag, border=5)
4848

4949
flag = wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALL
50-
subscription_key = util.SubscriptionKey.get().decode('utf-8')
50+
subscription_key = util.SubscriptionKey.get()
5151
self.subscription_key_text = wx.TextCtrl(self, size=(-1, -1))
5252
self.subscription_key_text.SetValue(subscription_key)
5353
subgridsizer.Add(self.subscription_key_text, 1, flag=flag, border=5)
@@ -58,7 +58,7 @@ def __init__(self, parent):
5858
subgridsizer.Add(self.endpoint_label, flag=flag, border=5)
5959

6060
flag = wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALL
61-
endpoint = util.Endpoint.get().decode('utf-8')
61+
endpoint = util.Endpoint.get()
6262
self.endpoint_text = wx.TextCtrl(self, size=(-1, -1))
6363
self.endpoint_text.SetValue(endpoint)
6464
subgridsizer.Add(self.endpoint_text, 1, flag=flag, border=5)
@@ -86,8 +86,8 @@ def __init__(self, parent):
8686
def OnSave(self, evt):
8787
"""Save the key and endpoint."""
8888
util.SubscriptionKey.set(
89-
self.subscription_key_text.GetValue().encode('utf-8'))
90-
util.Endpoint.set(self.endpoint_text.GetValue().encode('utf-8'))
89+
self.subscription_key_text.GetValue())
90+
util.Endpoint.set(self.endpoint_text.GetValue())
9191
text = (
9292
'Settings successfully saved on your disk.\nYou do not need to '
9393
'paste the key next time.')

0 commit comments

Comments
 (0)