Beispiel #1
0
 def _switch(self, state=None):
     super(InputBox, self)._switch(state)
     # Draw dynamic stuff on active state
     if self._image_state == "image":
         # Draw text
         text = Simple(Font["mono"].render(self.text, True, (0,0,0)))
         text.rect.midleft = (self._text_offset, self.rect.h / 2)
         area = ((6-self._text_pos,0), (self.rect.w-8, self.rect.h))
         self.image.blit(text.image, text.pos, area)
         # Draw cursor
         if self._blink:
             x = self._chars[self._cursor_pos][0] + self._text_pos
             pygame.draw.line(self.image, (0,0,0), (x, 6),
                              (x, self.rect.h-6))
         # Draw selection highlighting
         self._draw_selection(self.image, 5, self.rect.h - 9)
     # Draw text when switching to non-focused state
     else:
         if self._text or 1:  # Blit input text into box...
             text = Simple(Font["mono"].render(self.text, True, (70,70,70)))
         else:  # ...or default text if empty.
             text = Simple(Font["mono"].render(self._settings["default"],
                                               True, (70,70,70)))
         text.rect.midleft = (self._text_pos, self.rect.h / 2)
         self.image.blit(text.image, text.pos)
 def _switch(self, state=None):
     Simple._switch(self, state)
     if self._settings["show_value"] is not False:
         lbl = "%.*f" % (self._settings["show_value"], self.value)
         val = self._settings["label_font"].render(
             lbl, True, self._settings["label_col"])
         x = self._images["handle"].rect.centerx - (val.get_width() / 2)
         x = max(0, min(self.rect.w - val.get_width(), x))
         y = self._images["handle"].rect.top - val.get_height()
         self.image.blit(val, (x,y))
Beispiel #3
0
 def _switch(self, state=None):
     Simple._switch(self, state)
     if self._settings["show_value"] is not False:
         lbl = "%.*f" % (self._settings["show_value"], self.value)
         val = self._settings["label_font"].render(
             lbl, True, self._settings["label_col"])
         x = self._images["handle"].rect.centerx - (val.get_width() / 2)
         x = max(0, min(self.rect.w - val.get_width(), x))
         y = self._images["handle"].rect.top - val.get_height()
         self.image.blit(val, (x, y))
Beispiel #4
0
    def _draw_base(self):
        # Draw main images
        for state in ("off", "on"):
            image = "image" if (state == "off") else "active"
            self._images[image].fill(self._settings[state + "_col"])

            # Render the labels
            col = self._settings[state + "_label_col"]
            on = Simple(Font["widget"].render("ON", True, col))
            off = Simple(Font["widget"].render("OFF", True, col))
            on.rect.center = (self.rect.w * .25 - 1, self.rect.h / 2)
            off.rect.center = (self.rect.w * .75 + 1, self.rect.h / 2)

            # Blit all text
            self._images[image].blit(on.image, on.pos)
            self._images[image].blit(off.image, off.pos)
Beispiel #5
0
    def __init__(self, keymap_file, parent=None, **kwargs):
        """
        Extend Simple and prepare the key order.

        keymap_file -- String containing filename containing keymap.
                       Key order should be on second line.
        parent,kwargs -- Pass through to Simple

        """
        size = self._default_screen.size
        Simple.__init__(self, size, parent, **kwargs)
        # Load key order
        with open(keymap_file) as f:
            f.readline()
            self._key_order = eval(f.readline())
        assert isinstance(self._key_order, list)
Beispiel #6
0
 def update(self, time):
     """Update counter each frame."""
     text = Simple(Font["widget"].render(
         self._settings["label"] +
         str(round(self._settings["clock"].get_fps(), 1)), True, Font.col))
     text.rect.center = (self.rect.w / 2, self.rect.h / 2)
     self.image = text.image
Beispiel #7
0
    def __init__(self, keymap_file, parent=None, **kwargs):
        """
        Extend Simple and prepare the key order.

        keymap_file -- String containing filename containing keymap.
                       Key order should be on second line.
        parent,kwargs -- Pass through to Simple

        """
        size = self._default_screen.size
        Simple.__init__(self, size, parent, **kwargs)
        # Load key order
        with open(keymap_file) as f:
            f.readline()
            self._key_order = eval(f.readline())
        assert isinstance(self._key_order, list)
Beispiel #8
0
 def _create_handles(self):
     # Create scroll bars and handles
     self._scroll_x = self._scroll_y = None
     self._handle_x = self._handle_y = None
     if self._settings["widget"].rect.w > self.rect.w:
         ratio = float(self.rect.w) / self._settings["widget"].rect.w
         self._scroll_x = Simple((self.rect.w * ratio, 3))
         self._scroll_x._parent = self
         self._scroll_x.image.fill(self._settings["col"])
         self._scroll_x.pos = (0, self.rect.h - 3)
         self._handle_x = _ScrollHandleH(widget=self)
     if self._settings["widget"].rect.h > self.rect.h:
         ratio = float(self.rect.h) / self._settings["widget"].rect.h
         self._scroll_y = Simple((3, self.rect.h * ratio))
         self._scroll_y._parent = self
         self._scroll_y.image.fill(self._settings["col"])
         self._scroll_y.pos = (self.rect.w - 3, 0)
         self._handle_y = _ScrollHandleV(widget=self)
Beispiel #9
0
    def _draw_final(self):
        self._images["close_off"].pos = (2, 2)
        self._images["close_over"].pos = (2, 2)
        self._set_over()

        if self._settings["title"]:
            t = Simple(Font["widget"].render(self._settings["title"], True,
                                             Font.col))
            t.rect.x = self._images["close_off"].rect.right
            self._images["image"].blit(t.image, t.pos)
Beispiel #10
0
 def _draw_label(self):
     # Clear previous renderings
     del self._settings["label"][1:]
     label = self._settings["label"][0].split("\n")
     f = self._settings["label_font"]
     h = f.get_ascent()
     for count, line in enumerate(label):
         lbl = Simple(f.render(line, True, self._settings["label_col"]))
         self._settings["label"].append(lbl)
         y = (self.rect.h - (h * len(label)) + f.get_descent()) / 2 + \
             (h * count)
         lbl.rect.midtop = (self.rect.w / 2, y)
Beispiel #11
0
 def add(self, order=None, fade=True, focus=False):
     self.rect.center = self._parent_combo.rect_abs.center
     # Attempt to keep within screen dimensions
     self.rect.bottom = min(self.rect.bottom, get_screen().rect.bottom)
     self.rect.top = max(self.rect.top, 0)
     Simple.add(self, order, fade, focus)
Beispiel #12
0
 def _switch(self, state=None):
     Simple._switch(self, state)
     if self.selection > -1:
         val = self._settings["values"][self.selection]
         txt = Font["widget"].render(val, True, Color("black"))
         self.image.blit(txt, (5, (self.rect.h-txt.get_height())/2))
Beispiel #13
0
 def add(self, order=None, fade=True, focus=False):
     self.rect.center = self._parent_combo.rect_abs.center
     # Attempt to keep within screen dimensions
     self.rect.bottom = min(self.rect.bottom, get_screen().rect.bottom)
     self.rect.top = max(self.rect.top, 0)
     Simple.add(self, order, fade, focus)
Beispiel #14
0
 def _switch(self, state=None):
     Simple._switch(self, state)
     if self.selection > -1:
         val = self._settings["values"][self.selection]
         txt = Font["widget"].render(val, True, Color("black"))
         self.image.blit(txt, (5, (self.rect.h - txt.get_height()) / 2))