| 1 |
#!/usr/bin/python3 |
| 2 |
import os |
| 3 |
import sys |
| 4 |
import yaml |
| 5 |
import logging |
| 6 |
import conf2Utils |
| 7 |
import tkinter as tk |
| 8 |
import tkinter.ttk as ttk |
| 9 |
import tkinter.messagebox as msgbox |
| 10 |
import tkinter.filedialog as filedialog |
| 11 |
import tkinter.simpledialog as simpledialog |
| 12 |
import dbus |
| 13 |
from gi.repository import GLib |
| 14 |
|
| 15 |
target_view = {} |
| 16 |
|
| 17 |
def on_tree_right_click(event): |
| 18 |
global right_select_item |
| 19 |
item = tree.identify_row(event.y) |
| 20 |
if item and tree.parent(item) == "": |
| 21 |
right_select_item = item |
| 22 |
download_menu.post(event.x_root, event.y_root) |
| 23 |
|
| 24 |
def close_menu(event): |
| 25 |
download_menu.unpost() |
| 26 |
|
| 27 |
def on_search(): |
| 28 |
text = search_button.cget('text') |
| 29 |
if text == 'search': |
| 30 |
search_button.config(text='cancel') |
| 31 |
view_frame.pack_forget() |
| 32 |
search_frame.pack(side='bottom', fill='both', expand=True) |
| 33 |
search_tree.delete(*search_tree.get_children()) |
| 34 |
search_entry.config(state='normal') |
| 35 |
# search_entry.event_generate("<KeyRelease>") |
| 36 |
elif text == 'cancel': |
| 37 |
search_button.config(text='search') |
| 38 |
search_frame.pack_forget() |
| 39 |
view_frame.pack(side='bottom', fill='both', expand=True) |
| 40 |
items = tree.selection() |
| 41 |
if items: |
| 42 |
text = tree.item(items[0], 'tags')[0] |
| 43 |
search_entry.delete(0, 'end') |
| 44 |
search_entry.insert(0, text) |
| 45 |
else: |
| 46 |
search_entry.delete(0, 'end') |
| 47 |
search_entry.config(state='readonly') |
| 48 |
|
| 49 |
def on_search_entry_change(event): |
| 50 |
new_text = event.widget.get() |
| 51 |
search_tree.delete(*search_tree.get_children()) |
| 52 |
if new_text == '': |
| 53 |
return |
| 54 |
for key in search_list.keys(): |
| 55 |
name_list = key.split('/') |
| 56 |
if new_text in name_list[-1] or key.startswith(new_text): |
| 57 |
search_tree.insert('', 'end', text= key) |
| 58 |
|
| 59 |
def on_download(): |
| 60 |
class MultiSelectDialog(tk.simpledialog.Dialog): |
| 61 |
def body(self, master): |
| 62 |
self.results = [] |
| 63 |
self.options = list(target_view.keys()) |
| 64 |
self.vars = [] |
| 65 |
for i, option in enumerate(self.options): |
| 66 |
var = tk.IntVar() |
| 67 |
checkbutton = tk.Checkbutton(master, text=option, variable=var) |
| 68 |
checkbutton.grid(row=i, sticky='w') |
| 69 |
self.vars.append(var) |
| 70 |
|
| 71 |
select_all_button = tk.Button(master, text="全选", command=self.all_select) |
| 72 |
select_all_button.grid(row=len(self.options), column=0, sticky='w') |
| 73 |
|
| 74 |
select_none_button = tk.Button(master, text="全不选", command=self.none_select) |
| 75 |
select_none_button.grid(row=len(self.options), column=1, sticky='w') |
| 76 |
|
| 77 |
def apply(self): |
| 78 |
self.results = [option for var, option in zip(self.vars, self.options) if var.get() == 1] |
| 79 |
|
| 80 |
def all_select(self): |
| 81 |
for var in self.vars: |
| 82 |
var.set(1) |
| 83 |
|
| 84 |
def none_select(self): |
| 85 |
for var in self.vars: |
| 86 |
var.set(0) |
| 87 |
|
| 88 |
global target_view |
| 89 |
dialog = MultiSelectDialog(root, title="Multi-Select Dialog") |
| 90 |
if dialog.results != []: |
| 91 |
path = filedialog.askdirectory(mustexist=True, title=' Choose a folder') |
| 92 |
if path: |
| 93 |
try: |
| 94 |
converter._value_override_default(target_view) |
| 95 |
for app in dialog.results: |
| 96 |
yaml_file_path = f'{path}/{app}.yaml' |
| 97 |
if os.path.exists(yaml_file_path): |
| 98 |
msgbox.askyesno(message=f'{yaml_file_path} is existed. Do you want to replace it') |
| 99 |
else: |
| 100 |
with open(yaml_file_path, 'w') as yaml_file: |
| 101 |
yaml_file.write(yaml.safe_dump({app:target_view[app]}, allow_unicode = True)) |
| 102 |
msgbox.showinfo(message='Save successed') |
| 103 |
except Exception as e: |
| 104 |
msgbox.showinfo(message='Save failed') |
| 105 |
|
| 106 |
def on_download_one(): |
| 107 |
global target_view |
| 108 |
app = tree.item(right_select_item, 'text') |
| 109 |
apps = [] |
| 110 |
apps.append(app) |
| 111 |
path = filedialog.askdirectory(mustexist=True, title=' Choose a folder') |
| 112 |
if path: |
| 113 |
success = converter.editor_save(apps, target_view, path) |
| 114 |
if success: |
| 115 |
msgbox.showinfo(message='Save successed') |
| 116 |
else: |
| 117 |
msgbox.showinfo(message='Save failed') |
| 118 |
|
| 119 |
def on_import_file(): |
| 120 |
pass |
| 121 |
|
| 122 |
def on_set(): |
| 123 |
try: |
| 124 |
if combobox.get() != 'custom': |
| 125 |
msgbox.showinfo(message='Not custom veiw') |
| 126 |
|
| 127 |
user = destination_file.split('/')[2] |
| 128 |
|
| 129 |
key = id = value = permission = type = range = '' |
| 130 |
for widget in inner_frame.winfo_children(): |
| 131 |
if isinstance(widget, tk.Text): |
| 132 |
if 'key' == widget.winfo_name(): |
| 133 |
key = widget.get(1.0, 'end') |
| 134 |
key = key.strip() |
| 135 |
if 'id' == widget.winfo_name(): |
| 136 |
id = widget.get(1.0, 'end') |
| 137 |
id = id.strip() |
| 138 |
if 'type' == widget.winfo_name(): |
| 139 |
type = widget.get(1.0, 'end') |
| 140 |
type = type.strip() |
| 141 |
if 'permission' == widget.winfo_name(): |
| 142 |
permission = widget.get(1.0, 'end') |
| 143 |
permission = permission.strip() |
| 144 |
if 'range' == widget.winfo_name(): |
| 145 |
range = widget.get(1.0, 'end') |
| 146 |
range = range.strip() |
| 147 |
if 'custom' == widget.winfo_name(): |
| 148 |
value = widget.get(1.0, 'end') |
| 149 |
value = value.strip() |
| 150 |
|
| 151 |
path = search_entry.get() |
| 152 |
version = path.split('/')[1] |
| 153 |
|
| 154 |
# 类型检测 |
| 155 |
try: |
| 156 |
if type != 'enum': |
| 157 |
variant_type = GLib.VariantType(type) |
| 158 |
variant = GLib.Variant.parse(variant_type, value) |
| 159 |
except Exception as e: |
| 160 |
msgbox.showinfo('unknown keyword') |
| 161 |
return |
| 162 |
|
| 163 |
# 取值范围检测 |
| 164 |
if type == 'enum' and value not in range: |
| 165 |
msgbox.showinfo(message='Out of range') |
| 166 |
return |
| 167 |
elif type != 'enum' and range != '': |
| 168 |
try: |
| 169 |
min = GLib.Variant.parse(variant_type, range.split(',')[0].strip()) |
| 170 |
max = GLib.Variant.parse(variant_type, range.split(',')[1].strip()) |
| 171 |
if variant.compare(min) < 0 or variant.compare(max) > 0: |
| 172 |
msgbox.showinfo(message='Out of range') |
| 173 |
return |
| 174 |
except Exception as e: |
| 175 |
msgbox.showinfo(message=e) |
| 176 |
return |
| 177 |
|
| 178 |
bus = dbus.SystemBus() |
| 179 |
obj = bus.get_object('com.kylin.kysdk.conf2', '/com/kylin/kysdk/conf2') |
| 180 |
obj_interface = dbus.Interface(obj, dbus_interface='com.kylin.kysdk.conf2') |
| 181 |
success = obj_interface.set(user, id, version, key, value) |
| 182 |
if success: |
| 183 |
global target_view |
| 184 |
target_view = sqlhelper.db2dict(f'{destination_file}/.config/kylin-config/user.db') |
| 185 |
msgbox.showinfo(message='Set successed') |
| 186 |
else: |
| 187 |
msgbox.showinfo(message='Set failed') |
| 188 |
except Exception as e: |
| 189 |
print(e) |
| 190 |
|
| 191 |
def on_search_tree_select(event): |
| 192 |
items = search_tree.selection() |
| 193 |
text = search_tree.item(items, 'text') |
| 194 |
if text == '': |
| 195 |
return |
| 196 |
tree.selection_set(search_list[text]) |
| 197 |
tree.see(search_list[text]) |
| 198 |
search_frame.pack_forget() |
| 199 |
view_frame.pack(side='bottom', fill='both', expand=True) |
| 200 |
search_button_text = search_button.cget('text') |
| 201 |
if search_button_text == 'cancel': |
| 202 |
search_button.config(text='search') |
| 203 |
|
| 204 |
def on_tree_select(event): |
| 205 |
selected_item = tree.selection() |
| 206 |
global target_view |
| 207 |
if not selected_item: |
| 208 |
return |
| 209 |
item = selected_item[0] |
| 210 |
tag = tree.item(item, 'tags')[0] |
| 211 |
|
| 212 |
search_entry.config(state='normal') |
| 213 |
search_entry.delete(0, 'end') |
| 214 |
search_entry.insert(0, tag) |
| 215 |
search_entry.config(state='readonly') |
| 216 |
|
| 217 |
if tree.parent(item) == '': |
| 218 |
return |
| 219 |
|
| 220 |
group_list = tag.split('/') |
| 221 |
tmp = target_view |
| 222 |
for group in group_list: |
| 223 |
tmp = tmp[group] |
| 224 |
for widget in inner_frame.winfo_children(): |
| 225 |
widget.destroy() |
| 226 |
|
| 227 |
text = tree.item(item, 'text') |
| 228 |
|
| 229 |
name_label = tk.Label(inner_frame, text=f'名称', anchor='w') |
| 230 |
name_label.pack(side='top', fill='x') |
| 231 |
|
| 232 |
name_text = tk.Text(inner_frame, height=1, width=100, wrap='word', name='key') |
| 233 |
name_text.insert('1.0', text) |
| 234 |
name_text.config(state='disabled') |
| 235 |
name_text.pack(side='top', fill='x', expand=True) |
| 236 |
|
| 237 |
type = tmp['_type'] if '_type' in tmp else 'group' |
| 238 |
|
| 239 |
if len(group_list) > 1: |
| 240 |
group_list.pop(1) |
| 241 |
if type != 'group': |
| 242 |
group_list.pop(-1) |
| 243 |
|
| 244 |
id_label = tk.Label(inner_frame, text=f'路径', anchor='w') |
| 245 |
id_label.pack(side='top', fill='x') |
| 246 |
|
| 247 |
id_text = tk.Text(inner_frame, height=1, width=100, wrap='word', name='id') |
| 248 |
id_text.insert('1.0', '.'.join(group_list)) |
| 249 |
id_text.config(state='disabled') |
| 250 |
id_text.pack(side='top', fill='x', expand=True) |
| 251 |
|
| 252 |
type_label = tk.Label(inner_frame, text=f'类型', anchor='w') |
| 253 |
type_label.pack(side='top', fill='x') |
| 254 |
|
| 255 |
type_text = tk.Text(inner_frame, height=1, width=100, wrap='word', name='type') |
| 256 |
type_text.insert('1.0', type) |
| 257 |
type_text.config(state='disabled') |
| 258 |
type_text.pack(side='top', fill='x', expand=True) |
| 259 |
|
| 260 |
if tmp.get('_summary') is not None: |
| 261 |
summary_label = tk.Label(inner_frame, text=f'摘要', anchor='w') |
| 262 |
summary_label.pack(side='top', fill='x') |
| 263 |
|
| 264 |
summary_text = tk.Text(inner_frame, height=3, width=100, wrap='word', name='summary') |
| 265 |
summary_text.insert('1.0', tmp.get('_summary')) |
| 266 |
summary_text.config(state='disabled') |
| 267 |
summary_text.pack(side='top', fill='x', expand=True) |
| 268 |
|
| 269 |
if tmp.get('_description') is not None: |
| 270 |
decription_label = tk.Label(inner_frame, text=f'描述', anchor='w') |
| 271 |
decription_label.pack(side='top', fill='x') |
| 272 |
|
| 273 |
decription_text = tk.Text(inner_frame, height=3, width=100, wrap='word' ,name='description') |
| 274 |
decription_text.insert('1.0', tmp.get('_description')) |
| 275 |
decription_text.config(state='disabled') |
| 276 |
decription_text.pack(side='top', fill='x', expand=True) |
| 277 |
|
| 278 |
permission = tmp.get('_permission', 'public') |
| 279 |
permission_label = tk.Label(inner_frame, text=f'权限', anchor='w') |
| 280 |
permission_label.pack(side='top', fill='x') |
| 281 |
|
| 282 |
permission_text = tk.Text(inner_frame, height=1, width=100, wrap='word', name='permission') |
| 283 |
permission_text.insert('1.0', permission) |
| 284 |
permission_text.config(state='disabled') |
| 285 |
permission_text.pack(side='top', fill='x', expand=True) |
| 286 |
|
| 287 |
if tmp.get('_range') is not None: |
| 288 |
decription_label = tk.Label(inner_frame, text=f'取值范围', anchor='w') |
| 289 |
decription_label.pack(side='top', fill='x') |
| 290 |
range = tmp.get('_range') |
| 291 |
if tmp.get('_type') == 'enum': |
| 292 |
if range.startswith('@'): |
| 293 |
path = search_entry.get() |
| 294 |
version_data = target_view[path.split('/')[0]][path.split('/')[1]] |
| 295 |
# _开头的应该是内部函数仅在类内部使用,但我实在懒得搬代码了 |
| 296 |
element_list = sqlhelper._recursive_search(version_data, range[1:]) |
| 297 |
value_list = [] |
| 298 |
for element in element_list: |
| 299 |
value_list.append(element['_nick']) |
| 300 |
range = str(value_list) |
| 301 |
else: |
| 302 |
data = yaml.safe_load(range) |
| 303 |
range = str(list(data.keys())) |
| 304 |
decription_text = tk.Text(inner_frame, height=3, width=100, wrap='word' ,name='range') |
| 305 |
decription_text.insert('1.0', range) |
| 306 |
decription_text.config(state='disabled') |
| 307 |
decription_text.pack(side='top', fill='x', expand=True) |
| 308 |
|
| 309 |
if '_default' in tmp: |
| 310 |
default_value = tmp['_default'] |
| 311 |
if isinstance(default_value, bool): |
| 312 |
default_value = 'true' if tmp['_default'] else 'false' |
| 313 |
|
| 314 |
default_label = tk.Label(inner_frame, text=f'默认值', anchor='w') |
| 315 |
default_label.pack(side='top', fill='x') |
| 316 |
|
| 317 |
default_text = tk.Text(inner_frame, height=5, width=100, wrap='word', name='default') |
| 318 |
default_text.insert('1.0', tmp['_default']) |
| 319 |
default_text.config(state='disabled') |
| 320 |
default_text.pack(side='top', fill='x', expand=True) |
| 321 |
|
| 322 |
if combobox.get() == 'custom': |
| 323 |
custom_value = tmp.get('_value') |
| 324 |
if custom_value is None: |
| 325 |
custom_value = '默认值' |
| 326 |
custom_label = tk.Label(inner_frame, text=f'当前值', anchor='w') |
| 327 |
custom_label.pack(side='top', fill='x') |
| 328 |
|
| 329 |
custom_text = tk.Text(inner_frame, height=5, width=100, wrap='word', name='custom') |
| 330 |
custom_text.insert('1.0', custom_value) |
| 331 |
custom_text.config(state='disabled') |
| 332 |
custom_text.pack(side='top', fill='x', expand=True) |
| 333 |
|
| 334 |
if type != 'group' and permission == 'public' and combobox.get() == 'custom': |
| 335 |
custom_text.config(state='normal') |
| 336 |
set_button = tk.Button(inner_frame, text='Set', command=on_set) |
| 337 |
set_button.pack(side='top') |
| 338 |
|
| 339 |
def on_combobox_select(event): |
| 340 |
selected_item = combobox.get() |
| 341 |
global target_view |
| 342 |
if selected_item == 'custom': |
| 343 |
target_view = sqlhelper.db2dict(f'{destination_file}/.config/kylin-config/user.db') |
| 344 |
else: |
| 345 |
dirs = [] |
| 346 |
for dir in list(reversed(options)): |
| 347 |
if dir == 'user': |
| 348 |
dirs.append(f'{destination_file}/.config/kylin-config/configs') |
| 349 |
else: |
| 350 |
dirs.append(f'/etc/kylin-config/{dir}') |
| 351 |
if dir == selected_item: |
| 352 |
break |
| 353 |
tmp = dirs.copy() |
| 354 |
target_view = yamlhelper.read_yaml_dirs(tmp) |
| 355 |
|
| 356 |
tree.delete(*tree.get_children()) |
| 357 |
for widget in inner_frame.winfo_children(): |
| 358 |
widget.destroy() |
| 359 |
search_list.clear() |
| 360 |
populate_tree(tree, '', target_view) |
| 361 |
view_frame.update() |
| 362 |
|
| 363 |
def populate_tree(tree, node, dictionary): |
| 364 |
global search_list |
| 365 |
tag = tree.item(node, 'tags') |
| 366 |
for key, value in dictionary.items(): |
| 367 |
if isinstance(value, dict): |
| 368 |
child_node = tree.insert(node, 'end', text=key) |
| 369 |
if isinstance(tag, str): |
| 370 |
tree.item(child_node, tags=(key)) |
| 371 |
else: |
| 372 |
tree.item(child_node, tags=(f'{tag[0]}/{key}')) |
| 373 |
search_list[f'{tag[0]}/{key}'] = child_node |
| 374 |
populate_tree(tree, child_node, value) |
| 375 |
|
| 376 |
root = tk.Tk() |
| 377 |
root.title("kconf2-editor") |
| 378 |
root.geometry('1024x768') |
| 379 |
root.bind("<Button-1>", close_menu) |
| 380 |
|
| 381 |
download_menu = tk.Menu(root, tearoff=0) |
| 382 |
download_menu.add_command(label="下载", command=on_download_one) |
| 383 |
# download_menu.add_command(label="导入到其他目录", command=on_import_file) |
| 384 |
|
| 385 |
search_list = {} |
| 386 |
|
| 387 |
destination_file = os.getenv('HOME') |
| 388 |
logger = logging.getLogger(f'{destination_file}/.log/widget.log') |
| 389 |
converter = conf2Utils.converter(logger) |
| 390 |
sqlhelper = conf2Utils.sqlHelper(logger) |
| 391 |
yamlhelper = conf2Utils.yamlHelper(logger) |
| 392 |
|
| 393 |
# 读取统一视图 |
| 394 |
target_view = sqlhelper.db2dict(f'{destination_file}/.config/kylin-config/user.db') |
| 395 |
|
| 396 |
# 创建一个Frame来包含按钮,使其一直位于界面上方 |
| 397 |
button_frame = tk.Frame(root, height=10) |
| 398 |
# 创建一个Frame来包含Treeview,占满界面其他空余部分 |
| 399 |
view_frame = tk.Frame(root) |
| 400 |
# 创建一个Frame来显示搜索结果,它与view_frame只会显示一个 |
| 401 |
search_frame = tk.Frame(root) |
| 402 |
|
| 403 |
# 排列root的三个子组件 |
| 404 |
button_frame.pack(side="top", fill="x") |
| 405 |
view_frame.pack(side='top', fill='both', expand=True) |
| 406 |
|
| 407 |
# 搜索栏 |
| 408 |
search_entry = tk.Entry(button_frame, state='readonly') |
| 409 |
search_entry.bind("<KeyRelease>", on_search_entry_change) |
| 410 |
|
| 411 |
# 搜索按钮 |
| 412 |
# search_icon = tk.PhotoImage('/etc/kylin-config/search.png') |
| 413 |
search_button = tk.Button(button_frame, text='search', command=on_search, width=20) |
| 414 |
|
| 415 |
# 下载按钮 |
| 416 |
# download_icon = tk.PhotoImage(file="/etc/kylin-config/download.png") |
| 417 |
download_button = tk.Button(button_frame, text='export', command=on_download, width=20) |
| 418 |
|
| 419 |
# 视图选择列表 |
| 420 |
with open('/etc/kylin-config/conf2.yaml', 'r') as file: |
| 421 |
configures = yaml.safe_load(file) |
| 422 |
options = configures['dirs'] |
| 423 |
if os.path.exists(f'{destination_file}/.config/kylin-config/configs'): |
| 424 |
options.append('mutable') |
| 425 |
options.append('custom') |
| 426 |
options.reverse() |
| 427 |
|
| 428 |
combobox = ttk.Combobox(button_frame, values=options, width=20, state='readonly') |
| 429 |
combobox.set(options[0]) |
| 430 |
combobox.bind("<<ComboboxSelected>>", on_combobox_select) |
| 431 |
|
| 432 |
# 排列button_frame子组件 |
| 433 |
search_entry.pack(side="left", fill="both", expand= True) |
| 434 |
combobox.pack(side='right') |
| 435 |
download_button.pack(side="right", fill="x") |
| 436 |
search_button.pack(side="right", fill="x") |
| 437 |
|
| 438 |
# 创建Frame在view_frame的左侧,显示配置树 |
| 439 |
left_frame = tk.Frame(view_frame) |
| 440 |
left_frame.pack(side='left', fill='both') |
| 441 |
|
| 442 |
# 创建Treeview,显示配置树 |
| 443 |
tree = ttk.Treeview(left_frame) |
| 444 |
tree.column('#0', width=200, stretch=True) |
| 445 |
tree.heading('#0', text='SubFolders') |
| 446 |
tree.bind("<<TreeviewSelect>>", on_tree_select) |
| 447 |
tree.bind("<Button-3>", on_tree_right_click) |
| 448 |
search_list.clear() |
| 449 |
populate_tree(tree, '', target_view) |
| 450 |
tree.pack(side='left', fill='both') |
| 451 |
|
| 452 |
# 创建滚动条 |
| 453 |
tree_scrollbar = ttk.Scrollbar(left_frame, orient="vertical", command=tree.yview) |
| 454 |
tree_scrollbar.pack(side="right", fill="y") |
| 455 |
tree.configure(yscrollcommand=tree_scrollbar.set) |
| 456 |
|
| 457 |
# 创建Frame在view_frame的右侧,显示配置信息 |
| 458 |
right_frame = tk.Frame(view_frame) |
| 459 |
right_frame.pack(side='right', fill='both', expand=True) |
| 460 |
|
| 461 |
# 创建一个Canvas |
| 462 |
canvas = tk.Canvas(right_frame) |
| 463 |
canvas.pack(side="left", fill="both", expand=True) |
| 464 |
canvas.config(scrollregion=canvas.bbox("all")) |
| 465 |
|
| 466 |
right_scrollbar = ttk.Scrollbar(right_frame, orient="vertical", command=canvas.yview) |
| 467 |
right_scrollbar.pack(side="right", fill="y") |
| 468 |
canvas.configure(yscrollcommand=right_scrollbar.set) |
| 469 |
|
| 470 |
# 将Canvas的窗口设置为Frame |
| 471 |
inner_frame = tk.Frame(canvas) |
| 472 |
|
| 473 |
canvas_window = canvas.create_window((0, 0), window=inner_frame, anchor="nw") |
| 474 |
inner_frame.bind("<Configure>", lambda event: canvas.config(scrollregion=canvas.bbox("all"))) |
| 475 |
# 控制滚动条滚动 Button-4是向上滚动, Button-5是向下滚动 event.num的数值代表按钮id |
| 476 |
def on_mouse_scroll(event): |
| 477 |
inner_height = inner_frame.winfo_height() |
| 478 |
canvas_height = canvas.winfo_height() |
| 479 |
# 内容长度是否需要滚动 |
| 480 |
if inner_height > canvas_height: |
| 481 |
# 仅响应在canvas空间区域的滚轮事件 |
| 482 |
if canvas.winfo_containing(event.x_root, event.y_root) == canvas: |
| 483 |
if event.num == 4: |
| 484 |
canvas.yview_scroll(-2, "units") |
| 485 |
elif event.num == 5: |
| 486 |
canvas.yview_scroll(2, "units") |
| 487 |
|
| 488 |
canvas.bind_all("<Button-4>", on_mouse_scroll) |
| 489 |
canvas.bind_all("<Button-5>", on_mouse_scroll) |
| 490 |
|
| 491 |
# 创建Treeview显示搜索匹配的路径 |
| 492 |
search_tree = ttk.Treeview(search_frame, show='tree') |
| 493 |
search_tree.bind("<<TreeviewSelect>>", on_search_tree_select) |
| 494 |
search_tree.pack(side='left', fill='both', expand=True) |
| 495 |
|
| 496 |
search_scrollbar = ttk.Scrollbar(search_frame, orient="vertical", command=search_tree.yview) |
| 497 |
search_scrollbar.pack(side="right", fill="y") |
| 498 |
search_tree.configure(yscrollcommand=search_scrollbar.set) |
| 499 |
|
| 500 |
root.mainloop() |