コード例 #1
0
ファイル: main.py プロジェクト: leigh-johnson/MAFIA
class Mafia(App):
    phase = 'day' #'day' or 'night'
    dayCount = 1
    nightCount = 1
    aliveList = []
    deadList = []
    setup = StringProperty()
    #setup = 'Vengeful'
    playerNumber = NumericProperty()
    #playerNumber = 5
    winningTeam = ''

    def reset(self, instance):
        Mafia.phase = 'day'
        Mafia.dayCount = 1
        Mafia.nightCount = 1
        Mafia.aliveList[:] = []
        Mafia.deadList[:] = []
        Mafia.setup = StringProperty()
        Mafia.playerNumber = NumericProperty(1)
        winningTeam = ''
        sm.current = 'titleScreen'

    def build(self):
        self.root = NavigationDrawer()
        self.root.side_panel_opacity = 0
        self.root.separator_image_width = sp(0)
        menu = BoxLayout(orientation='vertical')

        resetButton = Factory.GreenButton(text='New Game')
        settingsButton = Factory.OrangeButton(text='Settings')
        helpButton = Factory.PurpleButton(text='Help')
        menu.add_widget(resetButton)
        menu.add_widget(settingsButton)
        menu.add_widget(helpButton)
        resetButton.bind(on_press=self.reset)

        self.root.add_widget(menu)

        content = AnchorLayout(anchor_x='right', anchor_y='bottom', paddind=sp(5))



        toggleButton = IconButton (icon="atlas://img/icon/iconatlas/icon-menu", size_hint=(.15, .1),
            background_normal='atlas://img/button/buttonatlas/red',
            background_down='atlas://img/button/buttonatlas/orange')
        toggleButton.bind(on_press=lambda j: self.root.toggle_state())

        content.add_widget(sm)
        content.add_widget(toggleButton)
        self.root.add_widget(content)
        sm.current = 'titleScreen'
        return self.root
コード例 #2
0
ファイル: main.py プロジェクト: leigh-johnson/MAFIA
    def build(self):
        self.root = NavigationDrawer()
        self.root.side_panel_opacity = 0
        self.root.separator_image_width = sp(0)
        menu = BoxLayout(orientation='vertical')

        resetButton = Factory.GreenButton(text='New Game')
        settingsButton = Factory.OrangeButton(text='Settings')
        helpButton = Factory.PurpleButton(text='Help')
        menu.add_widget(resetButton)
        menu.add_widget(settingsButton)
        menu.add_widget(helpButton)
        resetButton.bind(on_press=self.reset)

        self.root.add_widget(menu)

        content = AnchorLayout(anchor_x='right', anchor_y='bottom', paddind=sp(5))



        toggleButton = IconButton (icon="atlas://img/icon/iconatlas/icon-menu", size_hint=(.15, .1),
            background_normal='atlas://img/button/buttonatlas/red',
            background_down='atlas://img/button/buttonatlas/orange')
        toggleButton.bind(on_press=lambda j: self.root.toggle_state())

        content.add_widget(sm)
        content.add_widget(toggleButton)
        self.root.add_widget(content)
        sm.current = 'titleScreen'
        return self.root
コード例 #3
0
ファイル: main.py プロジェクト: jarradh/nurture
    def build(self):
        Window.size = (1200, 1600)

        # Setup Navigation Drawer UI and relationships
        drawer = NavigationDrawer()
        sidebar = Sidebar()
        drawer.anim_type = 'slide_above_anim'    
        drawer.add_widget(sidebar)
        nurture =Nurture(drawer, sidebar)
        drawer.bind(state=nurture.save)
        drawer.add_widget(nurture)

        return drawer
コード例 #4
0
    def __init__(self, **kwargs):

        super(TabDrawer, self).__init__(**kwargs)

        self.navdraw = NavigationDrawer()
        self.side_panel = BoxLayout(orientation='vertical')
        self.side_panel.tabbed_panel = self
        self.navdraw.add_widget(self.side_panel)
        self.add_widget(self.navdraw)

        self.add_widget(ConnectionLayout())

        pad_Layout = TabDrawerItem(text='control')
        pad_Layout.add_widget(Pad())
        self.add_widget(pad_Layout)

        for item in self.Data:
            self.add_widget(PidLayout(item))

        self.add_widget(LogLayout())
コード例 #5
0
class TabDrawer(BoxLayout, Sender):
    current_tab = ObjectProperty(None)
    current_text = StringProperty('BalanceBot')
    main_panel = ObjectProperty(None)
    orientation = 'vertical'

    Data = (('Stability', (
        ('Vertical', (0, -5, 5, 0.1)),
        ('kPs', (5, 0, 100, 0.1)),
        ('kIs', (5, 0, 100, 0.1)),
        ('kDs', (5, 0, 100, 0.1)),
    ), (
        ('Angle', (1, 0, 0)),
        ('PID_stab', (0, 1, 0)),
        ('P_stab', (0.5, 0.5, 0)),
        ('I_stab', (0, 0.5, 0.5)),
        ('D_stab', (0, 0, 1)),
    )), ('Deplacement', (
        ('Origine', (0, -100, 100, 1)),
        ('kPd', (5, 0, 10, 0.1)),
        ('kId', (5, 0, 10, 0.1)),
        ('kDd', (5, 0, 10, 0.1)),
    ), (
        ('Encoder', (1, 0, 0)),
        ('PID_dep', (0, 1, 0)),
        ('P_dep', (0.5, 0.5, 0)),
        ('I_dep', (0, 0.5, 0.5)),
        ('D_dep', (0, 0, 1)),
    )), ('Rotation', (
        ('Direction', (0, -100, 100, 1)),
        ('kPr', (5, 0, 10, 0.1)),
        ('kIr', (5, 0, 10, 0.1)),
        ('kDr', (5, 0, 10, 0.1)),
    ), (
        ('Dif_Enc', (1, 0, 0)),
        ('PID_rot', (0, 1, 0)),
        ('P_rot', (0.5, 0.5, 0)),
        ('I_rot', (0, 0.5, 0.5)),
        ('D_rot', (0, 0, 1)),
    )))

    def __init__(self, **kwargs):

        super(TabDrawer, self).__init__(**kwargs)

        self.navdraw = NavigationDrawer()
        self.side_panel = BoxLayout(orientation='vertical')
        self.side_panel.tabbed_panel = self
        self.navdraw.add_widget(self.side_panel)
        self.add_widget(self.navdraw)

        self.add_widget(ConnectionLayout())

        pad_Layout = TabDrawerItem(text='control')
        pad_Layout.add_widget(Pad())
        self.add_widget(pad_Layout)

        for item in self.Data:
            self.add_widget(PidLayout(item))

        self.add_widget(LogLayout())

    def add_widget(self, widget, index=0):
        if issubclass(widget.__class__, TabDrawerItem):
            #if len( self.children ) > 2 :
            self.side_panel.add_widget(widget)
            if len(self.side_panel.children) == 1:
                self.switch_to(widget)
        else:
            super(TabDrawer, self).add_widget(widget)
            #print widget, len(self.children), len(self.children) > 2

    def switch_to(self, header):
        if self.navdraw.state == 'open':
            self.navdraw.toggle_state()

        if self.current_tab:
            self.current_tab.state = 'normal'
        header.state = 'down'
        self.current_tab = header
        self.current_text = header.text
        if self.main_panel:
            self.navdraw.remove_widget(self.main_panel)
        self.navdraw.add_widget(header.content)
        self.main_panel = header.content

    def toggle_state(self):
        self.navdraw.toggle_state()

    def on_current_text(self, *args):
        self.send("get", self.current_text)

    def toggle_menu(self):
        self.current_tab.menu = not self.current_tab.menu
コード例 #6
0
    def build(self):
        navigationdrawer = NavigationDrawer()

        side_panel = BoxLayout(orientation='vertical')
        side_panel.add_widget(Label(text='Panel label'))
        side_panel.add_widget(Button(text='A button'))
        side_panel.add_widget(Button(text='Another button'))
        navigationdrawer.add_widget(side_panel)

        label_head = (
            '[b]Example label filling main panel[/b]\n\n[color=ff0000](p'
            'ull from left to right!)[/color]\n\nIn this example, the le'
            'ft panel is a simple boxlayout menu, and this main panel is'
            ' a BoxLayout with a label and example image.\n\nSeveral pre'
            'set layouts are available (see buttons below), but users ma'
            'y edit every parameter for much more customisation.')
        main_panel = BoxLayout(orientation='vertical')
        label_bl = BoxLayout(orientation='horizontal')
        label = Label(text=label_head,
                      font_size='15sp',
                      markup=True,
                      valign='top')
        label_bl.add_widget(Widget(size_hint_x=None, width=dp(10)))
        label_bl.add_widget(label)
        label_bl.add_widget(Widget(size_hint_x=None, width=dp(10)))
        main_panel.add_widget(Widget(size_hint_y=None, height=dp(10)))
        main_panel.add_widget(label_bl)
        main_panel.add_widget(Widget(size_hint_y=None, height=dp(10)))
        main_panel.add_widget(
            Image(source='red_pixel.png',
                  allow_stretch=True,
                  keep_ratio=False,
                  size_hint_y=0.2))
        navigationdrawer.add_widget(main_panel)
        label.bind(size=label.setter('text_size'))

        def set_anim_type(name):
            navigationdrawer.anim_type = name

        modes_layout = BoxLayout(orientation='horizontal')
        modes_layout.add_widget(Label(text='preset\nanims:'))
        slide_an = Button(text='slide_\nabove_\nanim')
        slide_an.bind(on_press=lambda j: set_anim_type('slide_above_anim'))
        slide_sim = Button(text='slide_\nabove_\nsimple')
        slide_sim.bind(on_press=lambda j: set_anim_type('slide_above_simple'))
        fade_in_button = Button(text='fade_in')
        fade_in_button.bind(on_press=lambda j: set_anim_type('fade_in'))
        reveal_button = Button(text='reveal_\nbelow_\nanim')
        reveal_button.bind(
            on_press=lambda j: set_anim_type('reveal_below_anim'))
        slide_button = Button(text='reveal_\nbelow_\nsimple')
        slide_button.bind(
            on_press=lambda j: set_anim_type('reveal_below_simple'))
        modes_layout.add_widget(slide_an)
        modes_layout.add_widget(slide_sim)
        modes_layout.add_widget(fade_in_button)
        modes_layout.add_widget(reveal_button)
        modes_layout.add_widget(slide_button)
        main_panel.add_widget(modes_layout)

        button = Button(text='toggle NavigationDrawer state (animate)',
                        size_hint_y=0.2)
        button.bind(on_press=lambda j: navigationdrawer.toggle_state())
        button2 = Button(text='toggle NavigationDrawer state (jump)',
                         size_hint_y=0.2)
        button2.bind(on_press=lambda j: navigationdrawer.toggle_state(False))
        button3 = Button(text='toggle _main_above', size_hint_y=0.2)
        button3.bind(on_press=navigationdrawer.toggle_main_above)
        main_panel.add_widget(button)
        main_panel.add_widget(button2)
        main_panel.add_widget(button3)

        return navigationdrawer
コード例 #7
0
	def __init__(self):
		#rate of intrest
		self.roi=0
		#declaring dates
		self.date_today=time.strftime('%d-%m-%Y')
		self.name='1st'
		super(first_screen,self).__init__()
		#main gird consists of all the 14 horizental layouts
		self.main_grid=GridLayout(rows=16,padding=10,spacing=10)

		#adding company name--Garuda.inc to the app
		self.Title=Label(text='~  [b]Garuda.inc[/b]',size_hint=[1,0.25],font_name='Montez-Regular',markup=True)
		self.main_grid.add_widget(self.Title)
		
		#adding selection of toggle buttons for intrest selection
		intrest_box=BoxLayout()
		self.gold=ToggleButton(text='Gold',state='down',group='intrest',background_normal='button-on.jpeg',background_down='button-down.jpeg',on_press=lambda a:self.intrest_action(1))
		self.silver=ToggleButton(text='Silver',group='intrest',background_normal='button-on.jpeg',background_down='button-down.jpeg',on_press=lambda a:self.intrest_action(2))
		self.other=ToggleButton(text='Other',group='intrest',background_normal='button-on.jpeg',background_down='button-down.jpeg',on_press=lambda a:self.intrest_action(3))
		intrest_box.add_widget(self.gold)
		intrest_box.add_widget(self.silver)
		intrest_box.add_widget(self.other)
		self.main_grid.add_widget(intrest_box)

		#adding selection of months for intrest calculation
		month_box=BoxLayout()
		self.month_minus=ToggleButton(text='0',group='months',background_normal='button-on.jpeg',background_down='button-down.jpeg',on_press=lambda a:self.month_action(1))
		self.month_plus=ToggleButton(text='1',state='down',group='months',background_normal='button-on.jpeg',background_down='button-down.jpeg',on_press=lambda a:self.month_action(2))
		self.month=ToggleButton(text='exjact',group='months',background_normal='button-on.jpeg',background_down='button-down.jpeg',on_press=lambda a:self.month_action(3))
		month_box.add_widget(self.month_minus)
		month_box.add_widget(self.month_plus)
		month_box.add_widget(self.month)
		self.main_grid.add_widget(month_box)

		#adding label to enter money
		entry_money=Label(text='[b]enter amount [/b]',markup=True)
		self.main_grid.add_widget(entry_money)

		#taking input amount from user
		self.amount=TextInput(text='',input_type='number',multiline=False)
		self.main_grid.add_widget(self.amount)

		#adding label to take date and changing date button 
		date_panel=BoxLayout()
		enter_date=Label(text='[b]Enter Date[/b]',markup=True)
		self.change_date=Button(text=self.date_today,markup=True,size_hint=[0.5,1],background_normal='button-on.jpeg',background_down='button-down.jpeg',on_press=lambda a:self.date_popup())
		date_panel.add_widget(enter_date)
		date_panel.add_widget(self.change_date)
		self.main_grid.add_widget(date_panel)

		#adding a inputs to take date
		date_box=BoxLayout(spacing=10,padding=10)
		self.datei=TextInput(multiline=False,input_type='number',text='')
		self.monthi=TextInput(multiline=False,input_type='number',text='')
		self.yeari=TextInput(multiline=False,input_type='number',text='',size_hint=[1.7,1])
		date_box.add_widget(self.datei)
		date_box.add_widget(self.monthi)
		date_box.add_widget(self.yeari)
		self.main_grid.add_widget(date_box)

		#select the condition
		self.main_grid.add_widget(BoxLayout(size_hint=[1,0.1]))
		sixm=BoxLayout(size_hint=(1,0.5))
		self.sixc1=CheckBox(group='term',size_hint=[0.1,1],state='down',on_press=lambda a:self.term_action(1))
		sixt=Label(text='[b] with compond  intrest \'6\' month                      [/b]',markup=True)
		sixm.add_widget(self.sixc1)
		sixm.add_widget(sixt)
		simm=BoxLayout(size_hint=(1,0.5))
		self.simc2=CheckBox(group='term',size_hint=[0.1,1],on_press=lambda a:self.term_action(2))
		simt=Label(text='[b]only simple intrest every month                    [/b]',markup=True)
		simm.add_widget(self.simc2)
		simm.add_widget(simt)
		self.main_grid.add_widget(sixm)
		self.main_grid.add_widget(simm)
		self.main_grid.add_widget(BoxLayout(size_hint=[1,0.1]))

		#ok button
		ok=Button(text='ok',background_normal='button-on.jpeg',background_down='button-down.jpeg',on_press=lambda a:self.intrest_cal())
		self.main_grid.add_widget(ok)

		#displaying the date
		see_date=Label(text='[b]the total number of days is[/b]',markup=True)
		self.dateo=TextInput(text='',font_name='fff',hint_text_color=[0,1,0.5,1],readonly=True,markup=True,foreground_color=[1,0,0,1])
		self.main_grid.add_widget(see_date)
		self.main_grid.add_widget(self.dateo)

		#displaying the amount
		see_amount=BoxLayout()
		amountt=Label(text='[b]the total amount is[/b]',markup=True)
		details=Button(text='full',size_hint=[0.4,1],background_normal='button-on.jpeg',background_down='button-down.jpeg',on_press=lambda a:popu2().open())
		see_amount.add_widget(amountt)
		see_amount.add_widget(details)
		self.main_grid.add_widget(see_amount)
		self.amounto=TextInput(text='',font_name='fff',hint_text_color=[0,1,0.5,1],readonly=True,markup=True,foreground_color=[1,0,0,1])
		self.main_grid.add_widget(self.amounto)

       	
        
		#side-hidden panel
		#to add this all to have to add main panel and the side panel to navigationdrawer
		navigationdrawer = NavigationDrawer()                
		navigationdrawer.anim_type = 'fade_in'    
		self.side_panel=BoxLayout(orientation='vertical')        
		value=['vijayawada','guntur','hyderabad','rajahmundry','nellore','visakhapatnam','kakinada','warangal','proddatur','bangalore','delhi','chennai','mumbai','kolkata']        
		
		s1=Spinner(text='vijayawada',values=value,size_hint_y=None,sync_height = True,background_normal='button-on.jpeg',background_down='button-down.jpeg')     
		tex1=Label(text='gold price in the city is')        
		self.rateo1=TextInput(readonly=True,font_name='fff',markup=True,foreground_color=[1,0,0,1])
		ok1=Button(text='ok',size_hint=[0.4,1],readonly=True,background_normal='button-on.jpeg',background_down='button-down.jpeg',on_press=lambda a:self.dis(s1.text,1))
		box1=BoxLayout()
		box1.add_widget(self.rateo1)
		box1.add_widget(ok1)
        
		s2=Spinner(text='guntur',values=value,size_hint_y=None,sync_height = True,background_normal='button-on.jpeg',background_down='button-down.jpeg')        
		tex2=Label(text='gold price in the city is')        
		self.rateo2=TextInput(readonly=True,font_name='fff',markup=True,foreground_color=[1,0,0,1])
		ok2=Button(text='ok',size_hint=[0.4,1],readonly=True,background_normal='button-on.jpeg',background_down='button-down.jpeg',on_press=lambda a:self.dis(s2.text,2))
		box2=BoxLayout()
		box2.add_widget(self.rateo2)
		box2.add_widget(ok2)
        
		tex3=Label(text='silver price in India(1KG)')        
		rateo3=TextInput(readonly=True,font_name='fff',markup=True,foreground_color=[1,0,0,1])
       
		but1=Button(text='about',background_normal='button-on.jpeg',background_down='button-down.jpeg')        
		self.side_panel.add_widget(s1)        
		self.side_panel.add_widget(tex1)        
		self.side_panel.add_widget(box1)        
		self.side_panel.add_widget(BoxLayout())        
		self.side_panel.add_widget(s2)        
		self.side_panel.add_widget(tex2)        
		self.side_panel.add_widget(box2)        
		self.side_panel.add_widget(BoxLayout())        
		self.side_panel.add_widget(tex3)        
		self.side_panel.add_widget(rateo3)        
		self.side_panel.add_widget(but1)
       
		navigationdrawer.add_widget(self.side_panel)
		navigationdrawer.add_widget(self.main_grid)

		#adding the complete grid to screen
		
		self.add_widget(navigationdrawer)
コード例 #8
0
ファイル: main.py プロジェクト: trinoculars/code-jam-6
    def build(self):
        self.icon = ICON
        Window.minimum_width, Window.minimum_height = Window.size
        root = FloatLayout()
        navdrawer = NavigationDrawer()
        navdrawer.toggle_state()
        navdrawer.anim_type = "slide_above_anim"

        self.chisel = chisel = Chisel()
        self.chisel_on_touch_down = chisel.on_touch_down
        self.chisel_on_touch_move = chisel.on_touch_move

        options_panel = OptionsPanel(chisel)
        navdrawer.add_widget(options_panel)

        burger = BurgerButton()
        burger.bind(on_release=navdrawer.toggle_state)

        rel_layout = RelativeLayout()
        rel_layout.add_widget(chisel)  # To push it when side panel is opened.
        navdrawer.add_widget(rel_layout)
        options_panel.build()
        options_panel.bind_to_burger(burger)
        navdrawer.bind(_anim_progress=self._set_side_panel_opacity)
        navdrawer.bind(_anim_progress=self.disable_chisel)

        root.add_widget(navdrawer)
        root.add_widget(burger)
        Window.add_widget(CURSOR, canvas="after")
        return root
コード例 #9
0
ファイル: main.py プロジェクト: aluchieneseiv/pycalc
    def build(self):
        self.store = JsonStore('scripts.json')

        self.appview = NavigationDrawer()
        self.appview.anim_type = 'reveal_below_anim'

        side_panel = BoxLayout(orientation='vertical')

        title = Label(text='Pycalc')
        title.size = self.appview.width, 30
        title.size_hint_y = None
        side_panel.add_widget(title)

        new_btn = Button(text='New Script')
        new_btn.size = self.appview.width, 50
        new_btn.size_hint_y = None
        new_btn.bind(on_press=lambda _: self.new_script())
        side_panel.add_widget(new_btn)

        s_in = TextInput()
        s_in.multiline = False
        s_in.size = self.appview.width, 50
        s_in.size_hint_y = None

        def show_s_in():
            s_in.height, s_in.opacity, s_in.disabled = 50, 1, False
            save_btn.height, save_btn.opacity, save_btn.disabled = 0, 0, True

            def focus():
                s_in.focus = True

            Clock.schedule_once(lambda dt: focus(), 0.1)

        def hide_s_in(x=False):
            if x:
                return
            s_in.height, s_in.opacity, s_in.disabled = 0, 0, True
            save_btn.height, save_btn.opacity, save_btn.disabled = 50, 1, False

        save_btn = Button(text='Save Script')
        save_btn.size = self.appview.width, 50
        save_btn.size_hint_y = None
        save_btn.bind(on_press=lambda _: show_s_in())
        side_panel.add_widget(save_btn)

        s_in.bind(on_text_validate=lambda instance: self.save_script(
            instance.text.strip()))
        s_in.bind(focused=lambda _, x: hide_s_in(x))
        hide_s_in()

        side_panel.add_widget(s_in)

        load_btn = Button(text='Load Script')
        load_btn.size = self.appview.width, 50
        load_btn.size_hint_y = None
        load_btn.bind(on_press=lambda _: self.load_script())
        side_panel.add_widget(load_btn)

        self.appview.add_widget(side_panel)

        self.main_panel = ScrollableText()
        self.appview.add_widget(self.main_panel)

        return self.appview
コード例 #10
0
ファイル: main.py プロジェクト: aluchieneseiv/pycalc
class CalcPyApp(App):
    def build(self):
        self.store = JsonStore('scripts.json')

        self.appview = NavigationDrawer()
        self.appview.anim_type = 'reveal_below_anim'

        side_panel = BoxLayout(orientation='vertical')

        title = Label(text='Pycalc')
        title.size = self.appview.width, 30
        title.size_hint_y = None
        side_panel.add_widget(title)

        new_btn = Button(text='New Script')
        new_btn.size = self.appview.width, 50
        new_btn.size_hint_y = None
        new_btn.bind(on_press=lambda _: self.new_script())
        side_panel.add_widget(new_btn)

        s_in = TextInput()
        s_in.multiline = False
        s_in.size = self.appview.width, 50
        s_in.size_hint_y = None

        def show_s_in():
            s_in.height, s_in.opacity, s_in.disabled = 50, 1, False
            save_btn.height, save_btn.opacity, save_btn.disabled = 0, 0, True

            def focus():
                s_in.focus = True

            Clock.schedule_once(lambda dt: focus(), 0.1)

        def hide_s_in(x=False):
            if x:
                return
            s_in.height, s_in.opacity, s_in.disabled = 0, 0, True
            save_btn.height, save_btn.opacity, save_btn.disabled = 50, 1, False

        save_btn = Button(text='Save Script')
        save_btn.size = self.appview.width, 50
        save_btn.size_hint_y = None
        save_btn.bind(on_press=lambda _: show_s_in())
        side_panel.add_widget(save_btn)

        s_in.bind(on_text_validate=lambda instance: self.save_script(
            instance.text.strip()))
        s_in.bind(focused=lambda _, x: hide_s_in(x))
        hide_s_in()

        side_panel.add_widget(s_in)

        load_btn = Button(text='Load Script')
        load_btn.size = self.appview.width, 50
        load_btn.size_hint_y = None
        load_btn.bind(on_press=lambda _: self.load_script())
        side_panel.add_widget(load_btn)

        self.appview.add_widget(side_panel)

        self.main_panel = ScrollableText()
        self.appview.add_widget(self.main_panel)

        return self.appview

    def new_script(self):
        global state
        global lexer
        state = State()
        lexer.state = state
        self.main_panel.layout.clear_widgets()
        self.main_panel.add_new_codeline()

    def save_script(self, name):
        lines = []
        for wid in reversed(self.main_panel.layout.children):
            if isinstance(wid, CodeInput) and len(wid.text) > 0:
                lines.append(wid.text)

        if len(lines) > 0:
            self.store.put(name, data=lines)

    def load_script(self):
        popup = Popup(title='Load script')

        def want_delete(btn, choice_callback, _):
            def delete(name):
                self.store.delete(name)
                btn.height, btn.opacity, btn.disabled = 0, 0, True

            saved_text = btn.text
            callback = lambda _: delete(saved_text)

            def lost_focus(_):
                btn.text = saved_text
                btn.color = (1, 1, 1, 1)
                btn.unbind(on_press=callback)
                btn.bind(on_release=choice_callback)

            btn.text = 'delete?'
            btn.color = (1, 0, 0, 1)
            btn.bind(on_press=callback)
            Clock.schedule_once(lost_focus, 2)
            btn.unbind(on_release=choice_callback)

        def create_clock(widget, touch, choice_callback, *args):
            if not isinstance(widget, Button):
                return

            if not widget.collide_point(*touch.pos):
                return

            callback = partial(want_delete, widget, choice_callback)
            Clock.schedule_once(callback, 0.5)
            touch.ud['event'] = callback

        def delete_clock(widget, touch, *args):
            if not isinstance(widget, Button):
                return

            if 'event' in touch.ud:
                Clock.unschedule(touch.ud['event'])
                del touch.ud['event']

        def choice(name):
            self.new_script()

            data = self.store.get(name)['data']

            for line in data:
                codeinput = self.main_panel.layout.children[0]

                codeinput.text = line
                self.main_panel.code_interpret(codeinput)

            popup.dismiss()

        scroll_content = ScrollView()
        content = BoxLayout(orientation='vertical', size_hint_y=None)
        content.bind(minimum_height=content.setter('height'))
        scroll_content.add_widget(content)
        for item in self.store:
            btn = Button(text=item)
            btn.size = content.width, 50
            btn.size_hint_y = None

            choice_callback = lambda _: choice(item)
            btn.bind(on_touch_down=partial(create_clock,
                                           choice_callback=choice_callback),
                     on_touch_up=delete_clock)
            btn.bind(on_release=choice_callback)
            content.add_widget(btn)
        close_btn = Button(text='Cancel')
        close_btn.size_hint = 0.3, None
        close_btn.height = 50
        close_btn.bind(on_press=popup.dismiss)
        content.add_widget(close_btn)
        popup.content = scroll_content

        popup.open()
コード例 #11
0
ファイル: prueba3.py プロジェクト: juvaber/guestbook
    def build(self):
        navigationdrawer = NavigationDrawer()

        side_panel = BoxLayout(orientation='vertical')
        side_panel.add_widget(Label(text='Panel label'))
        side_panel.add_widget(Button(text='A button'))
        side_panel.add_widget(Button(text='Another button'))
        navigationdrawer.add_widget(side_panel)

        label_head = (
            '[b]Example label filling main panel[/b]\n\n[color=ff0000](p'
            'ull from left to right!)[/color]\n\nIn this example, the le'
            'ft panel is a simple boxlayout menu, and this main panel is'
            ' a BoxLayout with a label and example image.\n\nSeveral pre'
            'set layouts are available (see buttons below), but users ma'
            'y edit every parameter for much more customisation.')
        main_panel = BoxLayout(orientation='vertical')
        label_bl = BoxLayout(orientation='horizontal')
        label = Label(text=label_head, font_size='15sp',
                      markup=True, valign='top')
        label_bl.add_widget(Widget(size_hint_x=None, width=dp(10)))
        label_bl.add_widget(label)
        label_bl.add_widget(Widget(size_hint_x=None, width=dp(10)))
        main_panel.add_widget(Widget(size_hint_y=None, height=dp(10)))
        main_panel.add_widget(label_bl)
        main_panel.add_widget(Widget(size_hint_y=None, height=dp(10)))
        main_panel.add_widget(Image(source='red_pixel.png', allow_stretch=True,
                                    keep_ratio=False, size_hint_y=0.2))
        navigationdrawer.add_widget(main_panel)
        label.bind(size=label.setter('text_size'))

        def set_anim_type(name):
            navigationdrawer.anim_type = name
        modes_layout = BoxLayout(orientation='horizontal')
        modes_layout.add_widget(Label(text='preset\nanims:'))
        slide_an = Button(text='slide_\nabove_\nanim')
        slide_an.bind(on_press=lambda j: set_anim_type('slide_above_anim'))
        slide_sim = Button(text='slide_\nabove_\nsimple')
        slide_sim.bind(on_press=lambda j: set_anim_type('slide_above_simple'))
        fade_in_button = Button(text='fade_in')
        fade_in_button.bind(on_press=lambda j: set_anim_type('fade_in'))
        reveal_button = Button(text='reveal_\nbelow_\nanim')
        reveal_button.bind(on_press=
                           lambda j: set_anim_type('reveal_below_anim'))
        slide_button = Button(text='reveal_\nbelow_\nsimple')
        slide_button.bind(on_press=
                          lambda j: set_anim_type('reveal_below_simple'))
        modes_layout.add_widget(slide_an)
        modes_layout.add_widget(slide_sim)
        modes_layout.add_widget(fade_in_button)
        modes_layout.add_widget(reveal_button)
        modes_layout.add_widget(slide_button)
        main_panel.add_widget(modes_layout)

        button = Button(text='toggle NavigationDrawer state (animate)',
                        size_hint_y=0.2)
        button.bind(on_press=lambda j: navigationdrawer.toggle_state())
        button2 = Button(text='toggle NavigationDrawer state (jump)',
                         size_hint_y=0.2)
        button2.bind(on_press=lambda j: navigationdrawer.toggle_state(False))
        button3 = Button(text='toggle _main_above', size_hint_y=0.2)
        button3.bind(on_press=navigationdrawer.toggle_main_above)
        main_panel.add_widget(button)
        main_panel.add_widget(button2)
        main_panel.add_widget(button3)

        return navigationdrawer
コード例 #12
0
    def build(self):
        self.icon = ICON
        cursor = Cursor()
        Window.minimum_width, Window.minimum_height = Window.size
        root = FloatLayout()
        navdrawer = NavigationDrawer()
        navdrawer.toggle_state()
        navdrawer.anim_type = "slide_above_anim"

        chisel = Chisel()

        options_panel = OptionsPanel(chisel)
        navdrawer.add_widget(options_panel)

        burger = BurgerButton()
        burger.bind(on_release=navdrawer.toggle_state)

        rel_layout = RelativeLayout(
        )  # This layout allows navdrawer to push contained widgets.
        rel_layout.add_widget(chisel)

        tools = (ToolButton(*args, chisel, cursor)
                 for args in zip(range(3), TOOLS_NORMAL, TOOLS_SELECTED))

        for tool in tools:
            tool.pos_hint = {"x": tool._id * .1 + .35, "y": .01}
            if tool._id == 0:  # First tool button is selected.
                tool.state = "down"
            rel_layout.add_widget(tool)

        navdrawer.add_widget(rel_layout)
        options_panel.build()
        options_panel.bind_to_burger(burger)

        def on_anim(instance, value):
            instance.side_panel.opacity = chisel.disabled = 1 if instance._anim_progress else 0

        navdrawer.bind(_anim_progress=on_anim)

        root.add_widget(navdrawer)
        root.add_widget(burger)

        Window.add_widget(cursor, canvas="after")
        return root