<commit_before>
import sys

if sys.platform != "darwin":
	print "GUI: your platform is probably not supported yet"

import objc
from AppKit import *
from collections import deque

try: pools
except NameError: pools = deque()

# just in case that we are not the main thread
pools.append(NSAutoreleasePool.alloc().init())

import os, sys
from State import state, modules
from utils import *
import appinfo

mydir = os.path.dirname(__file__) or os.getcwd()
try:
	app
except NameError: # only declare if not yet declared
	app = None

def setupAppleMenu():

	# http://www.cocoabuilder.com/archive/cocoa/192181-initializing-the-menubar-without-interface-builder.html
	# By <NAME>

	mainMenu = NSMenu.alloc().initWithTitle_("MainMenu")
	mi = mainMenu.addItemWithTitle_action_keyEquivalent_("Apple", None, "")
	m = NSMenu.alloc().initWithTitle_("Apple")

	# strange hack
	app.setAppleMenu_(m)
	mainMenu.setSubmenu_forItem_(m, mi)
	mi = m.addItemWithTitle_action_keyEquivalent_('Quit', 'terminate:', 'q')

	app.setMainMenu_(mainMenu)

	return m

import Traits

def buildControlAction(userAttr, inst):
	button = NSButton.alloc().initWithFrame_(((10.0, 10.0), (50.0, 30.0)))
	button.setBezelStyle_(2)
	try:
		class ButtonActionHandler(NSObject):
			def initWithArgs(self, userAttr, inst):
				self.init()
				self.userAttr = userAttr
				self.inst = inst
				return self
			def click(self, sender):
				print "click!!", sender, self.userAttr
				attr = self.userAttr.__get__(self.inst)
				from threading import Thread
				Thread(target=attr, name="click handler").start()
	except:
		ButtonActionHandler = objc.lookUpClass("ButtonActionHandler") # already defined earlier
	actionTarget = ButtonActionHandler.alloc().initWithArgs(userAttr, inst)
	actionTarget.retain() # TODO: where would we release this? ...
	button.setTarget_(actionTarget)
	button.setAction_("click")
	def update():
		button.setTitle_(userAttr.name.decode("utf-8"))
	return button, update

def buildControlOneLineTextLabel(userAttr, inst):
	label = NSTextField.alloc().initWithFrame_(((10.0, 10.0), (100.0, 25.0)))
	label.setBordered_(False)
	label.setBezeled_(True)
	#label.setDrawsBackground_(False)
	label.setEditable_(False)
	label.cell().setLineBreakMode_(NSLineBreakByTruncatingTail)
	def update():
		labelContent = userAttr.__get__(inst)
		s = "???"
		try:
			s = str(labelContent)
			s = s.decode("utf-8")
		except: pass
		label.setStringValue_(s)
	return label, update

def buildControlList(userAttr, inst):
	subview = NSBox.alloc().initWithFrame_(((10.0, 10.0), (80.0, 80.0)))
	subview.setTitle_(userAttr.name.decode("utf-8"))
	def update():
		pass
	return subview, update

def buildControlObject(userAttr, inst):
	subview = NSBox.alloc().initWithFrame_(((10.0, 10.0), (80.0, 80.0)))
	subview.setTitle_(userAttr.name.decode("utf-8"))
	def update():
		pass
	return subview, update

def buildControlImage(userAttr, inst):
	subview = NSView.alloc().initWithFrame_(((10.0, 10.0), (80.0, 80.0)))
	imgview = NSImageView.alloc().initWithFrame_(((0.0, 0.0), (80.0, 80.0)))
	imgview.setImageScaling_(NSScaleToFit)
	imgview2 = NSImageView.alloc().initWithFrame_(((0.0, 0.0), (10.0, 80.0)))
	imgview2.setImageScaling_(NSScaleToFit)
	subview.addSubview_(imgview)
	subview.addSubview_(imgview2)
	imgview.setAutoresizingMask_(NSViewWidthSizable|NSViewHeightSizable)
	imgview2.setAutoresizingMask_(NSViewHeightSizable)

	from threading import Lock
	lock = Lock()

	def update():
		def loadImage():
			# NOTE: TODO: this is hacky as it assumes this is the song thumbnail image
			# we need to abstract this more later on ...
			# just a hack because I want to go to sleep
			song = state.player.curSong
			pool = NSAutoreleasePool.alloc().init()
			if song:
				attr = userAttr.__get__(inst) # the attr is a function which is supposed to return some image data, e.g. a BMP
				imgData = attr()
				data = NSData.alloc().initWithBytes_length_(imgData, len(imgData))
				img = NSImage.alloc().initWithData_(data)
			else:
				img = NSImage.alloc().initWithSize_((10,10))
				img.lockFocus()
				NSColor.grayColor().set()
				NSBezierPath.fillRect_(((0,0),(10,10)))
				img.unlockFocus()

			img2 = NSImage.alloc().initWithSize_((5,1))<commit_msg>gui: automove cursor on resize<commit_after>
import sys

if sys.platform != "darwin":
	print "GUI: your platform is probably not supported yet"

import objc
from AppKit import *
from collections import deque

try: pools
except NameError: pools = deque()

# just in case that we are not the main thread
pools.append(NSAutoreleasePool.alloc().init())

import os, sys
from State import state, modules
from utils import *
import appinfo

mydir = os.path.dirname(__file__) or os.getcwd()
try:
	app
except NameError: # only declare if not yet declared
	app = None

def setupAppleMenu():

	# http://www.cocoabuilder.com/archive/cocoa/192181-initializing-the-menubar-without-interface-builder.html
	# By <NAME>

	mainMenu = NSMenu.alloc().initWithTitle_("MainMenu")
	mi = mainMenu.addItemWithTitle_action_keyEquivalent_("Apple", None, "")
	m = NSMenu.alloc().initWithTitle_("Apple")

	# strange hack
	app.setAppleMenu_(m)
	mainMenu.setSubmenu_forItem_(m, mi)
	mi = m.addItemWithTitle_action_keyEquivalent_('Quit', 'terminate:', 'q')

	app.setMainMenu_(mainMenu)

	return m

import Traits

def buildControlAction(userAttr, inst):
	button = NSButton.alloc().initWithFrame_(((10.0, 10.0), (50.0, 30.0)))
	button.setBezelStyle_(2)
	try:
		class ButtonActionHandler(NSObject):
			def initWithArgs(self, userAttr, inst):
				self.init()
				self.userAttr = userAttr
				self.inst = inst
				return self
			def click(self, sender):
				print "click!!", sender, self.userAttr
				attr = self.userAttr.__get__(self.inst)
				from threading import Thread
				Thread(target=attr, name="click handler").start()
	except:
		ButtonActionHandler = objc.lookUpClass("ButtonActionHandler") # already defined earlier
	actionTarget = ButtonActionHandler.alloc().initWithArgs(userAttr, inst)
	actionTarget.retain() # TODO: where would we release this? ...
	button.setTarget_(actionTarget)
	button.setAction_("click")
	def update():
		button.setTitle_(userAttr.name.decode("utf-8"))
	return button, update

def buildControlOneLineTextLabel(userAttr, inst):
	label = NSTextField.alloc().initWithFrame_(((10.0, 10.0), (100.0, 25.0)))
	label.setBordered_(False)
	label.setBezeled_(True)
	#label.setDrawsBackground_(False)
	label.setEditable_(False)
	label.cell().setLineBreakMode_(NSLineBreakByTruncatingTail)
	def update():
		labelContent = userAttr.__get__(inst)
		s = "???"
		try:
			s = str(labelContent)
			s = s.decode("utf-8")
		except: pass
		label.setStringValue_(s)
	return label, update

def buildControlList(userAttr, inst):
	subview = NSBox.alloc().initWithFrame_(((10.0, 10.0), (80.0, 80.0)))
	subview.setTitle_(userAttr.name.decode("utf-8"))
	def update():
		pass
	return subview, update

def buildControlObject(userAttr, inst):
	subview = NSBox.alloc().initWithFrame_(((10.0, 10.0), (80.0, 80.0)))
	subview.setTitle_(userAttr.name.decode("utf-8"))
	def update():
		pass
	return subview, update

def buildControlImage(userAttr, inst):
	subview = NSView.alloc().initWithFrame_(((10.0, 10.0), (80.0, 80.0)))
	imgview = NSImageView.alloc().initWithFrame_(((0.0, 0.0), (80.0, 80.0)))
	imgview.setImageScaling_(NSScaleToFit)
	imgview2 = NSImageView.alloc().initWithFrame_(((0.0, 0.0), (10.0, 80.0)))
	imgview2.setImageScaling_(NSScaleToFit)
	subview.addSubview_(imgview)
	subview.addSubview_(imgview2)
	imgview.setAutoresizingMask_(NSViewWidthSizable|NSViewHeightSizable)
	imgview2.setAutoresizingMask_(NSViewHeightSizable|NSViewMinXMargin|NSViewMaxXMargin)

	from threading import Lock
	lock = Lock()

	def update():
		def loadImage():
			# NOTE: TODO: this is hacky as it assumes this is the song thumbnail image
			# we need to abstract this more later on ...
			# just a hack because I want to go to sleep
			song = state.player.curSong
			pool = NSAutoreleasePool.alloc().init()
			if song:
				attr = userAttr.__get__(inst) # the attr is a function which is supposed to return some image data, e.g. a BMP
				imgData = attr()
				data = NSData.alloc().initWithBytes_length_(imgData, len(imgData))
				img = NSImage.alloc().initWithData_(data)
			else:
				img = NSImage.alloc().initWithSize_((10,10))
				img.lockFocus()
				NSColor.grayColor().set()
				NSBezierPath.fillRect_(((0,0),(10,10)))
				img.unlockFocus()

			img2 = NSImage.alloc().initWithSize_((5,1))
{'fraction_non_alphanumeric': 0.1344308894942556, 'fraction_numerical': 0.025820206087883452, 'mean_word_length': 4.900768693221523, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5569741', 'n_tokens_mistral': 3212, 'n_tokens_neox': 2896, 'n_words': 651}