[go: up one dir, main page]

Menu

[r90]: / file / trunk / spop_file.py  Maximize  Restore  History

Download this file

342 lines (283 with data), 11.7 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
#!/usr/bin/python
#-*- coding: UTF-8 -*-
#Import Python Modules from System
from Tkinter import *
import tkMessageBox
import os
import stat
import time
#Import the own python modules from lib
filecheck = __import__("lib/filecheck")
# Loading the right language
lang_load = list(open(filecheck.config_file))
_lang = lang_load[3]
_lang = _lang[:-1]
lang_load = "share/language/lang_"+_lang
language = __import__(lang_load)
# Version Number
<<<<<<< .mine
__version__ = "0.1+Alpha2"
=======
__version__ = "0.1.5"
>>>>>>> .r89
# The Application Class
class Application:
# Command to quit the programm
def quit(self, whatever=None):
if self.config_line[9]== "yes\n":
if tkMessageBox.askokcancel(language.quit, language.quit_wish):
self.root.destroy()
else:
pass
else:
self.root.destroy()
# Command to get the selected listbox index
def get_selection(self, whatever=None):
self.listbox_index = self.listbox.curselection()
self.selection = self.listbox.get(self.listbox_index)
# Update Path Entry
def update_path_entry(self, whatever=None):
self.path_entry.insert(END, self.selection)
# Command to change the directory
def change_directory(self, whatever=None):
self.path = self.path_entry.get()
self.file_list = os.listdir(self.path)
# Commmand to insert a slash after the path in the path entry
def insert_slash(self, whatever=None):
for self.letter in self.path_entry.get():
self.last_letter = self.letter[0]
if self.last_letter != "/":
self.path_entry.insert(END, "/")
else:
pass
# Update Listbox
def update_listbox(self, whatever=None):
self.listbox.delete(0, END)
self.file_list.sort()
for item in self.file_list:
self.listbox.insert(END, item)
# Command for get the listbox index and enter it to path entry
def use_index(self, whatever=None):
self.get_selection()
self.update_path_entry()
self.change_directory()
self.insert_slash()
self.update_listbox()
self.get_listbox_info()
# Command to go home
def go_home(self, whatever=None):
self.path_entry.delete(0, END)
self.path_entry.insert(END, self.home)
self.change_directory()
self.insert_slash()
self.update_listbox()
self.get_listbox_info()
# Command cd.
# Use following command= get_selection , change_directory, update_path_entry, insert_slash and update_listbox
def cd(self, whatever=None):
self.change_directory()
self.insert_slash()
self.update_listbox()
self.get_listbox_info()
# Command to get the file information
def get_info(self, whatever=None):
self.get_selection()
self.filepath = self.path_entry.get()
self.sel_file = self.filepath+self.selection
self.file_stat = os.stat(self.sel_file)
self.filesize = self.file_stat[stat.ST_SIZE]
#Info what you see
self.file_name = language.filename+": "+self.selection
self.file_path = "\n"+language.path+": "+self.filepath
self.filesize = self.filesize*1.0
if int(self.filesize) > 1048576.0:
self.file_size = int(self.filesize)/1024.0/1024.0
self.suffix = " MB"
elif int(self.filesize) > 1024.0:
self.file_size = int(self.filesize)/1024.0
self.suffix = " KB"
else:
self.file_size = int(self.filesize)
self.suffix = " B"
self.file_size = "\nFilesize: "+str(self.file_size)+self.suffix
if stat.S_ISDIR(self.file_stat[stat.ST_MODE]):
self.file_typ = "\nFiletyp: Directory\n"
else:
self.file_typ = "\nFiletyp: File\n"
self.modified_time = "\n"+language.last_modified+": "+str(time.strftime("%m/%d/%Y %I:%M:%S %p",time.localtime(self.file_stat[stat.ST_MTIME])))
self.access_time = "\n"+language.last_access+": "+str(time.strftime("%m/%d/%Y %I:%M:%S %p",time.localtime(self.file_stat[stat.ST_ATIME])))
self.create_time = "\n"+language.created_at+": "+str(time.strftime("%m/%d/%Y %I:%M:%S %p",time.localtime(self.file_stat[stat.ST_CTIME])))
self.file_info_text.delete("1.0", END)
self.file_info_text.insert(END, str(self.selection)+str(self.file_path)+str(self.file_size)+str(self.file_typ)+"\nTime:"+str(self.modified_time)+str(self.access_time)+str(self.create_time))
# Command to get the listbox informations
def get_listbox_info(self):
self.listbox_info = self.listbox.size()
self.info_entry.delete(0, END)
self.info_entry.insert(END, self.listbox_info)
if int(self.listbox_info) > 1:
self.info_entry.insert(END, " Objects")
elif int(self.listbox_info) == 0:
self.info_entry.delete(0, END)
self.info_entry.insert(END, "No Objects in this Directory")
else:
self.info_entry.insert(END, " Object")
# Command to open a file
def open_file(self, whatever=None):
self.get_info()
if self.file_typ == "\nFiletyp: Directory\n":
self.use_index()
else:
windows.open_window()
# The Window where you can choose the programm to open the selected file
def open_window(self, whatever=None):
self.open_file_window = Toplevel()
self.open_file_window.title("Open with")
self.open_file_label = Label(self.open_file_window, text="Tell me the programm you want to open this file")
self.open_file_label.pack()
self.open_file_entry = Entry(self.open_file_window)
self.open_file_entry.pack()
self.open_file_button = Button(self.open_file_window, text="Open", command=self.get_file_entry)
self.open_file_button.pack()
self.open_file_entry.bind("<Control-m>", self.get_file_entry)
self.open_file_entry.bind("<Control-M>", self.get_file_entry)
def get_file_entry(self, whatever=None):
self.program_name = self.open_file_entry.get()
os.system(self.program_name+" "+self.filepath+self.selection+" &")
self.open_file_window.destroy()
# About Window
def about_window(self, whatever=None):
# Import the about text in the right language
self.abouttext = "abouttext_"+_lang
self.abouttext = open("share/text/"+self.abouttext, "r")
self.abouttext = self.abouttext.read()
# Import the list of the developers
self.devellist = open("share/text/developers", "r")
self.devellist = self.devellist.read()
self.about_window = Toplevel()
self.about_window.title(language.aboutspop)
self.about_window.geometry("320x250+250+250")
self.about_frame = Frame(self.about_window)
self.about_frame.pack()
self.about_label = Label(self.about_frame, text="sPOP File Version "\
+__version__+"\n\n"+self.abouttext+"\n"+\
language.developer+"\n"+self.devellist)
self.about_label.pack()
self.about_button = Button(self.about_window, text=language.close,\
command=self.about_window.destroy)
self.about_button.pack(side=BOTTOM)
# Command Test
def test(self, whatever=None):
print self.listbox.index(1)
# The window
def __init__(self):
# The beginner path should be /home/<USER>
self.home = os.getenv("HOME")
self.path = self.home
# Things should loaded
self.config_line = list(open(filecheck.config_file))
# The Window
self.root = Tk()
self.root.title("sPOP File")
self.root.protocol("WM_DELETE_WINDOW", self.quit)
# The Menubar at the window
self.menubar = Menu(self.root)
# Menu called "File" in the Menubar
self.filemenu = Menu(self.menubar)
self.filemenu.add_command(label="TEST", command=self.test)
self.filemenu.add_command(label="Open File")
self.filemenu.add_command(label="File Info", command=self.get_info)
self.filemenu.add_separator()
self.filemenu.add_command(label=language.quit)
# Menu called "Edit" in the Menubar
self.editmenu = Menu(self.menubar)
self.editmenu.add_command(label=language.copy)
self.editmenu.add_command(label=language.paste)
self.editmenu.add_command(label=language.cut)
#Menu called "Go" in the Menubar
self.gomenu = Menu(self.menubar)
self.gomenu.add_command(label="Use Index", command=self.use_index)
self.gomenu.add_command(label=language.change_directory, command=self.cd)
self.gomenu.add_command(label=language.home)
self.gomenu.add_command(label=language.upper_folder)
# Menu called "Help" in the Menubar
self.helpmenu = Menu(self.menubar)
self.helpmenu.add_command(label=language.info, command=self.about_window)
# Add the "File" Menu to the Menubar
self.menubar.add_cascade(label=language._file, menu=self.filemenu)
self.menubar.add_cascade(label=language.edit, menu=self.editmenu)
self.menubar.add_cascade(label=language.go, menu=self.gomenu, command=self.go_home)
self.menubar.add_cascade(label=language.help, menu=self.helpmenu)
# Display the Menubar in the window
self.root.config(menu=self.menubar)
# Path Entry
self.path_frame = Frame(self.root)
self.path_frame.pack(side=TOP, fill=X)
self.button_back = Button(self.path_frame, text="Back")
self.button_back.pack(side=LEFT)
self.button_home = Button(self.path_frame, text="Home", command=self.go_home)
self.button_home.pack(side=LEFT)
self.path_entry = Entry(self.path_frame)
self.path_entry.pack(side=LEFT, fill=X, expand=YES)
self.path_entry.insert(0, self.path)
self.path_entry.insert(END, "/")
self.path_ok_button = Button(self.path_frame, text=language.ok, command=self.cd)
self.path_ok_button.pack(side=RIGHT)
# Left Frame
self.left_frame = Frame(self.root)
self.left_frame.pack(side=LEFT, fill=Y)
# Listbox Frame
self.listbox_frame = Frame(self.left_frame)
self.listbox_frame.pack(fill=Y, expand=1)
# Scrollbar
self.listbox_scrollbar = Scrollbar(self.listbox_frame, orient=VERTICAL)
# Listbox
self.listbox = Listbox(self.listbox_frame, yscrollcommand=self.listbox_scrollbar.set, selectbackground="yellow")
self.listbox.pack(side=LEFT,fill=Y)
self.listbox_scrollbar.pack(side=RIGHT, fill=Y)
self.listbox_scrollbar.config(command=self.listbox.yview)
# Info Label
self.info_entry = Entry(self.left_frame)
self.info_entry.pack(side=LEFT)
# File Info / Preview Frame
self.fileprev_frame = Frame(self.root)
self.fileprev_frame.pack(ipady=110)
# File Info Frame
self.file_frame = Frame(self.fileprev_frame)
self.file_frame.pack(side=TOP)
# Preview Frame
self.preview_frame = Frame(self.fileprev_frame)
self.preview_frame.pack(side=TOP)
# File Information
self.file_info_label = Label(self.file_frame, text="File Information")
self.file_info_label.pack()
self.file_info_text = Text(self.file_frame)
self.file_info_text.pack()
# Preview
self.preview_label = Label(self.preview_frame, text="Preview")
self.preview_label.pack(side=TOP)
# Get File List
self.list = os.listdir(self.path)
self.list.sort()
for item in self.list:
self.listbox.insert(END, item)
self.get_listbox_info()
# Hotkeys
self.root.bind("<Mod1-c>",self.cd)
self.root.bind("<Mod1-C>",self.cd)
self.root.bind("<Mod1-l>",self.use_index)
self.root.bind("<Mod1-L>",self.use_index)
self.root.bind("<Mod1-h>",self.go_home)
self.root.bind("<Mod1-H>",self.go_home)
self.root.bind("<Mod1-i>",self.get_info)
self.root.bind("<Mod1-I>",self.get_info)
self.root.bind("<Mod1-o>",self.open_file)
self.root.bind("<Mod1-O>",self.open_file)
self.root.bind("<Mod1-t>",self.test)
self.root.bind("<Mod1-T>",self.test)
self.root.bind("<Button-1>",self.get_info)
self.root.bind("<Double-Button-1>",self.open_file)
self.root.bind("<Down>",self.test)
# Command to show window
self.root.mainloop()
if __name__ == "__main__":
Application()