# Path: Utilities/jtools.py
# class OutOfOrderException(Exception):
# class AnalysisError(Exception):
# class CycledList(list):
#     def __getitem__(self, key):
# def slurm_id_from_output(sbatch_output):
# def check_slurm_for_job(squeue_output):
# def get_slurm_exit_state(sjobexitmod_output):
# def write_finished_file(f):
# def midpoint(x1, x2):
# def distance(x1, x2):
# def ANobj_times_to_time_window(t):
# def break_path(p, line_length):
# def text_location(xrange, yrange):
# def valid_int_from_str(s):
# def valid_float_from_str(s):
# def complex_mag(z):
# def complex_mag_list(zz):
# def type_verify(var, typ):
# def time_window_to_filelike_str(w):
# def scan_config(f):
# def in_tkStringVar_array(s, tksvarr):
# def valid_probe_array(s, f = DEFAULT_CONFIG_FILE):
# def return_methods():
# def valid_method(s):
# def probe_positions(probe_array):
# def valid_window(s):
# def remove_key(d, k):
# def time_window_parser(s):
# def t_in_window(t, win):
# def window_subset(w1, w2):
# def valid_num_or_range(s):
# def valid_shot_str(s):
# def shot_str_parser(s):
# def reverse_shot_str_parser(shot_list):
# def squareish_grid(n, swapxy=False):
# def find_closest(arr, x):


    import tkinter as tk
    import Tkinter as tk
import subprocess
from CONSTANTS import *
from Utilities import jtools as jt
        no = tk.Button(master=win, text="No", font=(font_name, 18), command=win.destroy)
        no.grid(row=1, column=1, sticky=tk.N)
        return

    def yes_cancel(self):
        subprocess.check_output("scancel {}".format(self.jobid), shell=True)
        self.root.destroy()
        return

    def countdown(self):
        self._cur -= 1
        self.total_time += 1
        if self._cur <= 0:
            sjobexitmod_output = subprocess.check_output("sjobexitmod -l {}".format(self.jobid), shell=True)
            exit_state = jt.get_slurm_exit_state(sjobexitmod_output)
            if exit_state == "PENDING" or exit_state == "assigned":
                self._cur = self.default_wait_time
            elif exit_state == "RUNNING":
                self._cur = self.default_wait_time
            elif exit_state == "COMPLETED":
                self.message.set("Clustering is complete!\nPlease wait while the\nthe object is loaded.\n"
                                 "Total time elapsed:\n{} seconds".format(self.total_time))
                self.root.event_generate("<<slurm_clustering_complete>>", when="tail")
                return
            elif exit_state == "FAILED":
                self.root.event_generate("<<clustering_failed>>", when="tail")
                return
            elif exit_state == "CANCELLED+":
                self.root.event_generate("<<clustering_failed>>", when="tail")
            else:

# Path: Utilities/jtools.py
# class OutOfOrderException(Exception):
# class AnalysisError(Exception):
# class CycledList(list):
#     def __getitem__(self, key):
# def slurm_id_from_output(sbatch_output):
# def check_slurm_for_job(squeue_output):
# def get_slurm_exit_state(sjobexitmod_output):
# def write_finished_file(f):
# def midpoint(x1, x2):
# def distance(x1, x2):
# def ANobj_times_to_time_window(t):
# def break_path(p, line_length):
# def text_location(xrange, yrange):
# def valid_int_from_str(s):
# def valid_float_from_str(s):
# def complex_mag(z):
# def complex_mag_list(zz):
# def type_verify(var, typ):
# def time_window_to_filelike_str(w):
# def scan_config(f):
# def in_tkStringVar_array(s, tksvarr):
# def valid_probe_array(s, f = DEFAULT_CONFIG_FILE):
# def return_methods():
# def valid_method(s):
# def probe_positions(probe_array):
# def valid_window(s):
# def remove_key(d, k):
# def time_window_parser(s):
# def t_in_window(t, win):
# def window_subset(w1, w2):
# def valid_num_or_range(s):
# def valid_shot_str(s):
# def shot_str_parser(s):
# def reverse_shot_str_parser(shot_list):
# def squareish_grid(n, swapxy=False):
# def find_closest(arr, x):


# Path: GUI/ClusteringWindow.py
    import tkinter as tk
    import Tkinter as tk
import subprocess
from CONSTANTS import *
from Utilities import jtools as jt

        no = tk.Button(master=win, text="No", font=(font_name, 18), command=win.destroy)
        no.grid(row=1, column=1, sticky=tk.N)
        return

    def yes_cancel(self):
        subprocess.check_output("scancel {}".format(self.jobid), shell=True)
        self.root.destroy()
        return

    def countdown(self):
        self._cur -= 1
        self.total_time += 1
        if self._cur <= 0:
            sjobexitmod_output = subprocess.check_output("sjobexitmod -l {}".format(self.jobid), shell=True)
            exit_state = jt.get_slurm_exit_state(sjobexitmod_output)
            if exit_state == "PENDING" or exit_state == "assigned":
                self._cur = self.default_wait_time
            elif exit_state == "RUNNING":
                self._cur = self.default_wait_time
            elif exit_state == "COMPLETED":
                self.message.set("Clustering is complete!\nPlease wait while the\nthe object is loaded.\n"
                                 "Total time elapsed:\n{} seconds".format(self.total_time))
                self.root.event_generate("<<slurm_clustering_complete>>", when="tail")
                return
            elif exit_state == "FAILED":
                self.root.event_generate("<<clustering_failed>>", when="tail")
                return
            elif exit_state == "CANCELLED+":
                self.root.event_generate("<<clustering_failed>>", when="tail")
            else:

                print("UNKNOWN EXIT STATE: ({})".format(exit_state))