def BoxLayout(self): # top layout self.layout_top = BoxLayout(orientation='horizontal') self.next_button = Button(text='Next Client', on_press=lambda a: self.next_client()) self.next_button.size_hint = (.2, 1) logo = Image(source='../../Marketing/simbolo_semfundo.png') logo.size_hint = (.6, 1) qr = Image(source='qr.png') qr.size_hint = (.2, 1) self.layout_top.add_widget(qr) self.layout_top.add_widget(logo) self.layout_top.add_widget(self.next_button) self.layout_top.size_hint = (1, 0.2) # center layout self.layout_center = StackLayout(orientation='lr-bt') self.scrlv = ScrollView(size_hint=(0.9, 0.95)) self.s = Slider(min=0, max=1, value=25, orientation='vertical', step=0.01, size_hint=(0.1, 0.95)) self.scrlv.bind(scroll_y=partial(self.slider_change, self.s)) # what this does is, whenever the slider is dragged, it scrolls the previously added scrollview by the same amount the slider is dragged self.s.bind(value=partial(self.scroll_change, self.scrlv)) self.layout_grid = GridLayout(cols=3, size_hint_y=None) self.layout_grid.bind(minimum_height=self.layout_grid.setter('height')) self.scrlv.add_widget(self.layout_grid) self.layout_center.add_widget(self.scrlv) self.layout_center.add_widget(self.s) # bottom layout self.layout_bottom = BoxLayout(orientation='horizontal') label_total = Label(text='Total:', font_size=30, color=[0, 0, 0, 1]) label_total.size_hint = (.5, 1) self.value = Label(text="0€", font_size=30, color=[0, 0, 0, 1]) self.value.size_hint = (.5, 1) self.layout_bottom.add_widget(label_total) self.layout_bottom.add_widget(self.value) self.layout_bottom.size_hint = (1, 0.1) # global layout layout_global = BoxLayout(orientation='vertical') layout_global.add_widget(self.layout_top) layout_global.add_widget(self.layout_center) layout_global.add_widget(self.layout_bottom) return layout_global
def __init__(self, **kwargs): super(UiowaScreen, self).__init__(**kwargs) self.layout = FloatLayout() self.layout.width = Window.width self.layout.height = Window.height self.layout.x = 0 self.layout.y = 0 self.add_widget(self.layout) img = Image(source=self.uiowaImage) img.size = (Window.width * 1.0, Window.height * 1.0) img.pos = (0, 0) img.opacity = .8 self.add_widget(img, 1) with self.layout.canvas: #sets canvas instructions for the rightlayout and draws a blue rect. filling the entire layout Color(1, 1, 1, .7) #WHITE Rectangle(pos=(.15 * self.layout.height, .30 * self.layout.height), size=(.45 * self.layout.width, .55 * self.layout.height)) qr = Image(source=self.qrCode) qr.size_hint = (.39, .39) qr.pos_hint = {'x': .56, 'y': .12} self.add_widget(qr) logo = Image(source=self.uiLogo) logo.size_hint = (.33, .33) logo.pos_hint = {'x': .59, 'y': .58} self.add_widget(logo) uiowaText = Label( text= 'The GravBox project is the result of the hard work of students of the University of Iowa\'s Physics and Astronomy Department. To learn more about physics and astronomy at the University of Iowa, and the research work being done in these areas, please scan the QR code to the right.', valign='middle', halign='center', font_size='24sp', text_size=(.4 * self.layout.width, None), color=(0, 0, 0, 1)) uiowaText.pos_hint = {'x': -.18, 'y': .075} self.add_widget(uiowaText) backBtn = MyButton(text='BACK') # back button backBtn.size_hint = (.1, .1) backBtn.pos_hint = {'x': .27, 'y': .16} backBtn.background_color = [.4, .4, .4, 1] backBtn.bind( on_release=self.backButton ) #when the button is released the callback function is called self.add_widget(backBtn)
def addImage(self, filename): image = Image(source=filename) image.size_hint = None, None image.width = metrics.sp(120) image.height = metrics.sp(120) self.add_widget(image) return
def __init__(self, side="right", **kwargs): super(TrashCan, self).__init__(**kwargs) self.opacity = 0.5 if side == "top": self.size_hint = 1, None self.height = self.img_size self.pos_hint = {"x": 0, "y": 1} elif side == "bottom": self.size_hint = 1, None self.height = self.img_size self.pos_hint = {"x": 0, "y": 0} elif side == "right": self.orientation = "vertical" self.size_hint = None, 1 self.width = self.img_size self.pos_hint = {"x": 1, "y": 0} elif side == "left": self.orientation = "vertical" self.size_hint = None, 1 self.width = self.img_size self.pos_hint = {"x": 0, "y": 0} b1 = BoxLayout() img = Image(source="trashcan.png") img.size = self.img_size, self.img_size img.size_hint = None, None b2 = BoxLayout() self.add_widget(b1) self.add_widget(img) self.add_widget(b2)
def __init__(self, team, next = False, **kwargs): super(crestButton,self).__init__(**kwargs) self.team = team self.size_hint = (None,None) self.size = (90,90) if next == True: self.background_normal = './data/images/crest_'+team['name']+'.png' self.background_down = './data/images/crest_'+team['name']+'.png' else: self.background_normal = './data/images/crest_'+team['name']+'_no.png' self.background_down = './data/images/crest_'+team['name']+'_no.png' position_list = [(-48+180-45,150+320-45),(48+180-45,150+320-45), (-48+180-45,56+320-45), (48+180-45,56+320-45)] self.pos = position_list[g.save.tournament['teams'].index(team)] if team['result'] is not '': sign = Image(source='./data/images/crest-marker-'+team['result']+'.png') sign.size_hint = (None,None) sign.size = (90,90) sign.pos = position_list[g.save.tournament['teams'].index(team)] self.add_widget(sign) self.bind(on_release = self.crest_click)
def __init__(self, **kwargs): super(AboutScreen, self).__init__(**kwargs) self.layout = FloatLayout() self.layout.width = Window.width self.layout.height = Window.height self.layout.x = 0 self.layout.y = 0 self.add_widget(self.layout) img = Image(source=self.aboutImage) img.size = (Window.width * 1.0, Window.height * 1.0) img.pos = (0, 0) img.opacity = .8 self.add_widget(img, 1) with self.layout.canvas: #sets canvas instructions for the rightlayout Color(1, 1, 1, .7) #BLUE Rectangle(pos=(.05 * self.layout.height, .05 * self.layout.height), size=(.45 * self.layout.width, .9 * self.layout.height)) group = Image(source=self.groupPhoto) group.size_hint = (.5, .5) group.pos = (Window.width * .49, Window.height * .37) self.add_widget(group) nameLabel = Label( text= 'From left to right: Jianbo Lu, Jacob Isbell, Sophie Deam, Wyatt Bettis, Ross McCurdy, Erin Maier, Sadie Moore, Zachary Luppen, Mason Reed', text_size=(.45 * self.layout.width, .3 * self.layout.height), halign='center', font_size='18sp', color=(0, 0, 0, 1)) nameLabel.pos = (Window.width * .24, Window.height * -.10) self.add_widget(nameLabel) aboutText = Label( text= 'GravBox is the interface application for the Augmented Reality (AR) Sandbox for gravitational dynamics simulations designed and built at the University of Iowa by Dr. Hai Fu\'s 2016-2017 Introduction to Astrophysics class. \n\nThe GravBox application was developed by Zachary Luppen, Erin Maier, and Mason Reed. The sandbox was designed and built by Wyatt Bettis, Ross McCurdy, and Sadie Moore. The gravitational algorithm was written by Sophie Deam, Jacob Isbell, and Jianbo Lu. Graphic design was contributed by Jeremy Swanston. \n\nThe original AR Sandbox is the result of an NSF-funded project on informal science education for freshwater lake and watershed science developed by the UC Davis\' W.M. Keck Center for Active Visualization in the Earth Sciences, together with the UC Davis Tahoe Environmental Research Center, Lawrence Hall of Science, and ECHO Lake Aquarium and Science Center.\n\n To learn more about the GravBox project, contact Hai Fu at [email protected], or visit our Github at https://github.com/GravBoxInterface/GravBox', valign='middle', halign='center', font_size='19sp', text_size=(.4 * self.layout.width, None), color=(0, 0, 0, 1)) aboutText.pos = (-.39 * self.layout.height, 0) self.add_widget(aboutText) backBtn = MyButton(text='BACK') # back button backBtn.size_hint = (.1, .1) backBtn.pos_hint = {'x': .69, 'y': .12} backBtn.background_color = [.4, .4, .4, 1] backBtn.bind( on_release=self.backButton ) #when the button is released the callback function is called self.add_widget(backBtn)
def update_widgets(self, *args, **kwargs): contact = self.state.edited_contact if contact.profile_picture: pic = Image(source=contact.profile_picture) else: pic = Button(text="Set Picture") pic.size_hint = (0.2, 1) self.add_widget(pic) self.add_widget( Label(text="{}".format(contact.name), size_hint=(0.8, 1)))
def build(self): # Image ac_image = Image(source='static/ac1.png') ac_image.size_hint = (1.25, 1.5) ac_image.pos_hint = {'center_x': 0.5} self.add_widget(ac_image) # Details details_box = MDBoxLayout(orientation='horizontal', size_hint_y=0.5) self.temprature = MDLabel(text='18°C') self.temprature.color = [1] * 4 self.fan_speed = MDLabel(text='Fan: 2') self.fan_speed.color = [1] * 4 details_box.add_widget(self.temprature) details_box.add_widget(self.fan_speed) self.add_widget(details_box)
def placeWorldItems(self): for each in requiredItems: x = Image(source=self.resource_path('artAssets/{}.png'.format(each))) x.allow_stretch = True x.keep_ratio = True x.size_hint = (.03,.03) if(allWorldItems[each] in lightWorldLocations): x.pos_hint = {'center_x':lightWorldLocations[allWorldItems[each]][0],'center_y':lightWorldLocations[allWorldItems[each]][1]} x.text = '{}:{}'.format(each, allWorldItems[each]) x.reload() self.ids.lightScatter.add_widget(x,0) elif(allWorldItems[each] in darkWorldLocations): x.pos_hint = {'center_x':darkWorldLocations[allWorldItems[each]][0],'center_y':darkWorldLocations[allWorldItems[each]][1]} x.reload() self.ids.darkScatter.add_widget(x,0) else: pass
def update_test_image(self, *_): """Regenerate the watermark preview image.""" if self.watermark_settings: test_image = self.watermark_settings.ids['testImage'] test_image.clear_widgets() if os.path.isfile(self.watermark_image): image = KivyImage(source=self.watermark_image) size_x = test_image.size[0] * (self.watermark_size / 100) size_y = test_image.size[1] * (self.watermark_size / 100) image.size = (size_x, size_y) image.size_hint = (None, None) image.opacity = self.watermark_opacity / 100 x_pos = test_image.pos[0] + ((test_image.size[0] - size_x) * (self.watermark_horizontal / 100)) y_pos = test_image.pos[1] + ((test_image.size[1] - size_y) * (self.watermark_vertical / 100)) image.pos = (x_pos, y_pos) test_image.add_widget(image)
def move_piece(self, from_row, from_col, to_row, to_col, moved_piece_color): """ To be called when the client receives a "piece_moved" command :return: """ app = App.get_running_app() # Clear the image that showed where the last piece moved from self.clear_just_moved_indicator() # Need to mirror the rows and columns if the player isn't the client if moved_piece_color == "red" and app.player.is_red or moved_piece_color == 'black' and not app.player.is_red: pass else: # Mirror the movements from_row = self.mirror_row(from_row) from_col = self.mirror_col(from_col) to_row = self.mirror_row(to_row) to_col = self.mirror_col(to_col) # Get the widget being moved moving_piece = app.board_helper.get_widget_at(from_row, from_col) piece_being_entered = app.board_helper.get_widget_at(to_row, to_col) #print("Moving piece", moving_piece.id()) # Animate the motion animation_widget = Image(source=moving_piece.source, color=moving_piece.color, keep_ratio=False, allow_stretch=True) animation_widget.size_hint = (None, None) animation_widget.size = moving_piece.size animation_widget.pos = self.to_window(*moving_piece.pos) Window.add_widget(animation_widget) new_pos = piece_being_entered.pos moving_piece.opacity = 0 app.is_animating = True anim = Animation(pos=new_pos, transition='out_expo')#, duration=0) anim.bind(on_complete=partial(self.finish_piece_movement, piece_being_entered, moving_piece)) anim.start(animation_widget) # Move the turn indicator self.move_turn_indicator()
def __init__(self, scatter, root): self.scatter = scatter self.root = root self.current_popup_menu = 0 try: with open(main_page.file_dir + main_page.file_name, 'r') as f: self.obstacle_list = json.load(f) for obstacle in self.obstacle_list['obstacle_list']: image = Image(source=main_page.icon_dir + obstacle['image'], size=obstacle['size'][:2]) image.center_x = obstacle['position'][0] image.center_y = obstacle['position'][1] image.allow_stretch = True image.size_hint = None, None self.scatter.add_widget(image, index=1) OBSTACLE_IMAGE[obstacle['id']] = image except Exception, e: self.obstacle_list = {"obstacle_list": []}
def __init__(self, **kwargs): # accesses properties and methods from FloatLayout super().__init__(**kwargs) global bestPopCount, store # create a cloud layout layer where all the clouds will be spawned (this will be above the sky background) cloud_layout = CloudLayout() self.add_widget(cloud_layout) # in the json file set as store in global variables, get the best score value saved to local memory in at the # key 'bestScore' bestPopCount = store.get('bestScore')['best'] # create a new float layout for menu items self.menu_layout = FloatLayout() # create the start button start_button = Button() # the start button width and height should both take up 30% of the screen start_button.size_hint = (.3, .3) # the start button should be located in the middle of the screen horizontally and 30% up the screen vertically start_button.pos_hint = {'center_x': .5, 'center_y': .3} # set the start button text to say "start" start_button.text = "Start" # change its font style start_button.font_name = "PressStart2P.ttf" # make the font medium sized start_button.font_size = "20sp" # upon the buttons release it will remove the layout with all menu items attached to it start_button.bind(on_release=self.remove_layout) # creates an image object for the title image title = Image() # the image should take up no more than 90% of the screen horizontally and no more than 90% of screen vertically title.size_hint = (.9, .9) # the title image is centered horizontally and located 70% up screen vertically title.pos_hint = {'center_x': .5, 'center_y': .7} # changes the title image to the title image .png file title.source = "Assets/popper_pig_title.png" # add the start button and the title to the menu layout self.menu_layout.add_widget(start_button) self.menu_layout.add_widget(title) # add the menu layout self.add_widget(self.menu_layout)
def __init__(self, **kwargs): super(MainWindow, self).__init__(**kwargs) ImageViewer = Image(source="") # the interactive writing window ImageViewer.size_hint = (None, None) ImageViewer.size = (1021, 576) ImageViewer.pos = (0, 240 - 152) self.add_widget(ImageViewer) # The reason to put the interactive texts and the TextField in the MainWindow is that MainWindow is updated immediately # workpanel is static LabelReminder = Label(font_size="15sp", text="", color=(1, .3, .3, 1), halign='left', text_size=(300, 150)) LabelReminder.size_hint = ( None, None) # the interactive text, which is initially set to red LabelReminder.size = (300, 150) LabelReminder.valign = 'top' LabelReminder.text = "" LabelReminder.pos = (1050, 210 - 152) self.add_widget(LabelReminder) textinput = TextInput(multiline=False) #the TextField textinput.size_hint = (None, None) textinput.size = (300, 40) textinput.pos = (1040, 250 - 152) self.add_widget(textinput) self.uievents = UIEvents(ImageViewer, LabelReminder, textinput) WorkingPanel = WorkPanel(self.uievents) WorkingPanel.pos = (0, 240) self.add_widget(WorkingPanel)
def __init__(self, ms, **kwargs): super(MasterClient.Home, self).__init__(**kwargs) self.ms = ms # Float Layout Top Bar self.float_layout = FloatLayout() self.float_layout.size_hint = (None, None) # self.float_layout.pos_hint = (None, None) # Não pode definir no FloatLayout self.float_layout.size = (402, 85) self.float_layout.y = 630 # Top Bar image self.top_bar = Image() self.float_layout.add_widget(self.top_bar) self.top_bar.source = ("interface/Home/top_bar1.png") self.top_bar.y = 630 # AddContact button self.add_contact_btn = Button() self.float_layout.add_widget(self.add_contact_btn) self.add_contact_btn.size_hint = (None, None) self.add_contact_btn.size = (40, 40) self.add_contact_btn.pos = (345, 643) self.add_contact_btn.background_color = (1.0, 1.0, 1.0, 0) self.add_contact_btn.on_press = self.press_add_contact_button # Switch status button self.switch_status = Button() self.float_layout.add_widget(self.switch_status) self.switch_status.size_hint = (None, None) self.switch_status.size = (43, 24) self.switch_status.pos = (20, 651) self.switch_status.background_color = (1.0, 1.0, 1.0, 0) self.switch_status.on_press = self.press_switch_status # Switch status image self.switch_img = Image() self.add_widget(self.float_layout) self.switch_status.add_widget(self.switch_img) self.switch_img.source = ("interface/Home/switch_on.png") self.switch_img.size = (43, 24) self.switch_img.pos = (20, 651) # Scroll View self.scroll_view = ScrollView() self.add_widget(self.scroll_view) self.scroll_view.size_hint = (None, None) self.scroll_view.size = (402, 630) self.scroll_view.y = self.scroll_view.parent.x self.scroll_view.orientation = "vertical" self.scroll_view.background_color = (255, 0, 0, 1) # Box View chats self.box = BoxLayout() self.scroll_view.add_widget(self.box) self.box.id = "box" self.box.orientation = "vertical" self.box.size_hint_y = None self.box.bind(minimum_height=self.box.setter("height")) self.box.y = self.box.parent.y print(len(contacts)) for contact in contacts: print("entrei aqui no coisa do bicho do negoço") print(contact) ### # Box button box_button = Button() self.box.add_widget(box_button) box_button.size_hint = (None, None) box_button.width = 402 box_button.height = 80 #box_button.background_color = (255, 255, 255, 1) # Contact photo image contact_photo = Image() box_button.add_widget(contact_photo) contact_photo.source = ("interface/Home/contact.png") contact_photo.size_hint = (None, None) contact_photo.pos_hint = (None, None) contact_photo.size = (80, 80) contact_photo.pos = (0, 0) # Contact status img contact_img_status = Image() box_button.add_widget(contact_img_status) contact_img_status.source = ("interface/online.png") contact_img_status.size_hint = (None, None) contact_img_status.pos_hint = (None, None) contact_img_status.size = (80, 80) contact_img_status.pos = (330, contact_img_status.parent.y) # Contact name label lbl_name = Label() box_button.add_widget(lbl_name) lbl_name.text = contact_name lbl_name.size = (15, 120) lbl_name.pos = (90, contact_img_status.parent.y)
def on_touch_down(self, touch): print "TOUCH", touch.pos if main_page.current_obstacle == {}: return x, y = touch.pos image = Image(source=main_page.icon_dir + main_page.current_obstacle['Image'], size=main_page.current_obstacle['Initial_Size'][:2]) image.center_x = touch.pos[0] image.center_y = touch.pos[1] image.size_hint = None, None image.allow_stretch = True print type(self.root) print self.root.pos, self.root.size if self.root.pos[0] + image.width / 2 <= x and x <= self.root.pos[ 0] + self.root.size[0] - image.width / 2: if self.root.pos[1] + image.height / 2 <= y and y <= self.root.pos[ 1] + self.root.size[1] - image.height / 2: not_collision, collide_obstacle = collision_detect( self.obstacle_list, image, touch.pos) if check_button_clicked(self.root, self.current_popup_menu, touch.pos): if self.current_popup_menu != 0: for item in self.current_popup_menu: self.root.remove_widget(item) self.current_popup_menu = 0 elif not_collision: if self.current_popup_menu != 0: for item in self.current_popup_menu: self.root.remove_widget(item) self.current_popup_menu = 0 self.scatter.add_widget(image, index=1) obstacle = {} obstacle['title'] = main_page.current_obstacle['Name'] obstacle['position'] = touch.pos obstacle['size'] = main_page.current_obstacle[ 'Initial_Size'] obstacle['image'] = main_page.current_obstacle['Image'] obstacle['id'] = hashlib.sha256( str(touch.pos[0]) + str(touch.pos[1])).hexdigest() OBSTACLE_IMAGE[obstacle['id']] = image self.obstacle_list['obstacle_list'].append(obstacle) with open(main_page.file_dir + main_page.file_name, 'w') as f: json.dump(self.obstacle_list, f) else: if self.current_popup_menu != 0: for item in self.current_popup_menu: self.root.remove_widget(item) self.current_popup_menu = 0 menu = [] for idx in range(NUM_MENU): tmp_btn = Button(text="Delete", background_color=(0x81, 0xd4, 0xfa), size_hint=(.1, .1)) tmp_btn.pos = [ touch.pos[0], touch.pos[1] - tmp_btn.size[1] - idx * tmp_btn.size[1] ] tmp_btn.id = collide_obstacle['id'] + "," + str(idx) print tmp_btn.id menu.append(tmp_btn) self.current_popup_menu = menu for item in menu: self.root.add_widget(item)
def show_collision(self): image = Image(source=collision) self.parent.add_widget(image) image.pos_hint = self.pos_hint image.size_hint = (0.1, 0.1)
def show_startup(self): startPop = Popup(title='Help', auto_dismiss=True, size_hint=(0.9, 0.4), separator_color=(0, 0, 1, 1), title_align='center', title_color=(1, 1, 1, 1), title_size='16sp', title_font='fonts/Fcarbim.ttf') layStart = GridLayout(cols=2, spacing=10) but_playNextCards = Image(source='icons/PlayDown.png') but_playNextCards.size_hint = (None, 1) but_playNextCards.width = '40dp' lbl_playNextCards = Label(text=' Play current cards') lbl_playNextCards.halign = 'left' lbl_playNextCards.valign = 'middle' lbl_playNextCards.bind(size=lbl_playNextCards.setter('text_size')) but_startGame = Image(source='icons/ShuffleCardsDown.png') but_startGame.size_hint = (None, 1) but_startGame.width = '40dp' lbl_startGame = Label(text=' Start new game') lbl_startGame.halign = 'left' lbl_startGame.valign = 'middle' lbl_startGame.bind(size=lbl_startGame.setter('text_size')) but_duration = Image(source='icons/noofcards.png') but_duration.size_hint = (None, 1) but_duration.width = '40dp' lbl_duration = Label(text=' How many cards to play') lbl_duration.halign = 'left' lbl_duration.valign = 'middle' lbl_duration.bind(size=lbl_duration.setter('text_size')) but_background = Image(source='icons/but_backofcards.png') but_background.size_hint = (None, 1) but_background.width = '40dp' lbl_background = Label(text=' Change the background') lbl_background.halign = 'left' lbl_background.valign = 'middle' lbl_background.bind(size=lbl_background.setter('text_size')) but_exit = Image(source='icons/Exit.png') but_exit.size_hint = (None, 1) but_exit.width = '40dp' lbl_exit = Label(text=' Exit game') lbl_exit.halign = 'left' lbl_exit.valign = 'middle' lbl_exit.bind(size=lbl_exit.setter('text_size')) layStart.add_widget(but_playNextCards) layStart.add_widget(lbl_playNextCards) layStart.add_widget(but_startGame) layStart.add_widget(lbl_startGame) layStart.add_widget(but_duration) layStart.add_widget(lbl_duration) layStart.add_widget(but_background) layStart.add_widget(lbl_background) layStart.add_widget(but_exit) layStart.add_widget(lbl_exit) startPop.add_widget(layStart) startPop.open()