def show_copied_popup(self, address): btnclose = Button(text='Close this popup', size_hint_y=None, height='50sp') content = BoxLayout(orientation='vertical') row_length = 15 for i in range(0, len(address), row_length): content.add_widget(Label(text=address[i:i + row_length])) content.add_widget(btnclose) popup = Popup(content=content, title='Copied Address', size_hint=(None, None), size=('300dp', '300dp')) btnclose.bind(on_release=popup.dismiss) button = Button(text='Open popup', size_hint=(None, None), size=('150sp', '70dp'), on_release=popup.open) popup.open() col = AnchorLayout() col.add_widget(button) return col
def parse_weather(self): json = my_screenmanager.get_screen('screen1').json_data #picture_url = "http://openweathermap.org/img/w/{}.png".format( json['weather'][0]['icon'] ) print('JSON: ', json) #print('PICS: ', picture_url) al = AnchorLayout() bl = BoxLayout(orientation='vertical', size_hint=[None, None], size=[300, 200]) if json == None: bl.add_widget(Label(text="{}".format('Данных нет'))) else: #bl.add_widget( Image( source = picture_url, size_hint_y = None ) ) bl.add_widget(Label(text="{}".format(json['name']))) bl.add_widget( Label(text="Температура: макс. - {}, мин. - {}".format( json['main']['temp'], json['main']['temp_min']))) bl.add_widget( Label(text="Погода: main - {}, details - {}".format( json['weather'][0]['main'], json['weather'][0] ['description']))) bl.add_widget( Label(text="Облачность: {}%".format(json['clouds']['all']))) bl.add_widget( Label(text="Скорость ветра: {}".format(json['wind']['speed']))) city_button = Button(text='Назад') city_button.bind(on_press=self.changer) bl.add_widget(city_button) al.add_widget(bl) return self.add_widget(al)
def build(self): def GetAMTime(now): hour = now.hour minute = str(now.minute) Sub = " AM" if now.minute < 10: minute = "0" + minute if now.hour > 12: hour = now.hour - 12 Sub = " PM" elif now.hour < 12: Sub = " AM" hour = str(hour) return hour + ":" + minute + Sub def GetTwentyFourTime(now): print('Getting 24 Hour Time') hour = str(now.hour) minute = str(now.minute) if now.minute < 10: minute = "0" + minute print(hour + ":" + minute) return hour + ":" + minute MenuClock = Label(text="Time", color=Black, size_hint_y=None, height=30) ClockAnchor = AnchorLayout(anchor_y='top', anchor_x='right') ClockAnchor.add_widget(MenuClock) def timeupdate(): MenuClock.text = GetAMTime(datetime.now()) pass Clock.schedule_interval(lambda dt: timeupdate(), 0.5) return ClockAnchor
def build(self): self.title = "Menu" self.al = AnchorLayout(anchor_x='right', anchor_y='bottom', padding=[160, 85, 0, 0]) self.gl = GridLayout(cols=2) self.b1 = Button(text='Редактор \n файлов', size_hint=(None, None), size=(180, 90), on_press=self.update) self.b2 = Button(text='Калькулятор', size_hint=(None, None), size=(180, 90), on_press=self.calculator) self.b3 = Button(text='X и O', size_hint=(None, None), size=(180, 90), on_press=self.XandO) self.b4 = Button(text='Книги', size_hint=(None, None), size=(180, 90), on_press=self.books) self.b5 = Button(text='Картинки', size_hint=(None, None), size=(180, 90), on_press=self.pictures) self.b6 = Button(text='Кодировки', size_hint=(None, None), size=(180, 90), on_press=self.code) self.gl.add_widget(self.b1) self.gl.add_widget(self.b2) self.gl.add_widget(self.b3) self.gl.add_widget(self.b4) self.gl.add_widget(self.b5) self.gl.add_widget(self.b6) self.al.add_widget(self.gl) return self.al
def build(self): a = AnchorLayout(anchor_x='center', anchor_y='center') img = image(source="inventory.png") a.add_widget(img) gl = GridLayout(cols=1, row_force_default=True, row_default_height=40, padding=100) self.textinput = TextInput(text="QR Code", multiline=False) gl.add_widget(self.textinput) submit = Button(text="Go", on_press=self.submit) gl.add_widget(submit) img = image(source="inventory.png") layout = FloatLayout(size=(500, 750)) layout.add_widget(img) layout.add_widget(gl) a.add_widget(layout) return a
def build(self): tp_label = ToolTipLabel( text= "Some really long text that doesn't fit in the label's bounding box.", size_hint=(None, None), width=300, height=60, font_size='18sp', shorten=True, shorten_from="right", color=[0, 0, 0, 1]) tp_label.text_size = tp_label.size container = AnchorLayout() container.add_widget(tp_label) with container.canvas.before: Color(.9, .9, .9) Rectangle(pos=container.pos, size=Window.size) return container
def viewimg(self, instance): """ Generate a ModalView of an clicked image with functional Buttons """ # print(instance.im_source) im = Image(source=instance.im_source) view_size = self.img_resize(im) # Define BoxLayout for ModalView Buttons image_ops = BoxLayout(size_hint=(None, None), size=(200, 30), spacing=4) # Define icons of functional Buttons using zmd.fontd file and garden.iconfonts btn_prev = Button(text='%s'%(icon('zmdi-caret-left', 24)), markup=True) btn_rename = Button(text='%s' % (icon('zmdi-file', 24)), markup=True) btn_effects = Button(text='%s' % (icon('zmdi-blur', 24)), markup=True) btn_next = Button(text='%s' % (icon('zmdi-caret-right', 24)), markup=True) # Add bindings to the buttons btn_next.bind(on_release=self.next_image) btn_prev.bind(on_release=self.prev_image) # btn_rename.bind(on_release=self.new_img_name) # Add Buttons to BoxLayout image_ops image_ops.add_widget(btn_prev) image_ops.add_widget(btn_rename) image_ops.add_widget(btn_effects) image_ops.add_widget(btn_next) # Define AnchorLayout "anchor" position and add BoxLayout "image_ops" anchor = AnchorLayout(anchor_x='center', anchor_y='bottom') anchor.add_widget(image_ops) # Fill ViewImage(ModalView) "view" with BoxLayout, Image and AnchorLayout image_container = BoxLayout() view = ViewImage(size_hint=(None, None), size=view_size) image_container.add_widget(im) view.add_widget(image_container) view.add_widget(anchor) # PopUp "view" view.open()
def _init_view(self): databus = self._databus settings = self._settings dashboard_state = self._dashboard_state self._init_global_gauges() # add the initial set of empty screens screens = self._screens screens += self._filter_dashboard_screens( self._settings.userPrefs.get_dashboard_screens()) for i in range(0, len(screens)): self.ids.carousel.add_widget(AnchorLayout()) # Find all of the global and set the objects they need gauges = list(kvFindClass(self, DigitalGauge)) for gauge in gauges: gauge.settings = settings gauge.data_bus = databus gauge.dashboard_state = dashboard_state # Initialize our alert type widgets self._alert_widgets['pit_stop'] = PitstopTimerView(databus, 'Pit Stop') self._notify_preference_listeners() self._show_last_view() if self._rc_api.connected: self._race_setup() self._rc_api.add_connect_listener(self._on_rc_connect) self._rc_api.addListener('alertmessage', self._on_alertmessage) self._initialized = True Clock.schedule_once( lambda dt: HelpInfo.help_popup( 'dashboard_gauge_help', self, arrow_pos='right_mid'), 2.0)
def settings_popup(self): description = Label(text='Here you can change the settings\n' 'of the game', height='100sp') voiceon = ToggleButton(group="voice", state="down", text='text-to-speech', size_hint_y=None, height='50sp') voiceoff = ToggleButton(group="voice", text='text-only', size_hint_y=None, height='50sp') lang_en = ToggleButton(group="language", state="down", text='English words', size_hint_y=None, height='50sp') lang_de = ToggleButton(group="language", text='German words', size_hint_y=None, height='50sp') closebutton = Button(text='Apply settings', size_hint_y=None, height='50sp') content = BoxLayout(orientation='vertical') # content = GridLayout(cols=2) # TODO turn this into a two-column layout content.add_widget(description) content.add_widget(voiceon) content.add_widget(voiceoff) content.add_widget(lang_en) content.add_widget(lang_de) content.add_widget(closebutton) self.popup = Popup(content=content, title='Hangman settings', size_hint=(None, None), size=('300dp', '400dp')) closebutton.bind(on_release=self.close_popup) voiceon.bind(on_release=self.turn_voice_on) voiceoff.bind(on_release=self.turn_voice_off) lang_en.bind(on_release=self.pick_lang_en) lang_de.bind(on_release=self.pick_lang_de) self.popup.open() col = AnchorLayout() return col
def build(self): al = AnchorLayout() bl = BoxLayout(orientation="vertical", size_hint=[.8, .8]) self.l1 = Label(multilene=False, font_size=52, text="0") bl.add_widget(self.l1) gl = GridLayout(cols=4, padding=[5, 5], spacing=[3]) gl.add_widget(Button(text="7")) gl.add_widget(Button(text="8")) gl.add_widget(Button(text="9")) gl.add_widget(Button(text="*")) gl.add_widget(Button(text="4")) gl.add_widget(Button(text="5")) gl.add_widget(Button(text="6")) gl.add_widget(Button(text="-")) gl.add_widget(Button(text="1")) gl.add_widget(Button(text="2")) gl.add_widget(Button(text="3")) gl.add_widget(Button(text="/")) gl.add_widget(Button(text="C")) gl.add_widget(Button(text="0")) gl.add_widget(Button(text=".")) gl.add_widget(Button(text="=")) self.add_on_press(gl) bl.add_widget(gl) al.add_widget(bl) return al
def __init__(self, title, option_list, option_init=None, callback=None, multiselect=True, **kwargs): super().__init__(**kwargs) self.title = title self.callback = callback self.main_layout = AnchorLayout() if option_init is None: option_init = [True] * len(option_list) self.grid = GridLayout(cols=1) self.opt_boxes = [] self.labels = [] for i, opt in enumerate(option_list): box = BoxLayout(orientation='horizontal') check_box = CheckBox(active=option_init[i]) if not multiselect: check_box.group = "Single_Select_Only_Group" label = Label(text=str(opt)) self.opt_boxes.append(check_box) self.labels.append(label) box.add_widget(check_box) box.add_widget(label) self.grid.add_widget(box) cancel_button = Button(text="Cancel") cancel_button.bind(on_press=self.cancel_callback) ok_button = Button(text="Ok") ok_button.bind(on_press=self.ok_callback) box = BoxLayout(orientation='horizontal') box.add_widget(cancel_button) box.add_widget(ok_button) self.grid.add_widget(box) self.main_layout.add_widget(self.grid) self.content = self.main_layout self.size_hint = self.pHint Window.release_all_keyboards() self.open()
def add(self, instance): def close(instance): popup.dismiss() def submit(instance): self.db.append(author.text, name.text, year.text) content = AnchorLayout() bl_add = BoxLayout(spacing=5, orientation="vertical", size_hint=[.8, .7]) author = TextInput() name = TextInput() year = TextInput() gl_add = GridLayout(cols=2, padding=[30], spacing=3) gl_add.add_widget(Label(text='author: ')) gl_add.add_widget(author) gl_add.add_widget(Label(text='name: ')) gl_add.add_widget(name) gl_add.add_widget(Label(text='year: ')) gl_add.add_widget(year) bl_add.add_widget(gl_add) bl_add.add_widget(Button(text='submit', on_press=submit)) bl_add.add_widget(Button(text='close', on_press=close)) content.add_widget(bl_add) popup = Popup(title='add new book', content=content, size=(1000, 1000), size_hint=(None, None)) popup.open()
def __init__(self, **kwargs): super(ContentNavigationDrawer, self).__init__(**kwargs) ############################### self.orientation = 'vertical' self.padding = '8dp' self.spacing = '8dp' ############################### self.Anchor1 = AnchorLayout() self.Label1 = MDLabel() self.LSpace = MDLabel() self.Label2 = MDLabel() ### self.Button1 = MDRectangleFlatIconButton(icon="face", text='Users') self.Button2 = MDRectangleFlatIconButton(icon="folder", text='DB Import') self.Button3 = MDRectangleFlatIconButton(icon="folder-download", text='DB Export') self.Button4 = MDRectangleFlatIconButton(icon="information", text='About') ### self.Scrll = ScrollView() self.Pic1 = Image(source='icon.png') ############################### return
def create(self): self._carousel = Carousel() for i in range(1): layout = self.CustomStencilView() layout.add_widget(self.CustomImage(size_hint=(None, None), pos_hint={'center_x': 0.5, 'center_y': 0.5}, keep_ratio=True, allow_stretch=True, source=None)) self._carousel.add_widget(layout) self._carousel.fbind('index', self.index_callback) indicator_layout = AnchorLayout(size_hint=(1, None), height=dp(30), anchor_x='center', anchor_y='center', padding=(dp(0), dp(0), dp(0), dp(20))) self._box_layout = BoxLayout(orientation='horizontal', size_hint=(None, 1), spacing=dp(5)) self._box_layout.bind(minimum_width=self._box_layout.setter('width')) for i in range(1): if i == 0: indicator = self.Indicator(opacity=1, size_hint=(None, None), size=(dp(10), dp(10))) indicator.bind(pos=indicator.pos_callback) self._box_layout.add_widget(indicator) else: indicator = self.Indicator(opacity=0.5, size_hint=(None, None), size=(dp(10), dp(10))) indicator.bind(pos=indicator.pos_callback) self._box_layout.add_widget(indicator) indicator_layout.add_widget(self._box_layout) self.add_widget(self._carousel) self.add_widget(indicator_layout)
def add_input(self): input_num = self.ids.ComboTextInput.text spots_num = self.ids.ComboSpotsInput.text try: input_num = int(input_num) except ValueError: self.throw_value_error('Top Input') try: spots_num = int(spots_num) combo_output = Combination(input_num, spots_num) except ValueError: combo_output = Combination(input_num) if isinstance(spots_num, int): output_num = str( str(input_num) + '/' + str(spots_num) + ' spots: ' + combo_output) font_size = 60 else: font_size = 70 output_num = str(str(input_num) + ': ' + combo_output) label_text = self.add_newlines(output_num) output_label = ScaleLabel(text=label_text, size_hint=[0.8, .5], pos_hint={ 'right': 0.91, 'top': .79 }, font_size=font_size) layout_wrapper = AnchorLayout(anchor_x='center', anchor_y='center') layout_wrapper.add_widget(output_label) self.ids.ComboOutputGrid.add_widget(layout_wrapper)
def build(self): layout = GridLayout(cols = 2) layout.add_widget(Label(text = 'Mass')) self.Mass = TextInput(multiline = False) layout.add_widget(self.Mass) layout.add_widget(Label(text = 'Depth')) self.Depth = TextInput(multiline = False) layout.add_widget(self.Depth) layout.add_widget(Label(text = 'Width')) self.hWidth = TextInput(multiline = False) layout.add_widget(self.hWidth) self.popup = Popup(title = 'Test popup') GoBtn = Button(text = 'GO!') # GoBtn.bind(on_release = self.callback) GoBtn.bind(on_release = self.main) layout.add_widget(GoBtn) anchor = AnchorLayout(anchor_x = 'center', anchor_y = 'bottom') btn = Button(text = ('test')) anchor.add_widget(btn) return layout return anchor
def __init__(self, app, **kwargs): super().__init__(**kwargs) self.app = app self.orientation = "horizontal" self.padding = (5, 0) self.adaptive_height = True self.label = MDLabel() self.label.halign = "center" self.add_widget(self.label) self.add_widget(PlaceHolder()) self.check = Check(self.update_value) checkAnchor = AnchorLayout() checkAnchor.add_widget(self.check) checkAnchor.anchor_x = "center" self.add_widget(checkAnchor) checkAnchor.size_hint_x = 0.2 self.add_widget(PlaceHolder()) self.bind(text=self.update_text)
def on_enter(self): al = AnchorLayout(anchor_x='left', anchor_y='top', size_hint=(1, .1)) al.add_widget( Button(text="Back", on_press=lambda x: set_screen('menu'), size_hint=(.5, 1))) self.bl = BoxLayout(orientation='vertical', padding=15) self.gl = GridLayout(cols=2, spacing=15, size_hint=(1, .4)) self.qst_on = Label(text='') self.btn1 = Button(text='answ') self.btn2 = Button(text='answ') self.btn3 = Button(text='answ') self.btn4 = Button(text='answ') self.gl.add_widget(self.btn1) self.gl.add_widget(self.btn2) self.gl.add_widget(self.btn3) self.gl.add_widget(self.btn4) self.bl.add_widget(al) self.bl.add_widget(self.qst_on) self.bl.add_widget(self.gl) self.add_widget(self.bl) self.generate_q() self.generate_answ() self.check_answ()
def ui_layout(self): record_button_anchor = AnchorLayout( anchor_x='center', anchor_y='bottom', padding=[dp(25), dp(25), dp(25), dp(25)]) self.record_button = MDFloatingActionButton(icon='record', size=[dp(56), dp(56)]) self.record_button.md_bg_color = App.get_running_app( ).theme_cls.primary_color self.record_button.text_color = [1, 1, 1, 1] if platform not in ['ios', 'android']: self.record_button.bind(on_press=lambda x: self.decode_audio()) record_button_anchor.add_widget(self.record_button) self.decode_input = MDTextFieldRound(pos_hint={ 'center_x': 0.5, 'center_y': 0.5 }, size_hint=(0.85, 0.5)) self.decode_input.icon_left_dasabled = True # Moves widget out of the field of view self.decode_input.children[2].children[2].pos_hint = { 'center_x': 500, 'center_y': 500 } # This binds the right icon to record the input self.decode_input.icon_right = 'database-export' self.decode_input.children[2].children[0].bind( on_press=lambda x: self.clear_text()) decode_card = MDCard(padding=dp(24), spacing=dp(24), orientation='vertical', size_hint_x=0.85, size_hint_y=0.7, pos_hint={ 'top': 0.85, 'center_x': 0.5 }) decode_label = MDLabel(text='Decode Morse Code Audio', font_style='Body1', halign='center', size_hint=(1, 0.5)) decode_label.theme_text_color = 'Custom' decode_label.text_color = [1, 1, 1, 1] decode_card.add_widget(decode_label) decode_text = 'Hit record or enter Morse Code below to start decoding' self.decode_output_label = MDLabel(text=decode_text, font_style='Body1', halign='center', size_hint=(1, 0.5)) self.decode_output_label.theme_text_color = 'Custom' self.decode_output_label.text_color = [1, 1, 1, 1] if platform not in ['ios', 'android']: self.audio_indicator = AudioIndicator( stack_width=self.amr.bits_per_frame) else: self.audio_indicator = AudioIndicator(stack_width=40) self.audio_indicator.size_hint = (1, 2) decode_card.add_widget(self.audio_indicator) decode_card.add_widget(self.decode_output_label) decode_card.add_widget(self.decode_input) decode_card.md_bg_color = App.get_running_app().theme_cls.accent_color decode_card.elevation = 15 self.add_widget(decode_card) self.add_widget(record_button_anchor) # Nav Bar self.nav_bar = MyNavigationLayout() self.nav_bar_anchor = AnchorLayout(anchor_x='center', anchor_y='top') self.nav_bar_anchor.add_widget(self.nav_bar) self.add_widget(self.nav_bar_anchor)
def wrap_anchor(widget): anchor = AnchorLayout() anchor.add_widget(widget) return anchor
def __init__(self, **kwargs): upper = GridLayout(cols=10) lower = BoxLayout(orientation='vertical', spacing=2) self.orientation = 'horizontal' Window.size = (1000, 500) self.alpha = 0.5 self.num_latents = 10 self.temp_sliders = np.ones(self.num_latents) self.make_audio = False self.all_data = np.zeros((BATCHES, CHUNK)) super(LoginScreen, self).__init__(**kwargs) with self.canvas.before: Color(0, 0.05, 0.15) Rectangle(pos=(0, 0), size=(2000, 2000)) self.sliders = [] for i in range(0, 10): self.sliders.append( Slider(min=0, max=100, value=50, orientation='vertical')) self.sliders[i].fbind('value', self.slide) upper.add_widget(self.sliders[i]) #Button to start music by calling useSliderVals(). This will be changed to a more relevant function soon self.padAnchor6 = AnchorLayout(size_hint_y=0.3) self.playButton = Button(text='Play', size_hint_y=None, height=50, size_hint_x=0.3, font_size=24, background_color=[0, 1, 0]) self.playButton.bind(on_press=self.load_tracks) self.padAnchor6.add_widget(self.playButton) lower.add_widget(self.padAnchor6) #Button to reset values by calling reset() when clicked self.padAnchor = AnchorLayout(size_hint_y=0.3) self.resetButton = Button(text='Reset', size_hint_y=None, height=50, size_hint_x=0.3, font_size=24) self.resetButton.bind(on_press=self.reset) self.padAnchor.add_widget(self.resetButton) lower.add_widget(self.padAnchor) #Button to start music by calling useSliderVals(). This will be changed to a more relevant function soon self.padAnchor6 = AnchorLayout(size_hint_y=0.3) self.textinput3 = TextInput(hint_text='Model', size_hint_y=None, height=45, font_size=24, size_hint_x=None, width=300, multiline='false') self.padAnchor6.add_widget(self.textinput3) lower.add_widget(self.padAnchor6) self.padAnchor3 = AnchorLayout(size_hint_y=0.3) self.textinput1 = TextInput(hint_text='Audio File 1', size_hint_y=None, height=45, size_hint_x=None, width=300, font_size=24, multiline='false') self.padAnchor3.add_widget(self.textinput1) lower.add_widget(self.padAnchor3) self.alphaarr = [] self.padAnchor42 = AnchorLayout(size_hint_y=0.3) self.alphaarr.append( Slider(min=0, max=100, value=50, orientation='horizontal')) self.alphaarr[0].fbind('value', self.slide) self.padAnchor42.add_widget(self.alphaarr[0]) lower.add_widget(self.padAnchor42) self.padAnchor5 = AnchorLayout(size_hint_y=0.3) self.textinput2 = TextInput(hint_text='Audio File 2', size_hint_x=None, width=300, size_hint_y=None, height=45, font_size=24, multiline='false') self.padAnchor5.add_widget(self.textinput2) lower.add_widget(self.padAnchor5) self.add_widget(upper) self.add_widget(lower) Clock.schedule_interval(self.loop, POLL_TIME)
def dispatch_departure(self, node): cls = node.__class__ if cls is nodes.document: self.pop() elif cls is nodes.section: self.section -= 1 elif cls is nodes.title: assert (isinstance(self.current, RstTitle)) if not self.title: self.title = self.text self.set_text(self.current, 'title') self.pop() elif cls is nodes.Text: pass elif cls is nodes.paragraph: self.do_strip_text = False assert (isinstance(self.current, RstParagraph)) self.set_text(self.current, 'paragraph') self.pop() elif cls is nodes.literal_block: assert (isinstance(self.current, RstLiteralBlock)) self.set_text(self.current.content, 'literal_block') self.pop() elif cls is nodes.emphasis: self.text += '[/i]' elif cls is nodes.strong: self.text += '[/b]' elif cls is nodes.literal: self.text += '[/font]' elif cls is nodes.block_quote: self.pop() elif cls is nodes.enumerated_list: self.idx_list = None self.pop() elif cls is nodes.bullet_list: self.pop() elif cls is nodes.list_item: self.pop() elif cls is nodes.system_message: self.pop() elif cls is nodes.warning: self.pop() elif cls is nodes.note: self.pop() elif cls is nodes.definition_list: self.pop() elif cls is nodes.term: assert (isinstance(self.current, RstTerm)) self.set_text(self.current, 'term') self.pop() elif cls is nodes.definition: self.pop() elif cls is nodes.field_list: self.pop() elif cls is nodes.field_name: assert (isinstance(self.current, RstFieldName)) self.set_text(self.current, 'field_name') self.pop() elif cls is nodes.field_body: self.pop() elif cls is nodes.table: self.pop() elif cls is nodes.colspec: pass elif cls is nodes.entry: self.pop() elif cls is nodes.reference: self.text += '[/color][/ref]' elif cls is role_doc: docname = self.text[self.doc_index:] rst_docname = docname if rst_docname.endswith('.rst'): docname = docname[:-4] else: rst_docname += '.rst' # try to preload it filename = self.root.resolve_path(rst_docname) self.root.preload(filename) # if exist, use the title of the first section found in the # document title = docname if filename in self.root.toctrees: toctree = self.root.toctrees[filename] if len(toctree): title = toctree[0]['title'] # replace the text with a good reference text = '[ref=%s]%s[/ref]' % (rst_docname, self.colorize(title, 'link')) self.text = self.text[:self.doc_index] + text elif cls is role_video: width = node['width'] if 'width' in node.attlist() else 400 height = node['height'] if 'height' in node.attlist() else 300 uri = node['source'] if uri.startswith('/') and self.root.document_root: uri = join(self.root.document_root, uri[1:]) video = RstVideoPlayer(source=uri, size_hint=(None, None), size=(width, height)) anchor = AnchorLayout(size_hint_y=None, height=height + 20) anchor.add_widget(video) self.current.add_widget(anchor)
def dispatch_visit(self, node): cls = node.__class__ if cls is nodes.document: self.push(self.root.content) elif cls is nodes.section: self.section += 1 elif cls is nodes.title: label = RstTitle(section=self.section, document=self.root) self.current.add_widget(label) self.push(label) #assert(self.text == '') elif cls is nodes.Text: if self.do_strip_text: node = node.replace('\n', ' ') node = node.replace(' ', ' ') node = node.replace('\t', ' ') node = node.replace(' ', ' ') if node.startswith(' '): node = ' ' + node.lstrip(' ') if node.endswith(' '): node = node.rstrip(' ') + ' ' if self.text.endswith(' ') and node.startswith(' '): node = node[1:] self.text += node elif cls is nodes.paragraph: self.do_strip_text = True label = RstParagraph(document=self.root) if isinstance(self.current, RstEntry): label.mx = 10 self.current.add_widget(label) self.push(label) elif cls is nodes.literal_block: box = RstLiteralBlock() self.current.add_widget(box) self.push(box) elif cls is nodes.emphasis: self.text += '[i]' elif cls is nodes.strong: self.text += '[b]' elif cls is nodes.literal: self.text += '[font=fonts/RobotoMono-Regular.ttf]' elif cls is nodes.block_quote: box = RstBlockQuote() self.current.add_widget(box) self.push(box.content) assert (self.text == '') elif cls is nodes.enumerated_list: box = RstList() self.current.add_widget(box) self.push(box) self.idx_list = 0 elif cls is nodes.bullet_list: box = RstList() self.current.add_widget(box) self.push(box) self.idx_list = None elif cls is nodes.list_item: bullet = '-' if self.idx_list is not None: self.idx_list += 1 bullet = '%d.' % self.idx_list bullet = self.colorize(bullet, 'bullet') item = RstListItem() self.current.add_widget( RstListBullet(text=bullet, document=self.root)) self.current.add_widget(item) self.push(item) elif cls is nodes.system_message: label = RstSystemMessage() if self.root.show_errors: self.current.add_widget(label) self.push(label) elif cls is nodes.warning: label = RstWarning() self.current.add_widget(label) self.push(label.content) assert (self.text == '') elif cls is nodes.note: label = RstNote() self.current.add_widget(label) self.push(label.content) assert (self.text == '') elif cls is nodes.image: uri = node['uri'] if uri.startswith('/') and self.root.document_root: uri = join(self.root.document_root, uri[1:]) if uri.startswith('http://') or uri.startswith('https://'): image = RstAsyncImage(source=uri) else: image = RstImage(source=uri) align = node.get('align', 'center') root = AnchorLayout(size_hint_y=None, anchor_x=align, height=image.height) image.bind(height=root.setter('height')) root.add_widget(image) self.current.add_widget(root) elif cls is nodes.definition_list: lst = RstDefinitionList(document=self.root) self.current.add_widget(lst) self.push(lst) elif cls is nodes.term: assert (isinstance(self.current, RstDefinitionList)) term = RstTerm(document=self.root) self.current.add_widget(term) self.push(term) elif cls is nodes.definition: assert (isinstance(self.current, RstDefinitionList)) definition = RstDefinition(document=self.root) definition.add_widget(RstDefinitionSpace(document=self.root)) self.current.add_widget(definition) self.push(definition) elif cls is nodes.field_list: fieldlist = RstFieldList() self.current.add_widget(fieldlist) self.push(fieldlist) elif cls is nodes.field_name: name = RstFieldName(document=self.root) self.current.add_widget(name) self.push(name) elif cls is nodes.field_body: body = RstFieldBody() self.current.add_widget(body) self.push(body) elif cls is nodes.table: table = RstTable(cols=0) self.current.add_widget(table) self.push(table) elif cls is nodes.colspec: self.current.cols += 1 elif cls is nodes.entry: entry = RstEntry() self.current.add_widget(entry) self.push(entry) elif cls is nodes.transition: self.current.add_widget(RstTransition()) elif cls is nodes.reference: name = node.get('name', node.get('refuri')) self.text += '[ref=%s][color=%s]' % ( name, self.root.colors.get('link', self.root.colors.get('paragraph'))) if 'refname' in node and 'name' in node: self.root.refs_assoc[node['name']] = node['refname'] elif cls is nodes.target: name = None if 'ids' in node: name = node['ids'][0] elif 'names' in node: name = node['names'][0] self.text += '[anchor=%s]' % name self.text_have_anchor = True elif cls is role_doc: self.doc_index = len(self.text) elif cls is role_video: pass
def to_json(self, instance): path = '' filechoser_layout = AnchorLayout() #filechoser = FileChooserIconView( size_hint = (0.75,0.85), path=settings['kraken_path'] +'/picture') #, multiselect = True) filechoser = FileChooserIconView(size_hint=(0.75, 0.85), path='/home') #, multiselect = True) filechoser_list_layout = AnchorLayout(anchor_x='left', anchor_y='top') filechoser_list_layout.add_widget(filechoser) button_layout = AnchorLayout(anchor_x='left', anchor_y='bottom') box = BoxLayout(orientation='vertical', size_hint=(0.75, None), height=96) bli = BoxLayout(orientation='horizontal') ok_button = Button(text='Ok') cancel_button = Button(text='Cancel') bli2 = BoxLayout(orientation='horizontal') ti = TextInput(size_hint=(1, None), height=48) bli2.add_widget(Label(text='Enter File Name : ')) bli2.add_widget(ti) bli.add_widget(ok_button) bli.add_widget(cancel_button) box.add_widget(bli2) box.add_widget(bli) button_layout.add_widget(box) image_layout = AnchorLayout(anchor_x='right', anchor_y='center') wimg = Image(source=settings['kraken_path'] + '/picture/girl.jpg', size_hint=(0.25, None), size=(200, Window.size[1])) image_layout.add_widget(wimg) filechoser_layout.add_widget(filechoser_list_layout) filechoser_layout.add_widget(button_layout) filechoser_layout.add_widget(image_layout) popup_browser = Popup(title='Save File') popup_browser.add_widget(filechoser_layout) def save_path(instance): if ti.text != '': path = filechoser.path + '/' + ti.text else: path = filechoser.selection[0] # Save JSON cv = [] for child in self.drawing_space.children: cv.append(child) workflow = dict(cv=cv) with open(path, 'w') as f: json.dump(dict(workflow=workflow), f, cls=KrakenJsonEncoder) popup_browser.dismiss() def file_select(self, file): if file: wimg.source = file[0] cancel_button.bind(on_press=popup_browser.dismiss) ok_button.bind(on_press=save_path) filechoser.bind(selection=file_select) popup_browser.open()
def load_json(self, instance): path = '' filechoser_layout = AnchorLayout() #filechoser = FileChooserIconView( size_hint = (0.75,0.85), path=settings['kraken_path'] +'/picture') #, multiselect = True) filechoser = FileChooserIconView(size_hint=(0.75, 0.85), path='/home') #, multiselect = True) filechoser_list_layout = AnchorLayout(anchor_x='left', anchor_y='top') filechoser_list_layout.add_widget(filechoser) button_layout = AnchorLayout(anchor_x='left', anchor_y='bottom') box = BoxLayout(orientation='vertical', size_hint=(0.75, None), height=96) bli = BoxLayout(orientation='horizontal') ok_button = Button(text='Ok') cancel_button = Button(text='Cancel') bli2 = BoxLayout(orientation='horizontal') ti = TextInput(size_hint=(1, None), height=48) bli2.add_widget(Label(text='Enter File Name : ')) bli2.add_widget(ti) bli.add_widget(ok_button) bli.add_widget(cancel_button) box.add_widget(bli2) box.add_widget(bli) button_layout.add_widget(box) image_layout = AnchorLayout(anchor_x='right', anchor_y='center') wimg = Image(source=settings['kraken_path'] + '/picture/girl.jpg', size_hint=(0.25, None), size=(200, Window.size[1])) image_layout.add_widget(wimg) filechoser_layout.add_widget(filechoser_list_layout) filechoser_layout.add_widget(button_layout) filechoser_layout.add_widget(image_layout) popup_browser = Popup(title='Open File') popup_browser.add_widget(filechoser_layout) def save_path(instance): if ti.text != '': path = filechoser.path + '/' + ti.text else: path = filechoser.selection[0] # Open From File ds = self.drawing_space self.clear(instance) with open(path) as json_file: json_data = json.load(json_file) funs = json_data['workflow']['cv'] for fun in funs: if fun['name'] != 'Line': tr = ToolRectangle() tr.redraw(ds, fun['pos']['x'], fun['pos']['y'], fun['name'], fun['id'], fun['pars'], fun['in_cv'], fun['out_cv'], fun['level']) for fun in funs: if fun['name'] != 'Line': for child in ds.children: if child.id is fun['id']: a = child break for b in fun['out_cv']: for child in ds.children: if child.id == b: line_widget = self.new_line(a, child) line_widget.widgetA = a line_widget.widgetB = child line_widget.isLine = True line_widget.name = "Line" line_widget.id = str(uuid.uuid1()) a.connect.append([child, line_widget]) child.connect.append([a, line_widget]) popup_browser.dismiss() def file_select(self, file): if file: wimg.source = file[0] cancel_button.bind(on_press=popup_browser.dismiss) ok_button.bind(on_press=save_path) filechoser.bind(selection=file_select) popup_browser.open()
def __init__(self, **kwargs): super(LnJ, self).__init__(**kwargs) self.height = Window.height self.width = Window.width popsize_x = Window.width * .5 popsize_y = Window.height * .3 self.user = '' self.layout = AnchorLayout(anchor_x='left', anchor_y='top', width=Window.width, height=Window.height * .15) self.text_layout = AnchorLayout(anchor_x='left', anchor_y='top', size_hint_y=None, pos=(0, Window.height * .1), width=Window.width, height=Window.height) self.chat_container = FloatLayout(pos=(0, Window.height * .15), pos_hint=(None, None), height=Window.height * 2) self.boxlayout = BoxLayout(orientation='horizontal') self.boxlayout_2 = BoxLayout(orientation='horizontal') self.boxlayout_master = BoxLayout(orientation='vertical') self.chat_label = Label(text='', valign='bottom', halign='left', padding=(20, 10), pos=(0, 0)) self.textinput = TextInput(on_text_validate=self.send, multiline=False) self.scroller = ScrollView(scroll_distance=50, pos=(0, Window.height * .15), size=(Window.width, Window.height * .85)) self.textinput_username = TextInput( multiline=False, pos=(Window.width * .5 - popsize_x * .3 / 2, Window.height * .5 + popsize_y * .05), size_hint=(.6, .2), font_size=12, ) self.textinput_password = TextInput( multiline=False, pos=(Window.width * .5 - popsize_x * .3 / 2, Window.height * .5 - popsize_y * .09), size_hint=(.6, .2), font_size=12, ) self.username_label = Label(text="Username", pos=(self.width * .5 - 300, self.height * .5 - 40)) self.password_label = Label(text="Password", pos=(Window.width * .5 - 300, Window.height * .5 - 60)) floatlayout_popup_login = FloatLayout(size_hint=(1, 1)) floatlayout_popup_login.add_widget(self.textinput_username) floatlayout_popup_login.add_widget(self.textinput_password) floatlayout_popup_login.add_widget(self.username_label) floatlayout_popup_login.add_widget(self.password_label) self.popup_login = Popup(title='Login', content=floatlayout_popup_login, size_hint=(None, None), size=(popsize_x, popsize_y), auto_dismiss=False) self.btn1 = Button(text='Authenticate', width=200, on_press=self.popup_login.open) self.btn2 = Button(text='Send', on_press=self.send) #self.btn = Button(text='Connect') self.scroller.add_widget(self.chat_container) self.chat_container.add_widget(self.chat_label) self.boxlayout.add_widget(self.btn1) self.boxlayout.add_widget(self.btn2) self.boxlayout_2.add_widget(self.textinput) self.boxlayout_master.add_widget(self.boxlayout_2) self.boxlayout_master.add_widget(self.boxlayout) self.layout.add_widget(self.boxlayout_master) self.add_widget(self.layout) self.add_widget(self.scroller) self.btn_connect = Button(text='Connect', on_press=self.authenticate, pos=(Window.width * .5 - popsize_x * .475, Window.height * .5 - popsize_y * .3), size_hint=(1, .1)) floatlayout_popup_login.add_widget(self.btn_connect)
def set_content(self, instance_content_dialog): def _events_callback(result_press): self.dismiss() if result_press: self.events_callback(result_press, self) if self.device_ios: # create buttons for iOS self.background = self._background if instance_content_dialog.__class__ is ContentInputDialog: self.text_field = MDTextFieldRect( pos_hint={'center_x': .5}, size_hint=(1, None), multiline=False, height=dp(33), cursor_color=self.theme_cls.primary_color, hint_text=instance_content_dialog.hint_text) instance_content_dialog.ids.box_input.height = dp(33) instance_content_dialog.ids.box_input.add_widget( self.text_field) if self.text_button_cancel != '': anchor = 'left' else: anchor = 'center' box_button_ok = AnchorLayout(anchor_x=anchor) box_button_ok.add_widget( MDTextButton(text=self.text_button_ok, font_size='18sp', on_release=lambda x: _events_callback( self.text_button_ok))) instance_content_dialog.ids.box_buttons.add_widget(box_button_ok) if self.text_button_cancel != '': box_button_ok.anchor_x = 'left' box_button_cancel = AnchorLayout(anchor_x='right') box_button_cancel.add_widget( MDTextButton(text=self.text_button_cancel, font_size='18sp', on_release=lambda x: _events_callback( self.text_button_cancel))) instance_content_dialog.ids.box_buttons.add_widget( box_button_cancel) else: # create buttons for Android if instance_content_dialog.__class__ is ContentInputDialog: self.text_field = MDTextField( size_hint=(1, None), height=dp(48), hint_text=instance_content_dialog.hint_text) instance_content_dialog.ids.box_input.height = dp(48) instance_content_dialog.ids.box_input.add_widget( self.text_field) instance_content_dialog.ids.box_buttons.remove_widget( instance_content_dialog.ids.sep) box_buttons = AnchorLayout(anchor_x='right', size_hint_y=None, height=dp(30)) box = BoxLayout(size_hint_x=None, spacing=dp(5)) box.bind(minimum_width=box.setter('width')) button_ok = MDRaisedButton( text=self.text_button_ok, on_release=lambda x: _events_callback(self.text_button_ok)) box.add_widget(button_ok) if self.text_button_cancel != '': button_cancel = MDFlatButton( text=self.text_button_cancel, theme_text_color='Custom', text_color=self.theme_cls.primary_color, on_release=lambda x: _events_callback(self. text_button_cancel)) box.add_widget(button_cancel) box_buttons.add_widget(box) instance_content_dialog.ids.box_buttons.add_widget(box_buttons) instance_content_dialog.ids.box_buttons.height = button_ok.height instance_content_dialog.remove_widget( instance_content_dialog.ids.sep)
def build(self): sm.add_widget(HomePage.build(self)) sm.add_widget(SettingsMainPage.build(self)) sm.add_widget(PillPage.build(self)) MenuAnchor = AnchorLayout(anchor_y='bottom') MenuLayout = BoxLayout(orientation='horizontal', spacing=10, padding=10, size_hint_y=None, height=120) HomeLayout = RelativeLayout() SettingsLayout = RelativeLayout() PillLayout = RelativeLayout() HomeButton = Button(background_normal='', background_color=White) HomeImage = Image(source=HomeIcon, pos=(0, 10), color=White) HomeLabel = Label(text="HOME", color=Black, pos=(0, -40), font_size=20, font_name=DefaultFont) HomeLayout.add_widget(HomeButton) HomeLayout.add_widget(HomeImage) HomeLayout.add_widget(HomeLabel) SettingsButton = Button(background_normal='', background_color=White) SettingsImage = Image(source=SettingsIcon, pos=(0, 10), color=Gray) SettingsLabel = Label(text="SETTINGS", color=Gray, pos=(0, -40), font_size=20, font_name=DefaultFont) SettingsLayout.add_widget(SettingsButton) SettingsLayout.add_widget(SettingsImage) SettingsLayout.add_widget(SettingsLabel) PillButton = Button(background_normal='', background_color=White) PillImage = Image(source=PillIcon, pos=(0, 10), color=Gray) PillLabel = Label(text="PILLS", color=Gray, pos=(0, -40), font_size=20, font_name=DefaultFont) PillLayout.add_widget(PillButton) PillLayout.add_widget(PillImage) PillLayout.add_widget(PillLabel) def GotoSettings(self): print("Settings") SettingsImage.color = White SettingsLabel.color = Black HomeLabel.color = Gray HomeImage.color = Gray PillImage.color = Gray PillLabel.color = Gray if sm.current == 'home': sm.transition.direction = 'right' sm.current = 'settings' elif sm.current == 'pill': sm.transition.direction = 'right' sm.current = 'settings' else: sm.transition = NoTransition() sm.current = 'settings' sm.transition = SlideTransition() pass def GotoPill(self): print("Pills") SettingsImage.color = Gray SettingsLabel.color = Gray HomeLabel.color = Gray HomeImage.color = Gray PillImage.color = White PillLabel.color = Black if sm.current == 'settings': sm.transition.direction = 'left' sm.current = 'pill' elif sm.current == 'home': sm.transition.direction = 'left' sm.current = 'pill' else: sm.transition = NoTransition() sm.current = 'pill' sm.transition = SlideTransition() pass def GotoHome(self): print("Home") SettingsImage.color = Gray SettingsLabel.color = Gray HomeLabel.color = Black HomeImage.color = White PillImage.color = Gray PillLabel.color = Gray if sm.current == 'pill': sm.transition.direction = 'right' elif sm.current == 'settings': sm.transition.direction = 'left' else: sm.transition = NoTransition() sm.current = 'home' sm.transition = SlideTransition() pass HomeButton.bind(on_press=GotoHome) PillButton.bind(on_press=GotoPill) SettingsButton.bind(on_press=GotoSettings) MenuLayout.add_widget(SettingsLayout) MenuLayout.add_widget(HomeLayout) MenuLayout.add_widget(PillLayout) MenuAnchor.add_widget(MenuLayout) return MenuAnchor
def set_content(self, instance_content_dialog): def _events_callback(result_press): self.dismiss() if result_press and self.events_callback: self.events_callback(result_press, self) if self.device_ios: # create buttons for iOS self.background = self._background if isinstance(instance_content_dialog, ContentInputDialog): self.text_field = MDTextFieldRect( pos_hint={"center_x": 0.5}, size_hint=(1, None), multiline=False, height=dp(33), cursor_color=self.theme_cls.primary_color, hint_text=instance_content_dialog.hint_text, ) instance_content_dialog.ids.box_input.height = dp(33) instance_content_dialog.ids.box_input.add_widget( self.text_field ) if self.text_button_cancel != "": anchor = "left" else: anchor = "center" box_button_ok = AnchorLayout(anchor_x=anchor) box_button_ok.add_widget( MDTextButton( text=self.text_button_ok, font_size="18sp", on_release=lambda x: _events_callback(self.text_button_ok), ) ) instance_content_dialog.ids.box_buttons.add_widget(box_button_ok) if self.text_button_cancel != "": box_button_ok.anchor_x = "left" box_button_cancel = AnchorLayout(anchor_x="right") box_button_cancel.add_widget( MDTextButton( text=self.text_button_cancel, font_size="18sp", on_release=lambda x: _events_callback( self.text_button_cancel ), ) ) instance_content_dialog.ids.box_buttons.add_widget( box_button_cancel ) else: # create buttons for Android if isinstance(instance_content_dialog, ContentInputDialog): self.text_field = MDTextField( size_hint=(1, None), height=dp(48), hint_text=instance_content_dialog.hint_text, ) instance_content_dialog.ids.box_input.height = dp(48) instance_content_dialog.ids.box_input.add_widget( self.text_field ) instance_content_dialog.ids.box_buttons.remove_widget( instance_content_dialog.ids.sep ) box_buttons = AnchorLayout( anchor_x="right", size_hint_y=None, height=dp(30) ) box = BoxLayout(size_hint_x=None, spacing=dp(5)) box.bind(minimum_width=box.setter("width")) button_ok = MDRaisedButton( text=self.text_button_ok, on_release=lambda x: _events_callback(self.text_button_ok), ) box.add_widget(button_ok) if self.text_button_cancel != "": button_cancel = MDFlatButton( text=self.text_button_cancel, theme_text_color="Custom", text_color=self.theme_cls.primary_color, on_release=lambda x: _events_callback( self.text_button_cancel ), ) box.add_widget(button_cancel) box_buttons.add_widget(box) instance_content_dialog.ids.box_buttons.add_widget(box_buttons) instance_content_dialog.ids.box_buttons.height = button_ok.height instance_content_dialog.remove_widget( instance_content_dialog.ids.sep )
def ui_layout(self): play_button_anchor = AnchorLayout( anchor_x='center', anchor_y='bottom', padding=[dp(25), dp(25), dp(25), dp(25)]) # disable play button for now play_button = MDFloatingActionButton(icon='play', size=[dp(56), dp(56)]) play_button.disabled = True play_button.opacity = 0 # [76/255, 175/255, 80/255, 1] # play_button.md_bg_color = App.get_running_app().theme_cls.primary_color # play_button.text_color = [1, 1, 1, 1] # play_button.bind(on_press=lambda x: self.play_audio()) # play_button_anchor.add_widget(play_button) self.encode_input = MDTextFieldRound(pos_hint={ 'center_x': 0.5, 'center_y': 0.5 }, size_hint=(0.85, 0.5)) self.encode_input.icon_right = 'send' self.encode_input.children[2].children[0].bind( on_press=lambda x: self.play_prompt()) self.encode_input.icon_left = 'close-circle' self.encode_input.children[2].children[2].disabled = False self.encode_input.children[2].children[2].bind( on_press=lambda x: self.clear_input()) encode_card = MDCard(padding=dp(24), spacing=dp(24), orientation='vertical', size_hint_x=0.85, size_hint_y=0.7, pos_hint={ 'top': 0.85, 'center_x': 0.5 }) encode_label = MDLabel(text='Encode Morse Code Audio', font_style='Body1', halign='center', size_hint=(1, 0.5)) encode_label.theme_text_color = 'Custom' encode_label.text_color = [1, 1, 1, 1] self.encode_output_label = MDLabel( text='Enter text to convert to morse code', halign='center', size_hint=(1, 0.5)) self.encode_output_label.theme_text_color = 'Custom' self.encode_output_label.text_color = [1, 1, 1, 1] self.audio_indicator = AudioIndicator() self.audio_indicator.size_hint = (1, 2) Clock.schedule_interval(self.update_audio_indicator, 0.1) encode_card.add_widget(encode_label) encode_card.add_widget(self.audio_indicator) encode_card.add_widget(self.encode_output_label) encode_card.add_widget(self.encode_input) encode_card.md_bg_color = App.get_running_app().theme_cls.accent_color encode_card.elevation = 15 self.add_widget(encode_card) self.add_widget(play_button_anchor) # Nav Bar self.nav_bar = MyNavigationLayout() self.nav_bar_anchor = AnchorLayout(anchor_x='center', anchor_y='top') self.nav_bar_anchor.add_widget(self.nav_bar) self.add_widget(self.nav_bar_anchor) self.cur_sound_index = 0 self.sound_list = [] self.cur_sound = None