<commit_before>import itertools
from tkinter import Label, Button, StringVar, BooleanVar, DoubleVar, IntVar, Checkbutton, Tk
from tkinter.ttk import Frame, Notebook, Combobox, Entry
from tkinter import filedialog
from tkinter import messagebox
import os.path as osp
import webbrowser

from . import picketfence, vmat, ct, log_analyzer, starshot, planar_imaging, __version__, winston_lutz, utilities


class PylinacGUI(Frame):

    def __init__(self, master=None):
        super().__init__(master)
        self.pack()
        self.notebook = Notebook(self)
        self.init_pf()
        self.init_vmat()
        self.init_catphan()
        self.init_logs()
        # self.init_tg51()
        self.init_star()
        self.init_planar_imaging()
        self.init_winstonlutz()
        self.init_help()
        for child in self.winfo_children():
            child.grid_configure(padx=10, pady=10)

    def init_help(self):

        def upload():
            webbrowser.open('https://www.dropbox.com/request/YKRu4AmuPsXu55uQq761')

        def gotoforum():
            webbrowser.open('https://groups.google.com/forum/#!forum/pylinac')

        def gotogithub():
            webbrowser.open('https://github.com/jrkerns/pylinac')

        def gotortd():
            webbrowser.open('https://pylinac.readthedocs.io/en/latest/')

        self.help_tab = Frame(self.notebook)
        Label(self.help_tab, text='Having trouble?\nWant to donate your images for program improvement?\nUpload them below')
        Button(self.help_tab, text='Upload Files', command=upload)
        Label(self.help_tab, text='Complete documentation is available on ReadTheDocs')
        Button(self.help_tab, text='ReadTheDocs', command=gotortd)
        Label(self.help_tab, text='Help is also available in the Pylinac forum')
        Button(self.help_tab, text='Go to forum', command=gotoforum)
        Label(self.help_tab, text='The source code of this program and all analyses is available on Github')
        Button(self.help_tab, text='Github', command=gotogithub)
        self.notebook.add(self.help_tab, text='Help/Upload Images')
        for child in self.help_tab.winfo_children():
            child.grid_configure(padx=10, pady=5)

    def init_vmat(self):

        def load_open():
            f = filedialog.askopenfilename()
            self.vmat_openimg.set(f)

        def load_dmlc():
            f = filedialog.askopenfilename()
            self.vmat_dmlcimg.set(f)

        def analyze_vmat():
            images = (self.vmat_openimg.get(), self.vmat_dmlcimg.get())
            if self.vmat_test.get() == 'DRGS':
                v = vmat.DRGS(image_paths=images)
            else:
                v = vmat.DRMLC(image_paths=images)
            v.analyze(tolerance=self.vmat_tol.get())
            fname = osp.join(self.vmat_dmlcimg.get().replace('.dcm', '.pdf'))
            fname = utilities.file_exists(fname)
            v.publish_pdf(fname)
            self.vmat_pdf.set(fname)
            utilities.open_path(fname)

        self.vmat_tab = Frame(self.notebook)
        self.vmat_openimg = StringVar()
        self.vmat_dmlcimg = StringVar()
        self.vmat_test = StringVar(value='DRGS')
        self.vmat_tol = DoubleVar(value=1.5)
        self.vmat_pdf = StringVar()
        Button(self.vmat_tab, text='Load Open Image...', command=load_open).grid(column=1, row=1)
        Button(self.vmat_tab, text='Load DMLC Image...', command=load_dmlc).grid(column=1, row=3)
        Label(self.vmat_tab, textvariable=self.vmat_openimg).grid(column=1, row=2)
        Label(self.vmat_tab, textvariable=self.vmat_dmlcimg).grid(column=1, row=4)
        Label(self.vmat_tab, text='Test type:').grid(column=1, row=5)
        Combobox(self.vmat_tab, values=('DRGS', 'DRMLC'), textvariable=self.vmat_test).grid(column=2, row=5)
        Label(self.vmat_tab, text='Tolerance (%):').grid(column=1, row=6)
        Entry(self.vmat_tab, width=7, textvariable=self.vmat_tol).grid(column=2, row=6)
        Button(self.vmat_tab, text='Analyze', command=analyze_vmat).grid(column=1, row=8)
        Label(self.vmat_tab,
              text='Analysis will analyze the file(s) according to the settings, \nsave a PDF in the same directory as the original file location and then open it.').grid(
            column=1, row=9)
        Label(self.vmat_tab, text='Save file:').grid(column=1, row=10)
        Label(self.vmat_tab, textvariable=self.vmat_pdf).grid(column=1, row=11)
        self.notebook.add(self.vmat_tab, text='VMAT')
        for child in self.vmat_tab.winfo_children():
            child.grid_configure(padx=10, pady=5)

    def init_pf(self):

        def load_file():
            f = filedialog.askopenfilename()
            self.pf_file.set(f)

        def analyze_pf():
            mlc_type = self.pf_mlc.get()
            if self.pf_filter.get():
                pf = picketfence.PicketFence(self.pf_file.get(), mlc=mlc_type, filter=3)
            else:
                pf = picketfence.PicketFence(self.pf_file.get(), mlc=mlc_type)
            atol = self.pf_atol.get() if self.pf_atol.get() == 0 else None
            pickets = self.pf_pickets.get() if self.pf_pickets.get() == 0 else None
            pf.analyze(tolerance=self.pf_tol.get(),
                       action_tolerance=atol,
                       num_pickets=pickets,
                       )
            fname = osp.join(self.pf_file.get().replace('.dcm', '.pdf'))
            fname = utilities.file_exists(fname)
            pf.publish_pdf(fname)
            self.pf_pdf.set(fname)
            utilities.open_path(fname)

        self.pf_tab = Frame(self.notebook)
        self.pf_filter = BooleanVar(value=False)
        self.pf_file = StringVar()
        self.pf_tol = DoubleVar(value=0.5)
        self.pf_atol = DoubleVar(value=0.25)
        self.pf_pickets = IntVar(value=10)
        self.pf_pdf = StringVar()
        self.pf_mlc = StringVar()
        Checkbutton(self.pf_tab, text='Apply median filter', variable=self.pf_filter).grid(column=1, row=3)
        Button(self.pf_tab, text='Load File...', command=load_file).grid(column=1, row=1)
        Label(self.pf_tab, text='File:').grid(column=1, row=2)
        Label(self.pf_tab, textvariable=self.pf_file).grid(column=2, row=2)
        Label(self.pf_tab, text='Tolerance (mm):').grid(column=1, row=4)
        Entry(self.pf_tab, width=7, textvariable=self.pf_tol).grid(column=2, row=4)
        Label(self.pf_tab, text='Action Tolerance (mm):').grid(column=1, row=5)
        Entry(self.pf_tab, width=7, textvariable=self.pf_atol).grid(column=2, row=5)
        Label(self.pf_tab, text='Number of pickets:').grid(column=1, row=6)
        Entry(self.pf_tab, width=7, textvariable=self.pf_pickets).grid(column=2, row=6)
        Label(self.pf_tab, text='MLC type:').grid(column=1, row=7)
        Combobox(self.pf_tab, values=list(picketfence.MLCs.keys()), textvariable=self.pf_mlc, state='readonly').grid(column=2, row=7)
        Button(self.pf_tab, text='Analyze', command=analyze_pf).grid(column=1, row=8)
        Label(self.pf_tab, text='Analysis will analyze the file according to the settings, \nsave a PDF in the same directory as the original file location and then open it.').grid(column=1, row=9)
        self.notebook.add(self.pf_tab, text='Picket Fence')
        for child in self.pf_tab.winfo_children():
            child.grid_configure(padx=10, pady=5)

    def init_catphan(self):

        def load_dir():
            f = filedialog.askdirectory()
            self.ct_file.set(f)

        def load_zip():
            f = filedialog.askopenfilename()
            self.ct_file.set(f)

        def analyze_cbct():<commit_msg>fix picket fence gui new mlc class<commit_after>import itertools
from tkinter import Label, Button, StringVar, BooleanVar, DoubleVar, IntVar, Checkbutton, Tk
from tkinter.ttk import Frame, Notebook, Combobox, Entry
from tkinter import filedialog
from tkinter import messagebox
import os.path as osp
import webbrowser

from . import picketfence, vmat, ct, log_analyzer, starshot, planar_imaging, __version__, winston_lutz, utilities


class PylinacGUI(Frame):

    def __init__(self, master=None):
        super().__init__(master)
        self.pack()
        self.notebook = Notebook(self)
        self.init_pf()
        self.init_vmat()
        self.init_catphan()
        self.init_logs()
        # self.init_tg51()
        self.init_star()
        self.init_planar_imaging()
        self.init_winstonlutz()
        self.init_help()
        for child in self.winfo_children():
            child.grid_configure(padx=10, pady=10)

    def init_help(self):

        def upload():
            webbrowser.open('https://www.dropbox.com/request/YKRu4AmuPsXu55uQq761')

        def gotoforum():
            webbrowser.open('https://groups.google.com/forum/#!forum/pylinac')

        def gotogithub():
            webbrowser.open('https://github.com/jrkerns/pylinac')

        def gotortd():
            webbrowser.open('https://pylinac.readthedocs.io/en/latest/')

        self.help_tab = Frame(self.notebook)
        Label(self.help_tab, text='Having trouble?\nWant to donate your images for program improvement?\nUpload them below')
        Button(self.help_tab, text='Upload Files', command=upload)
        Label(self.help_tab, text='Complete documentation is available on ReadTheDocs')
        Button(self.help_tab, text='ReadTheDocs', command=gotortd)
        Label(self.help_tab, text='Help is also available in the Pylinac forum')
        Button(self.help_tab, text='Go to forum', command=gotoforum)
        Label(self.help_tab, text='The source code of this program and all analyses is available on Github')
        Button(self.help_tab, text='Github', command=gotogithub)
        self.notebook.add(self.help_tab, text='Help/Upload Images')
        for child in self.help_tab.winfo_children():
            child.grid_configure(padx=10, pady=5)

    def init_vmat(self):

        def load_open():
            f = filedialog.askopenfilename()
            self.vmat_openimg.set(f)

        def load_dmlc():
            f = filedialog.askopenfilename()
            self.vmat_dmlcimg.set(f)

        def analyze_vmat():
            images = (self.vmat_openimg.get(), self.vmat_dmlcimg.get())
            if self.vmat_test.get() == 'DRGS':
                v = vmat.DRGS(image_paths=images)
            else:
                v = vmat.DRMLC(image_paths=images)
            v.analyze(tolerance=self.vmat_tol.get())
            fname = osp.join(self.vmat_dmlcimg.get().replace('.dcm', '.pdf'))
            fname = utilities.file_exists(fname)
            v.publish_pdf(fname)
            self.vmat_pdf.set(fname)
            utilities.open_path(fname)

        self.vmat_tab = Frame(self.notebook)
        self.vmat_openimg = StringVar()
        self.vmat_dmlcimg = StringVar()
        self.vmat_test = StringVar(value='DRGS')
        self.vmat_tol = DoubleVar(value=1.5)
        self.vmat_pdf = StringVar()
        Button(self.vmat_tab, text='Load Open Image...', command=load_open).grid(column=1, row=1)
        Button(self.vmat_tab, text='Load DMLC Image...', command=load_dmlc).grid(column=1, row=3)
        Label(self.vmat_tab, textvariable=self.vmat_openimg).grid(column=1, row=2)
        Label(self.vmat_tab, textvariable=self.vmat_dmlcimg).grid(column=1, row=4)
        Label(self.vmat_tab, text='Test type:').grid(column=1, row=5)
        Combobox(self.vmat_tab, values=('DRGS', 'DRMLC'), textvariable=self.vmat_test).grid(column=2, row=5)
        Label(self.vmat_tab, text='Tolerance (%):').grid(column=1, row=6)
        Entry(self.vmat_tab, width=7, textvariable=self.vmat_tol).grid(column=2, row=6)
        Button(self.vmat_tab, text='Analyze', command=analyze_vmat).grid(column=1, row=8)
        Label(self.vmat_tab,
              text='Analysis will analyze the file(s) according to the settings, \nsave a PDF in the same directory as the original file location and then open it.').grid(
            column=1, row=9)
        Label(self.vmat_tab, text='Save file:').grid(column=1, row=10)
        Label(self.vmat_tab, textvariable=self.vmat_pdf).grid(column=1, row=11)
        self.notebook.add(self.vmat_tab, text='VMAT')
        for child in self.vmat_tab.winfo_children():
            child.grid_configure(padx=10, pady=5)

    def init_pf(self):

        def load_file():
            f = filedialog.askopenfilename()
            self.pf_file.set(f)

        def analyze_pf():
            mlc_type = self.pf_mlc.get()
            if self.pf_filter.get():
                pf = picketfence.PicketFence(self.pf_file.get(), mlc=mlc_type, filter=3)
            else:
                pf = picketfence.PicketFence(self.pf_file.get(), mlc=mlc_type)
            atol = self.pf_atol.get() if self.pf_atol.get() == 0 else None
            pickets = self.pf_pickets.get() if self.pf_pickets.get() == 0 else None
            pf.analyze(tolerance=self.pf_tol.get(),
                       action_tolerance=atol,
                       num_pickets=pickets,
                       )
            fname = osp.join(self.pf_file.get().replace('.dcm', '.pdf'))
            fname = utilities.file_exists(fname)
            pf.publish_pdf(fname)
            self.pf_pdf.set(fname)
            utilities.open_path(fname)

        self.pf_tab = Frame(self.notebook)
        self.pf_filter = BooleanVar(value=False)
        self.pf_file = StringVar()
        self.pf_tol = DoubleVar(value=0.5)
        self.pf_atol = DoubleVar(value=0.25)
        self.pf_pickets = IntVar(value=10)
        self.pf_pdf = StringVar()
        self.pf_mlc = StringVar()
        mlc_list = []
        for mlc in picketfence.MLC:
            mlc_list.append(mlc.value.get('name'))
        Checkbutton(self.pf_tab, text='Apply median filter', variable=self.pf_filter).grid(column=1, row=3)
        Button(self.pf_tab, text='Load File...', command=load_file).grid(column=1, row=1)
        Label(self.pf_tab, text='File:').grid(column=1, row=2)
        Label(self.pf_tab, textvariable=self.pf_file).grid(column=2, row=2)
        Label(self.pf_tab, text='Tolerance (mm):').grid(column=1, row=4)
        Entry(self.pf_tab, width=7, textvariable=self.pf_tol).grid(column=2, row=4)
        Label(self.pf_tab, text='Action Tolerance (mm):').grid(column=1, row=5)
        Entry(self.pf_tab, width=7, textvariable=self.pf_atol).grid(column=2, row=5)
        Label(self.pf_tab, text='Number of pickets:').grid(column=1, row=6)
        Entry(self.pf_tab, width=7, textvariable=self.pf_pickets).grid(column=2, row=6)
        Label(self.pf_tab, text='MLC type:').grid(column=1, row=7)
        Combobox(self.pf_tab, values=mlc_list, textvariable=self.pf_mlc, state='readonly').grid(column=2, row=7)
        Button(self.pf_tab, text='Analyze', command=analyze_pf).grid(column=1, row=8)
        Label(self.pf_tab, text='Analysis will analyze the file according to the settings, \nsave a PDF in the same directory as the original file location and then open it.').grid(column=1, row=9)
        self.notebook.add(self.pf_tab, text='Picket Fence')
        for child in self.pf_tab.winfo_children():
            child.grid_configure(padx=10, pady=5)

    def init_catphan(self):

        def load_dir():
            f = filedialog.askdirectory()
            self.ct_file.set(f)

        def load_zip():
            f = filedialog.askopenfilename()
            self.ct_file.set(f)

        def analyze_cbct():
{'fraction_non_alphanumeric': 0.1302736787362673, 'fraction_numerical': 0.011831242280439446, 'mean_word_length': 2.7549426409567976, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 8, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5065680', 'n_tokens_mistral': 5294, 'n_tokens_neox': 5156, 'n_words': 905}