コード例 #1
0
 def title_from_filename(filename):
     if filename.endswith('.js'):
         filename = filename.replace('Example', '').replace('.js', '')
         return common.camel_case_to_space(filename) + ' (Node.js)'
     elif filename.endswith('.html'):
         filename = filename.replace('Example', '').replace('.html', '')
         return common.camel_case_to_space(filename) + ' (HTML)'
     else:
         raise ValueError('Invalid filename ' + filename)
コード例 #2
0
 def title_from_filename(filename):
     if filename.endswith('.js'):
         filename = filename.replace('Example', '').replace('.js', '')
         return common.camel_case_to_space(filename) + ' (Node.js)'
     elif filename.endswith('.html'):
         filename = filename.replace('Example', '').replace('.html', '')
         return common.camel_case_to_space(filename) + ' (HTML)'
     else:
         raise ValueError('Invalid filename ' + filename)
コード例 #3
0
 def title_from_filename(filename):
     filename = filename.replace('Example', '').replace('.nb.txt', '')
     return common.camel_case_to_space(filename)
コード例 #4
0
 def title_from_file(f):
     f = f.replace('Example', '')
     f = f.replace('.cs', '')
     return common.camel_case_to_space(f)
コード例 #5
0
 def title_from_filename(filename):
     filename = filename.replace('Example', '').replace('.cs', '')
     return common.camel_case_to_space(filename)
コード例 #6
0
        def get_source_block(packet):
            is_getter = False
            elements_in = packet.get_elements('in')
            elements_out = packet.get_elements('out')

            if len(elements_out) > 0:
                is_getter = True

            block_name = '_'.join([self.get_tvpl_device_name(), packet.get_underscore_name()])
            block_uid = '_UID'
            block_host = '_HOST'
            block_port = '_PORT'
            block_display_device_name = self.get_long_display_name()
            block_display_function_name = common.camel_case_to_space(packet.get_camel_case_name())
            block_set_color = 'this.setColour(210);'
            block_help_url = 'this.setHelpUrl(\'' + '/'.join(['http://www.tinkerforge.com/en/doc/Software',
                                                              self.get_camel_case_category() +\
                                                              's',
                                                              self.get_camel_case_name() +\
                                                              '_' +\
                                                              self.get_camel_case_category() +\
                                                              '_JavaScript.html#' +\
                                                              self.get_camel_case_category() +\
                                                              self.get_camel_case_name() +\
                                                              '.' +\
                                                              packet.get_headless_camel_case_name()]) +\
                                                              '\');'
            block_set_previous_statement = 'this.setPreviousStatement(true);'
            block_set_next_statement = 'this.setNextStatement(true);'
            block_set_output = 'this.setOutput(false);'
            block_code_header = '''Blockly.Blocks['{blockname}'] = {{
  init: function() {{'''.format(blockname = block_name)

            if is_getter:
                block_set_previous_statement = 'this.setPreviousStatement(false);'
                block_set_next_statement = 'this.setNextStatement(false);'
                if len(elements_out) > 1:
                    block_set_output = 'this.setOutput(true, \'Array\');'
                elif len(elements_out) == 1:
                    block_set_output = 'this.setOutput(true, \'' + elements_out[0].get_tvpl_type() + '\');'
                if len(elements_in) < 1:
                    # Getters without in args
                    block_code_body = '''
    this.appendDummyInput()
        .appendField('{blockdescription}');
    this.appendValueInput('{uid}')
        .setCheck(\'String\');
    this.appendDummyInput()
        .appendField(\'at\');
    this.appendValueInput('{host}')
        .setCheck(\'String\');
    this.appendDummyInput()
        .appendField(\':\');
    this.appendValueInput('{port}')
        .setCheck(\'Number\');
'''.format(blockdescription = ' '.join([block_display_function_name, 'of', block_display_device_name]),
           uid = block_uid,
           host = block_host,
           port = block_port)

                    block_code_footer = '''    this.setInputsInline(true);
    {setoutput}
    {previousstatement}
    {nextstatement}
    {color}
    {helpurl}
  }}
}};
'''.format(setoutput = block_set_output,
           previousstatement = block_set_previous_statement,
           nextstatement = block_set_next_statement,
           color = block_set_color,
           helpurl = block_help_url)
                    return block_code_header + block_code_body + block_code_footer

            if not is_getter:
                if len(elements_in) < 1:
                    # Setters without in args
                    block_code_body = '''
    this.appendDummyInput()
        .appendField('{blockdescription}');
    this.appendValueInput('{uid}')
        .setCheck(\'String\');
    this.appendDummyInput()
        .appendField(\'at\');
    this.appendValueInput('{host}')
        .setCheck(\'String\');
    this.appendDummyInput()
        .appendField(\':\');
    this.appendValueInput('{port}')
        .setCheck(\'Number\');
'''.format(blockdescription = ' '.join([block_display_function_name, 'of', block_display_device_name]),
           uid = block_uid,
           host = block_host,
           port = block_port)

                    block_code_footer = '''    this.setInputsInline(true);
    {setoutput}
    {previousstatement}
    {nextstatement}
    {color}
    {helpurl}
  }}
}};
'''.format(setoutput = block_set_output,
           previousstatement = block_set_previous_statement,
           nextstatement = block_set_next_statement,
           color = block_set_color,
           helpurl = block_help_url)
                    return block_code_header + block_code_body + block_code_footer

            # Getters/setters with in args
            block_code_body = ''

            if len(elements_out) < 1:
                block_code_body = '''
    this.appendDummyInput()
        .appendField('{functionname}');
    this.appendDummyInput()
        .appendField('to');
'''.format(functionname = block_display_function_name)
            else:
                block_code_body = '''
    this.appendDummyInput()
        .appendField('{functionname}');
'''.format(functionname = block_display_function_name)

            for i, e in enumerate(elements_in):
                if e.get_constant_group():
                    # Create combobox with allowed input values
                    constant_group = e.get_constant_group()
                    combo_constants_array = ''
                    for index , constant in enumerate(constant_group.get_constants()):
                        if index == 0:
                            combo_constants_array = '['
                        combo_constants_array = combo_constants_array +\
                                                '[\'' +\
                                                common.camel_case_to_space(constant.get_camel_case_name()) +\
                                                '\'' +\
                                                ', ' +\
                                                '\'' +\
                                                str(constant.get_value()) +\
                                                '\']'
                        if index == len(constant_group.get_constants()) - 1:
                            combo_constants_array = combo_constants_array + ']'
                        else:
                            combo_constants_array = combo_constants_array + ', '

                    block_code_body = block_code_body + '''    this.appendDummyInput()
        .appendField('{ename}');
    this.appendDummyInput()
        .appendField(new Blockly.FieldDropdown({constantsarray}), '{fieldname}');
'''.format(ename = common.camel_case_to_space(e.get_headless_camel_case_name()).title(),
           constantsarray = combo_constants_array,
           fieldname = e.get_underscore_name().upper())

                    if i < len(elements_in) - 2:
                        block_code_body = block_code_body + '''    this.appendDummyInput()
        .appendField(',');
'''
                    elif i == len(elements_in) - 2:
                        block_code_body = block_code_body + '''    this.appendDummyInput()
        .appendField('and');
'''

                elif e.get_tvpl_type() == 'Boolean':
                    # Create combobox with boolean values
                    block_code_body = block_code_body + '''    this.appendDummyInput()
        .appendField('{ename}');
    this.appendDummyInput()
        .appendField(new Blockly.FieldDropdown([['True', '1'], ['False', '0']]), '{fieldname}');
'''.format(ename = common.camel_case_to_space(e.get_headless_camel_case_name()).title(),
           fieldname = e.get_underscore_name().upper())

                    if i < len(elements_in) - 2:
                        block_code_body = block_code_body + '''    this.appendDummyInput()
        .appendField(',');
'''
                    elif i == len(elements_in) - 2:
                        block_code_body = block_code_body + '''    this.appendDummyInput()
        .appendField('and');
'''

                elif e.get_tvpl_type() != 'Boolean':
                    # Create input field of specific types
                    block_code_body = block_code_body + '''    this.appendDummyInput()
        .appendField('{ename}');
    this.appendValueInput('{variablename}')
        .setCheck('{etvpltype}');
'''.format(ename = common.camel_case_to_space(e.get_headless_camel_case_name()).title(),
           variablename = e.get_underscore_name().upper(),
           etvpltype = e.get_tvpl_type())

                    if i < len(elements_in) - 2:
                        block_code_body = block_code_body + '''    this.appendDummyInput()
        .appendField(',');
'''
                    elif i == len(elements_in) - 2:
                        block_code_body = block_code_body + '''    this.appendDummyInput()
        .appendField('and');
'''

            block_code_body = block_code_body + '''    this.appendDummyInput()
        .appendField('of {devicename}');
    this.appendValueInput('{uid}')
        .setCheck("String");
    this.appendDummyInput()
        .appendField("at");
    this.appendValueInput('{host}')
        .setCheck("String");
    this.appendDummyInput()
        .appendField(":");
    this.appendValueInput('{port}')
        .setCheck("Number");
'''.format(devicename = block_display_device_name,
           uid = block_uid,
           host = block_host,
           port = block_port)

            block_code_footer = '''    this.setInputsInline(true);
    {output}
    {previousstatement}
    {nextstatement}
    {color}
    {helpurl}
  }}
}};
'''.format(output = block_set_output,
           previousstatement = block_set_previous_statement,
           nextstatement = block_set_next_statement,
           color = block_set_color,
           helpurl = block_help_url)

            return block_code_header + block_code_body + block_code_footer
コード例 #7
0
 def title_from_filename(filename):
     filename = filename.replace("Example", "").replace(".pas", "")
     return common.camel_case_to_space(filename)
コード例 #8
0
 def title_from_file(f):
     f = f.replace("Example", "")
     f = f.replace(".java", "")
     return common.camel_case_to_space(f)