Skip to content

Commit dfe38ce

Browse files
authored
fix list print issue for non str type (AtsushiSakai#30)
* fix style issue. * fix list print issue for non str type.
1 parent 878065a commit dfe38ce

File tree

2 files changed

+40
-20
lines changed

2 files changed

+40
-20
lines changed

pyjsonviewer/pyjsonviewer.py

+37-19
Original file line numberDiff line numberDiff line change
@@ -102,47 +102,59 @@ def insert_node(self, parent, key, value):
102102
if type(value) is not dict:
103103
if type(value) is list:
104104
value = value[0:MAX_N_SHOW_ITEM]
105-
value = "["+",".join(value)+"]"
105+
value = "[" + ",".join(map(str, value)) + "]"
106106
self.tree.insert(node, 'end', text=value, open=False)
107107
else:
108108
for (key, value) in value.items():
109109
self.insert_node(node, key, value)
110110

111-
def click_item(self, _):
111+
def click_item(self, event=None):
112112
"""
113113
Callback function when an item is clicked
114114
115-
:param _: event arg (not used)
115+
:param event: event arg (not used)
116116
"""
117117
item_id = self.tree.selection()
118118
item_text = self.tree.item(item_id, 'text')
119119

120120
if self.is_url(item_text):
121121
webbrowser.open(item_text)
122122

123-
def select_json_file(self, _):
124-
#:param _: event arg (not used)
123+
def select_json_file(self, event=None):
124+
"""
125+
:param event: event arg (not used)
126+
"""
125127
file_path = filedialog.askopenfilename(
126128
initialdir=self.initial_dir,
127129
filetypes=FILETYPES)
128130
self.set_table_data_from_json(file_path)
129131

130-
def expand_all(self, _):
131-
#:param _: event arg (not used)
132+
def expand_all(self, event=None):
133+
"""
134+
:param event: event arg (not used)
135+
"""
132136
for item in self.get_all_children(self.tree):
133137
self.tree.item(item, open=True)
134138

135-
def collapse_all(self, _):
136-
#:param _: event arg (not used)
139+
def collapse_all(self, event=None):
140+
"""
141+
:param event: event arg (not used)
142+
"""
137143
for item in self.get_all_children(self.tree):
138144
self.tree.item(item, open=False)
139145

140-
def find_window(self):
146+
def find_window(self, event=None):
147+
"""
148+
:param event: event arg (not used)
149+
"""
141150
self.search_box = tk.Entry(self.master)
142151
self.search_box.pack()
143152
self.search_box.bind('<Key>', self.find_word)
144153

145-
def find_word(self, _):
154+
def find_word(self, event=None):
155+
"""
156+
:param event: event arg (not used)
157+
"""
146158
search_text = self.search_box.get()
147159
self.find(search_text)
148160

@@ -161,15 +173,20 @@ def get_all_children(self, tree, item=""):
161173
children += self.get_all_children(tree, child)
162174
return children
163175

164-
def select_listbox_item(self, evt):
165-
w = evt.widget
176+
def select_listbox_item(self, event):
177+
"""
178+
:param event: event arg (not used)
179+
"""
180+
w = event.widget
166181
index = int(w.curselection()[0])
167182
value = w.get(index)
168183
self.set_table_data_from_json(value)
169184
self.sub_win.destroy() # close window
170185

171-
def select_json_file_from_history(self, _):
172-
#:param _: event arg (not used)
186+
def select_json_file_from_history(self, event=None):
187+
"""
188+
:param event: event arg (not used)
189+
"""
173190
self.sub_win = tk.Toplevel()
174191
lb = self.Listbox(self.sub_win)
175192
with open(HISTORY_FILE_PATH) as f:
@@ -309,10 +326,11 @@ def main():
309326
app.init_search_box()
310327

311328
root.config(menu=menubar)
312-
root.bind_all("<Control-o>",app.select_json_file)
313-
root.bind_all("<Control-h>",app.select_json_file_from_history)
314-
root.bind_all("<Control-e>",app.expand_all)
315-
root.bind_all("<Control-l>",app.collapse_all)
329+
root.bind_all("<Control-o>", lambda e: app.select_json_file(event=e))
330+
root.bind_all("<Control-h>",
331+
lambda e: app.select_json_file_from_history(event=e))
332+
root.bind_all("<Control-e>", lambda e: app.expand_all(event=e))
333+
root.bind_all("<Control-l>", lambda e: app.collapse_all(event=e))
316334

317335
root.mainloop()
318336

sample.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
"Abbrev": "ISO 8879:1986",
1313
"GlossDef": {
1414
"para": "A meta-markup language, used to create markup languages such as DocBook.",
15-
"GlossSeeAlso": ["GML", "XML", "TOML", "YAML"]
15+
"GlossSeeAlso": ["GML", "XML", "TOML", "YAML"],
16+
"GlossSeeAlso2": [1, 2, 3, 4],
17+
"GlossSeeAlso3": ["5", 2.3, "3", null, true]
1618
},
1719
"GlossSee": "マークアップ"
1820
}

0 commit comments

Comments
 (0)