def apply_kv(self): FuncWidget.apply_kv(self) if self.ref_func: return app = _get_app() with KvContext(): with GroupFuncList( parent=self, spacing='5dp', size_hint_y=None, orientation='vertical') as more: self.more = self.children_container = more more.group_widget = self more.is_visible @= self.show_more and self.is_visible with KvRule(more.children, app.drag_controller.widget_dragged, app.drag_controller.dragging): if more.children and not ( app.drag_controller.dragging and app.drag_controller.widget_dragged and app.drag_controller.widget_dragged.drag_cls in ('func', 'func_spinner')): more.padding = '15dp', '5dp', 0, 0 else: more.padding = '15dp', '5dp', 0, '12dp' more.height @= more.minimum_height more.size_hint_min_x @= more.minimum_width more.spacer_props = { 'size_hint_y': None, 'height': '50dp', 'size_hint_min_x': '40dp'} more.drag_classes = ['func', 'func_spinner'] more.controller @= self.func with more.canvas: color_back = Color() color_back.rgba = 152 / 255., 153 / 255., 155 / 255., 1. more_rect_back = Rectangle() more_rect_back.pos ^= more.x + dp(15), more.y more_rect_back.size ^= more.width - dp(15), dp(10) if ( app.drag_controller.dragging and app.drag_controller.widget_dragged and app.drag_controller.widget_dragged.drag_cls in ('func', 'func_spinner')) else 0 color = Color() color.rgba ^= app.theme.divider more_rect = Rectangle() more_rect.pos ^= more.x + dp(11), more.y more_rect.size ^= dp(2), more.height - dp(2)
def add_items(self,number): for item in range(0,number): rand = randint(1,3) t=TutoItem('tuto_assets/texture.png') t.l.opacity=0 t.remove_widget(t.children[0]) t.size=(256,256) t.size_hint=(None,None) Animation(pos=(randint(0,Window.width*0.5),randint(0,int(Window.height*0.8))),rotation=randint(0,360),d=0.2).start(t) with t.canvas.before: c=Color() c.rgba=self.colors[str(rand)] Rectangle(size=t.size) t.item['taille']=rand self.add_widget(t)
def update_color(self): now = self.date real = self.item["date"] offset = self.fresco.date_allowed_offset diff = abs(now - real) / float(offset) * 2.0 color = Color(71 / 360.0, 71 / 100.0, 87 / 100.0, mode="hsv") if diff < 1.0: color.h = 106 / 360.0 self.place_correctly = True else: h = (71 - 71 * (min(2.0, (diff - 1)) / 2.0)) / 360.0 color.h = h self.place_correctly = False self.color = color.rgba
def add_children_container( self, container, drag_classes, cls, color, drag_append_end=False): """Gets a StageChildrenList that is added to containter. """ app = _get_app() with KvContext(): with cls(parent=container) as widget: widget.spacing = '5dp' widget.size_hint_y = None widget.orientation = 'vertical' widget.spacer_props = { 'size_hint_y': None, 'height': '40dp', 'size_hint_min_x': '40dp'} widget.drag_classes = drag_classes widget.drag_target_stage = self.stage widget.drag_append_end = drag_append_end widget.height @= widget.minimum_height widget.size_hint_min_x @= widget.minimum_width widget.padding @= '5dp', 0, 0, ( 0 if widget.children and not ( app.drag_controller.dragging and app.drag_controller.widget_dragged and app.drag_controller.widget_dragged.drag_cls in drag_classes) else '12dp') widget.is_visible @= self.show_more and self.is_visible widget.stage_widget = self with widget.canvas: color_back = Color() color_back.rgba = 152 / 255., 153 / 255., 155 / 255., 1. rect_back = Rectangle() rect_back.pos ^= widget.x + dp(5), widget.y rect_back.size ^= widget.width - dp(5), dp(10) if ( app.drag_controller.dragging and app.drag_controller.widget_dragged and app.drag_controller.widget_dragged.drag_cls in drag_classes) else 0 color_inst = Color() color_inst.rgba = color rect = Rectangle() rect.pos ^= widget.x + dp(1), widget.y rect.size ^= dp(2), widget.height return widget
def update_color(self): if self.date is None: return now = self.date real = self.item['date'] offset = self.fresco.date_allowed_offset diff = abs(now - real) / float(offset) * 2. color = Color(71 / 360., 71 / 100., 87 / 100., mode='hsv') if diff < 1.: color.h = 106 / 360. self.place_correctly = True else: h = (71 - 71 * (min(2., (diff - 1)) / 2.)) / 360. color.h = h self.place_correctly = False self.color = color.rgba
def update_color(self, win): color = Color(71 / 360., 71 / 100., 87 / 100., mode='hsv') if self.auto_color == True : x1,y1 = self.pos x2,y2 = self.right_pos x1 -= self.imagemap.x y1 -= self.imagemap.y wind = Window.width + Window.height diff = (abs(x2-x1) + abs(y2-y1)) / wind #print diff, x2 - x1, y2 - y1 if diff < 0.05: color.h = 106 / 360. else: h = (71 - 71 * (min(2., 10*(diff - 0.01)) / 2.)) / 360. color.h = h else : if win == True : color.h = 106 / 360. else : color.h = 0 self.color = color.rgba
def on_touch_down(self, touch): # Scale screen if mouse scroll if(touch.button == "scrolldown"): if(self.scallerVar > 1000): self.scallerVar -= 100 elif(touch.button == "scrollup"): if(self.scallerVar < 30000): self.scallerVar += 100 # Cancel if right button if(touch.button == "right"): if(self.state == self.EDITOR_STATE): if(self.editorTool == "add"): self.changeTool("move") elif(self.editorTool == "delete"): self.changeTool("move") else: self.window.editMenu.setEditObject(None) # End level editor when right click # elif(self.editorTool == "move"): # self.window.endLevelEditor() # Save current pos p = self.to_local(*touch.pos) self.touches[0] = p if(self.state == self.EDITOR_STATE and touch.button == "left"): # Selecting none --> closes edit menu selectObject = None # If AddBarrier was clicked on, draw a line if(self.editorTool == "add"): self.adding_barrier = True self.addingShape = self.window.objectMenu.getData()["shape"] temp_shape = None with self.canvas: Color(1,0,0,0.5) if(self.addingShape == "Segment"): temp_shape = Line(points = [p[0], p[1], p[0], p[1]], width = 20*self.scaller) elif(self.addingShape == "Circle"): temp_shape = Ellipse(pos=(p[0]+1, p[1]+1), size=(1,1)) elif(self.addingShape == "Box"): if(self.addingStage == 0): temp_shape = Line(points = [p[0], p[1], p[0], p[1]], width = 20*self.scaller) else: temp_shape = self.temp_barrier self.temp_barrier = temp_shape # Delete Object elif(self.editorTool == "delete"): deletePoint = (p[0]/self.scaller, p[1]/self.scaller) for shape in reversed(self.simulation.space.shapes): if(shape.point_query(deletePoint)[0] < 0): if(not isinstance(shape, Car)): self.simulation.deleteObject(shape) break self.deleteObject = False # Move object else: movePoint = (p[0]/self.scaller, p[1]/self.scaller) for shape in self.simulation.space.shapes: if(shape.point_query(movePoint)[0] < 0): self.movingObject = True # Select object for editing selectObject = shape # Move depending on the type if(isinstance(shape, Car) or isinstance(shape, pymunk.Circle) or isinstance(shape, pymunk.Poly)): self.movingVar = shape if(isinstance(shape, pymunk.Segment)): # Use nearest endpoint self.movingVar = shape p1 = movePoint p2 = shape.a p3 = shape.b distance1 = math.sqrt(((p1[0]-p2[0])**2)+((p1[1]-p2[1])**2)) distance2 = math.sqrt(((p1[0]-p3[0])**2)+((p1[1]-p3[1])**2)) if(distance1 < distance2): self.movingPoint = "a" else: self.movingPoint = "b" if(not self.movingObject): touch.grab(self) # If object selected then edit if not then send None --> Closes menu self.window.editMenu.setEditObject(selectObject) else: if(self.viewState == self.FREE_VIEW or self.selectedCar == None): touch.grab(self)
def makepoint(coords,canvas): canvas.add(Color(1,0,0)) canvas.add(SmoothLine(circle=(coords[0],coords[1],2),width=3))
def Plano(self, *args): with self.wid.canvas: Color(225, 255, 255, 1.0, mode='rgba') Rectangle(pos=(200, 0), size=(400, 350))
def drawCrosshairOnVideoForImagePoint(self, ix, iy, iwidth, iheight, color=(1., 0, 0), group='overlay'): widget = self.ids.KivyCamera with widget.canvas: Color(*color) wx, wy = self.imagePointToWidgetPoint(ix, iy, iwidth, iheight, widget) Line(circle=(widget.x+wx, widget.y+wy, 2), group=group)
def render(self, canvas, dt): with canvas: Color(0.5, 0.5, 0.5, 1.0) Rectangle(pos=(self.x, self.y), size=(self.width, self.height))
def __init__(self, **kwargs): super(LineWidget, self).__init__(**kwargs) with self.canvas: Color(0, 1., 0) self.line = Line(points=())
def drawCalibration(self): self.ids.opticalScatter.canvas.clear() for y in range(7, -8, -1): points = [] for x in range(-15, 16, +1): points.append(x * 3 * 25.4 + self.bedWidth / 2.0) points.append(y * 3 * 25.4 + self.bedHeight / 2.0) with self.ids.opticalScatter.canvas: Color(0, 0, 1) Line(points=points) for x in range(-15, 16, +1): points = [] for y in range(7, -8, -1): points.append(x * 3 * 25.4 + self.bedWidth / 2.0) points.append(y * 3 * 25.4 + self.bedHeight / 2.0) with self.ids.opticalScatter.canvas: Color(0, 0, 1) Line(points=points) for y in range(7, -8, -1): points = [] for x in range(-15, 16, +1): if (self.inMeasureOnlyMode): points.append(x * 3 * 25.4 + self.measuredErrorsX[x + 15][7 - y] + self.bedWidth / 2.0) points.append(y * 3 * 25.4 + self.measuredErrorsY[x + 15][7 - y] + self.bedHeight / 2.0) else: points.append(x * 3 * 25.4 + self.calErrorsX[x + 15][7 - y] + self.bedWidth / 2.0) points.append(y * 3 * 25.4 + self.calErrorsY[x + 15][7 - y] + self.bedHeight / 2.0) with self.ids.opticalScatter.canvas: Color(1, 0, 0) Line(points=points) for x in range(-15, 16, +1): points = [] for y in range(7, -8, -1): if (self.inMeasureOnlyMode): points.append(x * 3 * 25.4 + self.measuredErrorsX[x + 15][7 - y] + self.bedWidth / 2.0) points.append(y * 3 * 25.4 + self.measuredErrorsY[x + 15][7 - y] + self.bedHeight / 2.0) else: points.append(x * 3 * 25.4 + self.calErrorsX[x + 15][7 - y] + self.bedWidth / 2.0) points.append(y * 3 * 25.4 + self.calErrorsY[x + 15][7 - y] + self.bedHeight / 2.0) with self.ids.opticalScatter.canvas: Color(1, 0, 0) Line(points=points)
def on_touch_down(self, touch): with self.canvas: Color(rgba=self.paint_color) touch.ud['line'] = Line(points=(touch.x, touch.y), width=self.line_width)
def build(self): # Set up the layout: layout = GridLayout(cols=7, spacing=20, padding=40, rows=4) with layout.canvas.before: Color(.2,.2,.2,1) self.rect = Rectangle(size=(1024,600), pos=layout.pos) speedSlider2 = Slider(orientation='vertical', min=7, max=15, value=7,step=1) speedSlider2.bind(on_touch_down=update_speed, on_touch_move=update_speed) speedSlider3 = Slider(orientation='vertical', min=7, max=15, value=7,step=1) speedSlider3.bind(on_touch_down=update_speed, on_touch_move=update_speed) speedSlider4 = Slider(orientation='vertical', min=7, max=15, value=7,step=1) speedSlider4.bind(on_touch_down=update_speed, on_touch_move=update_speed) speedSlider5 = Slider(orientation='vertical', min=7, max=15, value=7,step=1) speedSlider5.bind(on_touch_down=update_speed, on_touch_move=update_speed) speedSlider6 = Slider(orientation='vertical', min=7, max=15, value=7,step=1) speedSlider6.bind(on_touch_down=update_speed, on_touch_move=update_speed) speedSlider7 = Slider(orientation='vertical', min=7, max=15, value=7,step=1) speedSlider7.bind(on_touch_down=update_speed, on_touch_move=update_speed) speedSlider8 = Slider(orientation='vertical', min=7, max=15, value=7,step=1) speedSlider8.bind(on_touch_down=update_speed, on_touch_move=update_speed) speedSlider9 = Slider(orientation='vertical', min=7, max=15, value=7,step=1) speedSlider9.bind(on_touch_down=update_speed, on_touch_move=update_speed) speedSlider10 = Slider(orientation='vertical', min=7, max=15, value=7,step=1) speedSlider10.bind(on_touch_down=update_speed, on_touch_move=update_speed) speedSlider11 = Slider(orientation='vertical', min=7, max=15, value=7,step=1) speedSlider11.bind(on_touch_down=update_speed, on_touch_move=update_speed) speedSlider12 = Slider(orientation='vertical', min=7, max=15, value=7,step=1) speedSlider12.bind(on_touch_down=update_speed, on_touch_move=update_speed) speedSlider13 = Slider(orientation='vertical', min=7, max=15, value=7,step=1) speedSlider13.bind(on_touch_down=update_speed, on_touch_move=update_speed) speedSlider14 = Slider(orientation='vertical', min=7, max=15, value=7,step=1) speedSlider14.bind(on_touch_down=update_speed, on_touch_move=update_speed) inArduino = InputArduino(text="inArduino") Clock.schedule_interval(inArduino.update, 1.0/10.0) pul1 = InputButton1(text="pulsador1") Clock.schedule_interval(pul1.update, 1.0/10.0) pul2 = InputButton2(text="pulsador2") Clock.schedule_interval(pul2.update, 1.0/10.0) pul3 = InputButton3(text="pulsador3") Clock.schedule_interval(pul3.update, 1.0/10.0) sw1 = InputSW1(text="sw1") Clock.schedule_interval(sw1.update, 1.0/10.0) sw2 = InputSW2(text="sw2") Clock.schedule_interval(sw2.update, 1.0/10.0) sw3 = InputSW3(text="sw3") Clock.schedule_interval(sw3.update, 1.0/10.0) sw4 = InputSW4(text="sw4") Clock.schedule_interval(sw4.update, 1.0/10.0) ''' layout.add_widget(speedSlider1) layout.add_widget(speedSlider2) layout.add_widget(speedSlider3) layout.add_widget(speedSlider4) layout.add_widget(speedSlider5) layout.add_widget(speedSlider6) layout.add_widget(speedSlider7) layout.add_widget(speedSlider8) layout.add_widget(speedSlider9) layout.add_widget(speedSlider10) layout.add_widget(speedSlider11) layout.add_widget(speedSlider12) layout.add_widget(speedSlider13) layout.add_widget(speedSlider14) ''' button1.bind(on_press=press_callback) button2.bind(on_press=press_callback) button3.bind(on_press=press_callback) button4.bind(on_press=press_callback) button5.bind(on_press=press_callback) button6.bind(on_press=press_callback) button7.bind(on_press=press_callback) button8.bind(on_press=press_callback) button9.bind(on_press=press_callback) button10.bind(on_press=press_callback) button11.bind(on_press=press_callback) button12.bind(on_press=press_callback) button13.bind(on_press=press_callback) button14.bind(on_press=press_callback) button15.bind(on_press=press_callback) button16.bind(on_press=press_callback) button17.bind(on_press=press_callback) button18.bind(on_press=press_callback) button19.bind(on_press=press_callback) button20.bind(on_press=press_callback) button21.bind(on_press=press_callback) button22.bind(on_press=press_callback) button23.bind(on_press=press_callback) button24.bind(on_press=press_callback) layout.add_widget(button1) layout.add_widget(button2) layout.add_widget(button3) layout.add_widget(button4) layout.add_widget(button5) layout.add_widget(button6) layout.add_widget(button7) layout.add_widget(button8) layout.add_widget(button9) layout.add_widget(button10) layout.add_widget(button11) layout.add_widget(button12) layout.add_widget(button13) layout.add_widget(button14) layout.add_widget(button15) layout.add_widget(button16) layout.add_widget(button17) layout.add_widget(button18) layout.add_widget(button19) layout.add_widget(button20) layout.add_widget(button21) layout.add_widget(button22) layout.add_widget(button23) layout.add_widget(button24) layout.add_widget(pul1) layout.add_widget(pul2) layout.add_widget(pul3) return layout
def add_cross(self): with self.canvas.after: Color(0.5, 0.5, 0.5, 1) Line(points=(self.center_x, self.height + self.y, self.center_x, self.y), width=1) Line(points=(self.x, self.center_y, self.width, self.center_y), width=1)
def create_color(rgb): return Color(rgb[0], rgb[1], rgb[2])
def __init__(self, active=True, **kwargs): super(TashpMainPage, self).__init__(**kwargs) with self.canvas.before: Color(*SCREEN_BG_COLOR) Rectangle(size=self.size)
def update_bg(self, box, size): self.canvas.before.clear() with self.canvas.before: Color(*DOMAIN_BOX_BG_COLOR) Rectangle(size=self.size, pos=self.pos)
def __init__(self, spawn_x, key = Notes.C, speed=1.0, audio_callback=None, hurt_player_callback=None, dmg_rect_on_hit_callback=None, add_sound=None, remove_sound=None, clear_prog=None): super(Enemy, self).__init__() self.time = 0.0 # pos3D is 3D cartesian coords self.pos3D = [spawn_x,0,-D] # pos2D is for actual position on screen self.pos2D = self.convert_to_pos2D(self.pos3D) self.size = np.array((200,380))*Window.height/600 self.speed = speed # Callback Functions self.hurt_player_callback = hurt_player_callback self.dmg_rect_on_hit_callback = dmg_rect_on_hit_callback self.clear_prog = clear_prog #---------# # Visuals # #---------# self.texture = Image(source='../data/ogre.png').texture self.textures = [] self.texture_a = self.texture.get_region(0,435,107,145); self.textures.append(self.texture_a) self.texture_b = self.texture.get_region(107,435,107,145); self.textures.append(self.texture_b) self.texture_c = self.texture.get_region(215,435,107,145); self.textures.append(self.texture_c) self.texture_d = self.texture.get_region(322,435,107,145); self.textures.append(self.texture_d) self.anim_switch_time = 0.270 self.anim_time = self.anim_switch_time self.anim_frame = randint(0,100)%len(self.textures) s = self.size*self.scale_with_z() self.cbrect = CBRectangle(texture=self.textures[self.anim_frame], cbpos=(self.pos2D[0],self.pos2D[1]), cbsize=(s[0],s[1])) self.color = Color(0.65,0.65,0.65) self.add(self.color) self.add(self.cbrect) # self.color = Color(1,0.1,0.1) # s = self.size*self.scale_with_z() # self.cbrect = CBRectangle( cbpos=(self.pos2D[0],self.pos2D[1]), cbsize=(s[0],s[1]) ) # self.add(self.color) # self.add(self.cbrect) # If currently targeted by crosshair self.is_targeted = False self.is_dead = False # TODO: list of textures for different animation states # TODO: eventually replace with textures # self.texture = Image(source='../data/find_a_picture.png').texture # self.rect = Rectangle(texture=self.texture, pos=(0,0), size=(100,100)) #---------------# # Audio & Music # #---------------# self.key = key self.chord = Chord(key) self.dissonantPitches = self.chord.pitches # Assigned when this Enemy is killed self.resolvedPitches = [] #TODO: these are example pitches; we need to add the pitches from the notes of chord... self.seq = add_sound(self.dissonantPitches, self.get_closeness) # Note Display self.ND = Note_Display(key, self.dissonantPitches, self.pos2D[0], self.pos2D[1]+s[1]) self.add(self.ND) # Callback Functions self.audio_callback = audio_callback self.add_sound = add_sound self.remove_sound = remove_sound
def on_touch_down(self, touch): with self.canvas: Color(0, 0, 1) #diameter d = 60. Ellipse(pos=(touch.x - d / 2, touch.y - d / 2), size=(d, d))
def start_cef(self): '''Starts CEF. ''' # create texture & add it to canvas self.texture = Texture.create(size=self.size, colorfmt='rgba', bufferfmt='ubyte') self.texture.flip_vertical() with self.canvas: Color(1, 1, 1) self.rect = Rectangle(size=self.size, texture=self.texture) #configure cef settings = { "debug": True, # cefpython debug messages in console and in log_file "log_severity": cefpython.LOGSEVERITY_INFO, "log_file": "debug.log", # This directories must be set on Linux "locales_dir_path": cefpython.GetModuleDirectory() + "/locales", "resources_dir_path": cefpython.GetModuleDirectory(), "browser_subprocess_path": "%s/%s" % (cefpython.GetModuleDirectory(), "subprocess") } #start idle Clock.schedule_interval(self._cef_mes, 0) #init CEF cefpython.Initialize(settings) #WindowInfo offscreen flag windowInfo = cefpython.WindowInfo() windowInfo.SetAsOffscreen(0) #Create Broswer and naviagte to empty page <= OnPaint won't get called yet browserSettings = {} # The render handler callbacks are not yet set, thus an # error report will be thrown in the console (when release # DCHECKS are enabled), however don't worry, it is harmless. # This is happening because calling GetViewRect will return # false. That's why it is initially navigating to "about:blank". # Later, a real url will be loaded using the LoadUrl() method # and the GetViewRect will be called again. This time the render # handler callbacks will be available, it will work fine from # this point. # -- # Do not use "about:blank" as navigateUrl - this will cause # the GoBack() and GoForward() methods to not work. self.browser = cefpython.CreateBrowserSync(windowInfo, browserSettings, navigateUrl=self.start_url) #set focus self.browser.SendFocusEvent(True) self._client_handler = ClientHandler(self) self.browser.SetClientHandler(self._client_handler) self.set_js_bindings() #Call WasResized() => force cef to call GetViewRect() and OnPaint afterwards self.browser.WasResized() # The browserWidget instance is required in OnLoadingStateChange(). self.browser.SetUserData("browserWidget", self) if self.keyboard_mode == "global": self.request_keyboard()
def set_bgGreen(self): with self.canvas.before: Color(0, 1, 0, 0.50) self.rect = Rectangle(pos=self.pos, size=self.size) self.bind(pos=self.update_rect, size=self.update_rect)
import kivy from kivy.app import App from kivy.core.window import Window from kivy.uix.floatlayout import FloatLayout from kivy.uix.widget import Widget from kivy.uix.button import Button from kivy.graphics import Color, Rectangle from kivy.vector import Vector from kivy.clock import Clock FPS = 30 SPEED = 20 BOX_SIZE = (50, 50) BOX_COLOR = Color(0.4, 0.7, 0.4) class MainApp(App): v_x = 0.0 v_y = 0.0 def left(self, instance): self.v_x = -0.5 def right(self, instance): self.v_x = 0.5 def up(self, instance): self.v_y = 0.5 def down(self, instance):
def render(self, canvas, dt): with canvas: Color(0.2, 0.5, 0.7, 1.0) Ellipse(pos=(self.x, self.y), size=(self.radius * 2.0, self.radius * 2.0))
def PlaceStuff(self): with self.canvas.before: Color(0.1, .3, 0.1, 1) # green; colors range from 0-1 not 0-255 self.rect = Rectangle(size=self.size, pos=self.pos) with self.canvas.after: self.sudokuLayout = SudokuLayout()
def __init__(self, **kwargs): # make sure we aren't overriding any important functionality super().__init__(**kwargs) self.home_button1 = Button(text="Home", pos_hint={'center_x': 0.5, 'center_y': 0.95}, size_hint_y=None, height=144) self.home_button2 = Button(text="Home", pos_hint={'center_x': 0.5, 'center_y': 0.95}, size_hint_y=None, height=144) self.home_button1.bind(on_press=self.return_home) self.home_button2.bind(on_press=self.return_home) self.screen1 = Screen(name="1") self.search_screen = Screen(name="search") self.list_screen = Screen(name="list") # Add widgets---------------------------------------------------------- with self.screen1.canvas.before: Color(0, 0, 0, 1) self.screen1.rect = Rectangle(size=self.screen1.size, pos=self.screen1.pos) def update_rect(instance, value): instance.rect.pos = instance.pos instance.rect.size = instance.size # listen to size and position changes self.screen1.bind(pos=update_rect, size=update_rect) # Add image ---------------------------------------------------- self.screen1.add_widget(Image(source='Phrijj.png', size_hint=(1, 1), pos_hint={'center_x': 0.5, 'center_y': 0.6}), index=1) # -------------------------------------------------------------- # Add textinput ------------------------------------------------ self.textinput = TextInput(hint_text="Search for ingredients", multiline=False, size_hint_y=None, height=144, pos_hint={'center_x': 0.5, 'center_y': 0.95}, opacity=1) # Add dropdown menu -------------------------------------------- self.dropdown = DropDown() self.dropdown.add_widget(self.textinput) # Add buttons to dropdown menu search_button = Button(color=(0, 0, 0, 1), background_color=(255, 255, 255, 255), text="Search", size_hint_y=None, height=144) self.search_response_list = [] search_button.bind(on_press=lambda widget: self.send_search(self.textinput.text, self.search_response_list, self.home_button1)) self.dropdown.add_widget(search_button) show_button = Button(color=(0, 0, 0, 1), background_color=(255, 255, 255, 255), text="Show", size_hint_y=None, height=144) show_button.bind(on_press=lambda x: self.switch_screen(self.home_button2)) self.dropdown.add_widget(show_button) # -------------------------------------------------------------- # Add enter button --------------------------------------------- self.enter_button = Button(color=(0, 0, 0, 1), background_color=(255, 255, 255, 255), text="Start!", size_hint=(1, .2), pos_hint={'center_x': 0.5, 'center_y': 0.07}) self.enter_button.bind(on_release=self.dropdown.open) self.screen1.add_widget(self.enter_button, index=0) self.add_widget(self.screen1) self.add_widget(self.list_screen) self.add_widget(self.search_screen)
def on_size(self, *args): self.canvas.before.clear() with self.canvas.before: Color(1, 1, 1, 1) Rectangle(pos=self.pos, size=self.size)
def redraw_widget(self, *args): """ Method of redraw this widget """ with self.canvas.before: self.canvas.before.clear() Color(*get_color_from_hex(self.background_color)) Rectangle(pos=(self.x, self.y + 1), size=self.size)
def drawLine(self, gCodeLine, command): ''' drawLine draws a line using the previous command as the start point and the xy coordinates from the current command as the end point. The line is styled based on the command to allow visually differentiating between normal and rapid moves. If the z-axis depth is changed a circle is placed at the location of the depth change to alert the user. ''' try: xTarget = self.xPosition yTarget = self.yPosition zTarget = self.zPosition x = re.search("X(?=.)(([ ]*)?[+-]?([0-9]*)(\.([0-9]+))?)", gCodeLine) if x: xTarget = float(x.groups()[0]) * self.canvasScaleFactor if self.absoluteFlag == 1: xTarget = self.xPosition + xTarget y = re.search("Y(?=.)(([ ]*)?[+-]?([0-9]*)(\.([0-9]+))?)", gCodeLine) if y: yTarget = float(y.groups()[0]) * self.canvasScaleFactor if self.absoluteFlag == 1: yTarget = self.yPosition + yTarget z = re.search("Z(?=.)(([ ]*)?[+-]?([0-9]*)(\.([0-9]+))?)", gCodeLine) if z: zTarget = float(z.groups()[0]) * self.canvasScaleFactor #Draw lines for G1 and G0 with self.scatterObject.canvas: Color(self.data.drawingColor[0], self.data.drawingColor[1], self.data.drawingColor[2]) if command == 'G00': #draw a dashed line Line(points=(self.xPosition, self.yPosition, xTarget, yTarget), width=1, group='gcode', dash_length=4, dash_offset=2) #start a new straight line from the end of the dashed line self.line = Line(points=(), width=1, group='gcode') self.addPoint(xTarget, yTarget) else: self.addPoint(xTarget, yTarget) #If the zposition has changed, add indicators tol = 0.05 #Acceptable error in mm if abs(zTarget - self.zPosition) >= tol: with self.scatterObject.canvas: if zTarget - self.zPosition > 0: Color(0, 1, 0) radius = 1 else: Color(1, 0, 0) radius = 2 Line(circle=(self.xPosition, self.yPosition, radius), group='gcode') Color(self.data.drawingColor[0], self.data.drawingColor[1], self.data.drawingColor[2]) self.xPosition = xTarget self.yPosition = yTarget self.zPosition = zTarget except: print "Unable to draw line on screen: " + gCodeLine
def ejesEspaciales(self, *args): with self.wid.canvas: # Color(225, 255, 255, .1, mode='rgba') Color(0, 0, 0) Line(points=[200, 40, 600, 40], width=1) Line(points=[240, 0, 240, 285], width=1)
def actualise_camera(self, dt): self.painter.canvas.after.clear() self.painter.canvas.before.clear() (depth, _) = get_depth() # Get the depth from the kinect depth = depth.astype(np.float32) # Convert the depth to a 32 bit float _, depthThresh = cv2.threshold(depth, self.distance_hand_is_close, 255, cv2.THRESH_BINARY_INV) # Threshold the depth for a binary image. Thresholded at 600 arbitary units _, back = cv2.threshold(depth, self.distance_background, 255, cv2.THRESH_BINARY_INV) # Threshold the background in order to have an outlined background and segmented foreground _,wayBack = cv2.threshold(depth, 2000, 255, cv2.THRESH_BINARY_INV) blobData = BlobAnalysis(depthThresh) # Creates blobData object using BlobAnalysis class blobDataBack = BlobAnalysis(back) # Creates blobDataBack object using BlobAnalysis class blobDataWayBack = BlobAnalysis(wayBack) if(blobDataWayBack.counter != 0 and blobDataBack.counter==0): if(self.time==0): self.parent.check_users() self.time=100 else: self.time-=1 else: self.time=0 if(blobDataBack.counter==0):#not interractive self.parent.hide_overlay() for i in range(blobData.counter): # Iterate from 0 to the number of blobs minus 1 self.centroidList.append(blobData.centroid[i]) # Adds the centroid tuple to the centroidList --> used for drawing else: self.parent.show_overlay() # draw contours with self.painter.canvas.before: PushMatrix() Rotate(angle=180, axis=(0, 0, 1), origin=self.painter.center) Translate(self.painter.width / 2 - 320, self.painter.height / 2 - 240) for i in range(blobData.counter): # Iterate from 0 to the number of blobs minus 1 self.centroidList.append( blobData.centroid[i]) # Adds the centroid tuple to the centroidList --> used for drawing Color(self.RED[0], self.RED[1], self.RED[2], mode='rgb') Line(circle=(blobData.centroid[i][0], blobData.centroid[i][1], 20)) with self.painter.canvas.after: PopMatrix() del depth # Deletes depth --> opencv memory issue # Mouse Try statement try: centroidX = blobData.centroid[0][0] centroidY = blobData.centroid[0][1] if self.dummy: mousePtr = display.Display().screen().root.query_pointer()._data # Gets current mouse attributes dX = centroidX - self.strX # Finds the change in X dY = self.strY - centroidY # Finds the change in Y if abs(dX) > 1: # If there was a change in X greater than 1... mouseX = mousePtr["root_x"] - self.sensitivity_x * dX # New X coordinate of mouse if abs(dY) > 1: # If there was a change in Y greater than 1... mouseY = mousePtr["root_y"] - self.sensitivity_y * dY # New Y coordinate of mouse self.move_mouse(mouseX, mouseY) # Moves mouse to new location self.strX = centroidX # Makes the new starting X of mouse to current X of newest centroid self.strY = centroidY # Makes the new starting Y of mouse to current Y of newest centroid else: self.strX = centroidX # Initializes the starting X self.strY = centroidY # Initializes the starting Y self.dummy = True # Lets the function continue to the first part of the if statement except: # There may be no centroids and therefore blobData.centroid[0] will be out of range self.dummy = False # Waits for a new starting point
def draw(self, dt): self.loops += 1 # Check thread signals self.checkSignals() # Game mode if(self.state != "editor"): # self.simulation.update() self.window.statebar.ids["steps"].text = "Steps: "+str(self.simulation.space.steps) # Car control for shape in self.simulation.space.shapes: if(isinstance(shape, Car) and not isinstance(shape, CarAI)): if(self.keys["up"] == 1): shape.forward(dt*100) if(self.keys["down"] == 1): shape.backward(dt*100) if(self.keys["left"] == 1): shape.left(dt*100) if(self.keys["right"] == 1): shape.right(dt*100) # Editor mode elif(self.state == "editor"): # Undo action if(self.keys["lctrl"] == 1 and self.keys["z"] == 1 and not self.undoDone): # Do undo //Delete and create only if(self.changes.__len__() != 0): change = self.changes[self.changes.__len__()-1] match = None for shape in self.simulation.space.shapes: if(shape == change): self.simulation.deleteObject(shape, "nochange") self.changes.remove(shape) match = "found" if(match == None): self.simulation.space.add(change) self.canvas.add(Color(rgba=change.rgba)) self.canvas.add(change.ky) self.simulation.repaintObjects() self.changes.remove(change) self.undoDone = True # Reset undo action if(self.keys["z"] == 0 and self.undoDone): self.undoDone = False # Adding tool indication + rectangle adding grap rep if(self.editorTool == "add"): pos = self.to_local(*Window.mouse_pos) # Mouse indication shape if(self.addingIndication == None): with self.canvas: Color(0,0.8,0,0.6) self.addingIndication = Ellipse(pos=(pos[0]-5, pos[1]-5), size=(10,10)) else: self.addingIndication.pos = (pos[0]-5, pos[1]-5) # When adding rectangle show its graphical representation if(self.addingStage == 1): c = pos a = (self.temp_rect.points[0], self.temp_rect.points[1]) b = (self.temp_rect.points[2], self.temp_rect.points[3]) a, b, c, d = calculateRectangle(a,b,c) if(self.temp_barrier == None): if(a != None): with self.canvas: Color(0.8,0,0,0.6) self.temp_barrier = Quad(points=(a[0], a[1], b[0], b[1], d[0], d[1], c[0], c[1])) else: if(a != None): self.temp_barrier.points = (a[0], a[1], b[0], b[1], d[0], d[1], c[0], c[1]) # Deleting mouse indication elif(self.editorTool == "delete"): pos = self.to_local(*Window.mouse_pos) pos = (pos[0]-5, pos[1]-5) if(self.addingIndication == None): with self.canvas: Color(0.8,0,0,0.6) self.addingIndication = Ellipse(pos=pos, size=(10,10)) else: self.addingIndication.pos = pos else: if(self.addingIndication != None): self.canvas.remove(self.addingIndication) self.addingIndication = None # Barrier adding width change if(self.temp_barrier != None and isinstance(self.temp_barrier, Line)): if(self.keys["up"] == 1): if(self.temp_barrier.width/self.scaller < 100): self.temp_barrier.width += 1 elif(self.keys["down"] == 1): if(self.temp_barrier.width/self.scaller > 1 and self.temp_barrier.width > 1): self.temp_barrier.width -= 1 # Highligting else: pos = self.to_local(*Window.mouse_pos) pos = (pos[0]/self.scaller, pos[1]/self.scaller) for shape in reversed(self.simulation.space.shapes): # Highlight object when no moving if(not self.movingObject): # Highlight hover objects if(shape.point_query(pos)[0] < 0): if(self.tempHighlight != None): self.canvas.remove(self.tempHighlight) self.tempHighlight = None self.tempHighlight = self.highlightObject(shape) break # Cleanup highlight elif(self.tempHighlight != None): self.canvas.remove(self.tempHighlight) self.tempHighlight = None # Cleanup highlight elif(self.tempHighlight != None): self.canvas.remove(self.tempHighlight) self.tempHighlight = None # If we want to draw if(self.isDrawing): # Draw all kivy objects from space.shapes self.paintKivy() # Update camere if neccesary self.updateCamera()
def anim(self,dt): self.anm = Animation(deg1=-365.0,d = 4., t='in_quad') self.canvas.add(Color(0,1.,0)) self.anm.start(self) self.anm.bind(on_complete=self.update)
def set_color(self, new_color): self.last_color = new_color self.canvas.add(Color(*new_color))
def create_drawings(self): self._color = Color(*self.color) self._mesh = Mesh(mode='line_strip') self.bind( color=lambda instr, value: setattr(self._color, "rgba", value)) return [self._color, self._mesh]