def updateImage(): print("updateImage") global trackImage global trackTitle global trackAlbumTitle global trackPlayPauseBtn global currentTrackIsPlay url = 'https://cf-baby-music-box.cfapps.eu10.hana.ondemand.com/getCurrentSong/[email protected]' result = json.load(urllib.request.urlopen(url)) resultTrackImageUrl = result['item']['album']['images'][0]['url'] print(resultTrackImageUrl) resultTrackTitle = result['item']['name'] resultTrackAlbumTitle = result['item']['album']['name'] resultTrackIsPlay = result['is_playing'] trackImage.source = resultTrackImageUrl trackTitle.text = resultTrackTitle trackAlbumTitle.text = resultTrackAlbumTitle currentTrackIsPlay = resultTrackIsPlay if resultTrackIsPlay: trackPlayPauseBtn.unbind(on_press=playTrack) trackPlayPauseBtn.bind(on_press=pauseTrack) trackPlayPauseBtn.text = "%s" % (iconfonts.icon('fa-pause', 32)) else: trackPlayPauseBtn.unbind(on_press=pauseTrack) trackPlayPauseBtn.bind(on_press=playTrack) trackPlayPauseBtn.text = "%s" % (iconfonts.icon('fa-play', 32))
def toggleEdit(self, instance, value): if value == 'down': instance.text = '[size=25]%s[/size]'%(iconfonts.icon('fa-check-square-o')) self.selectedItems.add(instance) else: instance.text = '[size=25]%s[/size]'%(iconfonts.icon('fa-square-o')) self.selectedItems.remove(instance)
def test_icon(self): iconfonts.register('name', 'iconfont_sample.ttf', 'iconfont_sample.fontd') r = iconfonts.icon('icon-comment') self.assertEqual( "[font=iconfont_sample.ttf]%s[/font]" % (unichr(59397)), r) r = iconfonts.icon('icon-comment', 20) self.assertEqual( "[size=20][font=iconfont_sample.ttf]%s[/font][/size]" % (unichr(59397)), r)
def editLayout(self, popup): """start editing the current layout""" try: if popup: popup.dismiss() if not self.isEditing: # don't edit again if already editing. self.isEditing = True self.editActionBar = EditActionBar() # add this before any selectionbox, otherewise they are located incorrectly self.editActionBar.title = self.data.title self.rootLayout.add_widget(self.editActionBar, len(self.rootLayout.children)) for group in self.menu.children: edit = EditButton() if not group == self.menu.children[0]: edit.x = group.x + group.width - kivy.metrics.dp(20) edit.bind(state=self.toggleEdit) group.bind(size=edit.reposition, pos=edit.reposition) else: edit.text = '[size=30]%s[/size]'%(iconfonts.icon('fa-plus')) edit.x = group.x edit.bind(state=self.newGroup) group.bind(size=edit.repositionAdd, pos=edit.repositionAdd) edit.y = group.y + group.height - kivy.metrics.dp(20) group.add_widget(edit) self.editWorkSpace() except Exception as e: showError(e)
def addAddTo(self, addTo ,callback = None, section = None): add = EditButton() add.text = '[size=30]%s[/size]'%(iconfonts.icon('fa-plus')) addTo.add_widget(add) if section: add.section = section #provide ref to section which will become the parent of the asset if callback: add.bind(state=callback)
def playTrack(self): print("playTrack") global trackPlayPauseBtn trackPlayPauseBtn.text = "%s" % (iconfonts.icon('fa-pause', 32)) url = 'https://cf-baby-music-box.cfapps.eu10.hana.ondemand.com/playTrack/[email protected]' urllib.request.urlopen(url) trackPlayPauseBtn.unbind(on_press=playTrack) trackPlayPauseBtn.bind(on_press=pauseTrack) sleep(1) updateImage()
def add_icons(search=''): root.ids.grid.clear_widgets() keys = list(fontd.keys()) keys.sort() for icon_name in keys: if search and icon_name.find(search)==-1: continue lb = Label(markup=True, size_hint_y=None) lb.text= '[color=3280ff]%s[/color] '%(icon(icon_name, 32)) + icon_name root.ids.grid.add_widget(lb)
def showMainDropDown(self, attachTo): dropdown = DropDown(auto_width=False, width='140dp') btn = Button(text='%s New' % iconfonts.icon('fa-file-o'), markup=True, size_hint_y=None, height='44dp') btn.bind(on_release=lambda btn: self.newLayout(btn.parent.parent)) dropdown.add_widget(btn) btn = Button(text='%s Edit' % iconfonts.icon('fa-edit'), markup=True, size_hint_y=None, height='44dp') btn.bind(on_release=lambda btn: self.editLayout(btn.parent.parent)) dropdown.add_widget(btn) btn = Button(text='%s Credentials' % iconfonts.icon('fa-user'), markup=True, size_hint_y=None, height='44dp') btn.bind(on_release=lambda btn: self.editCredentials(btn.parent.parent)) dropdown.add_widget(btn) btn = Button(text='%s Capture scene' % iconfonts.icon('fa-camera'), markup=True, size_hint_y=None, height='44dp') btn.bind(on_release=lambda btn: self.captureScene(btn.parent.parent)) dropdown.add_widget(btn) btn = Button(text='%s Open' % iconfonts.icon('fa-folder-open-o'), markup=True, size_hint_y=None, height='44dp') btn.bind(on_release=lambda btn: self.openLayout(btn.parent.parent)) dropdown.add_widget(btn) dropdown.open(attachTo)
import os from os.path import join, dirname import json import sys filepath = join(os.getcwd(), __file__) sys.path.append(dirname(dirname(filepath))) from iconfonts import register, icon font_file = join(dirname(__file__), 'font-awesome.fontd') register('awesome_font', 'font-awesome.ttf', font_file) with open(font_file, 'r') as f: fontd = json.loads(f.read()) scroll = ScrollView(bar_width='24dp') grid = GridLayout(cols=1, size_hint_y=None, height='40dp') grid.bind(minimum_height=grid.setter('height')) scroll.add_widget(grid) keys = fontd.keys() keys.sort() for icon_name in keys: lb = Label(markup=True, size_hint_y=None) lb.text = '[color=3280ff]%s[/color] ' % (icon(icon_name, 32)) + icon_name grid.add_widget(lb) runTouchApp(scroll)
def __init__(self, **kwargs): super(HomeScreen, self).__init__(**kwargs) self.data = [{ 'text': '%s %s' % (icon('fa-sticky-note-o'), job.name), 'classview': 'RVLabel' } for job in Job.select().order_by(Job.name)]
def build(self): global trackImage global trackTitle global trackAlbumTitle global trackPlayPauseBtn # Set up the layout: layout = GridLayout(cols=1, spacing=0, padding=0, size_hint_y=None) layout.bind(minimum_height=layout.setter('height')) header = GridLayout(cols=1, spacing=0, padding=0) headerTitle = Label(text="Kinder Musik Box") header.add_widget(headerTitle) headerBar = BoxLayout() headerBarRight = RelativeLayout() headerBarRightIcons = BoxLayout(size_hint=(None, None), size=(100, 15), spacing=10, pos_hint={ 'right': 1, 'top': 1 }) volumeIcon = Label(size_hint=(None, None), size=(20, 25), markup=True, text="%s" % (iconfonts.icon('fa-volume', 15))) wlanIcon = Label(size_hint=(None, None), size=(20, 25), markup=True, text="%s" % (iconfonts.icon('fa-wifi', 15))) akkuIcon = Label(size_hint=(None, None), size=(20, 25), markup=True, text="%s" % (iconfonts.icon('fa-battery-half', 15))) headerBarRightIcons.add_widget(volumeIcon) headerBarRightIcons.add_widget(wlanIcon) headerBarRightIcons.add_widget(akkuIcon) headerBarRight.add_widget(headerBarRightIcons) headerBar.add_widget(headerBarRight) header.add_widget(headerBar) layout.add_widget(header) layoutTagInfo = GridLayout(cols=2, spacing=0, padding=0, row_default_height=50) tagInfos = GridLayout(cols=2, spacing=0, padding=0, row_default_height=100) tagLabel = Label(text="Kinder Musik Box") layoutTagInfo.add_widget(tagLabel) tagCode = LabelKeyCode(text="") Clock.schedule_interval(tagCode.update, 0.0) layoutTagInfo.add_widget(tagCode) layout.add_widget(tagInfos) layoutMain = GridLayout(cols=2, spacing=30, padding=30, row_default_height=200) layoutMain.add_widget(trackImage) layoutMainRight = GridLayout(cols=1, spacing=30, padding=30) layoutMainRightSongInfos = GridLayout(cols=2, spacing=30, padding=30) layoutMainRightSongInfos.add_widget(Label(text="Songtitle")) layoutMainRightSongInfos.add_widget(trackTitle) layoutMainRightSongInfos.add_widget(Label(text="Albumname")) layoutMainRightSongInfos.add_widget(trackAlbumTitle) layoutMainRight.add_widget(layoutMainRightSongInfos) layoutMainRightSongControl = GridLayout(cols=3, spacing=30, padding=30) nextTrackBtn = Button(size_hint=(None, None), size=(40, 40), markup=True, text="%s" % (iconfonts.icon('fa-forward', 32))) nextTrackBtn.bind(on_press=nextTrack) previousTrackBtn = Button(size_hint=(None, None), size=(40, 40), markup=True, text="%s" % (iconfonts.icon('fa-backward', 32))) previousTrackBtn.bind(on_press=previousTrack) layoutMainRightSongControl.add_widget(previousTrackBtn) layoutMainRightSongControl.add_widget(trackPlayPauseBtn) layoutMainRightSongControl.add_widget(nextTrackBtn) layoutMainRight.add_widget(layoutMainRightSongControl) layoutMainRightSongControlVol = GridLayout(cols=1) speedSlider = Slider(min=1, max=30, value=speed) #speedSlider.bind(on_touch_down=update_speed, on_touch_move=update_speed) layoutMainRightSongControlVol.add_widget(speedSlider) #layoutMainRight.add_widget(layoutMainRightSongControlVol) layoutMain.add_widget(layoutMainRight) layout.add_widget(layoutTagInfo) layout.add_widget(layoutMain) # Start flashing the LED #Clock.schedule_once(flash, 1.0/speed) root = ScrollView(size_hint=(1, None), size=(Window.width, Window.height)) # Make the background gray: with root.canvas.before: Color(.2, .2, .2, 1) root.add_widget(layout) updateImage() return root
#GPIO.output(flashLedPin, GPIO.LOW) #GPIO.setup(buttonPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) iconfonts.register('default_font', join(dirname(__file__), 'fonts/fa-light-300.ttf'), join(dirname(__file__), 'font-awesome.fontd')) # Define some helper functions: defaultKeyCode = 0 reader = SimpleMFRC522() trackImage = AsyncImage( source='https://dummyimage.com/300x400/000/fff.png&text=Track+image') trackTitle = Label(text='') trackAlbumTitle = Label(text='') trackPlayPauseBtn = Button(size_hint=(None, None), size=(40, 40), markup=True, text="%s" % (iconfonts.icon('fa-play', 32))) currentTrackIsPlay = False def updateImage(): print("updateImage") global trackImage global trackTitle global trackAlbumTitle global trackPlayPauseBtn global currentTrackIsPlay url = 'https://cf-baby-music-box.cfapps.eu10.hana.ondemand.com/getCurrentSong/[email protected]' result = json.load(urllib.request.urlopen(url)) resultTrackImageUrl = result['item']['album']['images'][0]['url'] print(resultTrackImageUrl) resultTrackTitle = result['item']['name']