Guest User

Untitled

a guest
Oct 9th, 2013
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.89 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. from __future__ import division
  5. from __future__ import print_function
  6. from __future__ import unicode_literals
  7. from __future__ import absolute_import
  8.  
  9. # cross-version compatibility
  10. import sys
  11. if sys.version_info.major < 3:
  12.     import Tkinter as tk
  13.     import ttk
  14.     import tkFileDialog as tkfiledialog
  15. else:
  16.     import tkinter as tk
  17.     from tkinter import ttk
  18.     from tkinter import filedialog as tkfiledialog
  19.  
  20.  
  21. class Example(ttk.Frame):
  22.     def __init__(self, parent):
  23.         # We can't use super() because in Python 2 the Tkinter objects
  24.         # derive from old-style classes.
  25.         ttk.Frame.__init__(self, parent, borderwidth=3)
  26.         self.parent = parent
  27.  
  28.         # Create the Tkinter Variables
  29.         self.destination_folder = tk.StringVar()
  30.         self.archiver = tk.StringVar()
  31.         self.compression = tk.StringVar()
  32.         self.exclude_home = tk.BooleanVar()
  33.         self.no_hidden = tk.BooleanVar()
  34.         self.user_options = tk.StringVar()
  35.  
  36.         # Set default values to the Tkinter Variables
  37.         self.destination_folder.set("/home/faramir")
  38.         self.archiver.set("tar")
  39.         self.compression.set("gzip")
  40.         self.exclude_home.set(False)
  41.         self.no_hidden.set(False)
  42.         self.user_options.set("")
  43.  
  44.         self.create_UI()
  45.  
  46.     def create_UI(self):
  47.         # set theming
  48.         self.style = ttk.Style()
  49.         self.style.theme_use("default")
  50.         self.pack(fill="both", expand=1)
  51.  
  52.         # set grid configuration
  53.         self.columnconfigure(1, weight=0)
  54.         self.columnconfigure(2, weight=1)
  55.         self.columnconfigure(3, weight=0)
  56.  
  57.         # add widgets
  58.         self.add_choose_folder(row=1, text="Destination folder:", variable=self.destination_folder)
  59.         self.add_combobox(row=2, text="Archiver:", variable=self.archiver, values=["tar", "bsdtar"])
  60.         self.add_combobox(row=3, text="Compression:", variable=self.compression, values=["gzip", "xz"])
  61.         self.add_entry(row=4, text="Additional archiver options:", variable=self.user_options)
  62.         self.add_checkbutton(row=5, text="Exclude /home but keep hidden files and folders", variable=self.exclude_home)
  63.         self.add_checkbutton(row=6, text="Don't keep /home 's hidden files and folders.", variable=self.no_hidden)
  64.  
  65.     def add_checkbutton(self, row, text, variable):
  66.         check_button = ttk.Checkbutton(self, text=text, variable=variable)
  67.         check_button.grid(row=row, column=1, columnspan=2, sticky="nsew")
  68.  
  69.     def add_choose_folder(self, row, text, variable):
  70.         # create the widgets
  71.         label = ttk.Label(self, text=text)
  72.         entry = ttk.Entry(self, textvariable=variable, state="readonly")
  73.         button = ttk.Button(self, text="...", command=lambda:variable.set(tkfiledialog.askdirectory()), width=2)
  74.         # place the widgets
  75.         label.grid(row=row, column=1, sticky="nse")
  76.         entry.grid(row=row, column=2, sticky="nsew")
  77.         button.grid(row=row, column=3)
  78.  
  79.     def add_combobox(self, row, text, variable, values):
  80.         # create the widgets
  81.         label = ttk.Label(self, text=text)
  82.         box = ttk.Combobox(self, textvariable=variable, state="readonly", values=values)
  83.         # place the widgets
  84.         label.grid(row=row, column=1, sticky="nse")
  85.         box.grid(row=row, column=2, sticky="nsew")
  86.  
  87.     def add_entry(self, row, text, variable):
  88.         # create the widgets
  89.         label = ttk.Label(self, text=text)
  90.         entry = ttk.Entry(self, textvariable=variable)
  91.         # place the widgets
  92.         label.grid(row=row, column=1, sticky="nse")
  93.         entry.grid(row=row, column=2, sticky="nsew")
  94.  
  95.  
  96.  
  97. def main():
  98.     root = tk.Tk()
  99.     root.title("backup.sh GUI")
  100.     app = Example(root)
  101.     app.update()
  102.     root.minsize(root.winfo_width(), root.winfo_height())
  103.     root.mainloop()
  104.  
  105.  
  106. if __name__ == '__main__':
  107.     main()
Advertisement
Add Comment
Please, Sign In to add comment