#!/usr/bin/env python
import plot_PSEC4 as plt

import numpy as np
import os
from Tkinter import *
import tkFileDialog
import tkMessageBox
import bokeh.plotting as bkh

## Quickly plot a PSEC log file ##

cwd = os.getcwd()
# Get the data file from a dialogue box and open it. Also store the filename.
root = Tk()
root.withdraw()
root.update()
f = tkFileDialog.askopenfile(mode='rb', 
    initialfile=cwd, 
    title='Select a file', 
    filetypes = (("txt Files", "*.txt"),("all files","*.*")))
root.destroy()
try:
    fname = f.name
except:
    print("No file selected")
    exit()
f.close()
oname = fname

oname = oname.replace('DATA', 'FIGS')+'.html'

p = plt.plot_PSEC(fname, oname)

directory = oname.split('/')[:-1]
directory = '/'.join(directory)
if not os.path.exists(directory):
    os.makedirs(directory)

bkh.save(p)
bkh.show(p)