def pres(self, pres_ctx): textarea = Html(u'<textarea>{text}</textarea>'.format( text=Html.escape_str(self.__text))) textarea = textarea.js_function_call('larch.controls.initCodeMirror', self.__config, self.__immediate_events, self.__channel) p = Html('<div>', textarea, '</div>') p = p.use_css('/static/codemirror-3.14/lib/codemirror.css') p = p.use_js('/static/codemirror-3.14/lib/codemirror.js') for mode in self.__modes: p = p.use_js( '/static/codemirror-3.14/mode/{0}/{0}.js'.format(mode)) for addon in _addon_js: p = p.use_js('/static/codemirror-3.14/addon/{0}'.format(addon)) for addon in _addon_css: p = p.use_css('/static/codemirror-3.14/addon/{0}'.format(addon)) if _code_mirror_theme is not None: p = p.use_css('/static/codemirror-3.14/theme/{0}.css'.format( _code_mirror_theme)) p = p.use_js('/static/larch/larch_ui.js').use_css( '/static/larch/larch_ui.css') p = p.with_event_handler('code_mirror_edit', lambda event: self.edit(event, event.data)) p = p.with_event_handler('code_mirror_focus', self.focus) p = p.with_event_handler('code_mirror_blur', self.blur) return p
def audio_capture_button(num_channels, format, audio_data_callback): """ Create an audio capture button :param num_channels: the number of channels; 1 = mono, 2 = stereo :param format: the data format; valid formats are provided by constants in the larch.media.audio module: FORMAT_WAV: WAV file format FORMAT_RAW8: raw data, 8-bit signed integer per sample per channel FORMAT_RAW16: raw data, 16-bit signed integer per sample per channel, FORMAT_RAWF32: raw data, 32-bit float per sample per channel audio_data_callback - a callback function that is invoked when audio data is received from the browser, of the form function(data_file, sample_rate, num_samples, num_channels), where: data_file - an object that contains the audio data, has a read method, the same kind of object as used to form file uploads. sample_rate - the sample rate of the received audio data, in Hz num_samples - the number of samples received; to get length in seconds, divide this number by sample_rate num_channels - the number of channels in the received data """ def _submit(event): num_channels = int(event.data['num_channels']) sample_rate = int(event.data['sample_rate']) num_samples = int(event.data['num_samples']) data_file = event.data['data'].file audio_data_callback(data_file, sample_rate, num_samples, num_channels) if format not in _valid_formats: raise ValueError, 'Unknown audio format \'{0}\''.format(format) button = Html('<button></button>').js_function_call( 'larch.media.initAudioCaptureButton', num_channels, format) button = button.with_event_handler('form_submit', _submit) button = button.use_js('/static/larch/larch_media.js') return button
def pres(self, pres_ctx): p = Html('<form enctype="multipart/form-data">', self.__contents, '</form>').js_function_call( 'larch.controls.initForm').with_event_handler( 'form_submit', self.submit) p = p.use_js('/static/jquery/js/jquery.form.min.js').use_js( '/static/larch/larch_ui.js').use_css('/static/larch/larch_ui.css') return p
def pres(self, pres_ctx): sz = '' if self.__width is not None: sz = ' style="width: {0};"'.format(self.__width) p = Html('<input type="text" value="{0}"{1}></input>'.format(self.__text, sz)).js_function_call('larch.controls.initTextEntry', self.__immediate_events, self.__channel) p = p.with_event_handler('text_entry_edit', lambda event: self.edit(event, event.data)) p = p.use_js('/files/static/larch/larch_ui.js').use_css('/files/static/larch/larch_ui.css') return p
def pres(self, pres_ctx): p = Html( *(['<select>'] + self.__options + ['</select>'])).js_function_call('larch.controls.initSelect') p = p.with_event_handler('select_choose', lambda event: self.choose(event, event.data)) p = p.use_js('/static/larch/larch_ui.js').use_css( '/static/larch/larch_ui.css') return p
def pres(self, pres_ctx): p = Html(self.__contents).js_function_call( 'larch.controls.initFocusable').js_shutdown_function_call( 'larch.controls.shutdownFocusable') p = p.with_event_handler('gain_focus', self.gain_focus) p = p.with_event_handler('lose_focus', self.lose_focus) p = p.use_js('/static/larch/larch_ui.js').use_css( '/static/larch/larch_ui.css') return p
def pres(self, pres_ctx): spin = Html('<input name={0} value={1} />'.format( self.__input_name, self.__value)) spin = spin.js_function_call('larch.controls.initSpinner', self.__channel) spin = spin.with_event_handler("spinner_change", self.__on_spinner_change) spin = spin.use_js('/static/larch/larch_ui.js').use_css( '/static/larch/larch_ui.css') return spin
def pres(self, pres_ctx): if self.__width is None: div = Html('<div></div>') else: div = Html('<div style="width: {0};"></div>'.format(self.__width)) div = div.js_function_call('larch.controls.initSlider', True, self.__options, self.__channel) div = div.with_event_handler("slider_change", lambda event: self.release(event, event.data)) div = div.with_event_handler("slider_slide", lambda event: self.slide(event, event.data)) div = div.use_js('/static/larch/larch_ui.js').use_css('/static/larch/larch_ui.css') return div
def pres(self, pres_ctx): if self.__width is None: div = Html('<div></div>') else: div = Html('<div style="width: {0};"></div>'.format(self.__width)) div = div.js_function_call('larch.controls.initSlider', True, self.__options, self.__channel) div = div.with_event_handler("slider_change", lambda event: self.release(event, event.data)) div = div.with_event_handler("slider_slide", lambda event: self.slide(event, event.data)) div = div.use_js('/files/static/larch/larch_ui.js').use_css('/files/static/larch/larch_ui.css') return div
def pres(self, pres_ctx): sz = '' if self.__width is not None: sz = ' style="width: {0};"'.format(self.__width) p = Html('<input type="text" value="{0}"{1}></input>'.format( self.__text, sz)).js_function_call('larch.controls.initTextEntry', self.__immediate_events, self.__channel) p = p.with_event_handler('text_entry_edit', lambda event: self.edit(event, event.data)) p = p.use_js('/static/larch/larch_ui.js').use_css( '/static/larch/larch_ui.css') return p
def pres(self, pres_ctx): if self.__use_edit_button: p = Html( u'<div class="__larch_ui_ckeditor_edit_container"><div>{text}</div></div>' .format(text=self.__text)).js_function_call( 'larch.controls.initCKEditorWithEditButton', self.__config, self.__immediate_events, self.__channel) else: p = Html(u'<div contenteditable="true">{text}</div>'.format( text=self.__text)) p = p.js_function_call('larch.controls.initCKEditor', self.__config, self.__immediate_events, self.__channel) p = p.js_shutdown_function_call('larch.controls.shutdownCKEditor') p = p.use_js('/static/ckeditor/ckeditor.js') p = p.use_js('/static/larch/larch_ui.js').use_css( '/static/larch/larch_ui.css') p = p.with_event_handler('ckeditor_edit', lambda event: self.edit(event, event.data)) p = p.with_event_handler('ckeditor_focus', self.focus) p = p.with_event_handler('ckeditor_blur', self.blur) return p
def pres(self, pres_ctx): contents = ['<div><ul>'] for i, (tab, content) in enumerate(self.__tab_label_and_content_pairs): contents.extend([ '<li><a href="#__larch_tabs_{0}_{1}">'.format( self.__tab_counter, i), tab, '</a></li>' ]) contents.append('</ul>') for i, (tab, content) in enumerate(self.__tab_label_and_content_pairs): contents.extend([ '<div id="__larch_tabs_{0}_{1}">'.format( self.__tab_counter, i), content, '</div>' ]) contents.append('</div>') tabs.__tab_counter += 1 t = Html(*contents) t = t.js_function_call('larch.controls.initTabs') t = t.use_js('/static/larch/larch_ui.js').use_css( '/static/larch/larch_ui.css') return t
def pres(self, pres_ctx): p = Html(*(['<select>'] + self.__options + ['</select>'])).js_function_call('larch.controls.initSelect') p = p.with_event_handler('select_choose', lambda event: self.choose(event, event.data)) p = p.use_js('/files/static/larch/larch_ui.js').use_css('/files/static/larch/larch_ui.css') return p