harbor run -t openthoughts/tasktrove-mix-h10-reward-staged-v2-mix-h10-staged-2245harbor download openthoughts/tasktrove-mix-h10-reward-staged-v2-mix-h10-staged-2245solution file
import tkinter as tk
from tkinter import CURRENT, END, INSERT, SEL, WORD, X, SEL_FIRST, SEL_LAST
from tkinter import scrolledtext
from typing import Union
from Cursorline import Cursorline
from FinishReasonIcon import FinishReasonIcon
from Notebook import Notebook
from ThoughttreeConfig import conf
class Sheet(tk.scrolledtext.ScrolledText):
FONT_NAME_MONOSPACE = "monospace"
# FONT_NAME_MONOSPACE = "DejaVu Sans Mono ExCond"
# FONT_NAME_MONOSPACE = "DejaVu Sans Mono"
FONT_NAME_PROPORTIONAL = "sans-serif"
# FONT_NAME_PROPORTIONAL = "DejaVu Sans"
# FONT_NAME_PROPORTIONAL = "DejaVu Sans Mono ExCond"
FONT = (FONT_NAME_PROPORTIONAL, 11)
def __init__(self, master=None, text="", scrollbar=True, padx=0, pady=0, height=0, **kw):
height = height or len(text.splitlines())
background = 'white'
# background = next_pastel_rainbow_color()
tk.scrolledtext.ScrolledText.__init__(
self, master, undo=True, wrap=WORD, padx=padx, pady=pady, background=background,
width=80, height=height, insertwidth=4, font=Sheet.FONT,
border=0, borderwidth=0, highlightthickness=0,
selectbackground="#66a2d4", selectforeground="white", **kw)
def jump_to_limit(e: tk.Event):
top, bottom = self.vbar.get()
if e.keysym == 'Prior' and top == 0.0:
limit = "1.0"
elif e.keysym == 'Next' and bottom == 1.0:
limit = tk.END
else:
return
self.mark_set(tk.INSERT, limit)
self.see(tk.INSERT)
if scrollbar:
self.vbar.config(width=18, takefocus=False, borderwidth=2)
else:
self.vbar.pack_forget()
self.scroll_output = conf.scroll_output
self.bind('<Prior>', jump_to_limit)
self.bind('<Next>', jump_to_limit)
self.pack(pady=0, fill=X, expand=True)
name, size = self.cget("font").rsplit(None, 1)
self.tag_configure('bold', font=(name, int(size), "bold"))
self.tag_configure('strikethrough', overstrike=True)
self.tag_configure("assistant", background="#F0F0F0", selectbackground="#4682b4", selectforeground="white")
Cursorline(self)
self.insert(END, text)
def undo_separator(self):
self.edit_separator()
def bold(self):
self.tag_selection('bold')
def strikethrough(self):
self.tag_selection('strikethrough')
def tag_selection(self, tag):
def min_index(i1, i2):
if self.compare(i1, '<=', i2):
return i1
else:
return i2
def max_index(i1, i2):
if self.compare(i1, '>=', i2):
return i1
else:
return i2
def range_intersection(ranges, single_range):
intersections = []
for index_range in ranges:
if self.compare(max_index(index_range[0], single_range[0]), "<", min_index(index_range[1], single_range[1])):
intersections.append((max_index(index_range[0], single_range[0]), min_index(index_range[1], single_range[1])))
return intersections
if not self.tag_ranges(SEL):
return
tag_ranges = self.tag_ranges(tag)
iters = [iter(tag_ranges)] * 2
ranges = list(zip(*iters))
sel = (self.index(SEL_FIRST), self.index(SEL_LAST))
tag_in_selection = range_intersection(ranges, sel)
if tag_in_selection:
self.tag_remove(tag, *sel)
else:
self.tag_add(tag, *sel)
def transfer_content(self, to_sheet):
content = self.get("1.0", tk.END)
to_sheet.insert("1.0", content)
for tag in self.tag_names():
ranges = self.tag_ranges(tag)
for i in range(0, len(ranges), 2):
to_sheet.tag_add(tag, ranges[i], ranges[i + 1])
to_sheet.tag_config(tag, **{k: v[4] for k, v in self.tag_configure(tag).items() if v[4]})
for name in self.window_names():
index = self.index(name)
window = self.nametowidget(name)
to_sheet.window_create(index, window=window)
def fork(self, index=INSERT, root=False):
index = self.index(index)
def next_level(hierarchical_id):
if hierarchical_id:
hierarchical_id = hierarchical_id.split(' ', 1)[0]
levels = hierarchical_id.split('.') + ['1']
else:
levels = ['1']
return '.'.join(levels)
def next_equal(hierarchical_id):
if hierarchical_id:
hierarchical_id = hierarchical_id.split(' ', 1)[0]
levels = hierarchical_id.split('.')
else:
levels = ['0']
levels = levels[:-1] + [str(int(levels[-1]) + 1)]
return '.'.join(levels)
def new_sibling(sibling_notebook):
last_tab_label = sibling_notebook.tab(len(sibling_notebook.tabs()) - 1, "text")
return next_equal(last_tab_label)
def new_child(parent):
if parent:
parent_tab_label = parent.tab(parent.select(), "text")
else:
parent_tab_label = ""
return next_level(parent_tab_label)
has_leading_text = bool(self.get("1.0", index).strip())
trailing_text = self.get(index, END)
trailing_text = trailing_text.rstrip()
parent = self.find_parent(Notebook)
new_notebook = not parent or has_leading_text
if new_notebook:
notebook = Notebook(self, height=self.winfo_height(), width=self.winfo_width())
sheet = Sheet(notebook, trailing_text, scrollbar=True)
notebook.
Complete the code above, taking into account the cross-file context provided. Your solution must work correctly with the related files in the project.
Place your complete solution in /app/solution.py