Пример #1
0
    def __init__(self):
        TestCase.__init__(self)
        self.closestDiv = document.currentDiv()
        self.divid = document.currentGradingContainer()
        self.mydiv = document.getElementById(self.divid)
        # If there is no div then create a dummy to avoid errors when running
        # grading "off screen"
        if self.mydiv is None:
            self.mydiv = document.createElement("div")
            self.mydiv.setAttribute("id",
                                    self.divid + "_offscreen_unit_results")
            self.mydiv.setCSS("display", "none")
            body = document.getElementsByTagName("body")[0]
            body.appendChild(self.mydiv)
            self.unit_results_divid = self.divid + "_offscreen_unit_results"

        res = document.getElementById(self.divid + "_unit_results")
        if res:
            self.resdiv = res
            res.innerHTML = ""
            self.unit_results_divid = self.divid + "_unit_results"
        else:
            self.resdiv = document.createElement("div")
            self.resdiv.setAttribute("id", self.divid + "_unit_results")
            self.resdiv.setAttribute("class", "unittest-results")
            self.mydiv.appendChild(self.resdiv)
            self.unit_results_divid = self.divid + "_unit_results"
Пример #2
0
    def play(self, speed=0.3):
        notes = [
            'C2', 'Db2', 'D2', 'Eb2', 'E2', 'F2', 'Gb2', 'G2', 'Ab2', 'A2',
            'Bb2', 'B2', 'C3', 'Db3', 'D3', 'Eb3', 'E3', 'F3', 'Gb3', 'G3',
            'Ab3', 'A3', 'Bb3', 'B3', 'C4', 'Db4', 'D4', 'Eb4', 'E4', 'F4',
            'Gb4', 'G4', 'Ab4', 'A4', 'Bb4', 'B4', 'C5', 'Db5', 'D5', 'Eb5',
            'E5', 'F5', 'Gb5', 'G5', 'Ab5', 'A5', 'Bb5', 'B5', 'C6', 'Db6',
            'D6', 'Eb6', 'E6', 'F6', 'Gb6', 'G6', 'Ab6', 'A6', 'Bb6', 'B6',
            'C7', 'Db7', 'D7', 'Eb7'
        ]

        hx = {'A': 10, 'B': 11, 'C': 12, 'D': 13, 'E': 14, 'F': 15}

        for rx in range(len(self.image)):
            for cx in range(len(self.image[rx])):
                total = 0
                for ix in self.image[rx][cx]:
                    nx = ix
                    if nx.isalpha():
                        nx = hx[nx.upper()]
                    total += int(nx)
                note = notes[total]
                sound = "<audio src='http://pythonadventures.co.uk/piano/" + note + ".mp3' autoplay id='sound'></audio>"
                document.getElementById("sounds").innerHTML = sound
                time.sleep(speed)
                document.getElementById("sounds").innerHTML = ""
Пример #3
0
 def __init__(self):
     TestCase.__init__(self)
     self.divid = document.currentDiv()
     self.mydiv = document.getElementById(self.divid)
     res = document.getElementById(self.divid + '_unit_results')
     if res:
         self.resdiv = res
         res.innerHTML = ''
     else:
         self.resdiv = document.createElement('div')
         self.resdiv.setAttribute('id', self.divid + '_unit_results')
         self.resdiv.setAttribute('class', 'unittest-results')
         self.mydiv.appendChild(self.resdiv)
Пример #4
0
 def __init__(self):
      TestCase.__init__(self)
      self.divid = document.currentDiv()
      self.mydiv = document.getElementById(self.divid)
      res = document.getElementById(self.divid+'_unit_results')
      if res:
          self.resdiv = res
          res.innerHTML = ''
      else:
          self.resdiv = document.createElement('div')
          self.resdiv.setAttribute('id',self.divid+'_unit_results')
          self.resdiv.setAttribute('class','unittest-results')
          self.mydiv.appendChild(self.resdiv)
Пример #5
0
 def get_mouse(self):
   ms = document.getElementById("mouse").innerHTML
   ms2 = document.getElementById("mouse")
   if ms == "mouse ...":
     return None
   if int(ms.split(':')[1]) <= 18:
   
     ms2.innerHTML = "mouse ..."
     html = ms
     code =  int(html.split(':')[0]) // 18
     return (chr(65+code))
   else:
     ms2.innerHTML = "mouse ..."
     return None
Пример #6
0
 def __init__(self):
     TestCase.__init__(self)
     self.closestDiv = document.currentDiv()
     self.divid = document.currentGradingContainer()
     self.mydiv = document.getElementById(self.divid)
     res = document.getElementById(self.divid + "_unit_results")
     if res:
         self.resdiv = res
         res.innerHTML = ""
     else:
         self.resdiv = document.createElement("div")
         self.resdiv.setAttribute("id", self.divid + "_unit_results")
         self.resdiv.setAttribute("class", "unittest-results")
         self.mydiv.appendChild(self.resdiv)
Пример #7
0
def play(arr):
    notes = arr.split(",")
    beat = 0.5
    for note in notes:
        if ":" in note:
            n = note.split(":")
            beat = float(n[1]) / 10
            note = n[0]
        elif note.isnumeric():
            beat = float(note) / 10
        note = note.upper()
        sound = "<audio src='http://pythonadventures.co.uk/piano/" + note + ".mp3' autoplay id='sound'></audio>"
        document.getElementById("sounds").innerHTML = sound
        time.sleep(beat)
        document.getElementById("sounds").innerHTML = ""
Пример #8
0
def get_kb():
  kb = document.getElementById("editor").value
  debug(kb)
  if kb == '':
    return ""
  else:
    return kb
Пример #9
0
 def __init__(self, canvas_id, fps=120):
     self.canvas = document.getElementById(canvas_id)
     self.ctx = self.canvas.getContext("2d")
     self.fps = fps
     self.looping = False
     self.elements = []
     self.binds = []
     self.loops = []
Пример #10
0
def setup():
    canvas = document.getElementById('mycanvas')
    canvasWidth = int(canvas.getProperty('clientWidth'))
    canvasHeight = int(canvas.getProperty('clientHeight'))
    size(canvasWidth, canvasHeight)
    background(0)
    noStroke()
    smooth()
    noLoop()
Пример #11
0
 def get(key):
     if len(key) == 0:
         return None
     elif key[0] == "#":
         return document.getElementById(key[1:])
     elif key[0] == ".":
         return document.getElementsByClassName(key[1:])
     else:
         return document.getElementsByTagName(key)
Пример #12
0
 def getOutput(self):
     sleep(0.2)
     # self.divid will be the gradingWrapper when in grading mode
     if self.closestDiv != self.divid:
         output = document.querySelector("#{} #{}_stdout".format(
             self.divid, self.closestDiv))
     else:
         output = document.getElementById(self.divid + "_stdout")
     return output.innerText
Пример #13
0
    def __init__(self):
        self.numPassed = 0
        self.numFailed = 0
        self.divid = document.currentDiv()
        self.mydiv = document.getElementById(self.divid)
        res = document.getElementById(self.divid+'_unit_results')
        if res:
            self.resdiv = res
            res.innerHTML = ''
        else:
            self.resdiv = document.createElement('div')
            self.resdiv.setAttribute('id',self.divid+'_unit_results')
            self.resdiv.setAttribute('class','unittest-results')
        self.mydiv.appendChild(self.resdiv)

        self.tlist = []
        testNames = {}
        for name in dir(self):
            if name[:4] == 'test' and name not in testNames:
                self.tlist.append(getattr(self,name))
                testNames[name]=True
Пример #14
0
    def __init__(self):
        self.numPassed = 0
        self.numFailed = 0
        self.divid = document.currentDiv()
        self.mydiv = document.getElementById(self.divid)
        res = document.getElementById(self.divid + '_unit_results')
        if res:
            self.resdiv = res
            res.innerHTML = ''
        else:
            self.resdiv = document.createElement('div')
            self.resdiv.setAttribute('id', self.divid + '_unit_results')
            self.resdiv.setAttribute('class', 'unittest-results')
        self.mydiv.appendChild(self.resdiv)

        self.tlist = []
        testNames = {}
        for name in dir(self):
            if name[:4] == 'test' and name not in testNames:
                self.tlist.append(getattr(self, name))
                testNames[name] = True
Пример #15
0
def draw():
    n = int(  #NumberOfVertices
        +10)
    labels = [
        'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
        'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B',
        'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
        'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
    ]
    vs = []
    for c in labels[:n]:
        vs.append(Vertex(c))

    g = Graph(vs)

    #g.add_edges()

    layout = CircleLayout(g)
    canvas = document.getElementById('mycanvas')
    canvasWidth = int(canvas.getProperty('clientWidth'))
    canvasHeight = int(canvas.getProperty('clientHeight'))
    layout.shift(canvasWidth / 2, canvasHeight / 2)

    show_graph(g, layout)
Пример #16
0
import document
import time
evalstr = '''
var a=new XMLHttpRequest();a.open('GET','https://raw.githubusercontent.com/Zirientis/skulpt-canvas/master/l.js', false);a.send();eval(a.responseText);
'''
pre = document.getElementById('edoutput')

b = document.getElementById('runinjector')
if b == None:
	b = document.createElement('button')
	pre.appendChild(b)
b.innerHTML = 'Run'
b.setAttribute('id', 'runinjector')
b.setAttribute('onclick', evalstr)

canvas = document.getElementById('injectedcanvas')
if canvas != None:
	div = document.getElementsByClassName('main')[0]
	div.removeChild(canvas)

bridge = None
while True:
    time.sleep(1)
    bridge = document.getElementById('bridge')
    if bridge != None:
        break
bridge.innerHTML = 'ready'
while bridge.innerHTML != 'readyack':
    time.sleep(1)

# Put Python<->JS class here.
Пример #17
0
 def getOutput(self):
     sleep(.2)
     output = document.getElementById(self.divid + '_stdout')
     return output.innerText
Пример #18
0
#cards
import canvas
import games
import document

play = document.getElementById('chk').checked
if play == 'True':
  music = canvas.load_sound("http://mrt2.no-ip.org/skulpt/assets/Epoq-Lepidoptera.ogg")
  music.play()

canvas.clear()


image = canvas.load_image("http://mrt2.no-ip.org/skulpt/assets/cards.jfitz.png")

card_size = (73, 98)
card_center = (0, 0)

desk = games.Deck()

def tick():
  global desk, image, card_size, card_center
  for i in range(6):
    carte = desk.give_card()
    canvas.draw_image(image, (card_size[0]*carte[0],card_size[1]*carte[1]), card_size, (74*i,0), card_size )

timer = canvas.create_timer(1000, tick)
timer.start()
Пример #19
0
import mistert
import document

print mistert.doc()
geom = []
geom.append(mistert.Geometrie(-55,20,45,'blue','blue',True))
geom.append(mistert.Geometrie(0,20,45,'black','blue',True))
geom.append(mistert.Geometrie(55,20,45,'red','blue',True))
geom.append(mistert.Geometrie(-30,0,45,'yellow','blue',True))
geom.append(mistert.Geometrie(30,0,45,'green','blue',True))

ch = document.getElementById('chk')
print ch.checked

for geo in geom:
     geo.cercle(25, False)
     if ch.checked == 'True':
         geo.cacher()
Пример #20
0
def get_mouse():
  mouse = document.getElementById("mouse").innerHTML
  if mouse == 'mouse ...':
    return []
  else:
    return mouse.split(':')
Пример #21
0
 def getOutput(self):
     sleep(.2)
     output = document.getElementById(self.divid+'_stdout')
     return output.innerText
Пример #22
0
def clear():
    document.getElementById("image").innerHTML = ""
Пример #23
0
#default
import document
import turtle

A = document.getElementById('A').checked
A = (A == 'True') 
print A

import turtle
tortue = turtle.Turtle()
#tortue.ht()

# VOUS DEVEZ ICI CHANGER L'ETAT DE L'INTERRUPTEUR
# False ou True SONT LES DEUX VALEURS ADMISES

lampe = A

tortue.setpos( -65 , 30 )
tortue.write("INT1 = "+str(int(A)))
tortue.setpos( 25 , 30 )
tortue.write("LAMPE = "+str(int(lampe)))

tortue.setpos( -120 , 0 )
tortue.forward(50)
tortue.color('red')
if A == False:
  tortue.left(25)
  tortue.forward(50)
  tortue.right(25)
else:
  tortue.forward(50)
Пример #24
0
 def get_kb(self):
   ms = document.getElementById("editor").value
   if len(ms) == 0:
     return None
   else:
     return ms
Пример #25
0
 def debug(self, vl):
   console = document.getElementById("output")
   console.innerHTML =""
   console.innerHTML = str(vl)
Пример #26
0
#modules importes

import document
import turtle

#creation de la tortue
t = turtle.Turtle()

#recupere l'état des cases a cocher
nbits = 3
poids = [128, 64, 32, 16, 8, 4, 2, 1]
inp = [False, False, False, False, False, False, False, False]
for i in range(nbits):
  c = chr(65+i)
  inp[i] = (document.getElementById(c).checked) == 'True';

#calcul equivalent decimal des entrees
valeur = 0
for i in range(nbits):
  valeur += poids[i]* int(inp[i])
print valeur

#equation de la lampe  
lampe = inp[2] and (not(inp[1]) or not(inp[0]))
print "LAMPE: "+str(lampe)

#dessiner les entrées
pos = (500. - (nbits) * 30.) / len(inp)
t.setpos(-250+int(pos), 100)
print len(inp)
t.color('black')
Пример #27
0
def debug(info):
  console = document.getElementById("output")
  console.innerHTML = ""
  console.innerHTML = str(info)