def add_switch_demo(self): clock = HClock() clock.is_visible = False self.add_component(clock) clock.bounds.x = (self.bounds.w - clock.bounds.w) / 2 clock.bounds.y = self.bounds.h - (2 * clock.bounds.h) fps = HFramesPerSecond() fps.is_visible = False self.add_component(fps) fps.bounds.x = (self.bounds.w - fps.bounds.w) / 2 fps.bounds.y = fps.bounds.h panel = HContainer() panel.insets = HInset(10, 10, 0, 10) panel.layout = HColumnLayout(panel) panel.layout.pad = HInset(0, 0, 2, 2) panel.layout.fill_width = False switch_clock = HSwitch() switch_clock.id = clock switch_clock.change_listeners.append(self.switch_flipped) switch_fps = HSwitch() switch_fps.id = fps switch_fps.change_listeners.append(self.switch_flipped) panel.add_component(HText('Use Switches to control On/Off functions')) panel.add_component(HText('Activate Time Display')) panel.add_component(switch_clock) panel.add_component(HText('Activate Frame Rate Display')) panel.add_component(switch_fps) window = DemoWindow('HSwitch Components') window.add_component(panel) window.is_visible = False self.add_component(window) panel.laf['Shape'] = rectangle return window
def add_side_bar(self): buttonInfos = (('Text Component Demo', self.text_demo), ('Image Component Demo', self.image_demo), ('Slider Component Demo', self.slider_demo), ('Switch Component Demo', self.switch_demo), ('Progress Bar Component Demo', self.progress_demo), ('Look and Feel Demo', self.lookandfeel_demo), ('Sample Clock Component', self.clock), ('Sample Frames Per Second Component', self.fps)) side_bar = HContainer() side_bar.insets = HInset(20, 20, 20, 20) side_bar.layout = HColumnLayout(side_bar) side_bar.layout.pad = HInset(0, 0, 4, 0) for buttonInfo in buttonInfos: button = HButton(buttonInfo[0]) button.id = buttonInfo[1] button.click_listeners.append(self.button_clicked) side_bar.add_component(button) self.add_component(side_bar) side_bar.laf['Shape'] = round_right_rect y = (self.bounds.h - side_bar.bounds.h) / 2 x = -side_bar.bounds.w + 20 side_bar.bounds.x = x side_bar.bounds.y = y side_bar.touch_listeners.append(self.drag_side_bar) return side_bar
def add_slider_demo(self): panel = HContainer() panel.insets = HInset(10, 10, 0, 10) panel.layout = HColumnLayout(panel) panel.layout.pad = HInset(0, 0, 4, 0) panel.add_component(HText('Sliders Adjust Background')) r, g, b = self.laf['Background'] slider = HSlider() slider.id = 'red' slider.value = r slider.change_listeners.append(self.slider_moved) panel.add_component(slider) slider = HSlider() slider.id = 'green' slider.value = g slider.change_listeners.append(self.slider_moved) panel.add_component(slider) slider = HSlider() slider.id = 'blue' slider.value = b slider.change_listeners.append(self.slider_moved) panel.add_component(slider) self.slider_text = HText() self.slider_moved(slider) panel.add_component(self.slider_text) window = DemoWindow('HSlider Components') window.add_component(panel) window.is_visible = False self.add_component(window) panel.laf['Shape'] = rectangle return window
def add_simple_window(self, inComponent, inTitle): panel = HContainer() panel.layout = HColumnLayout(panel) panel.add_component(inComponent) window = DemoWindow(inTitle) window.add_component(panel) window.is_visible = False self.add_component(window) return window
def add_lookandfeel_demo(self): buttonInfos = ((self.set_laf_1, 'left'), (self.set_laf_2, 'center'), (self.set_laf_3, 'right')) self.font_label = HText() self.font_size_label = HText() self.font_colour_label = HText() self.shape_label = HText() self.radius_label = HText() self.background_label = HText() self.border_label = HText() self.border_on_label = HText() self.border_width_label = HText() barInfos = (('Top ', 'Font Name', self.font_label), ('', 'Font Size', self.font_size_label), ('', 'Font Colour', self.font_colour_label), ('', 'Shape', self.shape_label), ('', 'Radius', self.radius_label), ('', 'Background', self.background_label), ('', 'Border', self.border_label), ('', 'Border On', self.border_on_label), ('Bottom ', 'Border Width', self.border_width_label)) panel = HContainer() panel.layout = HColumnLayout(panel) panel.layout.pad = HInset(0, 0, -0.5, -0.5) panel.insets = HInset(10, 10, 10, 10) panel.add_component(HText("A sample of the LookAndFeel properties")) bar = HContainer() bar.layout = HBarLayout(bar) bar.layout.pad = HInset(5, 5, 0, 0) bar.insets = HInset(5, 5, 10, 10) for i, buttonInfo in enumerate(buttonInfos): button = HButton('Sample L&F {}'.format(i)) button.id = buttonInfo[0] button.click_listeners.append(self.laf_button_clicked) bar.add_component(button, buttonInfo[1]) panel.add_component(bar) spacer = HComponent() spacer.laf_prefix = "Spacer " spacer.preferred_size = Size(10, 10) panel.add_component(spacer) for barInfo in barInfos: bar = HContainer() bar.laf_prefix = '{}Selection Bar '.format(barInfo[0]) bar.layout = HBarLayout(bar) bar.add_component(HText(barInfo[1]), 'left') bar.add_component(barInfo[2], 'right') panel.add_component(bar) self.set_laf_demo_labels() window = DemoWindow('Look and Feel Demo') window.add_component(panel) window.is_visible = False self.add_component(window) panel.laf['Shape'] = rectangle return window
def add_progress_demo(self): panel = HContainer() panel.layout = HColumnLayout(panel) panel.insets = HInset(10, 10, 0, 10) panel.add_component(HText('Progress bar linked to clock seconds')) panel.add_component(DemoProgressBar()) window = DemoWindow('HProgressBar Component') window.add_component(panel) window.is_visible = False self.add_component(window) panel.laf['Shape'] = rectangle return window
def add_text_demo(self): panel = HContainer() panel.insets = HInset(10, 10, 5, 5) panel.layout = HColumnLayout(panel) panel.layout.pad = HInset(0, 0, -0.5, 0) panel.layout.fill_width = False lines = '''Demonstration text components Simple control that will write text label on screen Choose any font available in Pythonista And any font size or colour Borders and Backgrounds can be configured with the Look-And-Feel Just like all of the other components''' for line in lines.splitlines(): panel.add_component(HText(line.strip())) window = DemoWindow('HText Components') window.add_component(panel, 'center') window.is_visible = False self.add_component(window) panel.laf['Shape'] = rectangle return window