[go: up one dir, main page]

Menu

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

Download this file

271 lines (220 with data), 9.1 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
#!/usr/bin/python
#-*- coding: UTF-8 -*-
from Tkinter import *
import tkFileDialog
import tkMessageBox
import codecs
import os
import stat
import time
# Version Number
__version__ = "0.Gamma0"
# Import the module to check if all files which are need are here
filecheck = __import__("lib/filecheck")
filecheck.FileCheck()
# Get the language module
lang_load = open(filecheck.language, "r")
_lang = lang_load.read()
lang_load = "share/language/lang_"+_lang
language = __import__(lang_load)
class Application:
# Command to destroy/quit the Application
def quit_window(self):
self.root.destroy()
# Command to open the AboutWindow
def about(self,whatever=None):
self.aboutwindow = AboutWindow()
# Command to list files in the path
def list_path(self, whatever=None):
self.index = self.listbox.curselection()
self.sel_file = self.listbox.get(self.index)
for self.letter in self.get_path_entry.get():
self.last_letter = self.letter[0]
if self.last_letter != "/":
self.get_path_entry.insert(END, "/")
else:
pass
self.get_path_entry.insert(END, self.sel_file)
self.listbox.delete(0, END)
self.path = self.get_path_entry.get()
os.chdir(self.path)
self.list = os.listdir(self.path)
self.list.sort()
for item in self.list:
self.listbox.insert(END, item)
# Change Directory command
def change_directory(self, whatever=None):
for self.letter in self.get_path_entry.get():
self.last_letter = self.letter[0]
if self.last_letter != "/":
self.get_path_entry.insert(END, "/")
else:
pass
self.path = self.get_path_entry.get()
os.chdir(self.path)
self.list = os.listdir(self.path)
self.list.sort()
for item in self.listbox.get(0, END):
self.listbox.delete(0, END)
for item in self.list:
self.listbox.insert(END, item)
# Command to go to Home Folder
def go_home(self, whatever=None):
self.home = filecheck.home
self.get_path_entry.delete(0, END)
self.get_path_entry.insert(END, self.home)
os.chdir(self.home)
self.list = os.listdir(self.path)
self.list.sort()
for item in self.listbox.get(0, END):
self.listbox.delete(0, END)
for item in self.list:
self.listbox.insert(END, item)
# Open File
def open_file(self, whatever=None):
self.info()
if self.file_typ == "\nFiletyp: Directory\n":
tkMessageBox.showerror("Error", "This is not a file. This is a directory. Please select a file")
else:
os.system("xterm -e nano "+self.sel_file+" &")
# Set Focus
def focus(self, whatever=None):
self.get_path_entry.icursor(END)
# Get Information
def info(self,whatever=None):
self.index = self.listbox.curselection()
self.filename = self.listbox.get(self.index)
self.filepath = self.get_path_entry.get()
self.sel_file = self.filepath+self.filename
self.file_stat = os.stat(self.sel_file)
self.filesize = self.file_stat[stat.ST_SIZE]
#Info what you see
self.file_name = "Filename: "+self.filename
self.file_path = "\nFilepath: "+self.filepath
if self.filesize > 1024.0:
self.file_size = int(self.filesize)/1024.0
self.suffix = " KB"
if self.filesize > 1048576.0:
self.file_size = int(self.filesize)/1024.0/1024.0
self.suffix = " MB"
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 = "\nLast modified: "+str(time.strftime("%m/%d/%Y %I:%M:%S %p",time.localtime(self.file_stat[stat.ST_MTIME])))
self.access_time = "\nLast access: "+str(time.strftime("%m/%d/%Y %I:%M:%S %p",time.localtime(self.file_stat[stat.ST_ATIME])))
self.create_time = "\nCreated 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.file_name)+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)+"\n\n\n"+str(self.file_stat[stat.ST_INO]))
# 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)
# The window
def __init__(self):
self.path = os.getenv("HOME")
self.root = Tk()
self.root.title("sPOP File ")
self.root.protocol("WM_DELETE_WINDOW", self.quit_window)
# self.root.geometry("500x350+100+100")
# 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="Open File", command=self.open_file)
self.filemenu.add_separator()
self.filemenu.add_command(label=language.quit, command=self.quit_window)
# 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 "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.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.get_path_entry = Entry(self.path_frame)
self.get_path_entry.pack(side=LEFT, fill=X, expand=YES)
self.get_path_entry.insert(0, self.path)
self.get_path_entry.insert(END, "/")
self.get_path_ok_button = Button(self.path_frame, text=language.ok, command=self.change_directory)
self.get_path_ok_button.pack(side=RIGHT)
# Listbox Frame
self.listbox_frame = Frame(self.root)
self.listbox_frame.pack(side=LEFT, fill=Y)
# 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)
# 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.root.bind("<Control-O>",self.open_file)
self.root.bind("<Control-o>",self.open_file)
self.root.bind("<Control-I>",self.info)
self.root.bind("<Control-i>",self.info)
self.root.bind("<Control-L>",self.focus)
self.root.bind("<Control-l>",self.focus)
self.root.bind("<Control-P>",self.list_path)
self.root.bind("<Control-p>",self.list_path)
self.root.bind("<Control-D>",self.change_directory)
self.root.bind("<Control-d>",self.change_directory)
# Command to show window
self.root.mainloop()
if __name__ == "__main__":
Application()