本文整理汇总了Python中View.View.read_json方法的典型用法代码示例。如果您正苦于以下问题:Python View.read_json方法的具体用法?Python View.read_json怎么用?Python View.read_json使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类View.View
的用法示例。
在下文中一共展示了View.read_json方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: FormCreator
# 需要导入模块: from View import View [as 别名]
# 或者: from View.View import read_json [as 别名]
#.........这里部分代码省略.........
def on_print(self, event):
"""Print button for debugging"""
event.Skip()
if self.view is not None:
for r in self.view.rects:
print("{0} : {1} - {2}".format(r.idtag, r.typerect, r.data))
def on_open(self, event):
"""
Open up an image and load it to the canvas
"""
event.Skip()
dirname = ""
dlg = wx.FileDialog(self, "Choose a file", dirname, "", "*.*", wx.OPEN)
if dlg.ShowModal() == wx.ID_OK:
self.filename = dlg.GetFilename()
dirname = dlg.GetDirectory()
self.img = join(dirname, self.filename)
self.view.image = wx.Bitmap(self.img, type=wx.BITMAP_TYPE_ANY)
self.view.rects = []
self.view.Refresh() # trigger onpaint
self.SetTitle("Form Creator : " + self.img)
# Read for an RMAP file
fname = self.filename.split(".")
fname.pop()
rmap_file = join(dirname, ".".join(fname + ["rmap"]))
if isfile(rmap_file):
# the file is here!
with open(rmap_file, "r") as f:
rmap_rects = loads(f.read())
self.view.read_json(rmap_rects)
self.rmap_loaded = True
self.SetStatusText(Preferences.RmapFound)
else:
self.SetStatusText(Preferences.noRmapFound)
self.rmap_loaded = False
dlg.Destroy()
def export_print_page(self, event):
"""Export a print page using a JSON file"""
event.Skip()
if self.view.image is not None:
# We don't require an RMAP file, just rect data that we can generate
dlg = wx.FileDialog(self, "Choose a JSON file to load", "", "", "", wx.SAVE)
if dlg.ShowModal() == wx.ID_OK:
filename = dlg.GetFilename()
dirname = dlg.GetDirectory()
dlg.Destroy()
else:
self.SetStatusText(Preferences.failedToOpen)
return False
rmap_data = self.view.rects
try:
with open(join(dirname, filename), "r") as f:
json_data = loads(f.read())
except Exception as e:
self.SetStatusText(Preferences.failedToExport)
return False
fd = self.img.split(".")
fd.pop()
fname = ".".join(fd)
rmap_data = View.filter_list(rmap_data)
rmap_data = View.clean_list(rmap_data)