<commit_before>#!/usr/bin/env python

import json
import pprint
try:
    from Tkinter import *  # Python 2
    import ttk
except ImportError:
    from tkinter import *  # Python 3
    from tkinter import ttk


class MainInterface(object):
    def __init__(self, obj):
        self.obj = obj
        self.item_values = {}

        self.window = Tk()
        self.window.title("Python Data Visualizer")
        self.window.bind("<Escape>", lambda e: e.widget.quit())
        self.window.geometry('700x500')
        self.window.grid_rowconfigure(0, weight=1)
        self.window.grid_columnconfigure(0, weight=1)

        self.pane = PanedWindow(orient=VERTICAL)
        self.pane.grid(row=0, column=0, sticky="nesw", in_=self.window)
        self.pane.grid_rowconfigure(0, weight=1)
        self.pane.grid_columnconfigure(0, weight=1)

        tree_view_frame = self.mk_tree_view(self.pane)
        self.tree_set_children('', obj)
        self.pane.add(tree_view_frame)

        value_view_frame = self.mk_value_view(self.pane)
        self.pane.add(value_view_frame)

    def mk_tree_view(self, master):
        """
        Construct the tree view frame.
        """
        tree_columns = (
            ("type", "Type"),
            ("value", "Value"),
        )

        frame = Frame(master)
        frame.grid_rowconfigure(0, weight=1)
        frame.grid_columnconfigure(0, weight=1)

        tree = ttk.Treeview(frame,
                            columns=[c[0] for c in tree_columns],
                            selectmode=BROWSE)
        for c in tree_columns:
            tree.heading(c[0], text=c[1])
        tree.bind('<<TreeviewSelect>>', self.ev_treeview_select)
        tree.bind('<<TreeviewOpen>>', self.ev_treeview_open)
        tree.grid(row=0, column=0, sticky="nsew", in_=frame)

        scrollbar = Scrollbar(frame, command=tree.yview)
        scrollbar.grid(row=0, column=1, sticky="ns", in_=frame)
        tree['yscrollcommand'] = scrollbar.set

        self.tree = tree
        return frame

    def mk_value_view(self, master):
        """
        Construct the value viewer frame.
        """
        frame = Frame(master, bg="#0000FF", bd=0)
        frame.grid_rowconfigure(0, weight=1)
        frame.grid_columnconfigure(0, weight=1)

        text = Text(frame)
        text.grid(row=0, column=0, sticky="nsew", in_=frame)

        scrollbar = Scrollbar(frame, command=text.yview)
        scrollbar.grid(row=0, column=1, sticky="ns", in_=frame)
        text['yscrollcommand'] = scrollbar.set

        self.text = text
        return frame

    def ev_treeview_select(self, ev):
        """
        <<TreeviewSelect>> event. When an item in the tree is selected, we
        update the Value view with a representation of the value that was
        selected.
        """
        item_id = self.tree.selection()[0]
        val_value = self.item_values[item_id]
        self.text.delete(1.0, END)
        self.text.insert("1.0", pprint.pformat(val_value))

    def ev_treeview_open(self, ev):
        """
        <<TreeviewOpen>> event. When an item in the tree is opened, we delete
        the placeholder in the tree and insert the child values of the selected
        item in the tree under the item.
        """
        item_id = self.tree.selection()[0]
        obj = self.item_values[item_id]
        self.tree_set_children(item_id, obj)

    def tree_set_row(self, obj_name, obj, parent='', depth=0):
        """
        Insert a row into the tree, determining the columns by the type of the
        object being added. A placeholder is added under the new item which
        makes it openable.
        """
        obj_type = type(obj).__name__
        obj_val = repr(obj)<commit_msg>Toggles for showing magic methods and raw values<commit_after>#!/usr/bin/env python

import json
import pprint
try:
    from Tkinter import *  # Python 2
    import ttk
except ImportError:
    from tkinter import *  # Python 3
    from tkinter import ttk


class MainInterface(object):
    def __init__(self, obj):
        self.obj = obj
        self.item_values = {}

        self.window = Tk()
        self.show_magic = IntVar()
        self.show_raw_value = IntVar()

        self.window.title("Python Data Visualizer")
        self.window.bind("<Escape>", lambda e: e.widget.quit())
        self.window.geometry('700x500')
        self.window.grid_rowconfigure(0, weight=1)
        self.window.grid_columnconfigure(0, weight=1)

        self.pane = PanedWindow(orient=VERTICAL)
        self.pane.grid(row=0, column=0, sticky="nesw", in_=self.window)
        self.pane.grid_rowconfigure(0, weight=1)
        self.pane.grid_columnconfigure(0, weight=1)

        options_frame = self.mk_options(self.pane)
        self.pane.add(options_frame)

        tree_view_frame = self.mk_tree_view(self.pane)
        self.tree_set_children('', obj)
        self.pane.add(tree_view_frame)

        value_view_frame = self.mk_value_view(self.pane)
        self.pane.add(value_view_frame)

    def mk_options(self, master):
        frame = Frame(master)
        c = Checkbutton(master, text="Show magic methods", variable=self.show_magic)
        c.grid(row=0, column=0, sticky="nesw", in_=frame)
        c = Checkbutton(master, text="Show raw value", variable=self.show_raw_value)
        c.grid(row=0, column=1, sticky="nesw", in_=frame)
        return frame

    def mk_tree_view(self, master):
        """
        Construct the tree view frame.
        """
        tree_columns = (
            ("type", "Type"),
            ("value", "Value"),
        )

        frame = Frame(master)
        frame.grid_rowconfigure(0, weight=1)
        frame.grid_columnconfigure(0, weight=1)

        tree = ttk.Treeview(frame,
                            columns=[c[0] for c in tree_columns],
                            selectmode=BROWSE)
        for c in tree_columns:
            tree.heading(c[0], text=c[1])
        tree.bind('<<TreeviewSelect>>', self.ev_treeview_select)
        tree.bind('<<TreeviewOpen>>', self.ev_treeview_open)
        tree.grid(row=0, column=0, sticky="nsew", in_=frame)

        scrollbar = Scrollbar(frame, command=tree.yview)
        scrollbar.grid(row=0, column=1, sticky="ns", in_=frame)
        tree['yscrollcommand'] = scrollbar.set

        self.tree = tree
        return frame

    def mk_value_view(self, master):
        """
        Construct the value viewer frame.
        """
        frame = Frame(master, bg="#0000FF", bd=0)
        frame.grid_rowconfigure(0, weight=1)
        frame.grid_columnconfigure(0, weight=1)

        text = Text(frame)
        text.grid(row=0, column=0, sticky="nsew", in_=frame)

        scrollbar = Scrollbar(frame, command=text.yview)
        scrollbar.grid(row=0, column=1, sticky="ns", in_=frame)
        text['yscrollcommand'] = scrollbar.set

        self.text = text
        return frame

    def ev_treeview_select(self, ev):
        """
        <<TreeviewSelect>> event. When an item in the tree is selected, we
        update the Value view with a representation of the value that was
        selected.
        """
        item_id = self.tree.selection()[0]
        val_value = self.item_values[item_id]
        self.text.delete(1.0, END)
        if self.show_raw_value.get() == 0:
            self.text.insert("1.0", pprint.pformat(val_value))
        else:
            self.text.insert("1.0", val_value)

    def ev_treeview_open(self, ev):
        """
        <<TreeviewOpen>> event. When an item in the tree is opened, we delete
        the placeholder in the tree and insert the child values of the selected
        item in the tree under the item.
        """
        item_id = self.tree.selection()[0]
        obj = self.item_values[item_id]
        self.tree_set_children(item_id, obj)

    def tree_set_row(self, obj_name, obj, parent='', depth=0):
        """
        Insert a row into the tree, determining the columns by the type of the
        object being added. A placeholder is added under the new item which
        makes it openable.
        """
        obj_type = type(obj).__name__
        obj_val = repr(obj)

        if self.show_magic.get() == 0 and obj_name.startswith("__"):
            return
{'fraction_non_alphanumeric': 0.115478515625, 'fraction_numerical': 0.012939453125, 'mean_word_length': 2.344081632653061, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4773232', 'n_tokens_mistral': 2615, 'n_tokens_neox': 2529, 'n_words': 590}