#!/usr/bin/python
#-*- coding: UTF-8 -*-
from Tkinter import *
import tkFileDialog
import tkMessageBox
import codecs
import os
# Version Number
__version__ = "0.Alpha"
# 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.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)
#Test
def test(self,whatever=None):
self.index = self.listbox.curselection()
self.sel_file = self.listbox.get(self.index)
print self.sel_file
self.get_path_entry.insert(END, "/")
self.get_path_entry.insert(END, self.sel_file)
# 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=language.path)
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.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.list_path)
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)
self.listbox.pack(side=LEFT, fill=Y)
self.listbox_scrollbar.pack(side=RIGHT, fill=Y)
self.listbox_scrollbar.config(command=self.listbox.yview)
# 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-T>",self.test)
self.root.bind("<Control-t>",self.test)
self.root.bind("<Control-L>",self.list_path)
self.root.bind("<Control-l>",self.list_path)
# Command to show window
self.root.mainloop()
if __name__ == "__main__":
Application()