예제 #1
0
    def layout(self, x, y):
        """
        Lays out the child Widgets, in order from left to right.

        @param x X coordinate of the lower left corner
        @param y Y coordinate of the lower left corner
        """
        Widget.layout(self, x, y)

        # Expand any expandable content to our height
        for item in self.content:
            if item.is_expandable() and item.height < self.height:
                item.expand(item.width, self.height)

        left = x
        if self.align == VALIGN_TOP:
            for item in self.content:
                item.layout(left, y + self.height - item.height)
                left += item.width + self.padding
        elif self.align == VALIGN_CENTER:
            for item in self.content:
                item.layout(left, y + self.height/2 - item.height/2)
                left += item.width + self.padding
        else: # VALIGN_BOTTOM
            for item in self.content:
                item.layout(left, y)
                left += item.width + self.padding
예제 #2
0
    def layout(self, x, y):
        """
        Lays out the child Widgets, in order from left to right.

        @param x X coordinate of the lower left corner
        @param y Y coordinate of the lower left corner
        """
        Widget.layout(self, x, y)

        # Expand any expandable content to our height
        for item in self.content:
            if item.is_expandable() and item.height < self.height:
                item.expand(item.width, self.height)

        left = x
        if self.align == VALIGN_TOP:
            for item in self.content:
                item.layout(left, y + self.height - item.height)
                left += item.width + self.padding
        elif self.align == VALIGN_CENTER:
            for item in self.content:
                item.layout(left, y + self.height / 2 - item.height / 2)
                left += item.width + self.padding
        else:  # VALIGN_BOTTOM
            for item in self.content:
                item.layout(left, y)
                left += item.width + self.padding
예제 #3
0
    def layout(self, x, y):
        """
        Lays out the child Widgets, in order from top to bottom.

        @param x X coordinate of the lower left corner
        @param y Y coordinate of the lower left corner
        """
        Widget.layout(self, x, y)

        # Expand any expandable content to our width
        for item in self.content:
            if item.is_expandable() and item.width < self.width:
                item.expand(self.width, item.height)

        top = y + self.height
        if self.align == HALIGN_RIGHT:
            for item in self.content:
                item.layout(x + self.width - item.width,
                            top - item.height)
                top -= item.height + self.padding
        elif self.align == HALIGN_CENTER:
            for item in self.content:
                item.layout(x + self.width/2 - item.width/2,
                            top - item.height)
                top -= item.height + self.padding
        else: # HALIGN_LEFT
            for item in self.content:
                item.layout(x, top - item.height)
                top -= item.height + self.padding
예제 #4
0
    def __init__(self, content=None, window=None, batch=None, group=None,
                 anchor=ANCHOR_CENTER, offset=(0, 0), parent=None,
                 theme=None, movable=True, on_enter=None, on_escape=None):
        """
        Creates a new dialog.

        @param content The Widget which we wrap
        @param window The window to which we belong; used to set the
                      mouse cursor when appropriate.  If set, we will
                      add ourself to the window as a handler.
        @param batch Batch in which we are to place our graphic elements;
                     may be None if we are to create our own Batch
        @param group Group in which we are to place our graphic elements;
                     may be None
        @param anchor Anchor point of the window, relative to which we
                      are positioned.  If ANCHOR_TOP_LEFT is specified,
                      our top left corner will be aligned to the window's
                      top left corner; if ANCHOR_CENTER is specified,
                      our center will be aligned to the window's center,
                      and so forth.
        @param offset Offset from the anchor point.  A positive X is always
                      to the right, a positive Y to the upward direction.
        @param theme The Theme which we are to use to generate our graphical
                     appearance.
        @param movable True if the dialog is able to be moved
        @param on_enter Callback for when user presses enter on the last
                        input within this dialog, i.e. form submit
        @param on_escape Callback for when user presses escape
        """
        assert isinstance(theme, dict)
        Wrapper.__init__(self, content=content)
        DialogEventManager.__init__(self)

        self.window = window
        self.anchor = anchor
        self.offset = offset
        self.theme = theme
        self.is_movable = movable
        self.on_enter = on_enter
        self.on_escape = on_escape
        if batch is None:
            self.batch = pyglet.graphics.Batch()
            self.own_batch = True
        else:
            self.batch = batch
            self.own_batch = False
        self.root_group = DialogGroup(parent=group)
        self.panel_group = pyglet.graphics.OrderedGroup(0, self.root_group)
        self.bg_group = pyglet.graphics.OrderedGroup(1, self.root_group)
        self.fg_group = pyglet.graphics.OrderedGroup(2, self.root_group)
        self.highlight_group = pyglet.graphics.OrderedGroup(3, self.root_group)
        self.needs_layout = True
        self.is_dragging = False

        if window is None:
            self.screen = Widget()
        else:
            width, height = window.get_size()
            self.screen = Widget(width=width, height=height)
            window.push_handlers(self)
예제 #5
0
    def layout(self, x, y):
        """
        Lays out the child Widgets, in order from top to bottom.

        @param x X coordinate of the lower left corner
        @param y Y coordinate of the lower left corner
        """
        Widget.layout(self, x, y)

        # Expand any expandable content to our width
        for item in self.content:
            if item.is_expandable() and item.width < self.width:
                item.expand(self.width, item.height)

        top = y + self.height
        if self.align == HALIGN_RIGHT:
            for item in self.content:
                item.layout(x + self.width - item.width, top - item.height)
                top -= item.height + self.padding
        elif self.align == HALIGN_CENTER:
            for item in self.content:
                item.layout(x + self.width / 2 - item.width / 2,
                            top - item.height)
                top -= item.height + self.padding
        else:  # HALIGN_LEFT
            for item in self.content:
                item.layout(x, top - item.height)
                top -= item.height + self.padding
예제 #6
0
 def setUp(self):
     self.sample_widget = Widget(
         name='sample',
         num_of_parts=5,
         created_date='2012-06-14',
         updated_date='2021-04-25',
         an_extra_prop=55555,
         a_complex_extra_prop={'stuff': [4.1, 'eggs', [3, 'spam']]})
예제 #7
0
    def size(self, dialog):
        """
        Recalculate the size of the Scrollable.

        @param dialog Dialog which contains us
        """
        if dialog is None:
            return
        Widget.size(self, dialog)
        if self.is_fixed_size:
            self.width, self.height = self.max_width, self.max_height

        self.hscrollbar_height = dialog.theme["hscrollbar"]["left"]["image"].height
        self.vscrollbar_width = dialog.theme["vscrollbar"]["up"]["image"].width

        if self.root_group is None:  # do we need to re-clone dialog groups?
            self.theme = dialog.theme
            self.batch = dialog.batch
            self.root_group = ScrollableGroup(0, 0, self.width, self.height, parent=dialog.fg_group)
            self.panel_group = pyglet.graphics.OrderedGroup(0, self.root_group)
            self.bg_group = pyglet.graphics.OrderedGroup(1, self.root_group)
            self.fg_group = pyglet.graphics.OrderedGroup(2, self.root_group)
            self.highlight_group = pyglet.graphics.OrderedGroup(3, self.root_group)
            Wrapper.delete(self)  # force children to abandon old groups

        Wrapper.size(self, self)  # all children are to use our groups

        if self.always_show_scrollbars or (self.max_width and self.width > self.max_width):
            if self.hscrollbar is None:
                self.hscrollbar = HScrollbar(self.max_width)
        else:
            if self.hscrollbar is not None:
                self.hscrollbar.delete()
                self.hscrollbar = None

        if self.always_show_scrollbars or (self.max_height and self.height > self.max_height):
            if self.vscrollbar is None:
                self.vscrollbar = VScrollbar(self.max_height)
        else:
            if self.vscrollbar is not None:
                self.vscrollbar.delete()
                self.vscrollbar = None

        self.width = min(self.max_width or self.width, self.width)
        self.content_width = self.width
        self.height = min(self.max_height or self.height, self.height)
        self.content_height = self.height

        if self.hscrollbar is not None:
            self.hscrollbar.size(dialog)
            self.hscrollbar.set(self.max_width, max(self.content.width, self.max_width))
            self.height += self.hscrollbar.height

        if self.vscrollbar is not None:
            self.vscrollbar.size(dialog)
            self.vscrollbar.set(self.max_height, max(self.content.height, self.max_height))
            self.width += self.vscrollbar.width
예제 #8
0
파일: frame.py 프로젝트: swindy/sy-game
    def layout(self, x, y):
        """
        Assigns a new position to the Wrapper.

        @param x X coordinate of the Wrapper's lower left corner
        @param y Y coordinate of the Wrapper's lower left corner
        """
        Widget.layout(self, x, y)
        if self.content is not None:
            x, y = GetRelativePoint(self, self.anchor, self.content, self.anchor, self.content_offset)
            self.content.layout(x, y)
예제 #9
0
파일: frame.py 프로젝트: swindy/sy-game
    def __init__(self, content=None, is_expandable=False, anchor=ANCHOR_CENTER, offset=(0, 0)):
        """
        Creates a new Wrapper around an included Widget.

        @param content The Widget to be wrapped.
        """
        Widget.__init__(self)
        self.content = content
        self.expandable = is_expandable
        self.anchor = anchor
        self.content_offset = offset
예제 #10
0
    def layout(self, x, y):
        """
        Assigns a new position to the Wrapper.

        @param x X coordinate of the Wrapper's lower left corner
        @param y Y coordinate of the Wrapper's lower left corner
        """
        Widget.layout(self, x, y)
        if self.content is not None:
            x, y = GetRelativePoint(self, self.anchor, self.content,
                                    self.anchor, self.content_offset)
            self.content.layout(x, y)
예제 #11
0
 def setUp(self):
     self.widget_store = WidgetStore()
     self.sample_widget_1 = Widget(
         name='sample1',
         num_of_parts=5,
         created_date='2012-06-14',
         updated_date='2021-04-25',
         an_extra_prop=55555,
         a_complex_extra_prop={'stuff': [4.1, 'eggs', [3, 'spam']]})
     self.sample_widget_2 = Widget(name='sample2',
                                   num_of_parts=10,
                                   created_date='2017-07-04',
                                   updated_date='2021-04-25')
예제 #12
0
    def size(self, dialog):
        """
        The default Wrapper wraps up its Widget snugly.

        @param dialog The Dialog which contains the Wrapper
        """
        if dialog is None:
            return
        Widget.size(self, dialog)
        if self.content is not None:
            self.content.size(dialog)
            self.width, self.height = self.content.width, self.content.height
        else:
            self.width = self.height = 0
예제 #13
0
    def ask_tricks(self, n):
        """
        Ask the user for the number of tricks.
        :param n: the maximum number of tricks
        """
        # Create the container with the fade in effect.
        container = Widget((self.screen.get_width()/2-200, 100), (400, self.screen.get_height()-120), 40)
        container.opacity = 0
        container.add_action(actions.FadeInAction(0.5))
        self._ask_tricks_widget = container
        self._background_widget.add_widget(container)

        # Create the question text.
        text_w = special_widgets.warning_widget((0, 0), (400, 60), "How many tricks do you make?", self._font,
                                                close_on_click=False)
        text_w.visible = True
        container.add_widget(text_w)

        # Create the numbers.
        class ChooseHandler(object):
            def __init__(self, view, nn):
                self._view = view
                self._n = nn
            def __call__(self, x, y):
                self._view._handle_say_tricks(self._n)
        for i in xrange(n+1):
            size = (50, 50)
            pos = ((i % 6) * (size[0]+20), 80 + (i/6) * (size[1] + 20))
            w = special_widgets.warning_widget(pos, size, str(i), self._font, close_on_click=False)
            w.visible = True
            w.handle_clicked = ChooseHandler(self, i)
            container.add_widget(w)
예제 #14
0
    def size(self, dialog):
        """
        The default Wrapper wraps up its Widget snugly.

        @param dialog The Dialog which contains the Wrapper
        """
        if dialog is None:
            return
        Widget.size(self, dialog)
        if self.content is not None:
            self.content.size(dialog)
            self.width, self.height = self.content.width, self.content.height
        else:
            self.width = self.height = 0
예제 #15
0
    def layout(self, x, y):
        """
        Lays out all Widgets within this layout.

        @param x X coordinate of lower left corner
        @param y Y coordinate of lower left corner
        """
        Widget.layout(self, x, y)

        row_index = 0
        placement = Widget()
        placement.y = y + self.height
        for row in self.content:
            col_index = 0
            placement.x = x
            placement.height = self.max_heights[row_index]
            placement.y -= placement.height
            for cell in row:
                placement.width = self.max_widths[col_index]
                if cell is not None:
                    if cell.is_expandable():
                        cell.expand(placement.width, placement.height)
                    cell.layout(*GetRelativePoint(placement, self.anchor, cell,
                                                  self.anchor, self.offset))
                placement.x += placement.width
                col_index += 1
            row_index += 1
예제 #16
0
    def __init__(self,
                 content=None,
                 is_expandable=False,
                 anchor=ANCHOR_CENTER,
                 offset=(0, 0)):
        """
        Creates a new Wrapper around an included Widget.

        @param content The Widget to be wrapped.
        """
        Widget.__init__(self)
        self.content = content
        self.expandable = is_expandable
        self.anchor = anchor
        self.content_offset = offset
예제 #17
0
    def __init__(self, content=[], align=HALIGN_CENTER, padding=5):
        """
        Creates a new VerticalLayout.

        @param content A list of Widgets to be arranged
        @param align HALIGN_LEFT if Widgets are to be left-justified,
                     HALIGN_CENTER if they should be centered, and
                     HALIGN_RIGHT if they are to be right-justified.
        @param padding This amount of padding is inserted between widgets.
        """
        assert isinstance(content, list) or isinstance(content, tuple)
        Widget.__init__(self)
        self.align = align
        self.padding = padding
        self.content = [x or Spacer() for x in content]
        self.expandable = []
예제 #18
0
 def test_widget_from_json_obj(self):
     with self.assertRaises(jsonschema.exceptions.ValidationError,
                            msg='invalid should fail'):
         Widget.from_json_obj({"Name": 5, "Creted": "dfgdfggdf"})
     sample_widget_json_rep = {
         "name": "sample",
         "num_of_parts": 5,
         "created_date": "2012-06-14",
         "updated_date": "2021-04-25",
         "an_extra_prop": 55555,
         "a_complex_extra_prop": {
             "stuff": [4.1, "eggs", [3, "spam"]]
         }
     }
     self.assertEqual(Widget.from_json_obj(sample_widget_json_rep),
                      self.sample_widget)
예제 #19
0
    def __init__(self, content=[], align=HALIGN_CENTER, padding=5):
        """
        Creates a new VerticalLayout.

        @param content A list of Widgets to be arranged
        @param align HALIGN_LEFT if Widgets are to be left-justified,
                     HALIGN_CENTER if they should be centered, and
                     HALIGN_RIGHT if they are to be right-justified.
        @param padding This amount of padding is inserted between widgets.
        """
        assert isinstance(content, list) or isinstance(content, tuple)
        Widget.__init__(self)
        self.align = align
        self.padding = padding
        self.content = [x or Spacer() for x in content]
        self.expandable = []
예제 #20
0
 def test_widget_eq(self):
     equal_widget = Widget(
         name='sample',
         num_of_parts=5,
         created_date='2012-06-14',
         updated_date='2021-04-25',
         an_extra_prop=55555,
         a_complex_extra_prop={'stuff': [4.1, 'eggs', [3, 'spam']]})
     non_equal_widget = Widget(
         name='cheese',
         num_of_parts=7,
         created_date='2021-04-14',
         updated_date='2021-04-14',
     )
     self.assertEqual(self.sample_widget, equal_widget)
     self.assertNotEqual(self.sample_widget, non_equal_widget)
예제 #21
0
    def _create_widgets(self):
        """
        Create the widgets and return the one that contains them all.
        :return: the background widget
        """
        # Create the background widget.
        bg = self._rm.get_image(BACKGROUND_IMAGE, self.screen.get_size())
        bg_widget = ImageWidget((0, 0), self.screen.get_size(), -1, bg)

        # Create the container for the input widgets.
        x = (self.screen.get_width() - INPUT_WIDTH - INPUT_PADDING[1] - INPUT_PADDING[3]) / 2
        y = self.screen.get_height() / 2
        w = INPUT_WIDTH + INPUT_PADDING[1] + INPUT_PADDING[3]
        h = self.screen.get_height() - y
        input_container = Widget((x, y), (w, h), 0)
        bg_widget.add_widget(input_container)

        # Create the input widgets.
        username_input = TextInput(
            (0, 0),
            INPUT_WIDTH,
            0,
            self._font,
            padding=INPUT_PADDING,
            color=INPUT_FORE_COLOR,
            fill=INPUT_FILL_COLOR,
            default_text="username",
            default_font=self._default_font,
        )
        host_input = copy.copy(username_input)
        host_input.default_text = "host"
        host_input.position = (0, INPUT_OFFSET)
        port_input = copy.copy(username_input)
        port_input.default_text = "port"
        port_input.position = (0, 2 * INPUT_OFFSET)
        input_container.add_widget(username_input)
        input_container.add_widget(host_input)
        input_container.add_widget(port_input)
        self._text_inputs = {"username": username_input, "host": host_input, "port": port_input}

        # Create the button widget.
        btn = special_widgets.simple_button((0, 3 * INPUT_OFFSET), (w, 100), "Login", self._font)

        def btn_clicked(x, y):
            self._ev_manager.post(events.LoginRequestedEvent())

        btn.handle_clicked = btn_clicked
        input_container.add_widget(btn)

        # Create the connection failed warning.
        self._connection_failed_warning = special_widgets.warning_widget(
            None, (400, 100), "Connection failed", self._font, screen_size=self.screen.get_size()
        )
        bg_widget.add_widget(self._connection_failed_warning)
        self._username_taken_warning = special_widgets.warning_widget(
            None, (400, 100), "Username already taken", self._font, screen_size=self.screen.get_size()
        )
        bg_widget.add_widget(self._username_taken_warning)

        return bg_widget
예제 #22
0
    def layout(self, x, y):
        """
        Lays out all Widgets within this layout.

        @param x X coordinate of lower left corner
        @param y Y coordinate of lower left corner
        """
        Widget.layout(self, x, y)

        row_index = 0
        placement = Widget()
        placement.y = y + self.height
        for row in self.content:
            col_index = 0
            placement.x = x
            placement.height = self.max_heights[row_index]
            placement.y -= placement.height
            for cell in row:
                placement.width = self.max_widths[col_index]
                if cell is not None:
                    if cell.is_expandable():
                        cell.expand(placement.width, placement.height)
                    cell.layout(*GetRelativePoint(placement, self.anchor,
                                                  cell, self.anchor,
                                                  self.offset))
                placement.x += placement.width
                col_index += 1
            row_index += 1
예제 #23
0
파일: frame.py 프로젝트: swindy/sy-game
    def layout(self, x, y):
        """
        Positions the Frame.

        @param x X coordinate of lower left corner
        @param y Y coordinate of lower left corner
        """
        self.x, self.y = x, y
        self.frame.update(x, y, self.width, self.height)

        # In some cases the frame graphic element may allocate more space for
        # the content than the content actually fills, due to repeating
        # texture constraints.  Always center the content.
        x, y, width, height = self.frame.get_content_region()
        interior = Widget(width, height)
        interior.x, interior.y = x, y
        x, y = GetRelativePoint(interior, self.anchor, self.content, self.anchor, self.content_offset)
        self.content.layout(x, y)
예제 #24
0
    def layout(self, x, y):
        """
        Positions the Frame.

        @param x X coordinate of lower left corner
        @param y Y coordinate of lower left corner
        """
        self.x, self.y = x, y
        self.frame.update(x, y, self.width, self.height)

        # In some cases the frame graphic element may allocate more space for
        # the content than the content actually fills, due to repeating
        # texture constraints.  Always center the content.
        x, y, width, height = self.frame.get_content_region()
        interior = Widget(width, height)
        interior.x, interior.y = x, y
        x, y = GetRelativePoint(interior, self.anchor, self.content,
                                self.anchor, self.content_offset)
        self.content.layout(x, y)
예제 #25
0
    def size(self, dialog):
        """
        Calculates size of the layout, based on its children.

        @param dialog The Dialog which contains the layout
        """
        if dialog is None:
            return
        Widget.size(self, dialog)
        height = 0
        if len(self.content) < 2:
            width = 0
        else:
            width = -self.padding
        for item in self.content:
            item.size(dialog)
            height = max(height, item.height)
            width += item.width + self.padding
        self.width, self.height = width, height
        self.expandable = [x for x in self.content if x.is_expandable()]
예제 #26
0
    def size(self, dialog):
        """
        Calculates size of the layout, based on its children.

        @param dialog The Dialog which contains the layout
        """
        if dialog is None:
            return
        Widget.size(self, dialog)
        height = 0
        if len(self.content) < 2:
            width = 0
        else:
            width = -self.padding
        for item in self.content:
            item.size(dialog)
            height = max(height, item.height)
            width += item.width + self.padding
        self.width, self.height = width, height
        self.expandable = [x for x in self.content if x.is_expandable()]
예제 #27
0
    def __init__(self, content=[[]], anchor=ANCHOR_TOP_LEFT, padding=5,
                 offset=(0, 0)):
        """
        Defines a new GridLayout.

        @param content A list of rows, each of which is a list of cells
                       within that row.  'None' may be used for empty cells,
                       and rows do not need to all be the same length.
        @param anchor Alignment of
        """
        assert ((isinstance(content, list) or isinstance(content, tuple)) and
                (len(content) == 0 or (isinstance(content[0], list) or
                                       isinstance(content[0], tuple))))
        Widget.__init__(self)
        self.content = content
        self.anchor = anchor
        self.padding = padding
        self.offset = offset
        self.max_heights = []
        self.max_widths = []
예제 #28
0
    def size(self, dialog):
        """Recalculates our size and the maximum widths and heights of
        each row and column in our table.

        @param dialog The Dialog within which we are contained
        """
        if dialog is None:
            return
        Widget.size(self, dialog)
        self.max_heights = [0] * len(self.content)
        width = 0
        for row in self.content:
            width = max(width, len(row))
        self.max_widths = [self.padding] * width
        row_index = 0
        for row in self.content:
            max_height = self.padding
            col_index = 0
            for cell in row:
                if cell is not None:
                    cell.size(dialog)
                    width, height = cell.width, cell.height
                else:
                    width = height = 0
                max_height = max(max_height, height + self.padding)
                max_width = self.max_widths[col_index]
                max_width = max(max_width, width + self.padding)
                self.max_widths[col_index] = max_width
                col_index += 1
            self.max_heights[row_index] = max_height
            row_index += 1
        if self.max_widths:
            self.width = reduce(lambda x, y: x + y, self.max_widths) \
                - self.padding
        else:
            self.width = 0
        if self.max_heights:
            self.height = reduce(lambda x, y: x + y, self.max_heights) \
                - self.padding
        else:
            self.height = 0
예제 #29
0
    def size(self, dialog):
        """Recalculates our size and the maximum widths and heights of
        each row and column in our table.

        @param dialog The Dialog within which we are contained
        """
        if dialog is None:
            return
        Widget.size(self, dialog)
        self.max_heights = [0] * len(self.content)
        width = 0
        for row in self.content:
            width = max(width, len(row))
        self.max_widths = [self.padding] * width
        row_index = 0
        for row in self.content:
            max_height = self.padding
            col_index = 0
            for cell in row:
                if cell is not None:
                    cell.size(dialog)
                    width, height = cell.width, cell.height
                else:
                    width = height = 0
                max_height = max(max_height, height + self.padding)
                max_width = self.max_widths[col_index]
                max_width = max(max_width, width + self.padding)
                self.max_widths[col_index] = max_width
                col_index += 1
            self.max_heights[row_index] = max_height
            row_index += 1
        if self.max_widths:
            self.width = reduce(lambda x, y: x + y, self.max_widths) \
                - self.padding
        else:
            self.width = 0
        if self.max_heights:
            self.height = reduce(lambda x, y: x + y, self.max_heights) \
                - self.padding
        else:
            self.height = 0
예제 #30
0
    def _create_widgets(self):
        """
        Create the widgets and return the one that contains them all.
        :return: the background widget
        """
        # Create the background widget.
        bg = self._rm.get_image(BACKGROUND_IMAGE, self.screen.get_size())
        bg_widget = ImageWidget((0, 0), self.screen.get_size(), -1, bg)

        # Create the container for the input widgets.
        x = (self.screen.get_width() - INPUT_WIDTH - INPUT_PADDING[1] - INPUT_PADDING[3]) / 2
        y = self.screen.get_height() / 2
        w = INPUT_WIDTH + INPUT_PADDING[1] + INPUT_PADDING[3]
        h = self.screen.get_height() - y
        input_container = Widget((x, y), (w, h), 0)
        bg_widget.add_widget(input_container)

        # Create the input widgets.
        username_input = TextInput((0, 0), INPUT_WIDTH, 0, self._font, padding=INPUT_PADDING, color=INPUT_FORE_COLOR,
                                   fill=INPUT_FILL_COLOR, default_text="username",
                                   default_font=self._default_font)
        host_input = copy.copy(username_input)
        host_input.default_text = "host"
        host_input.position = (0, INPUT_OFFSET)
        port_input = copy.copy(username_input)
        port_input.default_text = "port"
        port_input.position = (0, 2*INPUT_OFFSET)
        input_container.add_widget(username_input)
        input_container.add_widget(host_input)
        input_container.add_widget(port_input)
        self._text_inputs = {"username": username_input, "host": host_input, "port": port_input}

        # Create the button widget.
        btn = special_widgets.simple_button((0, 3*INPUT_OFFSET), (w, 100), "Login", self._font)

        def btn_clicked(x, y):
            self._ev_manager.post(events.LoginRequestedEvent())
        btn.handle_clicked = btn_clicked
        input_container.add_widget(btn)

        # Create the connection failed warning.
        self._connection_failed_warning = special_widgets.warning_widget(None, (400, 100), "Connection failed",
                                                                         self._font, screen_size=self.screen.get_size())
        bg_widget.add_widget(self._connection_failed_warning)
        self._username_taken_warning = special_widgets.warning_widget(None, (400, 100), "Username already taken",
                                                                      self._font, screen_size=self.screen.get_size())
        bg_widget.add_widget(self._username_taken_warning)

        return bg_widget
예제 #31
0
 def test_widget_from_json_str(self):
     sample_widget_json_str = json.dumps({
         "name": "sample",
         "num_of_parts": 5,
         "created_date": "2012-06-14",
         "updated_date": "2021-04-25",
         "an_extra_prop": 55555,
         "a_complex_extra_prop": {
             "stuff": [4.1, "eggs", [3, "spam"]]
         }
     })
     self.assertEqual(Widget.from_json_str(sample_widget_json_str),
                      self.sample_widget)
예제 #32
0
 def layout(self, x, y):
     self.x, self.y = x, y
     if self.background is not None:
         self.background.update(x, y, self.width, self.height)
     if self.highlight is not None:
         self.highlight.update(x, y, self.width, self.height)
     font = self.label.document.get_font()
     height = font.ascent - font.descent
     x, y = GetRelativePoint(self, self.anchor,
                             Widget(self.label.content_width, height),
                             self.anchor, (0, 0))
     self.label.x = x
     self.label.y = y - font.descent
예제 #33
0
    def __init__(self,
                 content=[[]],
                 anchor=ANCHOR_TOP_LEFT,
                 padding=5,
                 offset=(0, 0)):
        """
        Defines a new GridLayout.

        @param content A list of rows, each of which is a list of cells
                       within that row.  'None' may be used for empty cells,
                       and rows do not need to all be the same length.
        @param anchor Alignment of
        """
        assert (
            (isinstance(content, list) or isinstance(content, tuple)) and
            (len(content) == 0 or
             (isinstance(content[0], list) or isinstance(content[0], tuple))))
        Widget.__init__(self)
        self.content = content
        self.anchor = anchor
        self.padding = padding
        self.offset = offset
        self.max_heights = []
        self.max_widths = []
예제 #34
0
def put_widget(widget_name):
    try:
        try:  # if this succeeds, the widget already exists and is getting updated
            if not request.is_json:
                raise ValueError('request body was not parseable json')
            old_widget = get_widget_store().get_widget_by_name(widget_name)
            new_widget_json_obj = request.get_json()
            new_widget_json_obj.update({
                "updated_date":
                datetime.today().strftime("%Y-%m-%d"),
                "created_date":
                old_widget["Created date"]
            })
            new_widget = Widget.from_json_obj(new_widget_json_obj)
            get_widget_store().put_widget(new_widget)
            return jsonify(new_widget_json_obj), 200
        except LookupError:  # if we're here, a new widget is getting created
            new_widget_json_obj = request.get_json()
            new_widget_json_obj.update({
                "created_date":
                datetime.today().strftime("%Y-%m-%d"),
                "updated_date":
                datetime.today().strftime("%Y-%m-%d")
            })
            new_widget = Widget.from_json_obj(new_widget_json_obj)
            get_widget_store().put_widget(new_widget)
            return jsonify(new_widget_json_obj), 201
    except jsonschema.exceptions.ValidationError as ve:
        return (jsonify({
            "error class": "invalid widget representation",
            "uri": request.path,
            "cause": ve.message
        }), 400)
    except Exception:
        app.logger.exception('Unexpected exception')
        abort(500)
예제 #35
0
    def ask_tricks(self, n):
        """
        Ask the user for the number of tricks.
        :param n: the maximum number of tricks
        """
        # Create the container with the fade in effect.
        container = Widget((self.screen.get_width() / 2 - 200, 100),
                           (400, self.screen.get_height() - 120), 40)
        container.opacity = 0
        container.add_action(actions.FadeInAction(0.5))
        self._ask_tricks_widget = container
        self._background_widget.add_widget(container)

        # Create the question text.
        text_w = special_widgets.warning_widget((0, 0), (400, 60),
                                                "How many tricks do you make?",
                                                self._font,
                                                close_on_click=False)
        text_w.visible = True
        container.add_widget(text_w)

        # Create the numbers.
        class ChooseHandler(object):
            def __init__(self, view, nn):
                self._view = view
                self._n = nn

            def __call__(self, x, y):
                self._view._handle_say_tricks(self._n)

        for i in xrange(n + 1):
            size = (50, 50)
            pos = ((i % 6) * (size[0] + 20), 80 + (i / 6) * (size[1] + 20))
            w = special_widgets.warning_widget(pos,
                                               size,
                                               str(i),
                                               self._font,
                                               close_on_click=False)
            w.visible = True
            w.handle_clicked = ChooseHandler(self, i)
            container.add_widget(w)
예제 #36
0
def add_widgets():
    try:
        new_widget_json_objs = request.get_json()
        for new_widget_json_obj in new_widget_json_objs:
            new_widget_json_obj.update({
                "updated_date":
                datetime.today().strftime("%Y-%m-%d"),
                "created_date":
                datetime.today().strftime("%Y-%m-%d")
            })
        new_widgets = [Widget.from_json_obj(w) for w in new_widget_json_objs]
        get_widget_store().put_widgets(new_widgets)
        return jsonify(new_widget_json_objs), 200
    except jsonschema.exceptions.ValidationError as ve:
        return (jsonify({
            "error class": "invalid widget representation",
            "uri": request.path,
            "cause": ve.message
        }), 400)
    except Exception:
        app.logger.exception('Unexpected exception')
        abort(500)
예제 #37
0
 def teardown(self):
     for row in self.content:
         for cell in row:
             cell.teardown()
     self.content = []
     Widget.teardown(self)
예제 #38
0
 def teardown(self):
     self.content.teardown()
     self.content = None
     Widget.teardown(self)
예제 #39
0
 def delete(self):
     """Deletes all graphic elements within the layout."""
     for item in self.content:
         item.delete()
     Widget.delete(self)
예제 #40
0
 def delete(self):
     """Deletes graphic elements within the Wrapper."""
     if self.content is not None:
         self.content.delete()
     Widget.delete(self)
예제 #41
0
 def delete(self):
     """Deletes all graphic elements within the layout."""
     for row in self.content:
         for cell in row:
             cell.delete()
     Widget.delete(self)
예제 #42
0
 def teardown(self):
     self.content.teardown()
     self.content = None
     Widget.teardown(self)
예제 #43
0
 def teardown(self):
     for row in self.content:
         for cell in row:
             cell.teardown()
     self.content = []
     Widget.teardown(self)
예제 #44
0
 def teardown(self):
     for _, _, _, item in self.content:
         item.teardown()
     self.content = []
     Widget.teardown(self)
예제 #45
0
 def delete(self):
     """Deletes graphic elements within the Wrapper."""
     if self.content is not None:
         self.content.delete()
     Widget.delete(self)
예제 #46
0
 def delete(self):
     """Deletes all graphic elements within the layout."""
     for row in self.content:
         for cell in row:
             cell.delete()
     Widget.delete(self)
예제 #47
0
    def size(self, dialog):
        """
        Recalculate the size of the Scrollable.

        @param dialog Dialog which contains us
        """
        if dialog is None:
            return
        Widget.size(self, dialog)
        if self.is_fixed_size:
            self.width, self.height = self.max_width, self.max_height

        self.hscrollbar_height = \
            dialog.theme['hscrollbar']['left']['image'].height
        self.vscrollbar_width = \
            dialog.theme['vscrollbar']['up']['image'].width

        if self.root_group is None:  # do we need to re-clone dialog groups?
            self.theme = dialog.theme
            self.batch = dialog.batch
            self.root_group = ScrollableGroup(0,
                                              0,
                                              self.width,
                                              self.height,
                                              parent=dialog.fg_group)
            self.panel_group = pyglet.graphics.OrderedGroup(0, self.root_group)
            self.bg_group = pyglet.graphics.OrderedGroup(1, self.root_group)
            self.fg_group = pyglet.graphics.OrderedGroup(2, self.root_group)
            self.highlight_group = pyglet.graphics.OrderedGroup(
                3, self.root_group)
            Wrapper.delete(self)  # force children to abandon old groups

        Wrapper.size(self, self)  # all children are to use our groups

        if self.always_show_scrollbars or \
           (self.max_width and self.width > self.max_width):
            if self.hscrollbar is None:
                self.hscrollbar = HScrollbar(self.max_width)
        else:
            if self.hscrollbar is not None:
                self.hscrollbar.delete()
                self.hscrollbar = None

        if self.always_show_scrollbars or \
           (self.max_height and self.height > self.max_height):
            if self.vscrollbar is None:
                self.vscrollbar = VScrollbar(self.max_height)
        else:
            if self.vscrollbar is not None:
                self.vscrollbar.delete()
                self.vscrollbar = None

        self.width = min(self.max_width or self.width, self.width)
        self.content_width = self.width
        self.height = min(self.max_height or self.height, self.height)
        self.content_height = self.height

        if self.hscrollbar is not None:
            self.hscrollbar.size(dialog)
            self.hscrollbar.set(self.max_width,
                                max(self.content.width, self.max_width))
            self.height += self.hscrollbar.height

        if self.vscrollbar is not None:
            self.vscrollbar.size(dialog)
            self.vscrollbar.set(self.max_height,
                                max(self.content.height, self.max_height))
            self.width += self.vscrollbar.width
예제 #48
0
        new_date.setTimeZone(timezone)
    return new_date


def read_data(fname):
    df = pd.read_csv(fname)

    df = df.drop(df[df.mag < 0].index)
    magnitudes = df["mag"]

    timezone = QTimeZone(b'Europe/Berlin')

    times = df['time'].apply(lambda x: transform_date(x, timezone))

    return times, magnitudes


if __name__ == '__main__':
    options = argparse.ArgumentParser()
    options.add_argument('-f', '--file', type=str, required=True)
    args = options.parse_args()
    data = read_data(args.file)

    # Qt Application
    app = QApplication(sys.argv)

    widget = Widget(data)
    window = MainWindow(widget)
    window.show()

    sys.exit(app.exec_())
예제 #49
0
settings = get_config()

# Choosing theme
time = datetime.now().timetuple()
if time.tm_hour >= settings['time']['dark'] or time.tm_hour < settings['time'][
        'light']:
    theme_mode = 0
else:
    theme_mode = 1
# theme_mode = 1

# Rainmeter
if settings['rainmeter'][0]:
    widgets = settings['rainmeter'][1]
    for widget in widgets:
        working_widget = Widget(widget)
        working_widget.switch(theme_mode)

# Windows Theme
if settings['windows']:
    registry_keys = ["AppsUseLightTheme", "SystemUsesLightTheme"]
    for registry_key in registry_keys:
        working_key = Registry(registry_key)
        working_key.set(theme_mode)

# Wallpaper
if settings['wallpaper'][0]:
    if theme_mode == 1:
        wallpaper = settings['wallpaper'][1]["light"]
    elif theme_mode == 0:
        wallpaper = settings['wallpaper'][1]["dark"]
예제 #50
0
 def teardown(self):
     for _, _, _, item in self.content:
         item.teardown()
     self.content = []
     Widget.teardown(self)