def build(self): root = Widget() root.bind(on_touch_move=self.generate_one) aabb = b2AABB() aabb.lowerBound = b2Vec2(0, 0) aabb.upperBound = b2Vec2(10000, 10000) self.world = world = b2World(aabb, b2Vec2(0, -100), True) # plane for the ground, all other the window. # Define the ground body. groundBodyDef = b2BodyDef() groundBodyDef.position = [0, 0] # Call the body factory which allocates memory for the ground body # from a pool and creates the ground box shape (also from a pool). # The body is also added to the world. groundBody = world.CreateBody(groundBodyDef) # Define the ground box shape. groundShapeDef = b2PolygonDef() # The extents are the half-widths of the box. groundShapeDef.SetAsBox(10000, 1) # Add the ground shape to the ground body. groundBody.CreateShape(groundShapeDef) # generate circles self.circles = [] for x in xrange(5): c = Circle(y=500 + x * 5, x=500 + x, world=world) self.circles.append(c) root.add_widget(c) Clock.schedule_interval(self._update_world, 1 / 60.) return root
def build(self): root = Widget() root.bind(on_touch_move=self.generate_one) aabb = b2AABB() aabb.lowerBound = b2Vec2(0, 0) aabb.upperBound = b2Vec2(10000, 10000) self.world = world = b2World( aabb, b2Vec2(0, -100), True) # plane for the ground, all other the window. # Define the ground body. groundBodyDef = b2BodyDef() groundBodyDef.position = [0, 0] # Call the body factory which allocates memory for the ground body # from a pool and creates the ground box shape (also from a pool). # The body is also added to the world. groundBody = world.CreateBody(groundBodyDef) # Define the ground box shape. groundShapeDef = b2PolygonDef() # The extents are the half-widths of the box. groundShapeDef.SetAsBox(10000, 1) # Add the ground shape to the ground body. groundBody.CreateShape(groundShapeDef) # generate circles self.circles = [] for x in xrange(5): c = Circle(y=500 + x * 5, x=500+x, world=world) self.circles.append(c) root.add_widget(c) Clock.schedule_interval(self._update_world, 1 / 60.) return root
def build(self): root_widget = BoxLayout(orientation='vertical') drawing_widget = DrawingWidget() red_slider = Slider(min=0, max=1, value=0.5, size_hint_y=None, height=80) green_slider = Slider(min=0, max=1, value=0.5, size_hint_y=None, height=80) blue_slider = Slider(min=0, max=1, value=0.5, size_hint_y=None, height=80) colour_row = BoxLayout(orientation='horizontal', size_hint_y=None, height=80) colour_label = Label(text='output colour:') colour_widget = Widget() # We draw a Rectangle on colour_widget exactly the same way as # with DrawingWidget, just without making a new class with colour_widget.canvas: output_colour = Color(red_slider.value, green_slider.value, blue_slider.value) output_rectangle = Rectangle() def update_colour_widget_rect(instance, value): output_rectangle.pos = colour_widget.pos output_rectangle.size = colour_widget.size colour_widget.bind(pos=update_colour_widget_rect, size=update_colour_widget_rect) def update_colour_widget_colour(instance, value): output_colour.rgb = (red_slider.value, green_slider.value, blue_slider.value) red_slider.bind(value=update_colour_widget_colour) green_slider.bind(value=update_colour_widget_colour) blue_slider.bind(value=update_colour_widget_colour) root_widget.add_widget(drawing_widget) root_widget.add_widget(red_slider) root_widget.add_widget(green_slider) root_widget.add_widget(blue_slider) root_widget.add_widget(colour_row) colour_row.add_widget(colour_label) colour_row.add_widget(colour_widget) return root_widget
def box(self, r, g, b): from kivy.uix.widget import Widget from kivy.graphics import Color, Rectangle wid = Widget() with wid.canvas: Color(r, g, b) r = Rectangle(pos=wid.pos, size=wid.size) def linksp(instance, *largs): r.pos = instance.pos r.size = instance.size wid.bind(pos=linksp, size=linksp) return wid
class DfaScreen(App): def build(self): root = BoxLayout(orientation='vertical') self.__canvas = Widget() # with self.__canvas.canvas: # self.__canvas.canvas.add(Rectangle(size=(50, 50))) # #self.__canvas.bg_rect = Rectangle( source="cover.jpg", pos=self.pos, size=self.size) # self.__canvas.bind() root.add_widget(self.__canvas) self.__canvas_nav_bar = NavBar(self.__canvas) self.__canvas.bind(on_touch_down=self.onPressed) root.add_widget(self.__canvas_nav_bar.layout) return root def redraw(self, args): self.bg_rect.size = self.size self.bg_rect.pos = self.pos def onPressed(self, a, event): current_mode = self.get_current_mode() print(current_mode) if current_mode == "ADD_STATE": self.draw_state(event) elif current_mode == "MOVE_STATE": print("move state") elif current_mode == "ADD_TRANSITION_ARROW": print("add transition state") elif current_mode == "DELETE_STATE": print("delete state") elif current_mode == "EDIT_STATE": print("edit state") def draw_state(self, event): coordinates = event.pos x = coordinates[0] y = coordinates[1] canvas = self.get_canvas() Color(1, 1, 0) canvas.add(Color(1., 1., 0)) canvas.add(Ellipse(pos=(x - 50, y - 50), size=(100, 100))) def get_canvas(self): return self.__canvas.canvas def get_current_mode(self): current_mode = self.__canvas_nav_bar.get_current_mode() return current_mode
class ScratchApp(App): def __init__(self): super().__init__() self.widget = Widget(size=config.window.size) self.widget.bind(on_touch_up=lambda w, t: print('touch:', t)) with self.widget.canvas: Color(1, 1, 1) Rectangle(pos=(0, 0), size=config.window.size) # Translate(*config.window.origin) def build(self): self.icon = 'favicon.ico' self.title = config.window.title return self.widget
def create_spacer(cls, **kwargs): from kivy.utils import rgba from kivy.graphics import Color, Rectangle spacer = Widget(size_hint_min=('50dp', '50dp')) with spacer.canvas: color = kwargs.get('color', None) if color is None: color_inst = Color(.2, .2, .2, .7) else: color_inst = Color(*rgba(color)) rect_inst = Rectangle(size=spacer.size) spacer.bind( pos=lambda __, value: setattr(rect_inst, 'pos', value), size=lambda __, value: setattr(rect_inst, 'size', value), ) return spacer
def build(self): canvas = Widget() canvas.bind(on_touch_down=self.touchdown) self.world = world = b2World((0, -10), True) edges = self.world.CreateStaticBody(shapes=b2EdgeShape( vertices=[(-4000, 0), (0, 4000)])) edges.position.Set(0, 0) self.ball = ball = PongBall(y=200, x=200, world=world) canvas.add_widget(ball) self.serve_ball() Clock.schedule_interval(self.update, 1 / 60) return canvas
def build(self): canvas = Widget() canvas.bind(on_touch_down=self.touchdown) self.world = world = b2World((0,-10), True) edges = self.world.CreateStaticBody( shapes=b2EdgeShape(vertices=[(-4000,0),(0,4000)]) ) edges.position.Set(0,0) self.ball = ball = PongBall(y=200,x=200,world=world) canvas.add_widget(ball) self.serve_ball() Clock.schedule_interval(self.update, 1/60) return canvas
def build(self): canvas = Widget() canvas.bind(on_touch_down=self.generate) self.world = world = b2World((0, -100), True) groundShape = b2EdgeShape(vertices=[(-4000, 0), (4000, 0)]) ground = self.world.CreateStaticBody(shapes=groundShape, linearDamping=0) self.circles = [] for x in range(0, 1): c = Circle(y=500 + x * 5, x=500 + x, world=world) self.circles.append(c) canvas.add_widget(c) Clock.schedule_interval(self._update_world, 1 / 60.) return canvas
def build(self): canvas = Widget() canvas.bind(on_touch_down=self.generate) self.world = world = b2World((0,-100), True) groundShape = b2EdgeShape(vertices=[(-4000,0),(4000,0)]) ground = self.world.CreateStaticBody( shapes=groundShape, linearDamping = 0 ) self.circles = [] for x in range(0,1): c = Circle(y=500 + x*5, x=500+x, world=world) self.circles.append(c) canvas.add_widget(c) Clock.schedule_interval(self._update_world,1/60.) return canvas
def build(self): root = Widget() root.bind(on_touch_move=self.generate_one) self.world = world = b2d.b2World(gravity=(0, -100)) # plane for the ground, all other the window. # The ground ground = self.world.CreateBody( shapes=b2d.b2EdgeShape(vertices=[(0, 0), (1000, 0)]) ) # generate circles self.circles = [] for x in xrange(5): c = Circle(y=500 + x * 5, x=500+x, world=world) self.circles.append(c) root.add_widget(c) Clock.schedule_interval(self._update_world, 1 / 60.) return root
def __init__(self, **kwargs): super(RootWidget, self).__init__(**kwargs) grid = GridLayout(cols=2, row_force_default=True, row_default_height=50) leftClick = Button(text='Left Click', size_hint=(.5, .25)) leftClick.bind(on_press=self.leftClick) grid.add_widget(leftClick) rightClick = Button(text='Right Click', size_hint=(.5, .25), pos_hint={'right': .5}) rightClick.bind(on_press=self.rightClick) grid.add_widget(rightClick) trackPad = Widget() trackPad.bind(on_touch_move=self.on_touch_move) self.add_widget(trackPad) self.add_widget(grid)
def build(self): root = Widget() root.bind(on_touch_move=self.generate_one) ### Physics stuff self.world = pm.Space() self.world.gravity = (0.0, -100.0) ### walls static_lines = [pm.Segment(self.world.static_body, (0.0, 200.0), (1000.0,200.0), 5)] for line in static_lines: line.elasticity = 0.95 self.world.add(static_lines) # generate circles self.circles = [] for x in xrange(5): c = Circle(y=500 + x * 5, x=500+x, world=self.world) self.circles.append(c) root.add_widget(c) Clock.schedule_interval(self._update_world, 1 / 60.) return root
class ExerciseRunningStatisticsWidget(GridLayout): def __init__(self, exercise_sets_reps_weights_name, journal, **kwargs): super(ExerciseRunningStatisticsWidget, self).__init__(**kwargs) self.cols = 1 self.spacing = 1 self.exercise_name = exercise_sets_reps_weights_name excercise_label = Label(text="(ExerciseRunning, default plot type)", size_hint_y=0.1) self.add_widget(excercise_label) self.drawing_widget = Widget() self.add_widget(self.drawing_widget) self.drawing_widget.bind(size=self.update_drawing) def update_drawing(self, *args): self.drawing_widget.canvas.clear() self.drawing_widget.canvas.add(Color(1, 1, 1)) self.drawing_widget.bg_rect = Rectangle( pos=(0, 0), size=(self.drawing_widget.width, self.drawing_widget.height)) self.drawing_widget.canvas.add(self.drawing_widget.bg_rect) journal = App.get_running_app().journal drawing_instructions = \ ExerciseRunningStatisticsWidget.gen_drawing_instructions( self.exercise_name, journal, self.drawing_widget.bg_rect.size ) self.drawing_widget.canvas.add(drawing_instructions) @classmethod def gen_drawing_instructions(cls, ex_name, journal, rect_size): plot = InstructionGroup() # test plot.add(Color(1, 1, 0)) plot.add(Rectangle(pos=(0, 0), size=(100, 100))) # axes_offsets, axes_sizes, axes_instr = \ cls.axes_instructions( rect_size ) plot.add(axes_instr) dates_exces = cls.get_dates_exercises_pairs(ex_name, journal) ticks_instr = cls.ticks_instructions(axes_offsets, axes_sizes, dates_exces) plot.add(ticks_instr) plot.add(cls.plot_dists_times(dates_exces, axes_offsets, axes_sizes)) return plot @classmethod def axes_instructions(cls, rect_size): axes = InstructionGroup() offset_x = 0.05 * rect_size[0] offset_y = 0.1 * rect_size[1] line_width = 2 axes.add(Color(0, 0, 0)) axes.add( Line( points=[offset_x, offset_y, offset_x, rect_size[1] - offset_y], width=line_width)) axes.add( Line( points=[offset_x, offset_y, rect_size[0] - offset_x, offset_y], width=line_width)) return ((offset_x, offset_y), (rect_size[0] - 2 * offset_x, rect_size[1] - 2 * offset_y), axes) @classmethod def ticks_instructions(cls, axes_offsets, axes_sizes, dates_exces): x_ticks = InstructionGroup() ticks_len = 5 if len(dates_exces) != 0: x_ticks_distance = axes_sizes[0] / len(dates_exces) else: x_ticks_distance = 0 yyyy_mm_dd = [x.split(' ')[0] for (x, y) in dates_exces] for i, d in enumerate(yyyy_mm_dd): x_ticks.add( Line(points=[ axes_offsets[0] + (i + 1) * x_ticks_distance, axes_offsets[1], axes_offsets[0] + (i + 1) * x_ticks_distance, axes_offsets[1] - ticks_len ], width=3)) text_label = CoreLabel(text=d, font_size=15) text_label.refresh() texture = text_label.texture texture_size = list(texture.size) x_ticks.add( Rectangle(texture=texture, size=texture_size, pos=(axes_offsets[0] + (i + 1) * x_ticks_distance - 45, axes_offsets[1] - ticks_len - 25))) return x_ticks @classmethod def get_dates_exercises_pairs(cls, ex_name, journal): dates_exces = [] # move to Journal class? for tr in journal.trainings: for ex in tr.exercises: if ex_name == ex.description.get('name'): dates_exces.append((tr.description.get("start_time"), ex)) return dates_exces @classmethod def plot_dists_times(cls, dates_exces, axes_offset, axes_size): dists_times_instr = InstructionGroup() if len(dates_exces) != 0: distance_between_centers = axes_size[0] / len(dates_exces) else: distance_between_centers = 0 max_total = 0 for d, ex in dates_exces: # move to sep function ex_total = 0 dists = ex.description.get("distances") for dist in dists: try: ex_total = ex_total + float(dist) except ValueError: ex_total = ex_total + 0 if ex_total > max_total: max_total = ex_total if max_total != 0: y_distance = axes_size[1] / (max_total + 1) else: y_distance = 0 for i, (d, ex) in enumerate(dates_exces): distances = ex.description.get("distances") times = ex.description.get("times") float_dists = [] for dist in distances: try: float_dists.append(float(dist)) except ValueError: float_dists.append(0) for f_d, d in enumerate(float_dists): y_pos_top = axes_offset[1] + \ sum( float_dists[0:f_d+1] ) * y_distance y_pos_bottom = axes_offset[1] + \ sum( float_dists[0:f_d] ) * y_distance x_center_pos = \ axes_offset[0] + distance_between_centers * (i + 1) x_size = 10 y_size = y_pos_top - y_pos_bottom dists_times_instr.add( Line(points=[ x_center_pos - 5, y_pos_top, x_center_pos + 5, y_pos_top ], width=3)) text_label = CoreLabel(text=str(d), font_size=15) text_label.refresh() texture = text_label.texture texture_size = list(texture.size) dists_times_instr.add( Rectangle(texture=texture, size=texture_size, pos=(x_center_pos - 10, y_pos_bottom + (y_pos_top - y_pos_bottom) / 2))) return dists_times_instr
def build(self): root_widget = BoxLayout(orientation='vertical') drawing_widget = DrawingWidget() red_slider = Slider(min=0, max=1, value=0.5, size_hint_y=None, height=50) green_slider = Slider(min=0, max=1, value=0.5, size_hint_y=None, height=50) blue_slider = Slider(min=0, max=1, value=0.5, size_hint_y=None, height=50) color_row = BoxLayout(orientation='horizontal', size_hint_y=None, height=50) color_label = Label(text='output color:') color_widget = Widget() # Draw a rectangle on the color_widget and update the size with color_widget.canvas: output_color = Color(red_slider.value, green_slider.value, blue_slider.value) output_rectangle = Rectangle() color_widget.bind(pos=partial(update_rectangle, target=output_rectangle), size=partial(update_rectangle, target=output_rectangle)) # Update the value on output_color whenever the color slider values # changes. red_slider.bind(value=partial(update_color, target=output_color, sr=red_slider, sg=green_slider, sb=blue_slider)) green_slider.bind(value=partial(update_color, target=output_color, sr=red_slider, sg=green_slider, sb=blue_slider)) blue_slider.bind(value=partial(update_color, target=output_color, sr=red_slider, sg=green_slider, sb=blue_slider)) # Put everything together root_widget.add_widget(drawing_widget) root_widget.add_widget(red_slider) root_widget.add_widget(green_slider) root_widget.add_widget(blue_slider) root_widget.add_widget(color_row) color_row.add_widget(color_label) color_row.add_widget(color_widget) return root_widget
def FractionEq(self): def goBack(self): Fl.clear_widgets() GameSelector(self) # all these update_x are for window resizing def update_rect(*args): width = Fl.size[0] / 5 * 3 height = Fl.size[1] / 5 * 3 rec.pos = ((Fl.width / 5), (Fl.height * (3 / 11))) rec.size = (width, height) def update_line(*args): width = Fl.size[0] / 5 * 3 height = Fl.size[1] / 5 * 3 for x in range(1, denominator): line.points = [((width / denominator) * x) + Fl.size[0] / 5, (Fl.height * (13 / 15)), ((width / denominator) * x) + Fl.size[0] / 5, (Fl.height * (5 / 18))] line.dash_length = 60 line.dash_offset = 60 def update_numerator(*args): width = ((Fl.size[0] / 5 * 3) / denominator) * numerator height = Fl.size[1] / 5 * 3 line.dash_length = 60 line.dash_offset = 60 rec2.pos = ((Fl.width / 5), (Fl.height * (3 / 11))) rec2.size = (width, height) def update_sliderNum(*args): width = Fl.size[0] / 5 * 3 height = Fl.size[1] / 5 * 3 for x in range(1, slider.value): line2.points = [((width / slider.value) * x) + Fl.size[0] / 5, (Fl.height * (13 / 15)), ((width / slider.value) * x) + Fl.size[0] / 5, (Fl.height * (5 / 18))] # draws lines on canvas def sliderLines(): with wid3.canvas: wid3.canvas.clear() Color(.1, .1, .1) for x in range(1, slider.value): line2 = Line(points=[ (((width / slider.value) * x) + Fl.size[0] / 5), (Fl.height * (13 / 15)), (((width / slider.value) * x) + Fl.size[0] / 5), (Fl.height * (5 / 18)) ], width=4, color=(.23, .6, .2)) Fl.add_widget(wid3) def sliderValFunc(instance, val): sliderVal.text = "%d" % val Fl.remove_widget(wid3) sliderLines() return sliderVal.text def newQuestionFunc(self): randomQuestion = Fractions.level1() questionLabel.text = randomQuestion currFraction = questionLabel.text.split("/") denominator = int(currFraction[1]) Fl.clear_widgets() FractionEq(self) # checks students response def answerChecker(self): if int(slider.value) % denominator == 0: equivNumerator = int(slider.value) / denominator equiviFrac = int(equivNumerator) * numerator newFrac = "%i/%i" % (equiviFrac, slider.value) response = "%i/%i" % (equiviFrac, int(slider.value)) checkAnswerBtn.background_normal = '' checkAnswerBtn.background_color = (.1, .7, .2, .9) rightSound.play() rightResponse = TimedRightResponse() correctResp = Label(text='%s is equal to %s' % (str(questionLabel.text), str(newFrac)), color=(0, 0, 0, 1), font_size=62, pos_hint={ "x": .4, 'y': .06 }, size_hint=(.2, .1)) Fl.add_widget(correctResp) else: wrongSound.play() checkAnswerBtn.background_normal = ('') checkAnswerBtn.background_color = (1, .3, .3, .9) checkAnswerBtn.text = ("TRY AGAIN") try: sql = "UPDATE login SET incorrect = incorrect || ' " + str( slider.value) + str("/") + str( denominator) + ",' WHERE user = '******';" cursor.execute(sql) conn.commit() print(sql) except: sql = "UPDATE login SET incorrect = incorrect || '" + str( slider.value) + str("/") + str( denominator) + "' WHERE user = "******"; " print(sql) print("Failed to add inc. ans") wrongResponse = TimedWrongResponse() class TimedRightResponse(Widget): myCount = 0 boolRun = True def __init__(self, **kwargs): Clock.schedule_interval(self.update, 1) super(TimedRightResponse, self).__init__(**kwargs) def update(self, *args): if self.boolRun == True: if self.myCount < 1: print(self.myCount) self.myCount += 1 else: checkAnswerBtn.background_color = (.4, .4, .4, 1) checkAnswerBtn.text = 'Check Answer' self.myCount = 0 self.boolRun = False class TimedWrongResponse(Widget): myCount = 0 boolRun = True def __init__(self, **kwargs): Clock.schedule_interval(self.update, 1) super(TimedWrongResponse, self).__init__(**kwargs) def update(self, *args): if self.boolRun == True: if self.myCount < 1: print(self.myCount) self.myCount += 1 else: checkAnswerBtn.background_color = (.4, .4, .4, 1) checkAnswerBtn.text = 'Check Answer' self.myCount = 0 self.boolRun = False wid = Widget() wid1 = Widget() wid2 = Widget() # --------Fix me------------------- dropdown = DropDown() dropBtn1 = Button(text='level 1', size_hint_y=None, height=44) dropBtn1.bind(on_release=lambda btn: dropdown.select(dropBtn1.text)) dropdown.add_widget(dropBtn1) dropBtn2 = Button(text='level 2', size_hint_y=None, height=44) dropBtn2.bind(on_release=lambda btn: dropdown.select(dropBtn2.text)) dropdown.add_widget(dropBtn2) dropBtn3 = Button(text='level 3', size_hint_y=None, height=44) dropBtn3.bind(on_release=lambda btn: dropdown.select(dropBtn3.text)) dropdown.add_widget(dropBtn3) mainbutton = Button(text='Level Selector', size_hint=(.1, .08), pos_hint={ "x": .85, "y": .79 }) mainbutton.bind(on_release=dropdown.open) dropdown.bind(on_select=lambda instance, x: setattr(mainbutton, 'text', x)) # -------------------------- logo = Image(source='Images/SH_box2BSHSUName_021_horizontalstack_3_29.png', allow_stretch=True, pos_hint={ "x": .01, 'y': .9 }, size_hint=(.2, .1)) backBtnImage = Image(source='Images/eback-button-6-921315_2_15.png', pos_hint={ "x": .01, 'y': .83 }, size_hint=(.04, .07), keep_ratio=True) backBtn = Button(pos_hint={ "x": .01, 'y': .83 }, size_hint=(.141, .07), background_color=(1, 1, 1, .01)) backBtn.bind(on_release=goBack) questionLabel = Label(text=Fractions.level1(), font_size=68, color=(.1, .1, .1, 1), pos_hint={ 'x': .5, 'y': .93 }, size_hint=(.001, .001)) slider = Slider(min=1, max=28, step=1, pos_hint={ 'x': .2, 'y': .15 }, size_hint=(.6, .05)) slider.bind(value=sliderValFunc) sliderVal = Label(text='1', font_size=68, color=(.1, .1, .1, 1), pos_hint={ 'x': .5, 'y': .22 }, size_hint=(.001, .001)) newQuestionBtn = Button(text='New Question', size_hint=(.1, .08), pos_hint={ 'x': .25, 'y': .05 }) newQuestionBtn.bind(on_release=newQuestionFunc) checkAnswerBtn = Button( text='Check Answer', # background_color = (1,1,1,1), size_hint=(.1, .08), pos_hint={ 'x': .65, 'y': .05 }) checkAnswerBtn.bind(on_release=answerChecker) currFraction = questionLabel.text.split("/") numerator = int(currFraction[0]) denominator = int(currFraction[1]) width = Fl.size[0] / 5 * 3 height = Fl.size[1] / 5 * 3 # draws blank canvas with wid.canvas: Color(.9, .9, .9) rec = Rectangle(size=(width, height), pos=((Fl.width / 2) - (Fl.width / 4), (Fl.height / 2) - (Fl.height / 4))) wid.bind(pos=update_rect) wid.bind(size=update_rect) # draws smallest denominator lines with wid1.canvas: Color(.1, .1, .1) for x in range(1, denominator): line = Line(points=[(((width / denominator) * x) + Fl.size[0] / 5), (Fl.height * (13 / 15)), (((width / denominator) * x) + Fl.size[0] / 5), (Fl.height * (5 / 18))], dash_length=60, dash_offset=60, width=1, color=(.23, .6, .2)) wid1.bind(pos=update_line) wid1.bind(size=update_line) # draws numerator box with wid2.canvas: Color(.3, .3, .6) rec2 = Rectangle(size=((width / denominator) * numerator, height), pos=((Fl.width / 2) - (Fl.width / 3), (Fl.height / 2) - (Fl.height / 4))) wid2.bind(pos=update_numerator) wid2.bind(size=update_numerator) # draws slider lines # make this a function!! Fl.add_widget(logo) Fl.add_widget(backBtnImage) Fl.add_widget(backBtn) Fl.add_widget(slider) Fl.add_widget(questionLabel) Fl.add_widget(sliderVal) Fl.add_widget(newQuestionBtn) Fl.add_widget(checkAnswerBtn) Fl.add_widget(wid) Fl.add_widget(wid1) Fl.add_widget(wid2) Fl.add_widget(mainbutton)
class Entry(BoxLayout): def __init__(self, theme, number, name, minutes, seconds, order, **kwargs): super(Entry, self).__init__(**kwargs) self.orientation = 'horizontal' self.size_hint = [1, None] self.size = [150, 50] self.number = number self.name = name self.minutes = minutes self.seconds = seconds self.order = order # format the minutes and seconds values to a proper string displaying the time self.time = self.time_to_string(self.minutes, self.seconds) # the number to put the items into a specific sequence self.number_label = Label(text=str(self.number), font_size='20sp', font_name='gothic', color=theme.get_secondary_accent(), size_hint=[None, None], size=[50, 50]) self.number_label.bind(size=self.number_label.setter('text_size')) self.add_widget(self.number_label) # the label with the name of the player self.name_label = Label(text=self.name, font_name='gothic', font_size='25sp', halign='left', valign='center', color=theme.get_secondary(), size_hint=[1, None], size=[250, 50]) self.name_label.bind(size=self.name_label.setter('text_size')) self.add_widget(self.name_label) # the label with the time self.time_label = Label(text=self.time, font_size='20sp', font_name='gothic', valign='center', halign='right', color=theme.get_secondary(), size_hint=[None, None], size=[80, 50]) self.time_label.bind(size=self.time_label.setter('text_size')) self.add_widget(self.time_label) # the widget that can indicate to which one of the orders it belongs self.order_widget = Widget(size_hint=[None, None], size=[50, 50]) with self.order_widget.canvas: if self.order == 'lost': self.color = Color(255, 0, 0, 1) elif self.order == 'won': self.color = Color(0, 255, 0, 1) self.order_indicator = Ellipse(pos=[ self.order_widget.pos[0] + 15, self.order_widget.pos[1] + 15 ], size=[20, 20]) self.order_widget.bind(pos=self.redraw, size=self.redraw) self.add_widget(self.order_widget) # the separator line with self.canvas: self.sep_color = theme.make_color(theme.get_secondary_accent()) self.separator = Line(points=[ self.pos[0] + 10, self.pos[1] + 10, self.pos[0] + self.width - 10, self.pos[1] + 10 ]) def __repr__(self): return f'<Entry>' def redraw(self, *args): self.order_indicator.pos = [ self.order_widget.pos[0] + 15, self.order_widget.pos[1] + 15 ] self.order_indicator.size = [20, 20] self.separator.points = [ self.pos[0] + 42, self.pos[1] + 1, self.pos[0] + self.width - 10, self.pos[1] + 1 ] def time_to_string(self, minutes, seconds): min_str = str(minutes) if len(min_str) == 1: min_str = '0' + min_str sec_str = str(seconds) if len(sec_str) == 1: sec_str = '0' + sec_str return min_str + ':' + sec_str + ' min' def apply_theme(self, theme): self.number_label.color = theme.get_secondary_accent() self.name_label.color = theme.get_secondary() self.time_label.color = theme.get_secondary() self.sep_color.rgba = theme.get_secondary_accent()
class CatanGUI(GridLayout): ################# #Build GUI class# ################# def __init__(self, **kwargs): super(CatanGUI, self).__init__(**kwargs) self.board = CatanBoard() self.mode = 'Thin' self.board.grid = self.board.ini_Grid() self.hexSize = 40 self.hexHeight = self.hexSize * 2 self.hexVert = 0.75 * self.hexHeight self.hexWidth = sqrt(3)/2 * self.hexHeight self.rows = 2 self.gridCanvas = Widget() self.gridCanvas.bind(pos=self.update_gridCanvas) self.gridCanvas.bind(size=self.update_gridCanvas) self.UI = GridLayout(cols=2, size_hint_y=0.2) self.randomiseButton = Button(text='Randomise') self.randomiseButton.bind(on_press=self.randomise_Grid) self.list_Adapter = ListAdapter(data=['Coastal', 'Thin Land Mass', 'Large Land Mass', 'Large Islands', 'Small Islands', 'Random'], cls=ListItemButton, selection_mode='single', allow_empty_selection=True) self.list_Adapter.bind(on_selection_change=self.item_Selected) self.random_Type = ListView(adapter=self.list_Adapter) self.UI.add_widget(self.random_Type) self.UI.add_widget(self.randomiseButton) self.add_widget(self.gridCanvas) self.add_widget(self.UI) self.startingX = self.gridCanvas.center_x self.startingY = self.gridCanvas.center_y + (self.gridCanvas.height * 6) def item_Selected(self, *args): try: self.mode = self.list_Adapter.selection[0].text except IndexError: pass def randomise_Grid(self, *args): self.board.grid = self.board.ini_Grid() self.board.colour_Grid(self.mode) self.update_gridCanvas() def update_gridCanvas(self, *args): self.gridCanvas.canvas.clear() xPos = self.startingX yPos = self.startingY with self.gridCanvas.canvas: for i in range(self.board.gridWidth): for j in range(self.board.gridHeight): if self.board.grid[i][j] != 'b': graphics.Color(self.board.grid[i][j].colour[0],self.board.grid[i][j].colour[1], self.board.grid[i][j].colour[2]) if j & 1: #Why 0.8655? I don't f*****g know is why. self.build_mesh(self.hexSize, xPos+(self.hexSize*0.8655), yPos) self.board.grid[i][j].x = xPos+(self.hexSize*0.8655) self.board.grid[i][j].y = yPos else: self.build_mesh(self.hexSize, xPos, yPos) self.board.grid[i][j].x = xPos self.board.grid[i][j].y = yPos yPos -= self.hexVert yPos = self.startingY xPos += self.hexWidth def build_mesh(self, size, centre_x, centre_y): vertices = [] indices = [] for i in range(6): istep = (pi * 2) / 6 * (i + 0.5) x = centre_x + size * cos(istep) y = centre_y + size * sin(istep) vertices.extend([x, y, 0, 0]) indices.append(i) return graphics.Mesh(vertices=vertices, indices=indices, mode='triangle_fan')
def build(self): s = Widget() s.bind(on_close=self.stop) OuiNonPopup(title="mokfzmofkfzemok pkm", on_oui=self.stop) return s
class KivyApp(App, Widget): def build(self): self.theme = 'd' #self.title = 'Hello world' #self.icon = f'btnpic{self.theme}t1.png' self.layout = FloatLayout() self.texture_install() # self.welcome_screen() # return self.layout def add(self, *instance): for inst in instance: self.layout.add_widget(inst) def remove(self, *instance): for inst in instance: self.layout.remove_widget(inst) ############################################################################################################## def texture_install(self): self.btnpicdt1 = fr'pictures\btnpic{self.theme}t1.png' self.btnpicdt2 = fr'pictures\btnpic{self.theme}t2.png' self.backgrounddt = fr'pictures\background{self.theme}t.png' def redraw(self, args): self.bg_rect.size = self.size self.bg_rect.pos = self.pos self.background = Widget() with self.background.canvas: self.background.bg_rect = Rectangle( source=self.backgrounddt, pos=self.pos, size=self.size) self.background.bind(pos=redraw, size=redraw) self.add(self.background) self.arch_back = False self.arch_change = False self.text_archive = Button( background_normal = self.btnpicdt2, background_down = self.btnpicdt2, size_hint = (1, .75), pos_hint = {'x': 0, 'y': 1},) self.arch_change_txt = False ############################################################################################################## def callback(self, instance, value): def firsttimer(who): self.layout.clear_widgets() self.typing_screen() #instance.text \\ value - normal/down if value == 'normal' and instance.text == 'Поиск': self.remove(self.welcome_btn, ) try: self.add(self.settings_btn) self.remove(self.set_part_1, self.set_part_2) except: pass self.animated_part_1 = Button( background_normal = self.btnpicdt2, background_down = self.btnpicdt2, size_hint = (.5, .25), pos_hint = {'x': 0, 'y': .75},) self.animated_part_2 = Button( background_normal = self.btnpicdt2, background_down = self.btnpicdt2, size_hint = (.5, .25), pos_hint = {'x': .5, 'y': .75},) self.settings_btn.text = '' self.settings_btn.background_down = self.btnpicdt2 self.settings_btn.unbind(state=self.callback) self.settings_btn1.text = '' self.settings_btn1.background_down = self.btnpicdt2 self.settings_btn1.unbind(state=self.callback) self.settings_btn2.text = '' self.settings_btn2.background_down = self.btnpicdt2 self.settings_btn2.unbind(state=self.callback) self.add(self.animated_part_1, self.animated_part_2) Clock.schedule_once(firsttimer, .55) self.animate(self.animated_part_1, self.animated_part_2, self.settings_btn, self.settings_btn1, self.settings_btn2) if value == 'normal' and instance.text == 'Архив': self.archive() if value == 'normal' and instance.text == 'Настройки': self.set_part_1 = Button( text='Тема', background_normal = self.btnpicdt2, background_down = self.btnpicdt1, size_hint = (.375, .15), pos_hint = {'x': .125, 'y': .5},) self.set_part_1.bind(state=self.callback) self.set_part_2 = Button( text='Очистка', background_normal = self.btnpicdt2, background_down = self.btnpicdt1, size_hint = (.375, .15), pos_hint = {'x': .5, 'y': .5},) self.set_part_2.bind(state=self.callback) self.remove(self.settings_btn) self.add(self.set_part_1, self.set_part_2) try: if value == 'normal' and instance == self.set_part_2 : cur.execute('''DELETE FROM archive''') con.commit() self.welcome_screen() if value == 'normal' and instance == self.set_part_1 : if self.theme == 'l': self.theme = 'd' else: self.theme = 'l' self.texture_install() self.welcome_screen() except: pass try: if instance == self.animated_part_3 and value == 'normal': if self.part_text < len(self.song_text)-1: self.part_text+=1 else: self.part_text = 0 self.text_screen() except: pass ############################################################################################################## def animate(self, *instance1): for instance in instance1: try: if instance == self.animated_part_1: animation = Animation(pos_hint = {'x': 0, 'y': .75}, size_hint = (.5, .25), duration=.5) animation &= Animation(pos_hint = {'x': 0, 'y': .5}, size_hint = (1, .25), duration=.5) if instance == self.animated_part_2: animation = Animation(pos_hint = {'x': .5, 'y': .75}, size_hint = (.5, .25), duration=.5) animation &= Animation(pos_hint = {'x': 0, 'y': .25}, size_hint = (1, .25), duration=.5) except: pass try: if instance == self.archive_layout_small: animation = Animation(pos_hint = {'x': 0, 'y': 0}, duration=.5) if instance == self.slider_archive: animation = Animation(pos_hint = {'x': 0, 'y': 0}, duration=.5) except: pass if self.arch_change == True: if instance == self.archive_layout_small: animation = Animation(pos_hint = {'x': 0, 'y': -1-0.1*len(self.spisok)}, duration=.5) if instance == self.slider_archive: animation = Animation(pos_hint = {'x': 0, 'y': -1-0.1*len(self.spisok)}, duration=.5) if instance == self.text_archive: animation = Animation(pos_hint = {'x': 0, 'y': 0}, duration=.5) if self.arch_change != True: if instance == self.text_archive: animation = Animation(pos_hint = {'x':0, 'y': -1}, duration=.5) if self.arch_change_txt == True: if instance == self.text_archive: animation = Animation(pos_hint = {'x':0, 'y': 1}, duration=.5) if self.arch_back == True: if instance == self.welcome_btn: self.welcome_btn.pos_hint= {'x': 0, 'y': 1.75} animation = Animation(pos_hint = {'x': 0, 'y': .75}, duration=.5) if instance == self.settings_btn: self.settings_btn.pos_hint = {'x': .125, 'y': 1.5} animation = Animation(pos_hint = {'x': .125, 'y': .5}, duration=.5) if instance == self.settings_btn1: self.settings_btn1.pos_hint = {'x': .125, 'y': 1.3} animation = Animation(pos_hint = {'x': .125, 'y': .3}, duration=.5) if instance == self.settings_btn2: self.settings_btn2.pos_hint = {'x': .125, 'y': 1.1} animation = Animation(pos_hint = {'x': .125, 'y': .1}, duration=.5) if instance == self.archive_layout_small: animation = Animation(pos_hint = {'x': 0, 'y': -1-0.1*len(self.spisok)}, duration=.5) if instance == self.slider_archive: animation = Animation(pos_hint = {'x': 0, 'y': -1-0.1*len(self.spisok)}, duration=.5) if self.arch_back != True: if instance == self.welcome_btn: animation = Animation(pos_hint = {'x': 0, 'y': -.25}, duration=.5) if instance == self.settings_btn: animation = Animation(pos_hint = {'x': .125, 'y': .5}, duration=.5) animation &= Animation(pos_hint = {'x': .125, 'y': -.4}, duration=.5) if instance == self.settings_btn1: animation = Animation(pos_hint = {'x': .125, 'y': .3}, duration=.5) animation &= Animation(pos_hint = {'x': .125, 'y': -.6}, duration=.5) if instance == self.settings_btn2: animation = Animation(pos_hint = {'x': .125, 'y': .1}, duration=.5) animation &= Animation(pos_hint = {'x': .125, 'y': -.8}, duration=.5) if instance == 1: animation = Animation(pos_hint = {'x': 0, 'y': .25}, size_hint = (1, .5), duration=.5) animation.start(self.animated_part_3) break try: if instance == self.animated_part_3: animation = Animation(pos_hint = {'x': 0, 'y': 0}, size_hint = (1, .75), duration=.5) except: pass try: if instance == self.settings_btn_back: animation = Animation(pos_hint = {'x': .125, 'y': .15*(-1)}, duration=.5) animation &= Animation(pos_hint = {'x': .125, 'y': .5}, duration=.5) if instance == self.settings_btn1_back: animation = Animation(pos_hint = {'x': .125, 'y': .35*(-1)}, duration=.5) animation &= Animation(pos_hint = {'x': .125, 'y': .3}, duration=.5) if instance == self.settings_btn2_back: animation = Animation(pos_hint = {'x': .125, 'y': .55*(-1)}, duration=.5) animation &= Animation(pos_hint = {'x': .125, 'y': .1}, duration=.5) if instance == self.button_input_text_1: animation = Animation(pos_hint = {'x': 0, 'y': .5}, size_hint = (1, .25), duration=.5) animation &= Animation(pos_hint = {'x': .5, 'y': .75}, size_hint = (.5, .25), duration=.5) if instance == self.button_input_text_2: animation = Animation(pos_hint = {'x': 0, 'y': .25}, size_hint = (1, .25), duration=.5) animation &= Animation(pos_hint = {'x': 0, 'y': .75}, size_hint = (.5, .25), duration=.5) except: pass animation.start(instance) ############################################################################################################## def archive(self): #self.text_archive.pos_hint = {'x':0, 'y': 1} #self.welcome_screen() def swipe_check(*args): def run2(who): def run3(who): self.arch_back = False self.welcome_screen() self.animate(self.settings_btn, self.settings_btn1, self.settings_btn2, self.welcome_btn,) Clock.schedule_once(run3, .55) if len(self.swipe_count) > 3: self.swipe_count = '' if args[1] == 1: self.swipe_count = '1' if args[1] == 2: self.swipe_count += '2' if args[1] == 3: self.swipe_count += '3' if self.swipe_count =='123' : self.arch_back = True self.animate( self.archive_layout_small, self.slider_archive ) Clock.schedule_once(run2, .55) def change_pos(*change_crd): self.plus_change = self.slider_archive.max - change_crd[1]//1 for num_block in range(len(self.block_list)-int(self.plus_change)): self.block_list[num_block].text = self.spisok[num_block+int(self.plus_change)] def text_link(button_name): self.text_archive.pos_hint = {'x':0, 'y': 1} def run2(who): self.arch_change = False self.archive_text(button_name) self.arch_change = True self.animate(self.archive_layout_small, self.slider_archive, self.text_archive) try: self.add(self.text_archive) except: pass Clock.schedule_once(run2, .55) self.spisok = cur.execute('SELECT * FROM archive;').fetchall() self.block_list = [] self.plus_change = 0 self.swipe_count = '' for num_block in range(len(self.spisok)): self.block_list.append(Button(text=f'{self.spisok[num_block][0]}\n{self.spisok[num_block][1]}', background_normal = self.btnpicdt2, background_down = self.btnpicdt1, size_hint=(1, .1), on_press=text_link)) self.archive_layout_main = BoxLayout(spacing=0, orientation='horizontal') self.archive_layout_small = StackLayout(pos_hint = {'x': 0, 'y': 1+0.1*len(self.spisok)}, size_hint=(5, 1), spacing=1) self.slider_archive = Slider( min=0, max=10, step=1, value = 11, orientation='vertical', background_vertical = self.btnpicdt2, cursor_image = self.btnpicdt1, cursor_size = (0, 0), pos_hint = {'x': 0, 'y': 1+0.1*len(self.spisok)}, background_width = 10) self.slider_swipe_archive = Slider( min=0, max=3, step=1, size_hint=(1, .092), cursor_size = (0, 0), background_width = 0) self.slider_swipe_archive.bind(value=swipe_check) if len(self.spisok) >= 10: self.slider_archive.cursor_size = (15, 20) self.slider_archive.max = len(self.spisok) - 9 self.slider_archive.value = len(self.spisok) - 9 self.slider_archive.bind(value=change_pos) def run1(who): #self.archive_layout_small.pos_hint = {} self.animate(self.archive_layout_small, self.slider_archive) #self.add(self.background) # self.add(self.archive_layout_main,) # try: self.archive_layout_main.add_widget(self.archive_layout_small) self.archive_layout_main.add_widget(self.slider_archive) except: pass # self.archive_layout_small.add_widget(self.slider_swipe_archive) for num_block in range(len(self.block_list)): self.archive_layout_small.add_widget(self.block_list[num_block]) self.animate(self.settings_btn, self.settings_btn1, self.settings_btn2, self.welcome_btn, ) self.settings_btn.text = '' self.settings_btn1.text = '' self.settings_btn2.text = '' self.welcome_btn.text = '' Clock.schedule_once(run1, .55) ############################################################################################################## def welcome_screen(self): self.layout.clear_widgets() self.welcome_btn = Button( #color = [.01, .46, .56, 1], text='Поиск', background_normal = self.btnpicdt2, background_down = self.btnpicdt1, size_hint = (1, .25), pos_hint = {'x': 0, 'y': .75},) self.welcome_btn.bind(state=self.callback) self.settings_btn = Button( text='Настройки', background_normal = self.btnpicdt2, background_down = self.btnpicdt1, size_hint = (.75, .15), pos_hint = {'x': .125, 'y': .5},) self.settings_btn.bind(state=self.callback) self.settings_btn1 = Button( text='Архив', background_normal = self.btnpicdt2, background_down = self.btnpicdt1, size_hint = (.75, .15), pos_hint = {'x': .125, 'y': .3},) self.settings_btn1.bind(state=self.callback) self.settings_btn2 = Button( text='', background_normal = self.btnpicdt2, background_down = self.btnpicdt1, size_hint = (.75, .15), pos_hint = {'x': .125, 'y': .1},) self.settings_btn2.bind(state=self.callback) self.add(self.background, self.settings_btn2, self.settings_btn1, self.settings_btn, self.welcome_btn) try: self.remove(self.animated_part_3) except: pass ############################################################################################################## def typing_screen(self): try: self.remove(self.animated_part_3) except: pass self.text1 = '' self.text2 = '' self.type_process = False self.big_letter = False def typing_process_control(instance, value): if instance == self.button_input_text_1: self.type_process = 1 elif instance == self.button_input_text_2: self.type_process = 2 self._keyboard = Window.request_keyboard(close_keyboard, self, 'text') if self._keyboard.widget: pass self._keyboard.bind(on_key_down=_on_keyboard_down) def _on_keyboard_down(keyboard, keycode, text, modifiers): if self.type_process == 1: if keycode[1] == 'backspace': self.text1 = self.text1[:-1] elif keycode[1] == 'enter': self.type_process = False self.finding_song() keyboard.release() elif keycode[1] == 'spacebar': self.text1+=' ' elif keycode[1] == 'shift': self.big_letter = True else: try: letter_check = 0 while letter_check <= len(allowed_letters): if f'{keycode[1]}' == allowed_letters[letter_check]: if self.big_letter == False: self.text1+=f'{keycode[1]}' else: self.text1+=f'{big_letter_list[letter_check]}' self.big_letter = False break letter_check+=1 except: pass self.button_input_text_1.text=f'{self.text1}' elif self.type_process == 2: if keycode[1] == 'backspace': self.text2 = self.text2[:-1] elif keycode[1] == 'enter': self.type_process = False self.finding_song() keyboard.release() elif keycode[1] == 'spacebar': self.text2+=' ' elif keycode[1] == 'shift': self.big_letter = True else: try: letter_check = 0 while letter_check <= len(allowed_letters): if f'{keycode[1]}' == allowed_letters[letter_check]: if self.big_letter == False: self.text2+=f'{keycode[1]}' else: self.text2+=f'{big_letter_list[letter_check]}' self.big_letter = False break letter_check+=1 except: pass self.button_input_text_2.text=f'{self.text2}' def close_keyboard(): self._keyboard.unbind(on_key_down=_on_keyboard_down) #self._keyboard = None self.button_input_text_1 = Button( text='Исполнитель', background_normal = self.btnpicdt2, background_down = self.btnpicdt1, size_hint = (1, .25), pos_hint = {'x': 0, 'y': .5},) self.button_input_text_1.bind(state=typing_process_control) self.button_input_text_2 = Button( # background_disabled_normal ="background.png", text='Название', background_normal = self.btnpicdt2, background_down = self.btnpicdt1, size_hint = (1, .25), pos_hint = {'x': 0, 'y': .25},) self.button_input_text_2.bind(state=typing_process_control) def secondtimer(who): self.welcome_screen() self.swipe_count = '' def swipe_check(*args): if len(self.swipe_count) > 3: self.swipe_count = '' if args[1] == 1: self.swipe_count += '1' if args[1] == 2: self.swipe_count += '2' if args[1] == 3: self.swipe_count += '3' # if self.swipe_count =='321': # print(self.swipe_count) if self.swipe_count =='123' and self.type_process == False: try: self._keyboard.unbind(on_key_down=_on_keyboard_down) except: pass self.settings_btn_back = self.settings_btn self.settings_btn1_back = self.settings_btn1 self.settings_btn2_back = self.settings_btn2 self.remove(self.settings_btn_back, self.settings_btn1_back, self.settings_btn2_back, self.button_input_text_1, self.button_input_text_2) self.button_input_text_1 = self.animated_part_1 self.button_input_text_2 = self.animated_part_2 self.animate(self.settings_btn_back, self.settings_btn1_back, self.settings_btn2_back, self.button_input_text_1, self.button_input_text_2) self.add(self.settings_btn_back, self.settings_btn1_back, self.settings_btn2_back, self.button_input_text_1, self.button_input_text_2) Clock.schedule_once(secondtimer, .55) self.slider_swipe = Slider( min=0, max=3, step=1, pos_hint={'y': .375}, cursor_size = (0, 0), background_width = 0) self.slider_swipe.bind(value=swipe_check) self.add(self.background, self.slider_swipe, self.button_input_text_1, self.button_input_text_2) ############################################################################################################## def finding_song(self): def firsttimer(who): self.text_screen() if self.text1 and self.text2: self.singer = '' for space_check in range(len(self.text1.split())): if space_check!=0: self.singer+='_' self.singer+=self.text1.split()[space_check] self.name1 = '' for space_check in range(len(self.text2.split())): if space_check!=0: self.name1+='_' self.name1+=self.text2.split()[space_check] self.singer = self.singer.lower() self.name1 = self.name1.lower() response = requests.get(f'https://www.amalgama-lab.com/songs/{self.singer[0]}/{self.singer}/{self.name1}.html') html_text = BeautifulSoup(response.text, 'lxml') self.original = html_text.find_all('div', class_='original') if self.original ==[]: self.layout.clear_widgets() self.typing_screen() else: self.translate = html_text.find_all('div', class_='translate') self.song_text = '' for string in range(len(self.original)): self.song_text+= str(self.original[string].text).lstrip() self.song_text+= '\n' self.song_text+= str(self.translate[string].text).lstrip() self.song_text+= '\n' self.song_text = self.song_text.split('\n\n') self.song_text = list(filter(lambda x: x != '' and x != '\n' , self.song_text)) self.part_text = 0 self.singer = self.singer.title().replace('_', ' ') self.name1 = self.name1.title().replace('_', ' ') execute_help = '' for i in range(len(self.song_text)): execute_help+=self.song_text[i] execute_help+='_1_' spisok_ch = cur.execute('SELECT * FROM archive;').fetchall() for ch_arch in spisok_ch: if ch_arch[0] == f'{self.name1} - {self.singer}': break else: time_now = datetime.now() text_execute = (f'{self.name1} - {self.singer}', f'{time_now.hour}:{time_now.minute} - {time_now.date()}', execute_help) cur.execute('INSERT INTO archive VALUES(?, ?, ?)', text_execute) con.commit() self.song_text.append('') self.animated_part_3 = Button( background_normal = self.btnpicdt2, background_down = self.btnpicdt2, size_hint = (1, .5), pos_hint = {'x': 0, 'y': .25},) self.animated_part_3.text_size=(self.layout.width//2.5, None) Clock.schedule_once(firsttimer, 1) self.add(self.animated_part_3) self.animate(self.animated_part_3) ############################################################################################################## def text_screen(self): def firsttimer(who): self.text_screen() self.add(self.slider_swipe, self.button_input_text_1, self.button_input_text_2) self.remove(self.animated_part_3) self.remove(self.slider_swipe, self.button_input_text_1, self.button_input_text_2) self.swipe_count = '' def second_swipe_check(*args): if len(self.swipe_count) > 3: self.swipe_count = '' if args[1] == 1: self.swipe_count = '1' if args[1] == 2: self.swipe_count += '2' if args[1] == 3: self.swipe_count += '3' # if self.swipe_count =='321': # print(self.swipe_count) if self.swipe_count =='123' : self.animated_part_3.text = '' self.animate(1) Clock.schedule_once(firsttimer, .5) self.slider_swipe_song_text = Slider( min=0, max=3, step=1, pos_hint={'y': .75}, cursor_size = (0, 0), background_width = 0) self.add(self.slider_swipe_song_text) self.slider_swipe_song_text.bind(value=second_swipe_check) self.animated_part_3.pos_hint = {'x': 0, 'y': 0} self.animated_part_3.size_hint = (1, .75) self.animated_part_3.text = f'{self.name1} - {self.singer} [{self.part_text} / {len(self.song_text)-1}]\n\n\n' + \ self.song_text[self.part_text] self.animated_part_3.bind(state=self.callback) ############################################################################################################## def archive_text(self, button_name): self.swipe_count = '' def second_swipe_check(*args): if len(self.swipe_count) > 3: self.swipe_count = '' if args[1] == 1: self.swipe_count = '1' if args[1] == 2: self.swipe_count += '2' if args[1] == 3: self.swipe_count += '3' # if self.swipe_count =='321': # print(self.swipe_count) if self.swipe_count =='123' : self.archive() self.animate(self.text_archive) self.slider_swipe_song_text_1 = Slider( min=0, max=3, step=1, pos_hint={'y': .75}, cursor_size = (0, 0), background_width = 0) self.add(self.slider_swipe_song_text_1) self.slider_swipe_song_text_1.bind(value=second_swipe_check) exex_hlp = button_name.text.split('\n') execution_help = f'SELECT * FROM archive WHERE name="{exex_hlp[0]}"' cur.execute(execution_help) helping = cur.fetchall() con.commit() def plus(who): if self.part_text < len(normal_text)-1 : self.part_text += 1 else: self.part_text = 0 self.text_archive.text = f'{helping[0][0]} [{self.part_text} / {len(normal_text)-1}]\n\n\n' +\ normal_text[self.part_text] self.part_text = 0 self.text_archive.bind(on_press=plus) normal_text = helping[0][2].split('_1_') self.text_archive.text = f'{helping[0][0]} [{self.part_text} / {len(normal_text)-1}]\n\n\n' +\ normal_text[self.part_text]
# draw frame buffer fb.add(Color(1, 0, 0, 1)) fb.add(Rectangle(pos=(0, 0), size=(100, 150))) fb.add(Color(0, 1, 0, 1)) fb.add(Rectangle(pos=(100, 0), size=(100, 150))) fb.add(Color(0, 0, 1, 1)) fb.add(Rectangle(pos=(200, 0), size=(200, 150))) fb.add(Color(1, 1, 1, 1)) fb.add(Rectangle(pos=(0, 75), size=(300, 75))) # draw Canvas root.canvas.add(Rectangle(size=(300, 150), texture=fb.texture)) # get color value def pick_color(self, t): # get window size (win_width, win_height) = Window.size # get touched_coordinate (touch_x, touch_y) = t.spos # frame buffer coordinate frame_buf_x = int(win_width * touch_x) frame_buf_y = int(win_height * touch_y) # get pixel on frame buffer coordinate pixel_value = fb.get_pixel_color(frame_buf_x, frame_buf_y) print('位置:\t', (frame_buf_y, frame_buf_x), '\tピクセル:', pixel_value) root.bind(on_touch_up=pick_color) Window.size = (300, 150) kivy04().run()
img = Image(source='index.jpeg') tx = img.texture root = Widget() # draw Rectangle root.canvas.add(Color(1, 0, 0, 1)) root.canvas.add(Rectangle(pos=(10, 210), size=(350, 100))) # draw Image root.canvas.add(Color(1, 1, 1, 1)) root.canvas.add(Rectangle(pos=(0, 0), texure=tx, size=(210, 200))) # draw Ellipse root.canvas.add(Color(0, 1, 0, 1)) root.canvas.add(Ellipse(pos=(200, 10), size=(170, 170))) # draw Line root.canvas.add(Color(1, 1, 1, 1)) root.canvas.add( Line(width=10, points=[580, 25, 400, 25, 580, 160, 400, 290, 580, 290])) # screen shot def save_shot(self, t): # method1 Window.screenshot(name='kivy04-2-1.png') # method2 self.export_to_png('kivy04-2-2.png') root.bind(on_touch_up=save_shot) Window.size = (600, 330) kivy04().run()
def bind(self, **kwargs): Widget.bind(self, **kwargs)