コード例 #1
0
def select(player_card):
    pc_num = random.randrange(0, 3)
    pc_card = pc_hand.choose_card(pc_num)
    if pc_num == 0:
        Template(document["pc0"]).render(select="selected")
    if pc_num == 1:
        Template(document["pc1"]).render(select="selected")
    if pc_num == 2:
        Template(document["pc2"]).render(select="selected")


# make class with variable in HTML and we can change it!!
# for player, I used javascript. (script.js)

    which_win = back.compare(player_card, pc_card)
    if not type(which_win) == str:
        which_win = 'even'
    document['whichWin'].text = which_win
    show_point()
    loser_judge()
コード例 #2
0
ファイル: html.py プロジェクト: MaxMorais/IAmPy
def get_html(doctype, name):
    meta = app.get_meta(doctype)
    print_format = app.get_doc('PrintFormat', meta.print.print_format)

    doc = app.get_doc(doctype, name)
    context = ODict(doc=doc, app=app)

    try:
        html = Template(print_format.template).render(**context)
    except Exception as e:
        print(error)
        html = ''

    return f'<div class="print-page">{html}</div>'
コード例 #3
0
ファイル: contador.py プロジェクト: geniodev/ApiHeroku
#Import dos conectores com a página
from browser import document, console
from browser.template import Template


#Função citada no name.html
def incr(event, element):
    console.log(
        event
    )  #imprime o console.log do javascript a função event( o que ta acontecendo )

    #Vai pegar o elemento com a tag: {myname}
    #document['write'], vai pegar o elemento com id='write', usando '.value' pega o valor do input
    element.data.counter += 1
    pass


# 'name' é o Id de onde está a Div. [nrm] passa a função.  '.render' vai renderizar e iniciar como '' a tag:  {myname}
Template('increment', [incr]).render(counter=0)
コード例 #4
0
ファイル: dev_env.py プロジェクト: vt100/brython
    print(output.style.overflow)
    save_stdout = sys.stdout
    save_stderr = sys.stderr
    sys.stdout = sys.stderr = Output()
    output_window.style.display = "block"
    output.text = ""
    try:
        exec(editor.text)
    finally:
        sys.stdout = save_stdout
        sys.stderr = save_stderr

width = window.innerWidth
height = window.innerHeight

tmpl = Template("content",
    [run, load, save, save_as, delete, size_up, size_down])

tmpl.render(editor_height=int(0.9 * height),
    height=int(0.6 * height), width=int(0.6 * width),
    top=int(0.2 * height), left=int(0.2 * width))

Template("dialog_window").render(
    height=int(0.6 * height), width=int(0.6 * width),
    top=int(0.2 * height), left=int(0.2 * width))

dialog = document["dialog"]

filebrowser = document["filebrowser"]
scripts = []
open_scripts = []
コード例 #5
0
                                   Class="w3-left",
                                   value=q[0],
                                   readonly="true",
                                   style=styleinput)
                div1 = html.DIV(id=x)
                div1 <= inputcheckbox + input + span
                container <= div1
                doc['app-3'] <= container
    for x in idcheck:
        if x not in bind_list:
            bind_list.append(x)
            doc["id" + str(x)].bind("click", remove_item)
            doc["c" + str(x)].bind("change", line)
            doc["m" + str(x)].bind("click", editing)
            doc["m" + str(x)].bind("blur", editing_focus)


Template(doc["app-1"]).render(name="to-do list")

Template(doc["app-2"], [create_task, save_task, show_task]).render()


def loading():
    """ hide loading id and show
    container-1 and container-2 """
    doc["index"].style.opacity = "1"
    doc['loading'].style.display = "none"


win.onload = loading()
コード例 #6
0

def format(n):
    n = float(n)
    millidx = max(
        0,
        min(
            len(millnames) - 1,
            int(math.floor(0 if n == 0 else math.log10(abs(n)) / 3))))

    return '{:.0f}{}'.format(n / 10**(3 * millidx), millnames[millidx])


b = country(country="The UK", population=format(63230000))

appl_tmpl = Template(doc["container-1"])
appl_tmpl.render(country=b['country'], population=b['population'])


def country(name, climate, population, capital):
    return {
        'name': name,
        'climate': climate,
        'population': population,
        'capital': capital
    }


b = country(name="The UK",
            climate={
                'temperature': 'cold',
コード例 #7
0
ファイル: interative.py プロジェクト: ichem/Brython
    'realname': 'Summers, Scott',
    'power': 'Optic blast',
    'info': 'http://www.superherodb.com/Cyclops/10-50/'
}, {
    'name': 'Rogue',
    'realname': 'Marie, Anna',
    'power': 'Absorbing powers',
    'info': 'http://www.superherodb.com/Rogue/10-831/'
}, {
    'name': 'Wolverine',
    'realname': 'Howlett, James',
    'power': 'Regeneration',
    'info': 'http://www.superherodb.com/Wolverine/10-161/'
}]

Template(doc["container-1"]).render(xmens=xmens,
                                    name="name",
                                    realname="realname",
                                    power="power",
                                    position=0)


def loading():
    """ hide loading id and show
    container-1 """
    doc['container-1'].style.display = "block"
    doc['loading'].style.display = "none"


win.onload = loading()
コード例 #8
0
from browser import document as doc, window as win
from browser.template import Template

Template(doc["container-1"]).render(red=0.45, green=0.61, blue=0.2)


def loading():
    """ hide loading id and show
    container-1 """
    doc['container-1'].style.display = "block"
    doc['loading'].style.display = "none"


win.onload = loading()
コード例 #9
0
ファイル: event.py プロジェクト: ichem/Brython
from browser import document as doc, window as win, alert
from browser.template import Template


def func_activate(ev, elt):
    alert("Activate")


Template(doc["container-1"], [func_activate]).render(activate="activate")

number = 0


def incr(ev, elt):
    elt.data.number += 1


def decr(ev, elt):
    elt.data.number -= 1


def incre(ev, elt):
    elt.data.number_2 += 1


def decre(ev, elt):
    elt.data.number_2 -= 1


def rest(ev, elt):
    elt.data.number = 0
コード例 #10
0
def formate(num, quant):
    """
    change format
    according to the result
    """
    num = num * quant
    if num < 1:
        num = 100 * num
        return '{0}p'.format(str(num))
    else:
        num = round(num, 2)
        return '£{0}'.format(str(num))


app_tmpl = Template(doc["container-1"])
app_tmpl.render(item=item,
                price=price,
                quantity=quantity,
                product=product,
                total=formate(price, quantity))


def update_value(ev, elt):
    """
      update new value
      """
    global product
    if ev.target.value == "banane":
        item = product[1][0]
        price = product[1][1]
コード例 #11
0
ファイル: index.py プロジェクト: davtoh/enterprise-website
articleContent = open('/static/home/python/news_file.txt').read()
articleTitle = articleContent.split('\n', 1)[0]
articleText = articleContent.split('\n', 1)[1]

# Article Object
article = [
    html.H1('{title}', Id='art_title'),
    html.P('{content}', Id="art_content")
]

# Navigation
nav = html.DIV([html.H1('{title}', Id='title'),
                html.H2('☰', Id='navbtn')],
               Class='nav')

# Content
cnt = html.DIV(html.DIV(article, Class="article"), Class='content')

# Footer
ftr = html.DIV(
    [html.P(('Copyright {} 2018 - All rights reserved.'.format(pageName)))],
    Class='footer')

# Push the elements to the DOM
document <= [nav, cnt, ftr]

# Render the template tags
Template(document['title']).render(title=pageName)
Template(document['art_title']).render(title=articleTitle)
Template(document['art_content']).render(content=articleText + " " +
                                         os.getcwd())
コード例 #12
0
def test_browser_Template():
    from browser import document
    from browser.template import Template

    Template(document["team"]).render(name="Liverpool FC")
コード例 #13
0
ファイル: single.py プロジェクト: ichem/Brython
from browser import document as doc, window as win
from browser.template import Template

Template(doc['container-1']).render(greeting="Hello", name="World")
Template(doc['container-2']).render(greeting="你好", name="世界")


def loading():
    """ hide loading id and show
    container-1 and container-2 """
    doc['container-1'].style.display = "block"
    doc['container-2'].style.display = "block"
    doc['loading'].style.display = "none"


win.onload = loading()
コード例 #14
0
from browser import document, html
from browser.template import Template

# https://brython.info/static_doc/fr/intro.html?lang=fr

tasks = ["Make my app with Brython", "I really loved Python ♥"]


def addTask(ev, elem):
    ev.preventDefault()
    task = document.get(name='task')[0]
    if len(task.value) <= 0: return
    elem.data.tasks.append(task.value)
    task.value = ""


def delTask(ev, elem):
    index = int(ev.target.value)
    del elem.data.tasks[index]


Template('todolist', [addTask, delTask]).render(tasks=tasks)
コード例 #15
0
from browser import document
from browser import html
from browser.template import Template

pageName = "Python 🐍"

articleContent = open('news_file.txt').read()
articleTitle = articleContent.split('\n', 1)[0]
articleText = articleContent.split('\n', 1)[1]

article = [
    html.H1('{title}', Id='art_title'),
    html.P('{text}', Id='art_content')
]

nav = html.DIV([html.H1('{title}', Id='title'),
                html.H2('☰', Id='navbtn')],
               Class="nav")

cnt = html.DIV(html.DIV(article, Class="article"), Class="content")

ftr = html.DIV(
    [html.P('Copyright {} 2018 - All rights reserved.'.format(pageName))],
    Class="footer")

document <= [nav, cnt, ftr]

Template(document['title']).render(title=pageName)
Template(document['art_title']).render(title=articleTitle)
Template(document['art_content']).render(text=articleText)
コード例 #16
0
def init_table():
    t_data = gen_table()
    Template('pick_data', [sort]).render(header=t_data[0], items=t_data[1:])
コード例 #17
0
ファイル: index.py プロジェクト: OSX-RSPlug-a/BrythonReqAPI
      </script>
  
      <script type="text/python" id="script1">
          from browser import document
  
          def show_text(e):
              document['output'].textContent = e.target.value;
  
          document['text'].bind('input', show_text)
      </script>
  
      <script type="text/python" id="script2">
          from browser import document
          from browser.template import Template
  
          Template(document['greet']).render(name='Brad')
      </script>

      <script type="text/python" id="script4">
          from browser import document, window
  
          def file_read(e):
              def onload(e):
                  document['file-text'].value = e.target.result 
              
              file = document['file-upload'].files[0]
              reader = window.FileReader.new()
              reader.readAsText(file)
              reader.bind('load', onload)
          
          document['file-upload'].bind('input', file_read)