# Path: basic_editor/scrolled_text.py
# class ScrolledText(tkinter.Text):
#     def __init__(self, master=None, **kw):
#         frame = tkinter.Frame(master)
#         frame.rowconfigure(0, weight=1)
#         frame.columnconfigure(0, weight=1)
# 
#         xscrollbar = tkinter.Scrollbar(frame, orient=tkinter.HORIZONTAL)
#         yscrollbar = tkinter.Scrollbar(frame, orient=tkinter.VERTICAL)
# 
#         frame.grid(row=0, column=0, sticky=tkinter.NSEW)
#         xscrollbar.grid(row=1, column=0, sticky=tkinter.EW)
#         yscrollbar.grid(row=0, column=1, sticky=tkinter.NS)
# 
#         _defaults_options = {"wrap": tkinter.NONE, "undo": tkinter.YES}
#         options = _defaults_options.copy()
#         options.update(kw)
#         options.update({'yscrollcommand': yscrollbar.set})
#         options.update({'xscrollcommand': xscrollbar.set})
# 
#         tkinter.Text.__init__(self, frame, **options)
# 
#         self.grid(row=0, column=0, sticky=tkinter.NSEW)
# 
#         xscrollbar.config(command=self.xview)
#         yscrollbar.config(command=self.yview)
# 
#         self.bind('<Control-KeyPress-a>', self.event_select_all)
#         self.bind('<Control-KeyPress-x>', self.event_cut)
#         self.bind('<Control-KeyPress-c>', self.event_copy)
#         self.bind('<Control-KeyPress-v>', self.event_paste)
# 
#     def event_select_all(self, event=None):
#         log.critical("Select all.")
#         self.tag_add(tkinter.SEL, "1.0", tkinter.END)
#         self.mark_set(tkinter.INSERT, "1.0")
#         self.see(tkinter.INSERT)
#         return "break"
# 
#     def event_cut(self, event=None):
#         if self.tag_ranges(tkinter.SEL):
#             self.event_copy()
#             self.delete(tkinter.SEL_FIRST, tkinter.SEL_LAST)
#         return "break"
# 
#     def event_copy(self, event=None):
#         if self.tag_ranges(tkinter.SEL):
#             text = self.get(tkinter.SEL_FIRST, tkinter.SEL_LAST)
#             self.clipboard_clear()
#             self.clipboard_append(text)
#         return "break"
# 
#     def event_paste(self, event=None):
#         text = self.selection_get(selection='CLIPBOARD')
#         if text:
#             self.insert(tkinter.INSERT, text)
#             self.tag_remove(tkinter.SEL, '1.0', tkinter.END)
#             self.see(tkinter.INSERT)
#         return "break"
# 
#     def __str__(self):
#         return str(self.frame)
# 
#     def save_position(self):
#         """
#         save cursor and scroll position
#         """
#         # save text cursor position:
#         self.old_text_pos = self.index(tkinter.INSERT)
#         # save scroll position:
#         self.old_first, self.old_last = self.yview()
# 
#     def restore_position(self):
#         """
#         restore cursor and scroll position
#         """
#         # restore text cursor position:
#         self.mark_set(tkinter.INSERT, self.old_text_pos)
#         # restore scroll position:
#         self.yview_moveto(self.old_first)
# 
# Path: basic_editor/status_bar.py
# class MultiStatusBar(tkinter.Frame):
#     """
#     code from idlelib.MultiStatusBar.MultiStatusBar
#     """
# 
#     def __init__(self, master, **kw):
#         tkinter.Frame.__init__(self, master, **kw)
#         self.labels = {}
# 
#     def set_label(self, name, text='', side=tkinter.LEFT):
#         if name not in self.labels:
#             label = tkinter.Label(self, bd=1, relief=tkinter.SUNKEN, anchor=tkinter.W)
#             label.pack(side=side)
#             self.labels[name] = label
#         else:
#             label = self.labels[name]
#         label.config(text=text)


import logging
import sys
import tkinter
from dragonlib.utils.logging_utils import pformat_program_dump
from basic_editor.scrolled_text import ScrolledText
from basic_editor.status_bar import MultiStatusBar
    Some code borrowed from Python IDLE

    :created: 2014 by Jens Diemer - www.jensdiemer.de
    :copyleft: 2014 by the DragonPy team, see AUTHORS for more details.
    :license: GNU GPL v3 or above, see LICENSE for more details.
"""






log = logging.getLogger(__name__)


class TokenWindow:
    def __init__(self, cfg, master):
        self.cfg = cfg
        self.machine_api = self.cfg.machine_api

        self.root = tkinter.Toplevel(master)
        self.root.geometry("+%d+%d" % (
            master.winfo_rootx() + master.winfo_width(),
            master.winfo_y()  # FIXME: Different on linux.
        ))
        self.root.columnconfigure(0, weight=1)
        self.root.rowconfigure(0, weight=1)
        self.base_title = f"{self.cfg.MACHINE_NAME} - Tokens"
        self.root.title(self.base_title)


# Path: basic_editor/scrolled_text.py
# class ScrolledText(tkinter.Text):
#     def __init__(self, master=None, **kw):
#         frame = tkinter.Frame(master)
#         frame.rowconfigure(0, weight=1)
#         frame.columnconfigure(0, weight=1)
# 
#         xscrollbar = tkinter.Scrollbar(frame, orient=tkinter.HORIZONTAL)
#         yscrollbar = tkinter.Scrollbar(frame, orient=tkinter.VERTICAL)
# 
#         frame.grid(row=0, column=0, sticky=tkinter.NSEW)
#         xscrollbar.grid(row=1, column=0, sticky=tkinter.EW)
#         yscrollbar.grid(row=0, column=1, sticky=tkinter.NS)
# 
#         _defaults_options = {"wrap": tkinter.NONE, "undo": tkinter.YES}
#         options = _defaults_options.copy()
#         options.update(kw)
#         options.update({'yscrollcommand': yscrollbar.set})
#         options.update({'xscrollcommand': xscrollbar.set})
# 
#         tkinter.Text.__init__(self, frame, **options)
# 
#         self.grid(row=0, column=0, sticky=tkinter.NSEW)
# 
#         xscrollbar.config(command=self.xview)
#         yscrollbar.config(command=self.yview)
# 
#         self.bind('<Control-KeyPress-a>', self.event_select_all)
#         self.bind('<Control-KeyPress-x>', self.event_cut)
#         self.bind('<Control-KeyPress-c>', self.event_copy)
#         self.bind('<Control-KeyPress-v>', self.event_paste)
# 
#     def event_select_all(self, event=None):
#         log.critical("Select all.")
#         self.tag_add(tkinter.SEL, "1.0", tkinter.END)
#         self.mark_set(tkinter.INSERT, "1.0")
#         self.see(tkinter.INSERT)
#         return "break"
# 
#     def event_cut(self, event=None):
#         if self.tag_ranges(tkinter.SEL):
#             self.event_copy()
#             self.delete(tkinter.SEL_FIRST, tkinter.SEL_LAST)
#         return "break"
# 
#     def event_copy(self, event=None):
#         if self.tag_ranges(tkinter.SEL):
#             text = self.get(tkinter.SEL_FIRST, tkinter.SEL_LAST)
#             self.clipboard_clear()
#             self.clipboard_append(text)
#         return "break"
# 
#     def event_paste(self, event=None):
#         text = self.selection_get(selection='CLIPBOARD')
#         if text:
#             self.insert(tkinter.INSERT, text)
#             self.tag_remove(tkinter.SEL, '1.0', tkinter.END)
#             self.see(tkinter.INSERT)
#         return "break"
# 
#     def __str__(self):
#         return str(self.frame)
# 
#     def save_position(self):
#         """
#         save cursor and scroll position
#         """
#         # save text cursor position:
#         self.old_text_pos = self.index(tkinter.INSERT)
#         # save scroll position:
#         self.old_first, self.old_last = self.yview()
# 
#     def restore_position(self):
#         """
#         restore cursor and scroll position
#         """
#         # restore text cursor position:
#         self.mark_set(tkinter.INSERT, self.old_text_pos)
#         # restore scroll position:
#         self.yview_moveto(self.old_first)
# 
# Path: basic_editor/status_bar.py
# class MultiStatusBar(tkinter.Frame):
#     """
#     code from idlelib.MultiStatusBar.MultiStatusBar
#     """
# 
#     def __init__(self, master, **kw):
#         tkinter.Frame.__init__(self, master, **kw)
#         self.labels = {}
# 
#     def set_label(self, name, text='', side=tkinter.LEFT):
#         if name not in self.labels:
#             label = tkinter.Label(self, bd=1, relief=tkinter.SUNKEN, anchor=tkinter.W)
#             label.pack(side=side)
#             self.labels[name] = label
#         else:
#             label = self.labels[name]
#         label.config(text=text)


# Path: basic_editor/token_window.py
import logging
import sys
import tkinter
from dragonlib.utils.logging_utils import pformat_program_dump
from basic_editor.scrolled_text import ScrolledText
from basic_editor.status_bar import MultiStatusBar

    Some code borrowed from Python IDLE

    :created: 2014 by Jens Diemer - www.jensdiemer.de
    :copyleft: 2014 by the DragonPy team, see AUTHORS for more details.
    :license: GNU GPL v3 or above, see LICENSE for more details.
"""






log = logging.getLogger(__name__)


class TokenWindow:
    def __init__(self, cfg, master):
        self.cfg = cfg
        self.machine_api = self.cfg.machine_api

        self.root = tkinter.Toplevel(master)
        self.root.geometry("+%d+%d" % (
            master.winfo_rootx() + master.winfo_width(),
            master.winfo_y()  # FIXME: Different on linux.
        ))
        self.root.columnconfigure(0, weight=1)
        self.root.rowconfigure(0, weight=1)
        self.base_title = f"{self.cfg.MACHINE_NAME} - Tokens"
        self.root.title(self.base_title)


        self.text = ScrolledText(