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 result(): s = self.state.value if s is True: hdr = Html( '<button onclick="{0}" style="width: 100%; text-align: left">' .format(post_event_js_code_for_handler('clicked')), self.__header, '</button>') hdr = hdr.js_function_call( 'larch.controls.initButton', {'icons': { 'primary': 'ui-icon-minus' }}) hdr = hdr.with_event_handler('clicked', on_clicked) ct = Html('<div class="dropdown_expander_content">', self.__content, '</div>') return Html(hdr, ct) elif s is False: hdr = Html( '<button onclick="{0}" style="width: 100%; text-align: left">' .format(post_event_js_code_for_handler('clicked')), self.__header, '</button>') hdr = hdr.js_function_call( 'larch.controls.initButton', {'icons': { 'primary': 'ui-icon-plus' }}) hdr = hdr.with_event_handler('clicked', on_clicked) return hdr else: raise TypeError, 'drop down expander: state type unknown'
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): css = ' class="{0}"'.format( self.__css_class) if self.__css_class is not None else '' p = Html('<a {2}href="javascript:" onclick="{0}">{1}</a>'.format( post_event_js_code_for_handler('clicked'), self.__link_text, css)) p = p.with_event_handler('clicked', self.clicked) return p
def pres(self, pres_ctx): options = {} if self.__disabled is not False: options['disabled'] = True if self.__primary_icon is not None or self.__secondary_icon is not None: icons = {} if self.__primary_icon is not None: icons['primary'] = self.__primary_icon if self.__secondary_icon is not None: icons['secondary'] = self.__secondary_icon options['icons'] = icons if self.__text is not None: p = Html( '<button type="button" onclick="{0}">'.format( post_event_js_code_for_handler('clicked')), self.__text, '</button>').js_function_call('larch.controls.initButton', options) else: options['text'] = False p = Html('<button type="button" onclick="{0}"></button>' ).js_function_call('larch.controls.initButton', options) p = p.with_event_handler('clicked', self.clicked).use_js( '/static/larch/larch_ui.js').use_css('/static/larch/larch_ui.css') 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): 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): 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): options = {} if self.__disabled is not False: options['disabled'] = True if self.__primary_icon is not None or self.__secondary_icon is not None: icons = {} if self.__primary_icon is not None: icons['primary'] = self.__primary_icon if self.__secondary_icon is not None: icons['secondary'] = self.__secondary_icon options['icons'] = icons if self.__text is not None: p = Html('<button type="button" onclick="{0}">'.format(post_event_js_code_for_handler('clicked')), self.__text, '</button>').js_function_call('larch.controls.initButton', options) else: options['text'] = False p = Html('<button type="button" onclick="{0}"></button>').js_function_call('larch.controls.initButton', options) p = p.with_event_handler('clicked', self.clicked).use_js('/files/static/larch/larch_ui.js').use_css('/files/static/larch/larch_ui.css') return p
def pres(self, pres_ctx): css = ' class="{0}"'.format(self.__css_class) if self.__css_class is not None else '' p = Html('<a {2}href="javascript:" onclick="{0}">{1}</a>'.format(post_event_js_code_for_handler('clicked'), self.__link_text, css)) p = p.with_event_handler('clicked', self.clicked) 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('/files/static/larch/larch_ui.js').use_css('/files/static/larch/larch_ui.css') return p
def pres(self, pres_ctx): p = Html('<li><a>', self.__item_content, '</a></li>') p = p.with_event_handler('menu_select', self.select) return p