コード例 #1
0
ファイル: buttons.py プロジェクト: scousematt/SpaceGame
    def __init__(self,
                 panel,
                 x,
                 y,
                 function_list,
                 text,
                 default_dict=base_gui.load_defaults()):
        DefaultButton.__init__(self,
                               panel,
                               x,
                               y,
                               function_list,
                               default_dict=base_gui.load_defaults())

        self.text = text

        button_dict = {
            'label_color':
            (200, 200, 200),  #self.default_dict['button_text_color'],
            'label_font': self.default_dict['button_font'],
            'label_fontsize': self.default_dict['button_fontsize']
        }
        self.children.append(
            labels.ButtonLabel(self.text,
                               self,
                               self.rect.x,
                               self.rect.y,
                               justify='center',
                               default_dict=button_dict))
コード例 #2
0
    def __init__(self,
                 text,
                 parent,
                 x,
                 y,
                 justify='left',
                 default_dict=base_gui.load_defaults(),
                 fontsize=None,
                 label_name=None):
        DefaultLabel.__init__(self,
                              text,
                              parent,
                              x,
                              y,
                              justify='left',
                              default_dict=base_gui.load_defaults(),
                              fontsize=None,
                              label_name=None)

        self.background_rect = self.children[0].rect.inflate(24, 2)
        self.background_rect.x += 10
        self.children = []
        self.children.append(
            DropDownColorBlock(self.parent,
                               self.default_dict['dropdown_label_back_color'],
                               self.background_rect))
        #  The image corrects itself and so does the label, the x needs to be reduced by panel.x
        self.image_rect = pygame.Rect(
            self.background_rect.right - 20 - self.parent.x,
            self.background_rect.top + 2, 20, 20)
        self.children.append(
            fundamentals.Image('dropdown.png', self.parent, self.image_rect))

        self.update_text_surface()
コード例 #3
0
ファイル: buttons.py プロジェクト: scousematt/SpaceGame
 def __init__(self,
              panel,
              x,
              y,
              function_list,
              image,
              default_dict=base_gui.load_defaults()):
     ButtonImage.__init__(self, panel, x, y, function_list, image)
コード例 #4
0
    def __init__(self, gui, title, text,
                 default_dict=base_gui.load_defaults()):

        self.gui = gui
        self.title = title
        self.text = text
        self.default_dict = default_dict

        self.set_panel_sizes()
        self.set_active()
コード例 #5
0
    def __init__(self,
                 text,
                 parent,
                 x,
                 y,
                 justify='left',
                 default_dict=base_gui.load_defaults(),
                 fontsize=None,
                 label_name=None):
        DefaultLabel.__init__(self,
                              text,
                              parent,
                              x,
                              y,
                              justify='left',
                              default_dict=base_gui.load_defaults(),
                              fontsize=None,
                              label_name=None)

        self.highlight = False
コード例 #6
0
ファイル: color_blocks.py プロジェクト: scousematt/SpaceGame
 def __init__(self,
              panel,
              color,
              rect,
              border_thickness,
              default_dict=base_gui.load_defaults(),
              drag_with_mouse=False):
     PanelColorBlock.__init__(self,
                              panel,
                              color,
                              rect,
                              drag_with_mouse=False)
     self.border_thickness = border_thickness
コード例 #7
0
ファイル: color_blocks.py プロジェクト: scousematt/SpaceGame
 def __init__(self,
              panel,
              color,
              rect,
              default_dict=base_gui.load_defaults()):
     # This is for things internal to panels where a block of color is needed, things like message box title background
     # it is essentially a colored pygame.rect
     base_gui.BaseGui.__init__(self)
     self.parent = panel
     self.color = color
     self.rect = rect
     self.default_dict = default_dict
     self.str = f'{type(self)} with color {self.color}'
コード例 #8
0
ファイル: panels.py プロジェクト: scousematt/SpaceGame
 def __init__(self,
              gui,
              name,
              x,
              y,
              width,
              height,
              full_list,
              view_num,
              dropdown,
              default_dict=base_gui.load_defaults(),
              visible=True,
              active=True):
     PanelScroll.__init__(self, gui, name, x, y, width, height, full_list,
                          view_num)
     #  As the name implies, this is created and controlled by a drop down label from another panel.
     self.dropdown = dropdown
     self.active_label = None
     self.highlight = None  # On mouseover
     self.old_highlight = True
コード例 #9
0
ファイル: panels.py プロジェクト: scousematt/SpaceGame
    def __init__(self,
                 gui,
                 name,
                 x,
                 y,
                 width,
                 height,
                 full_list,
                 view_num,
                 default_dict=base_gui.load_defaults(),
                 visible=True,
                 active=True):
        # DefaultPanel.__init__(self, gui, name, x, y, width, height, default_dict=load_defaults(), visible=True,
        # 					  active=True)
        DefaultPanel.__init__(self, gui, name, x, y, width, height)

        self.full_list = full_list
        self.view_num = view_num
        self.scrollbar = None
        self.scrollbar_changed = False
コード例 #10
0
ファイル: panels.py プロジェクト: scousematt/SpaceGame
    def __init__(self,
                 gui,
                 name,
                 x,
                 y,
                 width,
                 height,
                 default_dict=base_gui.load_defaults(),
                 visible=True,
                 active=True):
        base_gui.BaseGui.__init__(self)

        self.visible = visible
        self.active = active
        self.name = name
        self.x = x
        self.y = y
        self.width = width
        self.height = height
        self.gui = gui
        self.screen = self.gui.screen
        self.error = {}
        self.default_dict = default_dict
        self.background_color = self.default_dict['panel_background_color']
        self.border_color = self.default_dict['panel_border_color']

        self.changed = False  # updated by self.children objects
        self.children = []
        #  Elements of the object that will be displayed no matter the internal movement of the children. This is where images for corners
        #  and title bars, [x], etc would be.
        self.static_children = []
        self.rect = pygame.Rect(self.x, self.y, self.width, self.height)
        self.static_children.append(
            PanelColorBlock(self, self.background_color, self.rect))
        self.static_children.append(
            BlockWithBorder(self, self.border_color, self.rect,
                            self.default_dict['panel_border']))
        #  What is this used for?
        self.named_children_dict = {}

        self.str = f'{self.name} {type(self)} at {self.x}, {self.y}'
コード例 #11
0
ファイル: buttons.py プロジェクト: scousematt/SpaceGame
    def __init__(self,
                 panel,
                 x,
                 y,
                 function_list,
                 image,
                 default_dict=base_gui.load_defaults()):
        DefaultButton.__init__(self, panel, x, y, function_list, default_dict)
        # TODO All images are assumed to be square

        #  Center the image in the button.
        x_ = self.x + 0.5 * (self.button_width - self.button_height)

        #  This rect is for the image size not mouse click detection.
        self.image_rect = pygame.Rect(x_ - self.parent.x,
                                      self.y - self.parent.x,
                                      self.button_height, self.button_height)
        # Resize image to fit in button
        self.image = image

        self.setup()
コード例 #12
0
ファイル: panels.py プロジェクト: scousematt/SpaceGame
 def __init__(self,
              gui,
              name,
              x,
              y,
              width,
              height,
              default_dict=base_gui.load_defaults(),
              visible=True,
              active=True):
     DefaultPanel.__init__(self, gui, name, x, y, width, height)
     self.scrollbar = False
     #  While self.rect is the panel dimension, need a value for the overall height of the contents regardless of what is displayed.
     self.total_y = self.rect.height
     #  Displayed rect is the show output from total_rect, initially set to the panel rect
     self.display_rect = pygame.Rect(
         self.rect.x, self.rect.y, self.rect.w, self.rect.h
     )  #  Making sure that the 2 rects are not same in memory.
     self.old_display_rect_y = self.display_rect.y
     self.change_y = 0
     self.total_change_y = 0
     self.lowest_y = 0
     self.str = f'DynamicScrollbar'
コード例 #13
0
ファイル: panels.py プロジェクト: scousematt/SpaceGame
    def __init__(self,
                 gui,
                 name,
                 title,
                 text,
                 default_dict=base_gui.load_defaults(),
                 visible=True,
                 active=True,
                 image=None):
        dialogs.DefaultDialog.__init__(self,
                                       gui,
                                       title,
                                       text,
                                       default_dict=base_gui.load_defaults())
        DefaultPanel.__init__(self,
                              gui,
                              name,
                              self.x,
                              self.y,
                              self.width,
                              self.height,
                              default_dict=base_gui.load_defaults(),
                              visible=True,
                              active=True)

        self.static_children.append(
            PanelColorBlock(self,
                            self.default_dict['msg_title_background_color'],
                            self.title_rect,
                            drag_with_mouse=True))
        #  Use the title bar to detect mouse drag and drop
        self.title_bar = self.static_children[-1]
        self.static_children.append(
            labels.DefaultLabel(self.title,
                                self,
                                self.default_dict['msg_title_x'],
                                self.default_dict['msg_title_y'],
                                justify='centerx'))

        #  If there is an image, add the image. Need a rect for the image, so lets make one here.
        image_packer = 0
        if image:
            image_rect = pygame.Rect(
                self.default_dict['dialog_image_border'],
                self.default_dict['dialog_image_border'] +
                self.default_dict['msg_text_y'],
                self.width - 2 * default_dict['dialog_image_border'],
                default_dict['dialog_image_height'])
            self.children.append(fundamentals.Image(image, self, image_rect))
            image_packer = image_rect.bottom + self.default_dict['msg_text_y']
            self.end_of_text_y += image_packer
            self.rect.height += image_packer

        #  Add the main text
        for i, line in enumerate(self.formatted_text):
            self.create_label(line,
                              self.default_dict['msg_text_x'],
                              self.default_dict['msg_text_y'] + i *
                              (self.default_dict['msg_label_fontsize'] + 5) +
                              image_packer,
                              fontsize=self.default_dict['msg_label_fontsize'])

        #  Add to gui dialogs.
        self.gui.dialog_dict[self.name] = self
コード例 #14
0
    def __init__(self,
                 text,
                 parent,
                 x,
                 y,
                 justify='left',
                 default_dict=base_gui.load_defaults(),
                 fontsize=None,
                 label_name=None):
        base_gui.BaseGui.__init__(self)
        self.default_dict = default_dict
        self.parent = parent
        self.text = ''  # We establish self.text in the method self.change_text(text)
        self.rect = None
        self.x = x
        self.y = y

        if isinstance(text, (int, float)):
            # here we can test to see if we want colored numbers (red , green) or brackets around -ve
            text = f'{text}'

        self.name = label_name

        #  Set the label to screen coordinates.
        self.set_screen_coords()

        self.default_dict = default_dict
        self.justify = justify  #  Left, right, on centre y.

        self.text_color = self.default_dict['label_color']
        # Set the screen based on the parent type

        #  Setup output for __str__.
        self.str = f'{type(self)} {self.text} from Parent {self.parent}, Justify {self.justify}'

        #  Move all of this somewhere else, it shouldn't be in the __init__, confusing.
        if isinstance(self.parent, OBJECTS_WITH_TEXT_NOT_PANEL):
            self.screen = self.parent.parent.screen
        else:
            self.screen = self.parent.screen

        self.fontname = self.default_dict['label_font']

        if fontsize == None:
            self.fontsize = self.default_dict['label_fontsize']
        else:
            self.fontsize = base_gui.return_correct_type(fontsize)

        try:
            # Check to see if a font object has already been created
            self.font = self.parent.gui.font_dict[''.join(
                [self.fontname, str(self.fontsize)])]
        except KeyError:
            self.font = pygame.font.Font(self.fontname, self.fontsize)
            self.parent.gui.font_dict[''.join(
                [self.fontname, str(self.fontsize)])] = self.font
        except:
            try:
                # A dropdown list is the parent, rather than a panel, same with buttons
                self.font = self.parent.parent.gui.font_dict[''.join(
                    [self.fontname, str(self.fontsize)])]
            except KeyError:
                self.font = pygame.font.Font(self.fontname, self.fontsize)
                self.parent.parent.gui.font_dict[''.join(
                    [self.fontname, str(self.fontsize)])] = self.font

            except:
                self.error['font'] = True
        if not self.is_error():
            self.change_text(text)
コード例 #15
0
ファイル: buttons.py プロジェクト: scousematt/SpaceGame
 def __init__(self, panel, x, y, default_dict=base_gui.load_defaults()):
     Button.__init__(self, panel, x, y, [], 'OK', default_dict)
     for child in self.children:
         print(child.rect, type(child))
     self.function_list = [self.parent.close_dialog]
     self.on_click_method = self.function_list[0]
コード例 #16
0
import pygame

pygame.init()
screen = pygame.display.set_mode((800, 600))
pygame.display.set_caption('Put active panel name in here')
import base_gui

gui_defaults = base_gui.load_defaults()

gui = base_gui.GuiManager(screen, gui_defaults)


class Game():
    def __init__(self, value):
        self.value = value


game = Game(67)


def some_func(button):
    button.panel.change_background_color((23, 0, 100))
    button.change_text('test1')
    gui.change_label_text('Info', 'game_value', game.value)
    game.value += 10


def another_func(button):
    button.panel.change_background_color((23, 200, 200))
    button.change_text('test2')