Created
October 3, 2019 19:15
-
-
Save johnpierson/4b18b9c96467bfbb8fd34248e256f36b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
from System.Drawing import Point , Size , Graphics, Bitmap, Image, Font, FontStyle, Icon, Color, Region , Rectangle , ContentAlignment , SystemFonts | |
str_file = StringIO() | |
size1 = [100, 20] #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) | |
#john modifications | |
pic = Image.FromFile(IN[0]) | |
self.box1 = PictureBox() | |
self.box1.Image = pic | |
self.box1.SizeMode = PictureBoxSizeMode.Zoom | |
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() | |
def app_lost_focus(self, event): | |
self.BringToFront() | |
str_content = str_file.getvalue() | |
str_file.close() | |
width1 = 100 | |
form = WatchBox(str_content) | |
form.adjust_controls(*size1) | |
form.Deactivate += app_lost_focus | |
Application.Run(form) | |
OUT = form.text1 | |
Application.Exit() | |
form.Dispose() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment