Ejemplo n.º 1
0
    def __init__(self, calendar):
        Composite.__init__(self)

        self.calendar = calendar
        self.dayCheckBoxListener = DayCheckBoxListener(calendar)
        self.outer = VerticalPanel()
        self.setWidget(self.outer)
        self.setStyleName("DynaTable-DayFilterWidget")
        self.outer.add(DayCheckBox(self, "Sunday", 0))
        self.outer.add(DayCheckBox(self, "Monday", 1))
        self.outer.add(DayCheckBox(self, "Tuesday", 2))
        self.outer.add(DayCheckBox(self, "Wednesday", 3))
        self.outer.add(DayCheckBox(self, "Thursday", 4))
        self.outer.add(DayCheckBox(self, "Friday", 5))
        self.outer.add(DayCheckBox(self, "Saturday", 6))

        self.buttonAll = Button("All", self)
        self.buttonNone = Button("None", self)

        hp = HorizontalPanel()
        hp.setHorizontalAlignment(HasAlignment.ALIGN_CENTER)
        hp.add(self.buttonAll)
        hp.add(self.buttonNone)

        self.outer.add(hp)
        self.outer.setCellVerticalAlignment(hp, HasAlignment.ALIGN_BOTTOM)
        self.outer.setCellHorizontalAlignment(hp, HasAlignment.ALIGN_CENTER)
    def __init__(self, owner):
        self.owner = owner
        self.bar = DockPanel()
        self.gotoFirst = Button("<<", self)
        self.gotoNext = Button(">", self)
        self.gotoPrev = Button("<", self)
        self.status = HTML()

        self.setWidget(self.bar)
        self.bar.setStyleName("navbar")
        self.status.setStyleName("status")

        buttons = HorizontalPanel()
        buttons.add(self.gotoFirst)
        buttons.add(self.gotoPrev)
        buttons.add(self.gotoNext)
        self.bar.add(buttons, DockPanel.EAST)
        self.bar.setCellHorizontalAlignment(buttons, HasAlignment.ALIGN_RIGHT)
        self.bar.add(self.status, DockPanel.CENTER)
        self.bar.setVerticalAlignment(HasAlignment.ALIGN_MIDDLE)
        self.bar.setCellHorizontalAlignment(self.status,
                                            HasAlignment.ALIGN_RIGHT)
        self.bar.setCellVerticalAlignment(self.status,
                                          HasAlignment.ALIGN_MIDDLE)
        self.bar.setCellWidth(self.status, "100%")

        self.gotoPrev.setEnabled(False)
        self.gotoFirst.setEnabled(False)
Ejemplo n.º 3
0
    def __init__(self, menu = None, padding = 5, submenu_offset_x = 2, submenu_offset_y = 2,
                 x_align = 0, y_align = 0.5, pressed_offset = 0,
                 secondary_label = "", mnemonic = "", **kwargs):
        Button.__init__(self, padding=padding, pressed_offset = pressed_offset, x_align = x_align, y_align = y_align, **kwargs)

        self.expand = False

        #: submenu of the item
        self.menu = menu

        self.selected = False

        #: if specified will push the submeny by the given pixels
        self.submenu_offset_x = submenu_offset_x

        #: if specified will push the submeny by the given pixels
        self.submenu_offset_y = submenu_offset_y

        #: the secondary label element
        self.secondary_display_label = self.secondary_label_class("",
                                                                  color = "#666",
                                                                  fill=True,
                                                                  x_align=1,
                                                                  padding_right = 5,
                                                                  visible = True)
        self.container.add_child(self.secondary_display_label)

        #: text of the secondary label that is placed to the right of the primary
        self.secondary_label = secondary_label

        #: keypress that can also triger activation of this menu item
        #: This is string in for "Key+Key+Key". For example: "Shift+c"
        self.mnemonic = mnemonic

        self.connect("on-mnemonic-activated", self.on_mnemonic_activated)
Ejemplo n.º 4
0
def win_screen():
    quit_button = Button(display_dimensions, "Quit", (250, 0), (200, 100), red, text_color=white, text_size=25, action="quit")
    play_again_button = Button(display_dimensions, "Play Again", (0, 0), (200, 100), blue, text_color=white, text_size=25, action="play_again")
    start_menu_button = Button(display_dimensions, "Start Menu", (-250, 0), (200, 100), green, text_color=white, text_size=25, action="start_menu")
    buttons = [quit_button, play_again_button, start_menu_button]

    win_text = Text(display_dimensions, (0, -200), "You Win!!!", 60, black)

    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                quit_game()
            elif event.type == pygame.MOUSEBUTTONDOWN:
                    mouse_pos = pygame.mouse.get_pos()
                    if event.button == 1:
                        for button in buttons:
                            if button.check_if_clicked(mouse_pos):
                                if button.action == "quit":
                                    quit_game()
                                elif button.action == "play_again":
                                    game_loop()
                                elif button.action == "start_menu":
                                    start_menu()
                                else:
                                    print("Button action: {} does not exist".format(button.action))

        game_display.fill(white)

        for button in buttons:
            button.display(game_display, pygame.mouse.get_pos())

        win_text.display(game_display)

        pygame.display.update()
        clock.tick(FPS)
Ejemplo n.º 5
0
 def __init__(self, owner):
     self.owner = owner
     self.bar = DockPanel()
     self.gotoFirst = Button("<<", self)
     self.gotoNext = Button(">", self)
     self.gotoPrev = Button("<", self)
     self.status = HTML()
     
     self.initWidget(self.bar)
     self.bar.setStyleName("navbar")
     self.status.setStyleName("status")
     
     buttons = HorizontalPanel()
     buttons.add(self.gotoFirst)
     buttons.add(self.gotoPrev)
     buttons.add(self.gotoNext)
     self.bar.add(buttons, DockPanel.EAST)
     self.bar.setCellHorizontalAlignment(buttons, HasAlignment.ALIGN_RIGHT)
     self.bar.add(self.status, DockPanel.CENTER)
     self.bar.setVerticalAlignment(HasAlignment.ALIGN_MIDDLE)
     self.bar.setCellHorizontalAlignment(self.status, HasAlignment.ALIGN_RIGHT)
     self.bar.setCellVerticalAlignment(self.status, HasAlignment.ALIGN_MIDDLE)
     self.bar.setCellWidth(self.status, "100%")
     
     self.gotoPrev.setEnabled(False)
     self.gotoFirst.setEnabled(False)
Ejemplo n.º 6
0
class Popups(Sink):
    def __init__(self):
        self.fDialogButton = Button("Show Dialog", self)
        self.fPopupButton = Button("Show Popup", self)
        
        panel = VerticalPanel()
        panel.add(self.fPopupButton)
        panel.add(self.fDialogButton)
        
        list = ListBox()
        list.setVisibleItemCount(5)
        for i in range(10):
            list.addItem("list item " + i)
        panel.add(list)
        
        panel.setSpacing(8)
        self.initWidget(panel)

    def onShow(self):
        pass

    def onClick(self, sender):
        if sender == self.fPopupButton:
            p = MyPopup()
            left = sender.getAbsoluteLeft() + 10
            top = sender.getAbsoluteTop() + 10
            p.setPopupPosition(left, top)
            p.show()
        elif sender == self.fDialogButton:
            dlg = MyDialog()
            left = self.fDialogButton.getAbsoluteLeft() + 10
            top = self.fDialogButton.getAbsoluteTop() + 10
            dlg.setPopupPosition(left, top)
            dlg.show()
Ejemplo n.º 7
0
 def __init__(self, canvas):
     self.canvas = canvas
     self.table = Table(self.canvas,
                        Point(100, 25),
                        col_width=150,
                        font_size=10)
     self.selected_car = None
     self.show_route = False
     self.follow_car = False
     self.show_route_btn = Button(
         self.flip_show_route,
         self.canvas,
         Point(self.canvas.width / 2, 320),
         width=200,
         height=30,
         label='Show Route',
         font_size=10,
     )
     self.follow_btn = Button(
         self.flip_follow_car,
         self.canvas,
         Point(self.canvas.width / 2, 360),
         width=200,
         height=30,
         label='Follow Selected Car',
         font_size=10,
     )
     self.buttons = [self.show_route_btn, self.follow_btn]
Ejemplo n.º 8
0
class Popups(Sink):
    def __init__(self):
        self.fDialogButton = Button("Show Dialog", self)
        self.fPopupButton = Button("Show Popup", self)
        
        panel = VerticalPanel()
        panel.add(self.fPopupButton)
        panel.add(self.fDialogButton)
        
        list = ListBox()
        list.setVisibleItemCount(5)
        for i in range(10):
            list.addItem("list item " + i)
        panel.add(list)
        
        panel.setSpacing(8)
        self.setWidget(panel)

    def onShow(self):
        pass

    def onClick(self, sender):
        if sender == self.fPopupButton:
            p = MyPopup()
            left = sender.getAbsoluteLeft() + 10
            top = sender.getAbsoluteTop() + 10
            p.setPopupPosition(left, top)
            p.show()
        elif sender == self.fDialogButton:
            dlg = MyDialog()
            left = self.fDialogButton.getAbsoluteLeft() + 10
            top = self.fDialogButton.getAbsoluteTop() + 10
            dlg.setPopupPosition(left, top)
            dlg.show()
Ejemplo n.º 9
0
def game_loop() -> object:
    undo_button = Button(display_dimensions,
                         "Undo", (10, 10), (30, 30),
                         dark_pink,
                         centered=False,
                         text_size=11,
                         text_color=(217, 139, 121),
                         action="undo")
    pause_button = Button(display_dimensions,
                          "Pause", (display_dimensions[0] - 50, 10), (40, 30),
                          dark_pink,
                          centered=False,
                          text_size=10,
                          text_color=(217, 139, 121),
                          action="pause")

    buttons = [undo_button, pause_button]
    deck = Deck()
    deck.load_cards()
    deck.shuffle_cards()
    deck.load_piles(display_dimensions)
    hm = history_manager.HistoryManager(deck)

    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                quit_game()

            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_r:
                    game_loop()

                elif event.key == pygame.K_w:
                    pass

            if event.type == pygame.MOUSEBUTTONDOWN:
                mouse_pos = pygame.mouse.get_pos()
                if event.button == 1:
                    piles_to_update, valid_move = deck.handle_click(mouse_pos)
                    deck.update(piles_to_update, display_dimensions[1])
                    if valid_move:
                        hm.valid_move_made(deck)

                    for button in buttons:
                        if button.check_if_clicked(mouse_pos):
                            if button.action == "undo":
                                deck = hm.undo(deck)

                if event.button == 3:
                    deck.handle_right_click(mouse_pos)

        game_display.fill(pink)

        for button in buttons:
            button.display(game_display, pygame.mouse.get_pos())
        deck.display(game_display)
        pygame.display.update()
        clock.tick(FPS)
Ejemplo n.º 10
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self._active_elements = [
            Text('Fretboard Unlocker', Text.CENTRE, 20, font=FONTS['heading']),
            Button('play_namenotes', 'Play Name The Note', Button.CENTRE, 150, width=300),
            Button('play_findnotes', 'Play Find all Notes', Button.CENTRE, 220, width=300),
            Button('play_scaledegrees', 'Play name the scale degrees', Button.CENTRE, 290, width=300)
        ]
Ejemplo n.º 11
0
    def __init__(self, size):
        super().__init__(size)

        main_layer = WindowLayer(self)
        start_button = Button('Start Game', main_layer.rect.center)
        start_button.add_callback(MouseClickEvent.signal, self._start_game)
        main_layer.add_child(start_button)

        self.append_layer(main_layer)
Ejemplo n.º 12
0
 def __init__(self):
     super(SplashScreen, self).__init__()
     self.font = pygame.font.Font(MAIN_TITLE_FONT[0], 54)
     self.title = self.font.render(GAME_TITLE, True, (229, 22, 22))
     self.title_rect = self.title.get_rect(x=(SCREEN_SIZE[0] / 2) - 220, y=80)
     self.persist["screen_color"] = "black"
     self.next_state = "GAMEPLAY"
     self.menu = Menu([
         Button("Start", ((SCREEN_SIZE[0] / 2) - 125, 300, 250, 40)),
         Button("Credits", ((SCREEN_SIZE[0] / 2) - 125, 350, 250, 40))
     ])
     self.sound = Sound("assets/sound/MainTheme.wav")
     self.sound.play()
Ejemplo n.º 13
0
    def __init__(self,
                 title,
                 message,
                 affirmative_label,
                 decline_label="Cancel",
                 width=500,
                 modal=False):
        Dialog.__init__(self, title=title, width=width, modal=modal)

        scrollbox = ScrollArea(Label(markup=message,
                                     padding=5,
                                     overflow=pango.WrapMode.WORD),
                               scroll_horizontal=False,
                               border=0,
                               margin=2,
                               margin_right=3,
                               height=150)

        affirmative = Button(affirmative_label, id="affirmative_button")
        affirmative.connect("on-click", self._on_button_click)
        decline = Button(decline_label, id="decline_button")
        decline.connect("on-click", self._on_button_click)

        self.box.contents = VBox([
            scrollbox,
            HBox([HBox(), decline, affirmative], expand=False, padding=10)
        ])
Ejemplo n.º 14
0
    def initialize(self):
        print(f"Initializing the '{self.sceneName}' level...")

        self.startBtn = Button(310, 250, 160, 50, "START")
        self.infoBtn = Button(200, 350, 370, 50, "INSTRUCTIONS")
        self.quitBtn = Button(325, 450, 135, 50, "QUIT")
        self.backBtn = Button(20, 530, 130, 50, "BACK")

        # assign button colour
        self.startBtn.set_button_colour(colour.LIGHTBLUE, None)
        self.infoBtn.set_button_colour(colour.LIGHTBLUE, None)
        self.quitBtn.set_button_colour(colour.LIGHTBLUE, None)
        self.backBtn.set_button_colour(colour.LIGHTBLUE, None)

        # assign action functions to handle button click events
        self.startBtn.actionFunc = self.__onStartBtnClicked
        self.infoBtn.actionFunc = self.__onInfoBtnClicked
        self.quitBtn.actionFunc = self.__onQuitBtnClicked
        self.backBtn.actionFunc = self.__onBackBtnClicked

        self.background = load_image("intro.png")
        self.instructions = load_image("instructions.png")

        self.startGame = False
        self.quitGame = False
        self.showInstructions = False
Ejemplo n.º 15
0
    def __init__(self, file_path, parent_window, on_close):
        super().__init__(parent_window,
                         on_close,
                         caption='tabulr | Confirm background image',
                         width=640,
                         height=640)

        # Layer groups
        bg = OrderedGroup(0)
        fg = OrderedGroup(1)

        # Compute image sprite size, preserving aspect ratio
        bg_image = load(file_path)
        bg_image.anchor_x = bg_image.width // 2
        bg_image.anchor_y = bg_image.height // 2
        if bg_image.height > bg_image.width:
            scale = 640 / bg_image.height
        else:
            scale = 640 / bg_image.width

        # Background gradient
        gl.glEnable(gl.GL_BLEND)
        gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
        self.bg_gradient = self.batch.add(
            4, gl.GL_QUADS, fg, ('v2i', (0, 0, 640, 0, 640, 80, 0, 80)),
            ('c4B', (0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0)))

        # Draw bg image
        self.bg_sprite = Sprite(bg_image,
                                batch=self.batch,
                                group=bg,
                                x=320,
                                y=320)
        self.bg_sprite.scale = scale

        # Confirmation text
        self.confirm_text = Text('Is this the image you want to use?',
                                 group=fg,
                                 size=12,
                                 x=self.margin,
                                 y=self.margin,
                                 bold=True,
                                 batch=self.batch)

        # Confirmation buttons
        self.buttons = [
            Button('yes', self, self.batch, x=590, y=30, group=fg),
            Button('no', self, self.batch, x=550, y=30, group=fg)
        ]
Ejemplo n.º 16
0
    def __init__(self,
                 menu=None,
                 padding=5,
                 submenu_offset_x=2,
                 submenu_offset_y=2,
                 x_align=0,
                 y_align=0.5,
                 pressed_offset=0,
                 secondary_label="",
                 mnemonic="",
                 **kwargs):
        Button.__init__(self,
                        padding=padding,
                        pressed_offset=pressed_offset,
                        x_align=x_align,
                        y_align=y_align,
                        **kwargs)

        self.expand = False

        #: submenu of the item
        self.menu = menu

        self.selected = False

        #: if specified will push the submeny by the given pixels
        self.submenu_offset_x = submenu_offset_x

        #: if specified will push the submeny by the given pixels
        self.submenu_offset_y = submenu_offset_y

        #: the secondary label element
        self.secondary_display_label = self.secondary_label_class(
            "",
            color="#666",
            fill=True,
            x_align=1,
            padding_right=5,
            visible=True)
        self.container.add_child(self.secondary_display_label)

        #: text of the secondary label that is placed to the right of the primary
        self.secondary_label = secondary_label

        #: keypress that can also triger activation of this menu item
        #: This is string in for "Key+Key+Key". For example: "Shift+c"
        self.mnemonic = mnemonic

        self.connect("on-mnemonic-activated", self.on_mnemonic_activated)
Ejemplo n.º 17
0
    def __init__(self,
                 up=True,
                 expand=False,
                 width=15,
                 padding=0,
                 repeat_down_delay=100,
                 **kwargs):

        Button.__init__(self,
                        expand=expand,
                        width=width,
                        padding=padding,
                        repeat_down_delay=repeat_down_delay,
                        **kwargs)
        self.up = up
Ejemplo n.º 18
0
    def __init__(self, window, bus):
        super().__init__(window, bus)
        self.title = Text('Welcome to',
                          batch=self.batch,
                          x=self.margin,
                          y=(self.window.height // 2) + 100)
        self.title_bold = Text('tabulr',
                               bold=True,
                               batch=self.batch,
                               x=self.margin,
                               y=(self.window.height // 2) + 60)
        self.subtitle = Text(
            'Your schedule, from list to wallpaper. Like magic.',
            size=12,
            batch=self.batch,
            x=self.margin,
            y=self.window.height // 2)
        self.init_sprite(
            'next_button',
            Button('next',
                   self.window,
                   self.batch,
                   x=self.margin,
                   y=(self.window.height // 2) - 100))

        waves = Sprite(image('front-waves.png'), x=0, y=-30, batch=self.batch)
        waves.opacity = 140
        self.elapsed = 0
        self.init_sprite('waves', waves, is_button=False)
Ejemplo n.º 19
0
 def __init__(self):
     self.fDialogButton = Button("Show Dialog", self)
     self.fPopupButton = Button("Show Popup", self)
     
     panel = VerticalPanel()
     panel.add(self.fPopupButton)
     panel.add(self.fDialogButton)
     
     list = ListBox()
     list.setVisibleItemCount(5)
     for i in range(10):
         list.addItem("list item " + i)
     panel.add(list)
     
     panel.setSpacing(8)
     self.setWidget(panel)
    def __init__(self):
        DialogBox.__init__(self)
        # Use this opportunity to set the dialog's caption.
        self.setText("About the Mail Sample")

        # Create a DockPanel to contain the 'about' label and the 'OK' button.
        outer = DockPanel()
        outer.setSpacing(4)

        outer.add(Image(AboutDialog.LOGO_IMAGE), DockPanel.WEST)

        # Create the 'OK' button, along with a listener that hides the dialog
        # when the button is clicked. Adding it to the 'south' position within
        # the dock causes it to be placed at the bottom.
        buttonPanel = HorizontalPanel()
        buttonPanel.setHorizontalAlignment(HasAlignment.ALIGN_RIGHT)
        buttonPanel.add(Button("Close", self))
        outer.add(buttonPanel, DockPanel.SOUTH)

        # Create the 'about' label. Placing it in the 'rest' position within the
        # dock causes it to take up any remaining space after the 'OK' button
        # has been laid out.

        textplain = "This sample application demonstrates the construction "
        textplain += "of a complex user interface using pyjamas' built-in widgets.  Have a look "
        textplain += "at the code to see how easy it is to build your own apps!"
        text = HTML(textplain)
        text.setStyleName("mail-AboutText")
        outer.add(text, DockPanel.CENTER)

        # Add a bit of spacing and margin to the dock to keep the components from
        # being placed too closely together.
        outer.setSpacing(8)

        self.add(outer)
Ejemplo n.º 21
0
def buttonConstructor():
    UIfont = pygame.font.SysFont("arial", 30)
    return [
        Button("Wall", UIfont, 50, 620, wallfunc),
        Button("Start", UIfont, 120, 620, startfunc),
        Button("End", UIfont, 200, 620, endfunc),
        Button("Forest", UIfont, 270, 620, forestfunc),
        Button("CLEAR", UIfont, 410, 620, clearbutton),
        Button("Breadth", UIfont, 550, 620, breadthbutton),
        Button("DJ", UIfont, 675, 620, djbutton),
        Button("Greedy", UIfont, 725, 620, greedybutton),
        Button("A*", UIfont, 850, 620, astarbutton),
    ]
Ejemplo n.º 22
0
    def quit(self):
        self.state = self.FINISHED

        self._timer.stop()

        self._active_elements = [
            Button('main_menu', 'Return to main menu', Button.CENTRE, 400)
        ]
    def createTextThing(self, textBox):
        p = HorizontalPanel()
        p.setSpacing(4)

        p.add(textBox)

        echo = HTML()
        select_all = Button("select all")
        p.add(select_all)
        p.add(echo)
        
        listener=TextBoxListener(self, textBox, echo, select_all)
        select_all.addClickListener(listener)
        textBox.addKeyboardListener(listener)
        textBox.addClickListener(listener)

        return p
Ejemplo n.º 24
0
class GridTest:
	def onModuleLoad(self):
		self.page=0
		self.min_page=1
		self.max_page=10
		
		self.add=Button("Next >", self)
		self.sub=Button("< Prev", self)
		
		self.g=Grid()
		self.g.resize(5, 5)
		self.g.setHTML(0, 0, "<b>Grid Test</b>")
		self.g.setBorderWidth(2)
		self.g.setCellPadding(4)
		self.g.setCellSpacing(1)
		
		self.updatePageDisplay()
		RootPanel().add(self.sub)
		RootPanel().add(self.add)
		RootPanel().add(self.g)

	def onClick(self, sender):

		print "click", sender, self.add, self.sub

		if sender==self.add:
			self.page+=1
		elif sender==self.sub:
			self.page-=1
		print sender, self.page
		self.updatePageDisplay()
		

	def updatePageDisplay(self):
		if self.page<self.min_page: self.page=self.min_page
		elif self.page>self.max_page: self.page=self.max_page
		total_pages=(self.max_page-self.min_page) + 1
		
		self.g.setHTML(0, 4, "<b>page " + str(self.page) + ' of ' + str(total_pages) + "</b>")
		
		if self.page>=self.max_page:
			self.add.setEnabled(False)
		else:
			self.add.setEnabled(True)
			
		if self.page<=self.min_page:
			self.sub.setEnabled(False)
		else:
			self.sub.setEnabled(True)

		for y in range(1, 5):
			for x in range(5):
				txt = str(self.page) + ' (' + str(y) + ',' + str(x) + ')'
				print txt
				self.g.setText(y, x, txt)
Ejemplo n.º 25
0
 def __init__(self):
     super(Credits, self).__init__()
     self.font = pygame.font.Font(SUB_TITLE_FONT[0], 34)
     self.title = self.font.render("CREDITS", True, (255, 255, 255))
     self.title_rect = self.title.get_rect(x=(SCREEN_SIZE[0] / 2) - 80, y=50)
     self.next_state = "SPLASH"
     self.menu = Menu([
         Button("Back", ((SCREEN_SIZE[0] / 2) - 125, 390, 250, 40), active = True)
     ])
Ejemplo n.º 26
0
    def onModuleLoad(self):
        self.page = 0
        self.min_page = 1
        self.max_page = 10

        self.add = Button("Next >", self)
        self.sub = Button("< Prev", self)

        self.g = Grid()
        self.g.resize(5, 5)
        self.g.setHTML(0, 0, "<b>Grid Test</b>")
        self.g.setBorderWidth(2)
        self.g.setCellPadding(4)
        self.g.setCellSpacing(1)

        self.updatePageDisplay()
        RootPanel().add(self.sub)
        RootPanel().add(self.add)
        RootPanel().add(self.g)
Ejemplo n.º 27
0
    def __setattr__(self, name, val):
        if name == "menu":
            # make sure we re-parent also the submenu
            if getattr(self, "menu", None):
                self.menu.owner = None
            if val:
                val.owner = self
        elif name == "secondary_label":
            self.secondary_display_label.text = val
            if val:
                self.container.fill = self.secondary_display_label.visible = True
            else:
                self.container.fill = self.secondary_display_label.visible = False
            return
        elif name == "mnemonic":
            # trample over the secondary label. one can set it back if wants
            self.secondary_label = val

        Button.__setattr__(self, name, val)
Ejemplo n.º 28
0
    def __setattr__(self, name, val):
        if name == "menu":
            # make sure we re-parent also the submenu
            if getattr(self, "menu", None):
                self.menu.owner = None
            if val:
                val.owner = self
        elif name == "secondary_label":
            self.secondary_display_label.text = val
            if val:
                self.container.fill = self.secondary_display_label.visible = True
            else:
                self.container.fill = self.secondary_display_label.visible = False
            return
        elif name == "mnemonic":
            # trample over the secondary label. one can set it back if wants
            self.secondary_label = val

        Button.__setattr__(self, name, val)
Ejemplo n.º 29
0
	def onModuleLoad(self):
		self.page=0
		self.min_page=1
		self.max_page=10
		
		self.add=Button("Next >", self)
		self.sub=Button("< Prev", self)
		
		self.g=Grid()
		self.g.resize(5, 5)
		self.g.setHTML(0, 0, "<b>Grid Test</b>")
		self.g.setBorderWidth(2)
		self.g.setCellPadding(4)
		self.g.setCellSpacing(1)
		
		self.updatePageDisplay()
		RootPanel().add(self.sub)
		RootPanel().add(self.add)
		RootPanel().add(self.g)
class NavBar(Composite):
    def __init__(self, owner):
        self.owner = owner
        self.bar = DockPanel()
        self.gotoFirst = Button("&lt;&lt;", self)
        self.gotoNext = Button("&gt;", self)
        self.gotoPrev = Button("&lt;", self)
        self.status = HTML()

        self.setWidget(self.bar)
        self.bar.setStyleName("navbar")
        self.status.setStyleName("status")

        buttons = HorizontalPanel()
        buttons.add(self.gotoFirst)
        buttons.add(self.gotoPrev)
        buttons.add(self.gotoNext)
        self.bar.add(buttons, DockPanel.EAST)
        self.bar.setCellHorizontalAlignment(buttons, HasAlignment.ALIGN_RIGHT)
        self.bar.add(self.status, DockPanel.CENTER)
        self.bar.setVerticalAlignment(HasAlignment.ALIGN_MIDDLE)
        self.bar.setCellHorizontalAlignment(self.status,
                                            HasAlignment.ALIGN_RIGHT)
        self.bar.setCellVerticalAlignment(self.status,
                                          HasAlignment.ALIGN_MIDDLE)
        self.bar.setCellWidth(self.status, "100%")

        self.gotoPrev.setEnabled(False)
        self.gotoFirst.setEnabled(False)

    def onClick(self, sender):
        if sender == self.gotoNext:
            self.owner.startRow += self.owner.getDataRowCount()
            self.owner.refresh()
        elif sender == self.gotoPrev:
            self.owner.startRow -= self.owner.getDataRowCount()
            if self.owner.startRow < 0:
                self.owner.startRow = 0
            self.owner.refresh()
        elif sender == self.gotoFirst:
            self.owner.startRow = 0
            self.owner.refresh()
Ejemplo n.º 31
0
class NavBar(Composite):

    def __init__(self, owner):
        Composite.__init__(self)
        self.owner = owner
        self.bar = DockPanel()
        self.gotoFirst = Button("&lt;&lt;", self)
        self.gotoNext = Button("&gt;", self)
        self.gotoPrev = Button("&lt;", self)
        self.status = HTML()
        
        self.initWidget(self.bar)
        self.bar.setStyleName("navbar")
        self.status.setStyleName("status")
        
        buttons = HorizontalPanel()
        buttons.add(self.gotoFirst)
        buttons.add(self.gotoPrev)
        buttons.add(self.gotoNext)
        self.bar.add(buttons, DockPanel.EAST)
        self.bar.setCellHorizontalAlignment(buttons, HasAlignment.ALIGN_RIGHT)
        self.bar.add(self.status, DockPanel.CENTER)
        self.bar.setVerticalAlignment(HasAlignment.ALIGN_MIDDLE)
        self.bar.setCellHorizontalAlignment(self.status, HasAlignment.ALIGN_RIGHT)
        self.bar.setCellVerticalAlignment(self.status, HasAlignment.ALIGN_MIDDLE)
        self.bar.setCellWidth(self.status, "100%")
        
        self.gotoPrev.setEnabled(False)
        self.gotoFirst.setEnabled(False)
        
    def onClick(self, sender):
        if sender == self.gotoNext:
            self.owner.startRow += self.owner.getDataRowCount()
            self.owner.refresh()
        elif sender == self.gotoPrev:
            self.owner.startRow -= self.owner.getDataRowCount()
            if self.owner.startRow < 0:
                self.owner.startRow = 0
            self.owner.refresh()
        elif sender == self.gotoFirst:
            self.owner.startRow = 0
            self.owner.refresh()
Ejemplo n.º 32
0
    def __init__(self, conf_dict={}):
        self.__dict__.update(conf_dict)
        self.screen = pg.display.set_mode(self.WINDOW_SIZE)
        pg.display.set_caption("Flood it!")
        pg.font.init()
        self.font = pg.font.SysFont("AR PL UMing CN", int(20 * ZOOM))
        self.screen.fill([200, 200, 200])
        self.table = GameTable(self.COLORS.keys(),
                               self.TABLE_SIZE,
                               self.TABLE_POSITION,
                               self.BLOCK_SIDE)

        # 色块按钮起始坐标
        cl_x = self.TABLE_POSITION[0] + \
            self.BLOCK_SIDE * (self.TABLE_SIZE[0] + 1)
        cl_y = self.TABLE_POSITION[1] + \
            self.BLOCK_SIDE * (self.TABLE_SIZE[1] - 1)

        # "New game"按钮
        x = self.TABLE_POSITION[0] + self.BLOCK_SIDE * (self.TABLE_SIZE[0] + 1)
        w = self.BLOCK_SIDE * (len(self.COLORS) * 2 - 1)
        y = self.TABLE_POSITION[1]
        h = self.BLOCK_SIDE * 2
        self.rb = Button((x, y), (w, h), text=u"New Game!",
                         fontsize=int(20 * ZOOM))
        self.rb.show(self.screen)
        self.events = ClickEventListen()
        self.events.register(self.rb, self.reset)

        # 初始化色块按钮
        left = cl_x
        self.color_buttons = []
        for k, v in self.COLORS.iteritems():
            button = Button((left, cl_y), (self.BLOCK_SIDE,
                                           self.BLOCK_SIDE), color=v, fontsize=int(20 * ZOOM))
            button.show(self.screen)
            self.color_buttons.append(button)
            self.events.register(button, self.colors_click, number=k)
            left += self.BLOCK_SIDE * 2
        self.table.draw(self.screen, BLOCK_COLORS)
        self.wined = False
Ejemplo n.º 33
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self._game_data = {}

        self.state = self.READY

        self._timer = GameTimer()

        self._active_elements = []

        self._start_button = Button(
            'start_button', 'Start Game!', Button.CENTRE, 400)

        self._pause_button = Button(
            'pause_button', 'Pause', Button.CENTRE, 400)

        self._resume_button = Button(
            'resume_button', 'Resume!', Button.CENTRE, 400)

        self._active_elements = [
            self._start_button
        ]
Ejemplo n.º 34
0
class GridTest:
    def onModuleLoad(self):
        self.page = 0
        self.min_page = 1
        self.max_page = 10

        self.add = Button("Next >", self)
        self.sub = Button("< Prev", self)

        self.g = Grid()
        self.g.resize(5, 5)
        self.g.setHTML(0, 0, "<b>Grid Test</b>")
        self.g.setBorderWidth(2)
        self.g.setCellPadding(4)
        self.g.setCellSpacing(1)

        self.updatePageDisplay()
        RootPanel().add(self.sub)
        RootPanel().add(self.add)
        RootPanel().add(self.g)

    def onClick(self, sender):
        if sender == self.add:
            self.page += 1
        elif sender == self.sub:
            self.page -= 1
        self.updatePageDisplay()

    def updatePageDisplay(self):
        if self.page < self.min_page: self.page = self.min_page
        elif self.page > self.max_page: self.page = self.max_page
        total_pages = (self.max_page - self.min_page) + 1

        self.g.setHTML(0, 4,
                       "<b>page " + self.page + ' of ' + total_pages + "</b>")

        if self.page >= self.max_page:
            self.add.setEnabled(False)
        else:
            self.add.setEnabled(True)

        if self.page <= self.min_page:
            self.sub.setEnabled(False)
        else:
            self.sub.setEnabled(True)

        for y in range(1, 5):
            for x in range(5):
                self.g.setText(y, x, self.page + ' (' + y + ',' + x + ')')
Ejemplo n.º 35
0
    def __init__(self):
        Sink.__init__(self)
        disabledButton = Button("Disabled Button")
        disabledCheck = CheckBox("Disabled Check")
        normalButton = Button("Normal Button")
        normalCheck = CheckBox("Normal Check")
        panel = VerticalPanel()
        radio0 = RadioButton("group0", "Choice 0")
        radio1 = RadioButton("group0", "Choice 1")
        radio2 = RadioButton("group0", "Choice 2 (Disabled)")
        radio3 = RadioButton("group0", "Choice 3")

        hp=HorizontalPanel()
        panel.add(hp)
        hp.setSpacing(8)
        hp.add(normalButton)
        hp.add(disabledButton)
        
        hp=HorizontalPanel()
        panel.add(hp)
        hp.setSpacing(8)
        hp.add(normalCheck)
        hp.add(disabledCheck)
        
        hp=HorizontalPanel()
        panel.add(hp)
        hp.setSpacing(8)
        hp.add(radio0)
        hp.add(radio1)
        hp.add(radio2)
        hp.add(radio3)
        
        disabledButton.setEnabled(False)
        disabledCheck.setEnabled(False)
        radio2.setEnabled(False)
        
        panel.setSpacing(8)
        self.initWidget(panel)
    def __init__(self):
        disabledButton = Button("Disabled Button")
        disabledCheck = CheckBox("Disabled Check")
        normalButton = Button("Normal Button")
        normalCheck = CheckBox("Normal Check")
        panel = VerticalPanel()
        radio0 = RadioButton("group0", "Choice 0")
        radio1 = RadioButton("group0", "Choice 1")
        radio2 = RadioButton("group0", "Choice 2 (Disabled)")
        radio3 = RadioButton("group0", "Choice 3")

        hp = HorizontalPanel()
        panel.add(hp)
        hp.setSpacing(8)
        hp.add(normalButton)
        hp.add(disabledButton)

        hp = HorizontalPanel()
        panel.add(hp)
        hp.setSpacing(8)
        hp.add(normalCheck)
        hp.add(disabledCheck)

        hp = HorizontalPanel()
        panel.add(hp)
        hp.setSpacing(8)
        hp.add(radio0)
        hp.add(radio1)
        hp.add(radio2)
        hp.add(radio3)

        disabledButton.setEnabled(False)
        disabledCheck.setEnabled(False)
        radio2.setEnabled(False)

        panel.setSpacing(8)
        self.setWidget(panel)
Ejemplo n.º 37
0
def draw_promotion_prompt(screen, screen_width, screen_height, bwidth):
    board_center = position_to_board((3, 4), bwidth)
    screen_center = board_to_screen(board_center, screen_width, screen_height,
                                    bwidth)
    # Prompt window
    window = Window(250, 100)
    window.set_position(screen_center)
    # Yes and No buttons
    yes_button = Button('yes', 100, 50, GREEN)
    yes_button.set_position(
        (screen_center[0] + 10, screen_center[1] + 2 * window.height / 4))
    no_button = Button('no', 100, 50, RED)
    no_button.set_position(
        (2 * screen_center[0] - 140, screen_center[1] + 2 * window.height / 4))
    window.add_buttons([yes_button, no_button])
    # Draw window and buttons
    window.draw(screen)

    # Draw prompt at the center
    font = pygame.font.SysFont(None, 25)
    text_surf = font.render("Do you wish to promote?", True, BLACK)
    text_rect = text_surf.get_rect()
    board_center = position_to_board((5, 4), bwidth)
    screen_center = board_to_screen(board_center, screen_width, screen_height,
                                    bwidth)
    text_rect.center = (screen_center[0] + 25, screen_center[1] + 25)
    screen.blit(text_surf, text_rect)

    yes_surf = font.render("Yes", True, BLACK)
    yes_rect = yes_surf.get_rect()
    board_center = position_to_board((4, 5), bwidth)
    screen_center = board_to_screen(board_center, screen_width, screen_height,
                                    bwidth)
    yes_rect.center = (screen_center[0] + 10, screen_center[1] + 25)
    screen.blit(yes_surf, yes_rect)

    no_surf = font.render("No", True, BLACK)
    no_rect = no_surf.get_rect()
    board_center = position_to_board((6, 5), bwidth)
    screen_center = board_to_screen(board_center, screen_width, screen_height,
                                    bwidth)
    no_rect.center = (screen_center[0] + 40, screen_center[1] + 25)
    screen.blit(no_surf, no_rect)

    return window
    """
Ejemplo n.º 38
0
    def initialize(self):
        print(f"Initializing the '{self.sceneName}' level...")

        self.gameOverTxt = Text(400, 100, "courier new", 100, "GAME OVER!",
                                colour.LORANGE, Justify.CENTER)
        self.scoreTxt = Text(400, 200, "courier new", 50,
                             f"SCORE: {self.score}", colour.RED,
                             Justify.CENTER)

        self.againBtn = Button(225, 370, 350, 50, "PLAY AGAIN?")
        self.quitBtn = Button(330, 450, 140, 50, "QUIT")

        # assign button colour
        self.againBtn.set_button_colour(colour.LIGHTBLUE, None)
        self.quitBtn.set_button_colour(colour.LIGHTBLUE, None)

        # assign action functions to handle button click events
        self.againBtn.actionFunc = self.__onAgainBtnClicked__
        self.quitBtn.actionFunc = self.__onQuitBtnClicked__

        self.background = load_image("background1.gif")

        self.playAgain = False
        self.quitGame = False
 def onModuleLoad(self):
     b = Button("Click me", greet)
     RootPanel().add(b)
     if (1 or 0) and 0:
         RootPanel().add(Label("or FAILED"))
     else:
         RootPanel().add(Label("or OK"))
     if 0 & 1 == 0:
         RootPanel().add(Label("& OK"))
     else:
         RootPanel().add(Label("& FAILED"))
     if 1 | 1 != 1:
         RootPanel().add(Label("| FAILED"))
     else:
         RootPanel().add(Label("| OK"))
Ejemplo n.º 40
0
 def __init__(self):
     self.fDialogButton = Button("Show Dialog", self)
     self.fPopupButton = Button("Show Popup", self)
     
     panel = VerticalPanel()
     panel.add(self.fPopupButton)
     panel.add(self.fDialogButton)
     
     list = ListBox()
     list.setVisibleItemCount(5)
     for i in range(10):
         list.addItem("list item " + i)
     panel.add(list)
     
     panel.setSpacing(8)
     self.initWidget(panel)
Ejemplo n.º 41
0
    def __init__(self, title, message, affirmative_label,
                 decline_label = "Cancel", width=500, modal = False):
        Dialog.__init__(self, title = title, width = width, modal=modal)

        scrollbox = ScrollArea(Label(markup=message, padding=5, overflow=pango.WrapMode.WORD),
                                    scroll_horizontal = False,
                                    border = 0,
                                    margin=2, margin_right=3,
                                    height = 150)

        affirmative = Button(affirmative_label, id="affirmative_button")
        affirmative.connect("on-click", self._on_button_click)
        decline = Button(decline_label, id="decline_button")
        decline.connect("on-click", self._on_button_click)

        self.box.contents = VBox([scrollbox, HBox([HBox(), decline, affirmative], expand=False, padding=10)])
Ejemplo n.º 42
0
 def __init__(self, text):
     Button.__init__(self, text)
     self.color = "#444"
     self.get_min_size = lambda: (0, Label.get_min_size(self)[1])
Ejemplo n.º 43
0
    def __init__(self, padding = 0, direction = "up", **kwargs):
        Button.__init__(self, padding = padding, **kwargs)
        self.expand = False

        #: button direction - one of "up", "down", "left", "right"
        self.direction = direction
Ejemplo n.º 44
0
 def __init__(self, padding = 0, **kwargs):
     Button.__init__(self, padding = padding, **kwargs)
     self.draggable = True
     self.expand = False
     self.connect("on-drag", self.on_drag)
Ejemplo n.º 45
0
    def __init__(self, up=True, expand=False, width = 15, padding=0, repeat_down_delay = 100, **kwargs):

        Button.__init__(self, expand=expand, width=width, padding=padding,
                        repeat_down_delay=repeat_down_delay, **kwargs)
        self.up = up
Ejemplo n.º 46
0
class Floodit(object):
    """游戏"""

    def __init__(self, conf_dict={}):
        self.__dict__.update(conf_dict)
        self.screen = pg.display.set_mode(self.WINDOW_SIZE)
        pg.display.set_caption("Flood it!")
        pg.font.init()
        self.font = pg.font.SysFont("AR PL UMing CN", int(20 * ZOOM))
        self.screen.fill([200, 200, 200])
        self.table = GameTable(self.COLORS.keys(),
                               self.TABLE_SIZE,
                               self.TABLE_POSITION,
                               self.BLOCK_SIDE)

        # 色块按钮起始坐标
        cl_x = self.TABLE_POSITION[0] + \
            self.BLOCK_SIDE * (self.TABLE_SIZE[0] + 1)
        cl_y = self.TABLE_POSITION[1] + \
            self.BLOCK_SIDE * (self.TABLE_SIZE[1] - 1)

        # "New game"按钮
        x = self.TABLE_POSITION[0] + self.BLOCK_SIDE * (self.TABLE_SIZE[0] + 1)
        w = self.BLOCK_SIDE * (len(self.COLORS) * 2 - 1)
        y = self.TABLE_POSITION[1]
        h = self.BLOCK_SIDE * 2
        self.rb = Button((x, y), (w, h), text=u"New Game!",
                         fontsize=int(20 * ZOOM))
        self.rb.show(self.screen)
        self.events = ClickEventListen()
        self.events.register(self.rb, self.reset)

        # 初始化色块按钮
        left = cl_x
        self.color_buttons = []
        for k, v in self.COLORS.iteritems():
            button = Button((left, cl_y), (self.BLOCK_SIDE,
                                           self.BLOCK_SIDE), color=v, fontsize=int(20 * ZOOM))
            button.show(self.screen)
            self.color_buttons.append(button)
            self.events.register(button, self.colors_click, number=k)
            left += self.BLOCK_SIDE * 2
        self.table.draw(self.screen, BLOCK_COLORS)
        self.wined = False

    def show(self):
        pg.display.flip()

    def colors_click(self, number=None):
        assert number, "CLICK ERROR!"
        if self.wined:
            return
        if number in self.COLORS.keys():
            fill.fill(self.table, number, x=0, y=0)
            self.table.draw(self.screen, BLOCK_COLORS)
            self.wined = self.win()
        self.show()

    def win(self):
        if fill.filldone(self.table):
            font = pg.font.SysFont("AR PL UMing CN", int(32 * ZOOM))
            win_text = font.render("win", 1, (0, 0, 0))
            self.winrect = win_text.get_rect()
            self.winrect.centerx = (self.rb.x + self.rb.x1) // 2
            self.winrect.centery = self.rb.y1 * 2
            pg.draw.rect(self.screen, [200, 200, 200], self.winrect)
            self.screen.blit(win_text, self.winrect)
            return True
        return False

    def reset(self):
        self.wined = False
        del self.table
        self.table = GameTable(self.COLORS.keys(),
                               self.TABLE_SIZE,
                               self.TABLE_POSITION,
                               self.BLOCK_SIDE)
        self.table.draw(self.screen, BLOCK_COLORS)
        pg.draw.rect(self.screen, [200, 200, 200], self.winrect)
        self.show()

    def mainloop(self):
        while 1:
            events = pg.event.get()
            for event in events:
                if event.type == pg.QUIT:
                    sys.exit(0)
                self.events.listen(event)
Ejemplo n.º 47
0
 def do_render(self):
     if self.state == "normal":
         self.graphics.fill_area(0, 0, self.width, self.height, "#EDECEB")
     else:
         Button.do_render(self)
Ejemplo n.º 48
0
 def __init__(self, label="", pressed_offset = 0, expanded = False, **kwargs):
     Button.__init__(self, label=label, pressed_offset = pressed_offset, **kwargs)
     self.expanded = expanded
Ejemplo n.º 49
0
 def _position_contents(self):
     Button._position_contents(self)
     if hasattr(self, "secondary_display_label"):
         self.container.add_child(self.secondary_display_label)