<commit_before>'''PRIMEDesignerVisForBrython.py

Set up a GUI and handle updates and events during a run of
the PRIMEDesigner template in the Brython environment.
'''

from browser import window, document, html, alert, svg
import javascript
gui = None
#is this saying that all of these are now 'None'?
board = None
statusline = None
opselect = None
APANEL = None
MARGIN = 20
ROOM_SIZE = 100
GAME_WIDTH = ROOM_SIZE * 3
GAME_HEIGHT = ROOM_SIZE * 3

#The canvas and its context will go here when initialized for manipulation
roleCanvas = None
ctx = None

LAST_STATE = None # cache of current state for use in 
				#refresh of display after selection hiding button click.

print("Hello from PRIMEDesignerVisForBrython!  Starting to process it.")

LINE_WIDTH = 15
def set_up_gui(opselectdiv, statuslinediv):
	print("Entering set_up_gui in PRIMEDesignerVisForBrython.")
	global gui
	gui = html.DIV(Id = "thegui")
	set_up_board_svg_graphics()
	#alert("SVG stuff should now be set up.")
	gui <= opselectdiv
	gui <= statuslinediv
	document <= gui
	print("Leaving set_up_gui in PRIMEDesignerVisForBrython.")

def set_up_board_svg_graphics():
	#SHOW_SELECTION_Button isn't initialized before this call.
	#Does this mean that with the global keyword, you can either 
	#refer to a global variable or initialize a new one?
	boarddiv = html.DIV(Id = "boarddivid", style = {"backgroundColor":"#CCFFCC"})
	boarddiv <= html.I("Puzzle state:")
	#what is APANEL intended to be
	
	global ctx, roleCanvas
	roleCanvas = html.CANVAS(id = "roleCanvas", width = GAME_WIDTH, height = GAME_HEIGHT)
	ctx = roleCanvas.getContext('2d');
	
	global APANEL, board
	board = svg.svg(Id = "svgboard", 
					style = {"width":GAME_WIDTH, "height":GAME_HEIGHT,
							"backgroundColor":"#AAAABB"})
	APANEL = svg.g(Id = "panel")
	
	board <= APANEL	
	boarddiv <= board
	boarddiv <= roleCanvas
	gui <= boarddiv
		
# draws the game
def render_state_svg_graphics(state):
	global roleCanvas, ctx, APANEL
	
	# Clear svg panel
	while APANEL.lastChild:
		APANEL.removeChild(APANEL.lastChild)
	
	# Clear the roleCanvas
	ctx.clearRect(0,0, GAME_WIDTH, GAME_HEIGHT)
	
	if state['Role'] == "Architect":
		#Hide canvas, make sure svg stuff visible
		roleCanvas.style.display = "none"
		board.style.display = "initial"
		
		# Draw all the rooms.
		room_num = 1
		for room in state['Rooms']:
			drawRoom(room,room_num)
			room_num += 1
			
		THICKNESS = 1.5
		selected_room = state['Rooms'][state['Selected']]
			
		(x1, y1) = mapCoordsToDIV(selected_room.x1, selected_room.y1)
		(x2, y2) = mapCoordsToDIV(selected_room.x2, selected_room.y2)
			
		outline = svg.rect(x = x1, y = y1, width = x2 - x1, height = y2 - y1, fill = "none",
						style = {"stroke": "gold", "stroke-width": THICKNESS})
		APANEL <= outline
	else:
		#Hide svg stuff, make canvas visible
		board.style.display = "none"
		roleCanvas.style.display = "initial"

		img = html.IMG('', src = "metalfencing.jpg")
		ctx.drawImage(img, 0, 0, GAME_WIDTH, GAME_HEIGHT)
		
# draws a room.		
def drawRoom(room,room_num):
	# thickness of a room's walls.
	THICKNESS = .2
	
	#(x3,y3) and (x4,y4) make up the shorter end of the trapezoid
	# draws north wall
	wall = room.walls['N']
	x3 = wall.x2 - THICKNESS/pow(2,1/2)
	y3 = wall.y1 + THICKNESS/pow(2,1/2)
	x4 = wall.x1 + THICKNESS/pow(2,1/2)
	y4 = y3
	drawWall(wall,x3,y3,x4,y4,room_num)
	
	# draws south wall
	wall = room.walls['S']
	x3 = wall.x2 - THICKNESS/pow(2,1/2)
	y3 = wall.y1 - THICKNESS/pow(2,1/2)
	x4 = wall.x1 + THICKNESS/pow(2,1/2)
	y4 = y3
	drawWall(wall,x3,y3,x4,y4,room_num)
	
	# draws west wall
	wall = room.walls['W']
	x3 = wall.x2 + THICKNESS/pow(2,1/2)
	y3 = wall.y2 - THICKNESS/pow(2,1/2)<commit_msg>Trying to get this canvas thing to work<commit_after>'''PRIMEDesignerVisForBrython.py

Set up a GUI and handle updates and events during a run of
the PRIMEDesigner template in the Brython environment.
'''

from browser import window, document, html, alert, svg
import javascript
from javascript import JSConstructor 
gui = None
#is this saying that all of these are now 'None'?
board = None
statusline = None
opselect = None
APANEL = None
MARGIN = 20
ROOM_SIZE = 100
GAME_WIDTH = ROOM_SIZE * 3
GAME_HEIGHT = ROOM_SIZE * 3

#The canvas and its context will go here when initialized for manipulation
roleCanvas = None
ctx = None

LAST_STATE = None # cache of current state for use in 
				#refresh of display after selection hiding button click.

print("Hello from PRIMEDesignerVisForBrython!  Starting to process it.")

LINE_WIDTH = 15
def set_up_gui(opselectdiv, statuslinediv):
	print("Entering set_up_gui in PRIMEDesignerVisForBrython.")
	global gui
	gui = html.DIV(Id = "thegui")
	set_up_board_svg_graphics()
	#alert("SVG stuff should now be set up.")
	gui <= opselectdiv
	gui <= statuslinediv
	document <= gui
	print("Leaving set_up_gui in PRIMEDesignerVisForBrython.")

def set_up_board_svg_graphics():
	#SHOW_SELECTION_Button isn't initialized before this call.
	#Does this mean that with the global keyword, you can either 
	#refer to a global variable or initialize a new one?
	boarddiv = html.DIV(Id = "boarddivid", style = {"backgroundColor":"#CCFFCC"})
	boarddiv <= html.I("Puzzle state:")
	#what is APANEL intended to be
	
	global ctx, roleCanvas
	roleCanvas = html.CANVAS(id = "roleCanvas", width = GAME_WIDTH, height = GAME_HEIGHT)
	ctx = roleCanvas.getContext("2d");
	
	global APANEL, board
	board = svg.svg(Id = "svgboard", 
					style = {"width":GAME_WIDTH, "height":GAME_HEIGHT,
							"backgroundColor":"#AAAABB"})
	APANEL = svg.g(Id = "panel")
	
	board <= APANEL	
	boarddiv <= board
	boarddiv <= roleCanvas
	gui <= boarddiv
		
# draws the game
def render_state_svg_graphics(state):
	global roleCanvas, ctx, APANEL
	
	# Clear svg panel
	while APANEL.lastChild:
		APANEL.removeChild(APANEL.lastChild)
	
	# Clear the roleCanvas
	ctx.clearRect(0,0, GAME_WIDTH, GAME_HEIGHT)
	
	if state['Role'] == "Architect":
		#Hide canvas, make sure svg stuff visible
		roleCanvas.style.display = "none"
		board.style.display = "initial"
		
		# Draw all the rooms.
		room_num = 1
		for room in state['Rooms']:
			drawRoom(room,room_num)
			room_num += 1
			
		THICKNESS = 1.5
		selected_room = state['Rooms'][state['Selected']]
			
		(x1, y1) = mapCoordsToDIV(selected_room.x1, selected_room.y1)
		(x2, y2) = mapCoordsToDIV(selected_room.x2, selected_room.y2)
			
		outline = svg.rect(x = x1, y = y1, width = x2 - x1, height = y2 - y1, fill = "none",
						style = {"stroke": "gold", "stroke-width": THICKNESS})
		APANEL <= outline
	else:
		#Hide svg stuff, make canvas visible
		board.style.display = "none"
		roleCanvas.style.display = "initial"
		img = html.IMG(src = "wall.jpg")
		img.onload = ctx.drawImage(img.elt,3000,3000)
		#img.src = "wall.jpg"
		#alert(img.elt)
		ctx.drawImage(img.elt,300,300)
		ctx.fill()
	
		
# draws a room.		
def drawRoom(room,room_num):
	# thickness of a room's walls.
	THICKNESS = .2
	
	#(x3,y3) and (x4,y4) make up the shorter end of the trapezoid
	# draws north wall
	wall = room.walls['N']
	x3 = wall.x2 - THICKNESS/pow(2,1/2)
	y3 = wall.y1 + THICKNESS/pow(2,1/2)
	x4 = wall.x1 + THICKNESS/pow(2,1/2)
	y4 = y3
	drawWall(wall,x3,y3,x4,y4,room_num)
	
	# draws south wall
	wall = room.walls['S']
	x3 = wall.x2 - THICKNESS/pow(2,1/2)
	y3 = wall.y1 - THICKNESS/pow(2,1/2)
	x4 = wall.x1 + THICKNESS/pow(2,1/2)
	y4 = y3
	drawWall(wall,x3,y3,x4,y4,room_num)
	
	# draws west wall
	wall = room.walls['W']
	x3 = wall.x2 + THICKNESS/pow(2,1/2)
	y3 = wall.y2 - THICKNESS/pow(2,1/2)
{'fraction_non_alphanumeric': 0.12073806658644204, 'fraction_numerical': 0.025404465837678834, 'mean_word_length': 4.112781954887218, 'pattern_counts': {'":': 14, '<': 21, '<?xml version=': 0, '>': 3, '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': '101296', 'n_tokens_mistral': 3052, 'n_tokens_neox': 2817, 'n_words': 765}