<commit_before>package main

import (
	"fmt"
	"path/filepath"

	"github.com/mattn/go-gtk/gdk"
	"github.com/mattn/go-gtk/gtk"
)

const (
	cellSize  = 100
	lineWidth = 4
	largeFont = "DejaVu Sans 28"
	smallFont = "DejaVu Sans 12"
)

var (
	table     *gtk.Table
	cellLabel [][]*gtk.Label
	noteLabel [][]*gtk.Label

	white = gdk.NewColor("white")
)

func initUI() {
	gtk.Init(nil)
	size := puzzle.Size()
	table = gtk.NewTable(uint(size), uint(size), true)
	cellLabel = make([][]*gtk.Label, size)
	noteLabel = make([][]*gtk.Label, size)
	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetTitle(fmt.Sprintf("KenKen %s", filepath.Base(path)))
	window.Connect("destroy", gtk.MainQuit)
	window.SetResizable(false)
	for y := 0; y < size; y++ {
		cellLabel[y] = make([]*gtk.Label, size)
		noteLabel[y] = make([]*gtk.Label, size)
		for x := 0; x < size; x++ {
			attachCell(x, y)
		}
	}
	window.Add(table)
	window.Connect("configure-event", drawCages)
	window.Connect("expose-event", drawCages)
	window.ShowAll()
}

func runUI() {
	gtk.Main()
}

func attachCell(x, y int) {
	vbox := gtk.NewVBox(false, 0)
	vbox.SetSizeRequest(cellSize, cellSize)

	// Clue, if any
	label := gtk.NewLabel(clueString(x, y))
	label.ModifyFontEasy(smallFont)
	align := gtk.NewAlignment(0, 0, 0, 0)
	align.Add(label)
	vbox.PackStart(align, false, false, 0)

	// Cell contents
	str := ""
	if isConstant(x, y) {
		str = fmt.Sprintf("%d", puzzle.Answer[y][x])
	}
	label = gtk.NewLabel(str)
	cellLabel[y][x] = label
	label.ModifyFontEasy(largeFont)
	label.ModifyFG(gtk.STATE_INSENSITIVE, white)
	vbox.Add(label)

	// Notes
	label = gtk.NewLabel("")
	noteLabel[y][x] = label
	label.ModifyFontEasy(smallFont)
	align = gtk.NewAlignment(1, 0, 0, 0)
	align.Add(label)
	vbox.PackEnd(align, false, false, 0)

	button := gtk.NewButton()
	button.SetRelief(gtk.RELIEF_NONE)
	if isConstant(x, y) {
		button.SetSensitive(false)
	}
	button.Add(vbox)
	button.Connect("enter-notify-event", func() { button.GrabFocus() })
	button.Connect("expose-event", drawCages)
	button.Connect("clicked", click(x, y))
	button.Connect("key-press-event", keypress(x, y))

	table.AttachDefaults(button, uint(x), uint(x+1), uint(y), uint(y+1))
}

func setCellLabel(x, y, n int) {
	cellLabel[y][x].SetText(fmt.Sprintf("%d", n))
}

func clearCellLabel(x, y int) {
	cellLabel[y][x].SetText("")
}

func setNoteLabel(x, y int, digits string) {
	noteLabel[y][x].SetText(digits)
}

func drawCages() {
	a := table.GetAllocation()
	size := puzzle.Size()
	w := a.Width / size
	h := a.Height / size
	d := table.GetWindow().GetDrawable()
	gc := gdk.NewGC(d)
	gc.SetRgbFgColor(white)

	t := lineWidth

	d.DrawRectangle(gc, true, 0, 0, t, a.Height)
	d.DrawRectangle(gc, true, 0, 0, a.Width, t)
	d.DrawRectangle(gc, true, 0, a.Height-t, a.Width, t)
	d.DrawRectangle(gc, true, a.Width-t, 0, t, a.Height)

	for j := 0; j < size; j++ {
		y := j*h - t/2
		for i := 0; i < size; i++ {
			x := i*w - t/2
			if i > 0 && puzzle.Vertical[j][i-1] {
				d.DrawRectangle(gc, true, x, y, t, h+t/2)
			}
			if j > 0 && puzzle.Horizontal[i][j-1] {
				d.DrawRectangle(gc, true, x, y, w+t/2, t)
			}
		}
	}
}

var winning = false

func winnerWinner() {
	if winning {
		return
	}
	winning = true
	dialog := gtk.NewDialog()
	dialog.SetSizeRequest(200, 50)
	dialog.SetTitle("Congratulations!")
	button := gtk.NewButtonWithLabel("Done")
	button.Connect("clicked", gtk.MainQuit)
	dialog.GetVBox().Add(button)
	dialog.ShowAll()
}<commit_msg>Use gtk.NewMessageDialogWithMarkup for "game over"<commit_after>package main

import (
	"fmt"
	"path/filepath"

	"github.com/mattn/go-gtk/gdk"
	"github.com/mattn/go-gtk/gtk"
)

const (
	cellSize  = 100
	lineWidth = 4
	largeFont = "DejaVu Sans 28"
	smallFont = "DejaVu Sans 12"
)

var (
	table     *gtk.Table
	cellLabel [][]*gtk.Label
	noteLabel [][]*gtk.Label

	white = gdk.NewColor("white")
)

func initUI() {
	gtk.Init(nil)
	size := puzzle.Size()
	table = gtk.NewTable(uint(size), uint(size), true)
	cellLabel = make([][]*gtk.Label, size)
	noteLabel = make([][]*gtk.Label, size)
	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetTitle(fmt.Sprintf("KenKen %s", filepath.Base(path)))
	window.Connect("destroy", gtk.MainQuit)
	window.SetResizable(false)
	for y := 0; y < size; y++ {
		cellLabel[y] = make([]*gtk.Label, size)
		noteLabel[y] = make([]*gtk.Label, size)
		for x := 0; x < size; x++ {
			attachCell(x, y)
		}
	}
	window.Add(table)
	window.Connect("configure-event", drawCages)
	window.Connect("expose-event", drawCages)
	window.ShowAll()
}

func runUI() {
	gtk.Main()
}

func attachCell(x, y int) {
	vbox := gtk.NewVBox(false, 0)
	vbox.SetSizeRequest(cellSize, cellSize)

	// Clue, if any
	label := gtk.NewLabel(clueString(x, y))
	label.ModifyFontEasy(smallFont)
	align := gtk.NewAlignment(0, 0, 0, 0)
	align.Add(label)
	vbox.PackStart(align, false, false, 0)

	// Cell contents
	str := ""
	if isConstant(x, y) {
		str = fmt.Sprintf("%d", puzzle.Answer[y][x])
	}
	label = gtk.NewLabel(str)
	cellLabel[y][x] = label
	label.ModifyFontEasy(largeFont)
	label.ModifyFG(gtk.STATE_INSENSITIVE, white)
	vbox.Add(label)

	// Notes
	label = gtk.NewLabel("")
	noteLabel[y][x] = label
	label.ModifyFontEasy(smallFont)
	align = gtk.NewAlignment(1, 0, 0, 0)
	align.Add(label)
	vbox.PackEnd(align, false, false, 0)

	button := gtk.NewButton()
	button.SetRelief(gtk.RELIEF_NONE)
	if isConstant(x, y) {
		button.SetSensitive(false)
	}
	button.Add(vbox)
	button.Connect("enter-notify-event", func() { button.GrabFocus() })
	button.Connect("expose-event", drawCages)
	button.Connect("clicked", click(x, y))
	button.Connect("key-press-event", keypress(x, y))

	table.AttachDefaults(button, uint(x), uint(x+1), uint(y), uint(y+1))
}

func setCellLabel(x, y, n int) {
	cellLabel[y][x].SetText(fmt.Sprintf("%d", n))
}

func clearCellLabel(x, y int) {
	cellLabel[y][x].SetText("")
}

func setNoteLabel(x, y int, digits string) {
	noteLabel[y][x].SetText(digits)
}

func drawCages() {
	a := table.GetAllocation()
	size := puzzle.Size()
	w := a.Width / size
	h := a.Height / size
	d := table.GetWindow().GetDrawable()
	gc := gdk.NewGC(d)
	gc.SetRgbFgColor(white)

	t := lineWidth

	d.DrawRectangle(gc, true, 0, 0, t, a.Height)
	d.DrawRectangle(gc, true, 0, 0, a.Width, t)
	d.DrawRectangle(gc, true, 0, a.Height-t, a.Width, t)
	d.DrawRectangle(gc, true, a.Width-t, 0, t, a.Height)

	for j := 0; j < size; j++ {
		y := j*h - t/2
		for i := 0; i < size; i++ {
			x := i*w - t/2
			if i > 0 && puzzle.Vertical[j][i-1] {
				d.DrawRectangle(gc, true, x, y, t, h+t/2)
			}
			if j > 0 && puzzle.Horizontal[i][j-1] {
				d.DrawRectangle(gc, true, x, y, w+t/2, t)
			}
		}
	}
}

var winning = false

func winnerWinner() {
	if winning {
		return
	}
	winning = true
	dialog := gtk.NewMessageDialogWithMarkup(
		table.GetTopLevelAsWindow(), gtk.DIALOG_MODAL,
		gtk.MESSAGE_INFO, gtk.BUTTONS_OK, "<b>Correct!</b>",
	)
	dialog.Response(gtk.MainQuit)
	dialog.Run()
}
{'fraction_non_alphanumeric': 0.18509370913845707, 'fraction_numerical': 0.0120586953363359, 'mean_word_length': 4.125837676842889, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 9, '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': '2079290', 'n_tokens_mistral': 3099, 'n_tokens_neox': 2903, 'n_words': 572}