Exemplo n.º 1
0
def css_cached(state):
    try:
        return css_cached.cache[state.localization]
    except KeyError:
        pass
    css_cached.cache[state.localization] = the_css = css(state)
    utilities.write(
        os.path.join('HTML', ','.join(state.localization) + '.css'), the_css)
    return the_css  # The cache may have been cleared
Exemplo n.º 2
0
def generate_javascript(state):
    s = [
        '''
var messages = {} ;

function add_messages(lang, dict)
{
  for(var i in dict)
    {
      if ( messages[lang] === undefined )
           messages[lang] = {} ;
      messages[lang][i] = dict[i] ;
    }
}

function _(message)
{
  for(var lang in languages)
    if ( messages[languages[lang]] !== undefined
      && messages[languages[lang]][message] !== undefined )
       return messages[languages[lang]][message] ;
  return message ;
}

function triggerKeyboardEvent(el, keyCode)
{
    var eventObj = document.createEventObject
      ? document.createEventObject()
      : document.createEvent("Events") ;

    if(eventObj.initEvent){
      eventObj.initEvent("keypress", true, true) ;
    }

    eventObj.keyCode = keyCode ;
    eventObj.which = 0 ;
    eventObj.charCode = keyCode ;
    eventObj.target = el ;
    eventObj.eventPhase == Event.AT_TARGET ;

    if ( el.dispatchEvent )
      el.dispatchEvent(eventObj) ;
    else
      el.fireEvent("onkeypress", eventObj) ;
}

    '''
    ]
    for p in state.plugins_dict.values():
        if p.javascript:
            s.append('/* PLUGIN: ' + p.plugin.css_name + ' */')
            s.append(p.javascript)
    utilities.write(os.path.join('HTML', 'quenlig.js'), '\n'.join(s))
Exemplo n.º 3
0
def save_options(a_state, m_plugin):
    for plugin in a_state.plugins_list:
        a_plugin = plugin.plugin
        name = a_plugin["", "option_name"]
        if not name:
            continue
        value = a_state.form.get('option__' + a_plugin.css_name)
        if value is None:
            continue
        value = value.strip()
        if plugin.option == value:
            continue
        utilities.write(name, value, overwrite=True)

    from QUENLIG import state
    for s in state.states.values():
        for p in s.plugins_list:
            s.init_option(p)
Exemplo n.º 4
0
def update_roles(astudent):
    """Initialize the role list for the student and its 'ancestors'""" 
    if 'roles' in astudent.__dict__:
        return
    astudent.roles_filename = os.path.join(astudent.file, 'roles')
    if astudent.filename in default_roles:
        astudent.roles = default_roles[astudent.filename]
    else:
        default = "['Student']"
        utilities.write(astudent.roles_filename, default, overwrite=False)
        try:
            astudent.roles = eval(utilities.read(astudent.roles_filename))
        except:
            print('BUG', astudent, utilities.read(astudent.roles_filename))
            astudent.roles = eval(default)


    astudent.current_role = astudent.roles[0]
    astudent.old_role = None
    
    for role in astudent.roles:
        update_roles( student.student(role) )
Exemplo n.º 5
0
    def __call__(self, student_answer, state=None):

        utilities.write('xxx.c', student_answer + '\n')
        error = os.system("gcc -Wall xxx.c 2>xxx.errors")
        error_text = utilities.read('xxx.errors')
        if error:
            return False, '<pre>' + error_text + '</pre>'

        f = subprocess.Popen(
            ["./a.out"] + self.c_args,
            stdin=subprocess.PIPE,
            stdout=subprocess.PIPE,
        )
        result = f.communicate(self.c_input)

        ok, comment = self.children[0](result[0], state)

        if error_text != '':
            message = 'Message du compilateur : <pre>' + error_text + '</pre><hr>'
        else:
            message = ''

        return (ok, message + 'Ce que ce programme affiche : <pre>' +
                result[0] + '</pre>' + comment)
Exemplo n.º 6
0
 def change_acls(self, plugin, key):
     old = repr(self.acls)
     self.add_an_acl(plugin, key)
     if old != repr(self.acls):
         utilities.write(self.filename, repr(self.acls))
         reload() # Force plugins tree update