#!/usr/bin/python
#-*- coding: UTF-8 -*-
from Tkinter import *
import tkFileDialog
import tkMessageBox
import codecs
import os
# Import commands.py for Paste,Copy,Cut (from PyWord)
commands = __import__("lib/commands")
# Import the module to check if all files which are need are here
filecheck = __import__("lib/filecheck")
filecheck.FileCheck()
# Version Number
__version__ = "0.2.4.Alpha"
# 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):
if tkMessageBox.askokcancel(language.quit, language.quit_wish):
self.root.destroy()
# Command to open a file
def open_file(self,whatever=None,filename=None):
if not filename:
self._filename = tkFileDialog.askopenfilename()
else:
self._filename = filename
if not (self._filename == ""):
try:
f = open(self._filename,"r")
f2 = f.read()
except:
f = open(self._filename,"w")
f.write("\n")
f.close()
f = open(self._filename,"r")
f2 = f.read()
self.textfield.delete("1.0", "end")
self.textfield.insert("1.0", f2)
self.textfield.delete("end-1c","end")
f.close()
#get self.filename to the "new" filename
self.filename = self._filename
# Command to save a file with a filedialog to choice name and folder
def save_as_file(self,whatever=None):
self.filename = tkFileDialog.asksaveasfilename()
self.save = codecs.open(self.filename, "w", "utf-8")
self.save.write(self.textfield.get("1.0","end"))
self.save.close()
# Command to save a file with the filename
def save_file(self,whatever=None):
if self.filename == "":
self.save_as_file()
else:
self.save = codecs.open(self.filename, "w", "utf-8")
self.save.write(self.textfield.get("1.0","end"))
self.save.close()
# Command to delete the moment file and open a blank file, ask you befor
def new_file(self,whatever=None):
if tkMessageBox.askokcancel(language.newfile, language.start_newfile):
self.textfield.delete("1.0", "end")
self.filename = ""
# Command to open the AboutWindow
def about(self,whatever=None):
self.aboutwindow = AboutWindow()
# Command for insert the CLIPBOARD selection into the textfield
def paste_text(self,whatever=None):
commands.paste_text(self.textfield)
def copy_text(self,whatever=None):
commands.copy_text(self.textfield)
def cut_text(self,whatever=None):
commands.cut_text(self.textfield)
# New Font command
def new_font(self,event):
self.fontsize = self.fontsize_var.get()
self.fontstype = self.font_var.get()
self.textfield.configure(font=(self.fontstype, self.fontsize))
self.fonts = open(filecheck.fonts, "w")
self.fonts.writelines(self.fontstype+"\n"+self.fontsize )
# Get the momentary language
def lang_choose(self,whatever=None):
if self.var.get() == language.german:
lang = open(filecheck.language, "w")
lang = lang.write("ger")
else:
lang = open(filecheck.language, "w")
lang = lang.write("eng")
# Option Toplevel
def option_window(self, whatever=None):
self.option_window = Toplevel()
self.option_window.title("Option")
self.option_window.geometry("200x250+250+250")
self.option_frame = Frame(self.option_window)
self.option_frame.pack()
# Language Option
self.lang_frame = Frame(self.option_window, bd="10")
self.lang_frame.pack()
self.lang_label = Label(self.lang_frame, text=language.language)
self.lang_label.pack()
self.var = StringVar(self.lang_frame)
self.var.set(language.nowlang)
self.option = OptionMenu(self.lang_frame, self.var, language.english, language.german)
self.option.pack()
# Font Options
self.font_frame = Frame(self.option_window, bd="20")
self.font_frame.pack()
self.font_label = Label(self.font_frame, text=language.fonts)
self.font_label.pack()
self.font_var = StringVar(self.font_frame)
self.font_var.set(self.fontstype)
self.font_option = OptionMenu(self.font_frame, self.font_var,\
"Serif", "Sans", "Purisa", "Monospace", "Helvetica",\
command=self.new_font)
self.font_option.pack(side=LEFT)
self.fontsize_var = StringVar(self.font_frame)
self.fontsize_var.set(self.fontsize)
self.fontsize_option = OptionMenu(self.font_frame,\
self.fontsize_var, "8", "9", "10", "11", "12",\
"13", "14", "15", "16", "20", "24", "32", "48", \
command=self.new_font)
self.fontsize_option.pack(side=LEFT)
# The Buttons
self.button_frame = Frame(self.option_window, bd="10")
self.button_frame.pack(side=BOTTOM)
self.ok_button = Button(self.option_window, text=language._apply,\
command=self.lang_choose)
self.ok_button.pack(side=LEFT)
self.option_button = Button(self.option_window, text=language.close,\
command=self.option_window.destroy)
self.option_button.pack(side=RIGHT)
# The window
def __init__(self):
self.filename = ""
#Import Fonts
self.fonts = open(filecheck.fonts, "r").readlines()
self.fontstype = self.fonts[0]
self.fontstype = self.fontstype[:-1]
self.fontsize = self.fonts[1]
self.fontsize = int(self.fontsize)
self.root = Tk()
self.root.title("sPOP Note ")
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.newfile, command=self.new_file)
self.filemenu.add_command(label=language.openfile, command=self.open_file)
self.filemenu.add_command(label=language.savefile, command=self.save_file)
self.filemenu.add_command(label=language.saveasfile, command=self.save_as_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, command=self.copy_text)
self.editmenu.add_command(label=language.paste, command=self.paste_text)
self.editmenu.add_command(label=language.cut, command=self.cut_text)
self.editmenu.add_separator()
self.editmenu.add_command(label=language.preferences, command=self.option_window)
# Menu called "Help" in the Menubar
self.helpmenu = Menu(self.menubar)
self.helpmenu.add_command(label=language.info, command=self.about)
# 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)
# The Frame for the Textfield
self.textframe = Frame(self.root)
self.textframe.pack()
# The Scrollbar for the Textfield
self.yscrollbar = Scrollbar(self.textframe, relief="raised")
self.yscrollbar.pack(side=RIGHT, fill=Y)
# The Textfield
self.textfield = Text(self.textframe, bg="white", \
yscrollcommand=self.yscrollbar.set, relief="raised")
self.textfield.configure(font=(self.fontstype, self.fontsize))
self.textfield.pack()
# The command to use the Scrollbar for the y=horizontal viewing
self.yscrollbar.config(command=self.textfield.yview)
# Hotkeys
self.root.bind("<Control-O>",self.open_file)
self.root.bind("<Control-o>",self.open_file)
self.root.bind("<Control-S>",self.save_file)
self.root.bind("<Control-s>",self.save_file)
self.root.bind("<Control-N>",self.new_file)
self.root.bind("<Control-n>",self.new_file)
self.root.bind("<Control-Q>",self.quit_window)
self.root.bind("<Control-q>",self.quit_window)
self.root.bind("<Control-Q>",self.quit_window)
self.root.bind("<Control-q>",self.quit_window)
self.root.bind("<Control-C>",self.copy_text)
self.root.bind("<Control-c>",self.copy_text)
self.root.bind("<Control-X>",self.cut_text)
self.root.bind("<Control-x>",self.cut_text)
self.root.bind("<Control-V>",self.paste_text)
self.root.bind("<Control-v>",self.paste_text)
self.root.bind("<Control-P>",self.option_window)
self.root.bind("<Control-p>",self.option_window)
# Command to show window
self.root.mainloop()
class AboutWindow:
def __init__(self):
# 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 = Tk()
self.about_window.title(language.aboutspop)
self.about_window.geometry("320x250+250+250")
self.about_window.protocol("WM_DELETE_WINDOW", self.quit_about)
self.about_frame = Frame(self.about_window)
self.about_frame.pack()
self.about_label = Label(self.about_frame, text="sPOP Note Version "\
+__version__+"\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.quit_about)
self.about_button.pack(side=BOTTOM)
# Command to destroy/quit the AboutWindow
def quit_about(self):
self.about_window.destroy()
if __name__ == "__main__":
Application()