Merged PR 3543: Python 2/3 Compatible Support in Sample.
This commit is contained in:
Родитель
a07dcc0ec7
Коммит
20563fa163
|
@ -3,3 +3,4 @@ pillow
|
|||
pyflakes
|
||||
pylint
|
||||
requests
|
||||
wxpython
|
||||
|
|
|
@ -6,6 +6,7 @@ Description: util module for Python SDK sample.
|
|||
"""
|
||||
|
||||
from threading import Thread
|
||||
import io
|
||||
import operator
|
||||
import os.path
|
||||
|
||||
|
@ -51,7 +52,7 @@ class SubscriptionKey(object):
|
|||
cls.key = ''
|
||||
if not cls.key:
|
||||
if os.path.isfile(SUBSCRIPTION_KEY_FILENAME):
|
||||
with file(SUBSCRIPTION_KEY_FILENAME) as fin:
|
||||
with io.open(SUBSCRIPTION_KEY_FILENAME, encoding='utf-8') as fin:
|
||||
cls.key = fin.read().strip()
|
||||
else:
|
||||
cls.key = ''
|
||||
|
@ -62,8 +63,8 @@ class SubscriptionKey(object):
|
|||
def set(cls, key):
|
||||
"""Set the subscription key."""
|
||||
cls.key = key
|
||||
with file(SUBSCRIPTION_KEY_FILENAME, 'w') as fout:
|
||||
print >> fout, key
|
||||
with io.open(SUBSCRIPTION_KEY_FILENAME, 'w', encoding='utf-8') as fout:
|
||||
fout.write(key)
|
||||
CF.Key.set(cls.key)
|
||||
|
||||
@classmethod
|
||||
|
@ -85,7 +86,7 @@ class Endpoint(object):
|
|||
cls.endpoint = ''
|
||||
if not cls.endpoint:
|
||||
if os.path.isfile(ENDPOINT_FILENAME):
|
||||
with file(ENDPOINT_FILENAME) as fin:
|
||||
with io.open(ENDPOINT_FILENAME, encoding='utf-8') as fin:
|
||||
cls.endpoint = fin.read().strip()
|
||||
else:
|
||||
cls.endpoint = CF.BaseUrl.get()
|
||||
|
@ -96,8 +97,8 @@ class Endpoint(object):
|
|||
def set(cls, endpoint):
|
||||
"""Set the endpoint."""
|
||||
cls.endpoint = endpoint
|
||||
with file(ENDPOINT_FILENAME, 'w') as fout:
|
||||
print >> fout, endpoint
|
||||
with io.open(ENDPOINT_FILENAME, 'w', encoding='utf-8') as fout:
|
||||
fout.write(endpoint)
|
||||
CF.BaseUrl.set(cls.endpoint)
|
||||
|
||||
@classmethod
|
||||
|
@ -164,14 +165,14 @@ def draw_bitmap_rectangle(bitmap, faces):
|
|||
|
||||
def pil_image_to_wx_image(pil_image):
|
||||
"""Convert from PIL image to wx image."""
|
||||
wx_image = wx.EmptyImage(pil_image.width, pil_image.height)
|
||||
wx_image = wx.Image(pil_image.width, pil_image.height)
|
||||
wx_image.SetData(pil_image.convert("RGB").tobytes())
|
||||
return wx_image
|
||||
|
||||
|
||||
def key_with_max_value(item):
|
||||
"""Get the key with maximum value in a dict."""
|
||||
return max(item.iteritems(), key=operator.itemgetter(1))[0]
|
||||
return max(item.items(), key=operator.itemgetter(1))[0]
|
||||
|
||||
|
||||
def async(func):
|
||||
|
|
|
@ -124,7 +124,7 @@ class FindSimilarsResult(wx.Panel):
|
|||
self, label='{} Mode:'.format(mode))
|
||||
self.sizer.Add(static_text_caption, 0, wx.EXPAND)
|
||||
|
||||
for face_id, face in faces.iteritems():
|
||||
for face_id, face in faces.items():
|
||||
|
||||
static_line = wx.StaticLine(self)
|
||||
self.sizer.Add(static_line, 0, wx.EXPAND)
|
||||
|
@ -167,7 +167,7 @@ class CaptionWrapFaceList(wx.Panel):
|
|||
"""Set the data."""
|
||||
self.sizer.Clear(True)
|
||||
|
||||
for caption, faces in caption_faces_list.iteritems():
|
||||
for caption, faces in caption_faces_list.items():
|
||||
static_text = wx.StaticText(self, label=caption)
|
||||
self.sizer.Add(static_text, 0, wx.ALIGN_LEFT)
|
||||
wrap_face_list = WrapFaceList(self, faces, size)
|
||||
|
|
|
@ -110,8 +110,8 @@ class FindSimilarPanel(base.MyPanel):
|
|||
'Request: List {} will be used to build a person database. '
|
||||
'Checking whether the list exists.').format(
|
||||
self.large_face_list_id))
|
||||
print dir(util.CF)
|
||||
print util.CF.__file__
|
||||
print(dir(util.CF))
|
||||
print(util.CF.__file__)
|
||||
util.CF.large_face_list.get(self.large_face_list_id)
|
||||
large_face_list_exists = True
|
||||
self.log.log(
|
||||
|
|
|
@ -47,7 +47,7 @@ class SubscriptionPanel(MyPanel):
|
|||
subgridsizer.Add(self.subscription_key_label, flag=flag, border=5)
|
||||
|
||||
flag = wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALL
|
||||
subscription_key = util.SubscriptionKey.get().decode('utf-8')
|
||||
subscription_key = util.SubscriptionKey.get()
|
||||
self.subscription_key_text = wx.TextCtrl(self, size=(-1, -1))
|
||||
self.subscription_key_text.SetValue(subscription_key)
|
||||
subgridsizer.Add(self.subscription_key_text, 1, flag=flag, border=5)
|
||||
|
@ -58,7 +58,7 @@ class SubscriptionPanel(MyPanel):
|
|||
subgridsizer.Add(self.endpoint_label, flag=flag, border=5)
|
||||
|
||||
flag = wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALL
|
||||
endpoint = util.Endpoint.get().decode('utf-8')
|
||||
endpoint = util.Endpoint.get()
|
||||
self.endpoint_text = wx.TextCtrl(self, size=(-1, -1))
|
||||
self.endpoint_text.SetValue(endpoint)
|
||||
subgridsizer.Add(self.endpoint_text, 1, flag=flag, border=5)
|
||||
|
@ -86,8 +86,8 @@ class SubscriptionPanel(MyPanel):
|
|||
def OnSave(self, evt):
|
||||
"""Save the key and endpoint."""
|
||||
util.SubscriptionKey.set(
|
||||
self.subscription_key_text.GetValue().encode('utf-8'))
|
||||
util.Endpoint.set(self.endpoint_text.GetValue().encode('utf-8'))
|
||||
self.subscription_key_text.GetValue())
|
||||
util.Endpoint.set(self.endpoint_text.GetValue())
|
||||
text = (
|
||||
'Settings successfully saved on your disk.\nYou do not need to '
|
||||
'paste the key next time.')
|
||||
|
|
Загрузка…
Ссылка в новой задаче