# Copyright(c) 2017, Dimitar Venkov
# @5devene, dimitar.ven@gmail.com
# www.badmonkeys.net

import clr

clr.AddReference('System.Windows.Forms')
clr.AddReference('System.Drawing')
from System.Drawing import Point, Color, Font
from System.Windows.Forms import *
from cStringIO import StringIO

str_file = StringIO()
size1 = [30, 23] #height, width

def tolist(obj1):
	if hasattr(obj1,"__iter__"): return obj1
	else: return [obj1]

def write_str(str1, GCL, str_file=str_file, size1=size1):
	ln1 = len(str1)
	if ln1 > size1[1]:
		size1[1] = ln1
	
	str_file.write("%s%s\n" % ("".join(GCL), str1) )

def list2str(l1, writeInd, GCL=None, GCint=-1, size1=size1):
	if GCL is None:
		GCL = []
	GCint += 1
	GCL.append(None)
	for i, x in enumerate(l1):
		GCL[GCint] = "[%i] " % i if writeInd else "  "
		if hasattr(x, "Id"): #is element
			write_str("%s        %i" % (x.ToString(), x.Id), GCL)
		elif hasattr(x, "__iter__"):
			if not x:
				write_str("Empty List", GCL)
			else:
				list2str(x, writeInd, GCL, GCint, size1)
		elif x is None:
			write_str("null", GCL)
		else:
			write_str(x.ToString(), GCL)
		size1[0] += 19
	GCL.pop(GCint)
	GCint -= 1

class WatchBox(Form):
	def __init__(self, t1):
		self.Text = "SpringNodes: Expandable Watch Window"
		self.BackColor = Color.FromArgb(40,40,40)
		self.ControlBox = False
		self.TopMost = True
		self.FormBorderStyle = FormBorderStyle.Sizable
		self.StartPosition = FormStartPosition.CenterScreen
		self.Resize += self.resize1
		self.text1 = None

		self.button1 = Button()
		self.button1.Text = 'Close'
		self.button1.Font = Font("Calibri", 10)
		self.button1.AutoSize = True
		self.button1.Width = 200
		self.button1.ForeColor = Color.FromArgb(234,234,234)
		self.button1.Click += self.save
		self.Controls.Add(self.button1)
		
		self.box1 = RichTextBox()
		self.box1.Multiline = True
		self.box1.Location = Point(5, 5)
		self.box1.Font = Font("Calibri", 12)
		self.box1.BackColor = Color.FromArgb(53,53,53)
		self.box1.ForeColor = Color.FromArgb(234,234,234)
		self.box1.DetectUrls = True
		self.box1.Text = t1
		self.Controls.Add(self.box1)

	def adjust_controls(self, height1, width1):
		if height1 > 800:
			height1 = 800
			self.box1.ScrollBars = RichTextBoxScrollBars.Vertical
		if width1 < 23 : width1 = 23
		if width1 > 88: width1 = 88
		self.Width = 10 + (width1 + 2) * 9 #character width seems to vary between PCs
		self.Height = height1 + 90
		self.box1.Width = self.Width - 17
		self.box1.Height = self.Height - 80
		self.button1.Location = Point(self.Width/2 - 103, self.Height - 70)
	
	def resize1(self, sender, event):
		if self.Width < 210: self.Width = 230
		if self.Height < 120: self.Height = 120
		self.box1.Width = self.Width - 17
		self.box1.Height = self.Height - 80
		self.button1.Location = Point(self.Width/2 - 103, self.Height - 70)
	
	def save(self, sender, event):
		self.text1 = self.box1.Text
		self.Close()

l1 = [] if IN[0] is None else tolist(IN[0])
list2str(l1, IN[1])
str_content = str_file.getvalue()
str_file.close()

width1 = 100
form = WatchBox(str_content)
form.adjust_controls(*size1)

Application.Run(form)
OUT = form.text1
Application.Exit()
form.Dispose()
[((7, 0, 7, 40), 'clr.AddReference', 'clr.AddReference', ({(7, 17, 7, 39): '"""System.Windows.Forms"""'}, {}), "('System.Windows.Forms')", False, 'import clr\n'), ((8, 0, 8, 34), 'clr.AddReference', 'clr.AddReference', ({(8, 17, 8, 33): '"""System.Drawing"""'}, {}), "('System.Drawing')", False, 'import clr\n'), ((13, 11, 13, 21), 'cStringIO.StringIO', 'StringIO', ({}, {}), '()', False, 'from cStringIO import StringIO\n'), ((52, 19, 52, 43), 'System.Drawing.Color.FromArgb', 'Color.FromArgb', ({(52, 34, 52, 36): '40', (52, 37, 52, 39): '40', (52, 40, 52, 42): '40'}, {}), '(40, 40, 40)', False, 'from System.Drawing import Point, Color, Font\n'), ((62, 22, 62, 41), 'System.Drawing.Font', 'Font', ({(62, 27, 62, 36): '"""Calibri"""', (62, 38, 62, 40): '10'}, {}), "('Calibri', 10)", False, 'from System.Drawing import Point, Color, Font\n'), ((65, 27, 65, 54), 'System.Drawing.Color.FromArgb', 'Color.FromArgb', ({(65, 42, 65, 45): '234', (65, 46, 65, 49): '234', (65, 50, 65, 53): '234'}, {}), '(234, 234, 234)', False, 'from System.Drawing import Point, Color, Font\n'), ((71, 23, 71, 34), 'System.Drawing.Point', 'Point', ({(71, 29, 71, 30): '5', (71, 32, 71, 33): '5'}, {}), '(5, 5)', False, 'from System.Drawing import Point, Color, Font\n'), ((72, 19, 72, 38), 'System.Drawing.Font', 'Font', ({(72, 24, 72, 33): '"""Calibri"""', (72, 35, 72, 37): '12'}, {}), "('Calibri', 12)", False, 'from System.Drawing import Point, Color, Font\n'), ((73, 24, 73, 48), 'System.Drawing.Color.FromArgb', 'Color.FromArgb', ({(73, 39, 73, 41): '53', (73, 42, 73, 44): '53', (73, 45, 73, 47): '53'}, {}), '(53, 53, 53)', False, 'from System.Drawing import Point, Color, Font\n'), ((74, 24, 74, 51), 'System.Drawing.Color.FromArgb', 'Color.FromArgb', ({(74, 39, 74, 42): '234', (74, 43, 74, 46): '234', (74, 47, 74, 50): '234'}, {}), '(234, 234, 234)', False, 'from System.Drawing import Point, Color, Font\n'), ((89, 26, 89, 69), 'System.Drawing.Point', 'Point', ({(89, 32, 89, 50): 'self.Width / 2 - 103', (89, 52, 89, 68): 'self.Height - 70'}, {}), '(self.Width / 2 - 103, self.Height - 70)', False, 'from System.Drawing import Point, Color, Font\n'), ((96, 26, 96, 69), 'System.Drawing.Point', 'Point', ({(96, 32, 96, 50): 'self.Width / 2 - 103', (96, 52, 96, 68): 'self.Height - 70'}, {}), '(self.Width / 2 - 103, self.Height - 70)', False, 'from System.Drawing import Point, Color, Font\n')]