e8fc660c9369ef37c125e9739f8f8e97ccd5efd3
[yaffs2.git] / direct / python / yaffs_browser.py
1 import Tkinter as tk
2 from yaffsfs import *
3
4 yaffs_StartUp()
5 yaffs_mount("yaffs2/")
6 root_window =tk.Tk()
7
8 def load_file(self=0):
9     print "youloaded a file"
10 def back_a_directory(self=0):
11     pass
12     
13 def yaffs_ls(dname):
14     if dname[-1] != "/": dname = dname + "/"
15     dc = yaffs_opendir(dname)
16     if dc != 0 :
17         sep = yaffs_readdir(dc)
18         while bool(sep):
19             se = sep.contents
20             fullname = dname + se.d_name
21             #print fullname, " ", se.d_ino," ",ord(se.d_type)
22             st = yaffs_stat_struct()
23             result = yaffs_stat(fullname,byref(st))
24             perms = st.st_mode & 0777
25             isFile = True if st.st_mode & 0x8000 else False
26             isDir  = True if st.st_mode & 0x4000 else False
27
28             if isFile :
29                 print "File ",se.d_ino, hex(perms), st.st_size, fullname
30             elif isDir :
31                 print "Dir  ",se.d_ino, hex(perms), fullname
32                 yaffs_ls(fullname)
33             else :
34                 print "Other (",hex(st.st_mode),") ",se.d_ino, hex(perms), fullname
35
36             sep = yaffs_readdir(dc)
37         yaffs_closedir(dc)
38         return 0
39     else:
40         print "Could not open directory"
41         return -1
42
43     
44
45 ##toolbar 
46 toolbar_frame=tk.Frame(root_window)
47 button_open=tk.Button(toolbar_frame, command=load_file, text="load")
48 button_open.grid(column=0, row=0)
49 button_back=tk.Button(toolbar_frame, command=back_a_directory, text="back")
50 button_back.grid(column=1, row=0)
51 toolbar_frame.grid(row=0, column=0,  columnspan=3)
52 #root_window.bind("<Double-Button-1>", button_open)
53
54
55
56 ##mount list entry box init
57 mount_list_frame=tk.Frame(root_window)
58 mount_list_label=tk.Label(mount_list_frame, text="mount list")
59 mount_list_label.pack(side=tk.RIGHT)
60 mount_list_text_variable=tk.StringVar()
61
62 mount_list_text_variable.set("path")
63 mount_list_entry_box= tk.Entry(mount_list_frame,textvariable=mount_list_text_variable)
64 mount_list_entry_box.pack(side=tk.RIGHT)
65 mount_list_frame.grid(row=1, column=0, columnspan=2)
66
67
68
69
70 list_frame=tk.Frame(root_window)
71
72 ###header part of the browser
73 #
74 #name_button=tk.Button(list_frame, text="name")
75 #name_button.grid(row=0, column=0)
76 #
77 #type_button=tk.Button(list_frame, text="file type")
78 #type_button.grid(row=0, column=1)
79 #
80 #size_button=tk.Button(list_frame, text="size")
81 #size_button.grid(row=0, column=2)
82
83
84
85
86
87 ##list part of the browser
88 #
89 #name_list_box=tk.Listbox(list_frame,exportselection=0, height=20, width=30)
90 #
91 #
92 #
93 #displayed_list=[]
94 #for x in range(0,list.length_of_list ):
95 #
96 #    
97 #    type_spaces=" "
98 #    type_spaces=type_spaces* (10- len(list.type[x])) 
99 #    y=(list.name[x]+name_spaces+list.type[x]+list.size[x])
100 #    print (list.name[x]+name_spaces+list.type[x]+list.size[x])
101 #    name_list_box.insert(x,y)
102 #name_list_box.grid(column=0, row=1)
103 #
104 #
105 #list_frame.grid()
106 ##browser_frame.grid(row=1, column=0,columnspan=3 )
107 #name_list_box.bind("<Double-Button-1>", load_file)
108
109
110 yaffs_ls("/yaffs2")
111
112 root_window.mainloop()