Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env python
- # -*- coding: utf-8 -*-
- #
- # Support module generated by PAGE version 4.27f
- # in conjunction with Tcl version 8.6
- # Nov 26, 2019 04:38:18 PM CST platform: Linux
- # Nov 30, 2019 06:12:05 AM CST platform: Linux
- import sys
- import pickle as pkl
- from datetime import datetime
- import platform
- import os
- try: # Just in case the user is running Python 2.x
- import Tkinter as tk
- import tkFileDialog as filedialog
- import tkMessageBox as messagebox
- import tkFont as font
- except ImportError:
- import tkinter as tk
- from tkinter import messagebox
- from tkinter import font
- from tkinter import filedialog
- try:
- import ttk
- py3 = False
- except ImportError:
- import tkinter.ttk as ttk
- py3 = True
- def set_Tk_var():
- global pickleType
- pickleType = tk.StringVar()
- pickleType.set('')
- global entry_var
- entry_var = tk.StringVar()
- def on_btnExit():
- # print('depickle1_support.on_btnExit')
- # sys.stdout.flush()
- destroy_window()
- def on_btnFile():
- # print('depickle1_support.on_btnFile')
- # sys.stdout.flush()
- global fn, progpath
- title = "Select Pickle File"
- ft = (("Pickle files", "*.pkl"), ("all files", "*.*"))
- fn = filedialog.askopenfilename(initialdir=progpath,
- title=title,
- filetypes=ft)
- entry_var.set(fn)
- def on_btnGo():
- # print('depickle1_support.on_btnGo')
- # sys.stdout.flush()
- clear_stw()
- global fn
- with open(fn, 'rb') as f:
- try:
- data = pkl.load(f)
- except UnicodeDecodeError:
- f.seek(0) # in case the offset of the file is not in the beginning
- data = pkl.load(f, encoding='bytes') # encoding='latin1')
- print(type(data))
- pickleType.set(type(data))
- if type(data) is dict:
- for key, val in data.items():
- # print(f'key: {key} - value: {val}')
- w.Scrolledtext1.insert('end', f'key:{key} - value: {val}\n')
- elif type(data) is list:
- for d in data:
- w.Scrolledtext1.insert('end', f'{d}\n')
- else:
- w.Scrolledtext1.insert('end', f'{data}\n')
- def clear_stw():
- # Clear the ScrolledText Widget
- w.Scrolledtext1.delete('1.0', 'end')
- def init(top, gui, *args, **kwargs):
- global w, top_level, root
- w = gui
- top_level = top
- root = top
- # ======================================================
- # My init code starts here...
- # ======================================================
- pv = platform.python_version()
- print("Running under Python {0}".format(pv))
- # Get the current program path
- global progpath
- progpath = os.getcwd()
- print(progpath)
- # Set the main form title...
- root.title('Depickle')
- def destroy_window():
- # Function which closes the window.
- global top_level
- top_level.destroy()
- top_level = None
- if __name__ == '__main__':
- import depickle1
- depickle1.vp_start_gui()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement