Beispiel #1
0
 def __init__(self):
     super(Grx.Application, self).__init__()
     self.init()
     self.hold()
     self.WHITE = Grx.color_get_white()
     self.BLACK = Grx.color_get_black()
     self.default_text_opt = Grx.TextOptions.new(Grx.font_load('lucida', 10), self.BLACK)
Beispiel #2
0
 def handle_pen_down(self, x, y):
     if y <= self.color_picker_y:
         idx = x * len(self.colors) // Grx.get_width()
         self.fg_color = self.colors[self.color_lookup[idx]]
     else:
         self.pen_x, self.pen_y = x, y
         self.pen_down = True
         Grx.draw_pixel(self.pen_x, self.pen_y, self.fg_color)
Beispiel #3
0
 def do_activate(self):
     """This function overrides Grx.Application.activate"""
     for x in range(self.width):
         for y in range(self.height):
             on = random() > 0.82
             self.old_state[x][y] = on
             if on:
                 Grx.fast_draw_pixel(x, y, self.color[on])
Beispiel #4
0
 def handle_pen_down(self, x, y):
     if y <= self.color_picker_y:
         idx = x * len(self.colors) // Grx.get_width()
         self.fg_color = self.colors[self.color_lookup[idx]]
     else:
         self.pen_x, self.pen_y = x, y
         self.pen_down = True
         Grx.draw_pixel(self.pen_x, self.pen_y, self.fg_color)
Beispiel #5
0
    def _draw(self):
        self._update_state()
        for x in range(self.width):
            new_row = self.new_state[x]
            old_row = self.old_state[x]
            for y in range(self.height):
                if old_row[y] != new_row[y]:
                    Grx.fast_draw_pixel(x, y, self.color[new_row[y]])

        self.old_state, self.new_state = self.new_state, self.old_state

        return GLib.SOURCE_CONTINUE
Beispiel #6
0
 def __init__(self):
     super(Grx.Application, self).__init__()
     self.init()
     self.hold()
     self.WHITE = Grx.color_get_white()
     self.BLACK = Grx.color_get_black()
     fc_list = check_output(['fc-list', '--format=%{file}\n', ':scalable=False'])
     self.font_files = [f for f in fc_list.decode().splitlines()]
     self.font_files.sort()
     self.default_text_opt = Grx.TextOptions.new_full(
         # Don't want to use the dpi-aware font here so we can cram info on to small screens
         Grx.Font.load_full('lucida', 10, -1, Grx.FontWeight.REGULAR,
                            Grx.FontSlant.REGULAR, Grx.FontWidth.REGULAR, False, None),
         self.BLACK, self.WHITE,
         Grx.TextHAlign.LEFT, Grx.TextVAlign.TOP)
     self.v_offset = self.default_text_opt.get_font().get_height()
     self.font_index = 0
     self.next_index = 0
     self.prev_index = []
Beispiel #7
0
 def do_activate(self):
     Grx.clear_screen(self.WHITE)
     offset = 0
     try:
         for item in FONT_TABLE:
             font = Grx.Font.load_full(
                 None, FONT_SIZE, Grx.get_dpi(), Grx.FontWeight.REGULAR,
                 Grx.FontSlant.REGULAR, Grx.FontWidth.REGULAR, False, item[0], item[1])
             text_opt = Grx.TextOptions.new_full(
                 font, self.BLACK, self.WHITE, Grx.TextHAlign.CENTER, Grx.TextVAlign.TOP)
             Grx.draw_text(item[2], Grx.get_width() / 2, offset, text_opt)
             offset += font.get_height()
     except GLib.Error as err:
         Grx.draw_text(str(err), 10, 10, self.default_text_opt)
         print(err)
Beispiel #8
0
 def __init__(self):
     super(Grx.Application, self).__init__()
     self.init()
     self.hold()
     self.WHITE = Grx.color_get_white()
     self.BLACK = Grx.color_get_black()
     fc_list = check_output(
         ['fc-list', '--format=%{file}\n', ':scalable=False'])
     self.font_files = [f for f in fc_list.decode().splitlines()]
     self.font_files.sort()
     self.default_text_opt = Grx.TextOptions.new_full(
         # Don't want to use the dpi-aware font here so we can cram info on to small screens
         Grx.Font.load_full('lucida', 10, -1, Grx.FontWeight.REGULAR,
                            Grx.FontSlant.REGULAR, Grx.FontWidth.REGULAR,
                            False, None),
         self.BLACK,
         self.WHITE,
         Grx.TextHAlign.LEFT,
         Grx.TextVAlign.TOP)
     self.v_offset = self.default_text_opt.get_font().get_height()
     self.font_index = 0
     self.next_index = 0
     self.prev_index = []
Beispiel #9
0
 def __init__(self):
     super(Grx.Application, self).__init__()
     self.init()  # sets up graphics driver/mode
     self.hold()  # keeps the application running
     self.colors = OrderedDict([
         ('red', Grx.color_get(255, 0, 0)),
         ('green', Grx.color_get(0, 255, 0)),
         ('blue', Grx.color_get(0, 0, 255)),
         ('yellow', Grx.color_get(255, 255, 0)),
         ('cyan', Grx.color_get(0, 255, 255)),
         ('magenta', Grx.color_get(255, 0, 255)),
         ('black', Grx.color_get_black()),
         ('white', Grx.color_get_white()),
     ])
     self.color_lookup = []
     self.fg_color = self.colors['white']
     self.bg_color = self.colors['black']
     self.pen_x, self.pen_y = 0, 0
     self.pen_down = False
     self.color_picker_y = Grx.get_height() // 8
Beispiel #10
0
 def __init__(self):
     super(Grx.Application, self).__init__()
     self.init()  # sets up graphics driver/mode
     self.hold()  # keeps the application running
     self.colors = OrderedDict([
         ('red', Grx.color_get(255, 0, 0)),
         ('green', Grx.color_get(0, 255, 0)),
         ('blue', Grx.color_get(0, 0, 255)),
         ('yellow', Grx.color_get(255, 255, 0)),
         ('cyan', Grx.color_get(0, 255, 255)),
         ('magenta', Grx.color_get(255, 0, 255)),
         ('black', Grx.color_get_black()),
         ('white', Grx.color_get_white()),
     ])
     self.color_lookup = []
     self.fg_color = self.colors['white']
     self.bg_color = self.colors['black']
     self.pen_x, self.pen_y = 0, 0
     self.pen_down = False
     self.color_picker_y = Grx.get_height() // 8
Beispiel #11
0
def activate(app):
    w = Grx.get_width()
    colors = Grx.color_get_ega_colors()
    smile = demo.get_smiley_pixmap(32, 32)

    # draw the full width of the screen
    for x in range(0, w, 3):
        # draw a band with colored pixels
        for y in range(10, 30, 2):
            Grx.draw_pixel(x + y % 3, y, colors[(y - 1) % 16])

        # draw a band with pixels from a pixmap
        for y in range(40, 60, 2):
            Grx.draw_filled_pixel_with_pixmap(x + y % 3, y, smile)

        # draw a band with pixels from a pixmap, but offset this time
        for y in range(70, 90, 2):
            Grx.draw_pixel_with_offset_pixmap(16, 0, x + y % 3, y, smile)
Beispiel #12
0
 def __init__(self):
     super(Grx.Application, self).__init__()
     self.init()
     self.hold()
     Grx.mouse_set_cursor(None)
     self.source_id = 0
     self.width = Grx.get_width()
     self.height = Grx.get_height()
     self.old_state = [[0 for y in range(self.height)]
                       for x in range(self.width)]
     self.new_state = [[0 for y in range(self.height)]
                       for x in range(self.width)]
     self.color = (Grx.color_get_black(), Grx.color_get_white())
     self.connect("notify::is-active", self.on_notify_is_active)
Beispiel #13
0
    def do_event(self, event):
        if Grx.Application.do_event(self, event):
            return True

        t = event.type
        if t in (Grx.EventType.KEY_DOWN, Grx.EventType.KEY_UP):
            key_event = event.key
            print("key keysym", key_event.keysym)
            print("key unichar", key_event.unichar)
            print("key code", key_event.code)
            print("modifiers", key_event.modifiers)
            if key_event.keysym in (Grx.Key.LCASE_Q, Grx.Key.BACK_SPACE,
                                    Grx.Key.ESCAPE):
                self.quit()
        elif t in (Grx.EventType.BUTTON_PRESS, Grx.EventType.BUTTON_RELEASE):
            button_event = event.button
            print("button", button_event.button)
            print("modifiers", button_event.modifiers)
            Grx.clear_screen(Grx.color_get_black())
        elif t == Grx.EventType.BUTTON_DOUBLE_PRESS:
            button_event = event.button
            print("button double-press", button_event.button)
            print("modifiers", button_event.modifiers)
        elif t == Grx.EventType.TOUCH_DOWN:
            touch_event = event.touch
            Grx.draw_pixel(touch_event.x, touch_event.y, self.color)
            self.last_touch = (touch_event.x, touch_event.y)
            print("touch", touch_event.x, touch_event.y)
            print("modifiers", touch_event.modifiers)
        elif t == Grx.EventType.TOUCH_MOTION:
            touch_event = event.touch
            Grx.draw_line(self.last_touch[0], self.last_touch[1],
                          touch_event.x, touch_event.y, self.color)
            self.last_touch = (touch_event.x, touch_event.y)
        else:
            return False

        return True
Beispiel #14
0
    def do_event(self, event):
        if Grx.Application.do_event(self, event):
            return True

        t = event.type
        if t in (Grx.EventType.KEY_DOWN, Grx.EventType.KEY_UP):
            key_event = event.key
            print("key keysym", key_event.keysym)
            print("key unichar", key_event.unichar)
            print("key code", key_event.code)
            print("modifiers", key_event.modifiers)
            if key_event.keysym in (Grx.Key.LCASE_Q, Grx.Key.BACK_SPACE, Grx.Key.ESCAPE):
                self.quit()
        elif t in (Grx.EventType.BUTTON_PRESS, Grx.EventType.BUTTON_RELEASE):
            button_event = event.button
            print("button", button_event.button)
            print("modifiers", button_event.modifiers)
            Grx.clear_screen(Grx.color_get_black())
        elif t == Grx.EventType.BUTTON_DOUBLE_PRESS:
            button_event = event.button
            print("button double-press", button_event.button)
            print("modifiers", button_event.modifiers)
        elif t == Grx.EventType.TOUCH_DOWN:
            touch_event = event.touch
            Grx.draw_pixel(touch_event.x, touch_event.y, self.color)
            self.last_touch = (touch_event.x, touch_event.y)
            print("touch", touch_event.x, touch_event.y)
            print("modifiers", touch_event.modifiers)
        elif t == Grx.EventType.TOUCH_MOTION:
            touch_event = event.touch
            Grx.draw_line(self.last_touch[0], self.last_touch[1], touch_event.x, touch_event.y, self.color)
            self.last_touch = (touch_event.x, touch_event.y)
        else:
            return False

        return True
Beispiel #15
0
 def show_next_font(self, step, start_index):
     if step:
         self.prev_index.clear()
         self.font_index += step
         if self.font_index < 0:
             self.font_index = 0
         elif self.font_index >= len(self.font_files):
             self.font_index = len(self.font_files) - 1
     Grx.clear_screen(self.WHITE)
     file_name = self.font_files[self.font_index]
     Grx.draw_text('file: ' + file_name, 10, 10, self.default_text_opt)
     try:
         font = Grx.font_load_from_file(file_name)
         font_info = 'family: {}, style: {}, width: {}, height {}'.format(
             font.get_family(), font.get_style(), font.get_width(), font.get_height())
         Grx.draw_text(font_info, 10, 10 + self.v_offset, self.default_text_opt)
         dump_context = Grx.Context.new_subcontext(
             10, 10 + self.v_offset * 2, Grx.get_width() - 10, Grx.get_height() - 10)
         self.next_index = font.dump(dump_context, start_index, self.BLACK, self.WHITE)
         if self.next_index != -1 and self.next_index != start_index:
             self.prev_index.append(start_index)
     except GLib.Error as err:
         Grx.draw_text(str(err), 10, 10 + self.v_offset, self.default_text_opt)
Beispiel #16
0
 def __init__(self):
     super(Grx.Application, self).__init__()
     self.init()
     self.hold()
     self.color = Grx.color_get_white()
     self.last_touch = None
Beispiel #17
0
def activate(app):
    x = Grx.get_width() // 8
    y = Grx.get_height() // 8
    r1 = int(x * 0.8)
    r2 = int(y * 0.8)
    colors = Grx.color_get_ega_colors()
    white = colors[Grx.EgaColorIndex.WHITE]
    checker = demo.get_checkerboard_pixmap()
    line_opt0 = Grx.LineOptions()

    # just a plain old ellipse
    Grx.draw_ellipse(x, y, r1, r2, white)
    Grx.draw_filled_ellipse(x, y * 3, r1, r2, white)
    Grx.draw_ellipse_with_pixmap(x, y * 5, r1, r2, line_opt0, checker)
    Grx.draw_filled_ellipse_with_pixmap(x, y * 7, r1, r2, checker)

    # quarter a ellipses
    Grx.draw_ellipse_arc(x * 3, y, r1, r2, 0, 900, Grx.ArcStyle.OPEN, white)
    Grx.draw_filled_ellipse_arc(x * 3, y * 3, r1, r2, 0, 900,
                                Grx.ArcStyle.OPEN, white)
    Grx.draw_ellipse_arc_with_pixmap(x * 3, y * 5, r1, r2, 0, 900,
                                     Grx.ArcStyle.OPEN, line_opt0, checker)
    Grx.draw_filled_ellipse_arc_with_pixmap(x * 3, y * 7, r1, r2, 0, 900,
                                            Grx.ArcStyle.OPEN, checker)
    Grx.draw_ellipse_arc(x * 3, y, r1, r2, 1800, 2700,
                         Grx.ArcStyle.CLOSED_CHORD, white)
    Grx.draw_filled_ellipse_arc(x * 3, y * 3, r1, r2, 1800, 2700,
                                Grx.ArcStyle.CLOSED_CHORD, white)
    Grx.draw_ellipse_arc_with_pixmap(x * 3, y * 5, r1, r2, 1800, 2700,
                                     Grx.ArcStyle.CLOSED_CHORD, line_opt0,
                                     checker)
    Grx.draw_filled_ellipse_arc_with_pixmap(x * 3, y * 7, r1, r2, 1800, 2700,
                                            Grx.ArcStyle.CLOSED_CHORD, checker)

    # stretchy Pac-Man
    Grx.draw_ellipse_arc(x * 5, y, r1, r2, 450, 3150,
                         Grx.ArcStyle.CLOSED_RADIUS, white)
    Grx.draw_filled_ellipse_arc(x * 5, y * 3, r1, r2, 450, 3150,
                                Grx.ArcStyle.CLOSED_RADIUS, white)
    Grx.draw_ellipse_arc_with_pixmap(x * 5, y * 5, r1, r2, 450, 3150,
                                     Grx.ArcStyle.CLOSED_RADIUS, line_opt0,
                                     checker)
    Grx.draw_filled_ellipse_arc_with_pixmap(x * 5, y * 7, r1, r2, 450, 3150,
                                            Grx.ArcStyle.CLOSED_RADIUS,
                                            checker)

    # line options
    line_opt = Grx.LineOptions()
    line_opt.color = colors[Grx.EgaColorIndex.GREEN]
    line_opt.width = 1
    line_opt.n_dash_patterns = 2
    line_opt.dash_pattern0 = 2
    line_opt.dash_pattern1 = 2
    Grx.draw_ellipse_with_options(x * 7, y, r1, r2, line_opt)
    Grx.draw_ellipse_arc_with_options(x * 7, y * 3, r1, r2, 2250, 1350,
                                      Grx.ArcStyle.CLOSED_RADIUS, line_opt)
    Grx.draw_ellipse_arc_with_pixmap(x * 7, y * 5, r1, r2, 2250, 1350,
                                     Grx.ArcStyle.CLOSED_RADIUS, line_opt,
                                     checker)

    # reusable points
    points = Grx.generate_ellipse(x * 7, y * 7, r1, r2)
    Grx.draw_polygon(points, white)
Beispiel #18
0
def activate(app):
    white = Grx.color_get_white()
    x = Grx.get_width() // 10
    y = Grx.get_height() // 10

    line_opts = Grx.LineOptions()
    line_opts.color = white
    line_opts.width = 3
    line_opts.n_dash_patterns = 2
    line_opts.dash_pattern0 = 6
    line_opts.dash_pattern1 = 4
    line_opts0 = Grx.LineOptions()
    pat = demo.get_checkerboard_pixmap()
    Grx.draw_box(x * 1, y * 1, x * 3, y * 3, white)
    Grx.draw_box_with_options(x * 4, y * 1, x * 6, y * 3, line_opts)
    Grx.draw_box_with_pixmap(x * 7, y * 1, x * 9, y * 3, line_opts0, pat)

    img = demo.get_smiley_pixmap(x * 2, y * 2)
    Grx.draw_filled_box(x * 1, y * 4, x * 3, y * 6, white)
    Grx.draw_filled_box_with_pixmap(x * 4, y * 4, x * 6, y * 6, img)
    Grx.draw_filled_box_with_offset_pixmap(x * 2, y, x * 7, y * 4, x * 9,
                                           y * 6, img)

    frame_colors = Grx.FramedBoxColors()
    frame_colors.background = Grx.color_get(224, 223, 228)
    frame_colors.border_top = Grx.color_get(255, 255, 255)
    frame_colors.border_right = Grx.color_get(155, 157, 154)
    frame_colors.border_bottom = Grx.color_get(110, 110, 100)
    frame_colors.border_left = Grx.color_get(241, 239, 226)
    Grx.draw_framed_box(x * 1, y * 7, x * 3, y * 9, y / 4, frame_colors)
    Grx.draw_rounded_box(x * 4, y * 7, x * 6, y * 9, y / 4, white)
    Grx.draw_filled_rounded_box(x * 7, y * 7, x * 9, y * 9, y / 4, white)
Beispiel #19
0
 def handle_pen_move(self, x, y):
     if self.pen_down:
         Grx.draw_line(self.pen_x, self.pen_y, x, y, self.fg_color)
     self.pen_x, self.pen_y = x, y
Beispiel #20
0
 def __init__(self):
     super(Grx.Application, self).__init__()
     self.init()
     self.hold()
     self.color = Grx.color_get_white()
     self.last_touch = None
Beispiel #21
0
def activate(app):
    x = Grx.get_width() // 8
    y = Grx.get_height() // 8
    r1 = int(x * 0.8)
    r2 = int(y * 0.8)
    colors = Grx.color_get_ega_colors()
    white = colors[Grx.EgaColorIndex.WHITE]
    checker = demo.get_checkerboard_pixmap()
    line_opt0 = Grx.LineOptions()

    # just a plain old ellipse
    Grx.draw_ellipse(x, y, r1, r2, white)
    Grx.draw_filled_ellipse(x, y * 3, r1, r2, white)
    Grx.draw_ellipse_with_pixmap(x, y * 5, r1, r2, line_opt0, checker)
    Grx.draw_filled_ellipse_with_pixmap(x, y * 7, r1, r2, checker)

    # quarter a ellipses
    Grx.draw_ellipse_arc(x * 3, y, r1, r2, 0, 900, Grx.ArcStyle.OPEN, white)
    Grx.draw_filled_ellipse_arc(x * 3, y * 3, r1, r2, 0, 900,
                                Grx.ArcStyle.OPEN, white)
    Grx.draw_ellipse_arc_with_pixmap(x * 3, y * 5, r1, r2, 0, 900,
                                     Grx.ArcStyle.OPEN, line_opt0, checker)
    Grx.draw_filled_ellipse_arc_with_pixmap(x * 3, y * 7, r1, r2, 0, 900,
                                            Grx.ArcStyle.OPEN, checker)
    Grx.draw_ellipse_arc(x * 3, y, r1, r2, 1800, 2700,
                         Grx.ArcStyle.CLOSED_CHORD, white)
    Grx.draw_filled_ellipse_arc(x * 3, y * 3, r1, r2, 1800, 2700,
                                Grx.ArcStyle.CLOSED_CHORD, white)
    Grx.draw_ellipse_arc_with_pixmap(x * 3, y * 5, r1, r2, 1800, 2700,
                                     Grx.ArcStyle.CLOSED_CHORD, line_opt0,
                                     checker)
    Grx.draw_filled_ellipse_arc_with_pixmap(x * 3, y * 7, r1, r2, 1800, 2700,
                                            Grx.ArcStyle.CLOSED_CHORD, checker)

    # stretchy Pac-Man
    Grx.draw_ellipse_arc(x * 5, y, r1, r2, 450, 3150,
                         Grx.ArcStyle.CLOSED_RADIUS, white)
    Grx.draw_filled_ellipse_arc(x * 5, y * 3, r1, r2, 450, 3150,
                                Grx.ArcStyle.CLOSED_RADIUS, white)
    Grx.draw_ellipse_arc_with_pixmap(x * 5, y * 5, r1, r2, 450, 3150,
                                     Grx.ArcStyle.CLOSED_RADIUS, line_opt0,
                                     checker)
    Grx.draw_filled_ellipse_arc_with_pixmap(x * 5, y * 7, r1, r2, 450, 3150,
                                            Grx.ArcStyle.CLOSED_RADIUS,
                                            checker)

    # line options
    line_opt = Grx.LineOptions()
    line_opt.color = colors[Grx.EgaColorIndex.GREEN]
    line_opt.width = 1
    line_opt.n_dash_patterns = 2
    line_opt.dash_pattern0 = 2
    line_opt.dash_pattern1 = 2
    Grx.draw_ellipse_with_options(x * 7, y, r1, r2, line_opt)
    Grx.draw_ellipse_arc_with_options(x * 7, y * 3, r1, r2, 2250, 1350,
                                      Grx.ArcStyle.CLOSED_RADIUS, line_opt)
    Grx.draw_ellipse_arc_with_pixmap(x * 7, y * 5, r1, r2, 2250, 1350,
                                     Grx.ArcStyle.CLOSED_RADIUS, line_opt,
                                     checker)

    # reusable points
    points = Grx.generate_ellipse(x * 7, y * 7, r1, r2)
    Grx.draw_polygon(points, white)
Beispiel #22
0
    def do_activate(self):
        """called when the application starts
        overrides Grx.Application.do_activate
        """
        Grx.clear_screen(self.bg_color)

        count = len(self.colors)
        remaining = Grx.get_width()
        x0, y0 = 0, 0
        y1 = self.color_picker_y
        for c in self.colors:
            x1 = x0 + remaining // count
            Grx.draw_filled_box(x0, y0, x1, y1, self.colors[c])
            Grx.draw_box(x0, y0, x1, y1, self.fg_color)
            count -= 1
            remaining -= x1 - x0
            x0 = x1
            self.color_lookup.append(c)
        Grx.set_clip_box(0, y1 + 1, Grx.get_max_x(), Grx.get_max_y())
Beispiel #23
0
def activate(app):
    max_x = Grx.get_max_x()
    max_y = Grx.get_max_y()
    colors = Grx.color_get_ega_colors()

    # draw some horizontal lines
    for y in range(10, 20):
        Grx.draw_hline(0, max_x, y, colors[y % 16])

    # and some vertical lines
    for x in range(10, 20):
        Grx.draw_vline(x, 0, max_y, colors[x % 16])

    # and angled lines
    for x in range(30, 40):
        Grx.draw_line(20, x, x, 20, colors[x % 16])

    # then two connected lines at right angles
    for x in range(50, 60):
        points = Grx.generate_points((
            20, x,
            x, x,
            x, 20
        ))
        Grx.draw_polyline(points, colors[x % 16])

    # try out line options
    line_opt = Grx.LineOptions()
    line_opt.color = Grx.color_get_white()
    line_opt.width = 3
    line_opt.n_dash_patterns = 3
    line_opt.dash_pattern0 = 3
    line_opt.dash_pattern1 = 6
    Grx.draw_line_with_options(70, 30, 110, 30, line_opt)
    points = Grx.generate_points((
        70, 40,
        90, 40,
        90, 50,
        110, 50
    ))
    Grx.draw_polyline_with_options(points, line_opt)

    # and pixmaps
    checker = demo.get_checkerboard_pixmap()
    line_opt0 = Grx.LineOptions()
    Grx.draw_line_with_pixmap(70, 60, 110, 60, line_opt0, checker)
    for y in range(65, 70):
        Grx.draw_hline_with_offset_pixmap(y, 0, 70, y, 40, checker)
Beispiel #24
0
def activate(app):
    x = Grx.get_width() // 8
    y = Grx.get_height() // 8
    r = min(x, y) // 2
    colors = Grx.color_get_ega_colors()
    white = colors[Grx.EgaColorIndex.WHITE]
    checker = demo.get_checkerboard_pixmap()
    line_opt0 = Grx.LineOptions()

    # just a plain old circle
    Grx.draw_circle(x, y, r, white)
    Grx.draw_filled_circle(x, y * 3, r, white)
    Grx.draw_circle_with_pixmap(x, y * 5, r, line_opt0, checker)
    Grx.draw_filled_circle_with_pixmap(x, y * 7, r, checker)

    # quarter a circles
    Grx.draw_circle_arc(x * 3, y, r, 0, 900, Grx.ArcStyle.OPEN, white)
    Grx.draw_filled_circle_arc(x * 3, y * 3, r, 0, 900, Grx.ArcStyle.OPEN,
                               white)
    Grx.draw_circle_arc_with_pixmap(x * 3, y * 5, r, 0, 900, Grx.ArcStyle.OPEN,
                                    line_opt0, checker)
    Grx.draw_filled_circle_arc_with_pixmap(x * 3, y * 7, r, 0, 900,
                                           Grx.ArcStyle.OPEN, checker)
    Grx.draw_circle_arc(x * 3, y, r, 1800, 2700, Grx.ArcStyle.CLOSED_CHORD,
                        white)
    Grx.draw_filled_circle_arc(x * 3, y * 3, r, 1800, 2700,
                               Grx.ArcStyle.CLOSED_CHORD, white)
    Grx.draw_circle_arc_with_pixmap(x * 3, y * 5, r, 1800, 2700,
                                    Grx.ArcStyle.CLOSED_CHORD, line_opt0,
                                    checker)
    Grx.draw_filled_circle_arc_with_pixmap(x * 3, y * 7, r, 1800, 2700,
                                           Grx.ArcStyle.CLOSED_CHORD, checker)

    # Pac-Man
    Grx.draw_circle_arc(x * 5, y, r, 450, 3150, Grx.ArcStyle.CLOSED_RADIUS,
                        white)
    Grx.draw_filled_circle_arc(x * 5, y * 3, r, 450, 3150,
                               Grx.ArcStyle.CLOSED_RADIUS, white)
    Grx.draw_circle_arc_with_pixmap(x * 5, y * 5, r, 450, 3150,
                                    Grx.ArcStyle.CLOSED_RADIUS, line_opt0,
                                    checker)
    Grx.draw_filled_circle_arc_with_pixmap(x * 5, y * 7, r, 450, 3150,
                                           Grx.ArcStyle.CLOSED_RADIUS, checker)

    # line options
    line_opt = Grx.LineOptions()
    line_opt.color = colors[Grx.EgaColorIndex.GREEN]
    line_opt.width = 1
    line_opt.n_dash_patterns = 2
    line_opt.dash_pattern0 = 2
    line_opt.dash_pattern1 = 2
    Grx.draw_circle_with_options(x * 7, y, r, line_opt)
    Grx.draw_circle_arc_with_options(x * 7, y * 3, r, 2250, 1350,
                                     Grx.ArcStyle.CLOSED_RADIUS, line_opt)
    Grx.draw_circle_arc_with_pixmap(x * 7, y * 5, r, 2250, 1350,
                                    Grx.ArcStyle.CLOSED_RADIUS, line_opt,
                                    checker)
Beispiel #25
0
def activate(app):
    max_x = Grx.get_max_x()
    max_y = Grx.get_max_y()
    colors = Grx.color_get_ega_colors()

    # draw some horizontal lines
    for y in range(10, 20):
        Grx.draw_hline(0, max_x, y, colors[y % 16])

    # and some vertical lines
    for x in range(10, 20):
        Grx.draw_vline(x, 0, max_y, colors[x % 16])

    # and angled lines
    for x in range(30, 40):
        Grx.draw_line(20, x, x, 20, colors[x % 16])

    # then two connected lines at right angles
    for x in range(50, 60):
        points = Grx.generate_points((20, x, x, x, x, 20))
        Grx.draw_polyline(points, colors[x % 16])

    # try out line options
    line_opt = Grx.LineOptions()
    line_opt.color = Grx.color_get_white()
    line_opt.width = 3
    line_opt.n_dash_patterns = 3
    line_opt.dash_pattern0 = 3
    line_opt.dash_pattern1 = 6
    Grx.draw_line_with_options(70, 30, 110, 30, line_opt)
    points = Grx.generate_points((70, 40, 90, 40, 90, 50, 110, 50))
    Grx.draw_polyline_with_options(points, line_opt)

    # and pixmaps
    checker = demo.get_checkerboard_pixmap()
    line_opt0 = Grx.LineOptions()
    Grx.draw_line_with_pixmap(70, 60, 110, 60, line_opt0, checker)
    for y in range(65, 70):
        Grx.draw_hline_with_offset_pixmap(y, 0, 70, y, 40, checker)
Beispiel #26
0
def get_smiley_pixmap(width, height):
    """Gets a smiley face image

    Arguments:
    width: the width of the pixmap
    height: the height of the pixmap
    """
    global _demo_image
    if not _demo_image:
        demo_image_context = Grx.Context.new(27, 27)
        save = Grx.save_current_context()
        Grx.set_current_context(demo_image_context)
        Grx.clear_context(Grx.color_get(0, 0, 255))
        Grx.draw_filled_circle(13, 13, 13, Grx.color_get(255, 255, 0))
        Grx.draw_filled_circle(8, 8, 2, Grx.color_get_black())
        Grx.draw_filled_circle(18, 8, 2, Grx.color_get_black())
        Grx.draw_filled_ellipse_arc(13, 16, 7, 5, 1800, 3600,
                                    Grx.ArcStyle.CLOSED_CHORD,
                                    Grx.color_get_black())
        Grx.set_current_context(save)

        _demo_image = Grx.Pixmap.new_from_context(demo_image_context)

    return _demo_image.stretch(width, height)
Beispiel #27
0
def get_checkerboard_pixmap():
    """Gets a blue/red checkerboard pattern"""
    global _demo_pattern_context
    if not _demo_pattern_context:
        _demo_pattern_context = Grx.Context.new(32, 32)
        save = Grx.save_current_context()
        Grx.set_current_context(_demo_pattern_context)
        Grx.clear_context(Grx.color_get(0, 0, 255))
        Grx.draw_filled_box(0, 0, 16, 16, Grx.color_get(255, 0, 0))
        Grx.draw_filled_box(17, 17, 32, 32, Grx.color_get(255, 0, 0))
        Grx.set_current_context(save)

    return Grx.Pixmap.new_from_context(_demo_pattern_context)
Beispiel #28
0
 def handle_pen_move(self, x, y):
     if self.pen_down:
         Grx.draw_line(self.pen_x, self.pen_y, x, y, self.fg_color)
     self.pen_x, self.pen_y = x, y
Beispiel #29
0
 def show_next_font(self, step, start_index):
     if step:
         self.prev_index.clear()
         self.font_index += step
         if self.font_index < 0:
             self.font_index = 0
         elif self.font_index >= len(self.font_files):
             self.font_index = len(self.font_files) - 1
     Grx.clear_screen(self.WHITE)
     file_name = self.font_files[self.font_index]
     Grx.draw_text('file: ' + file_name, 10, 10, self.default_text_opt)
     try:
         font = Grx.font_load_from_file(file_name)
         font_info = 'family: {}, style: {}, width: {}, height {}'.format(
             font.get_family(), font.get_style(), font.get_width(),
             font.get_height())
         Grx.draw_text(font_info, 10, 10 + self.v_offset,
                       self.default_text_opt)
         dump_context = Grx.Context.new_subcontext(10,
                                                   10 + self.v_offset * 2,
                                                   Grx.get_width() - 10,
                                                   Grx.get_height() - 10)
         self.next_index = font.dump(dump_context, start_index, self.BLACK,
                                     self.WHITE)
         if self.next_index != -1 and self.next_index != start_index:
             self.prev_index.append(start_index)
     except GLib.Error as err:
         Grx.draw_text(str(err), 10, 10 + self.v_offset,
                       self.default_text_opt)
Beispiel #30
0
    def do_activate(self):
        """called when the application starts
        overrides Grx.Application.do_activate
        """
        Grx.clear_screen(self.bg_color)

        count = len(self.colors)
        remaining = Grx.get_width()
        x0, y0 = 0, 0
        y1 = self.color_picker_y
        for c in self.colors:
            x1 = x0 + remaining // count
            Grx.draw_filled_box(x0, y0, x1, y1, self.colors[c])
            Grx.draw_box(x0, y0, x1, y1, self.fg_color)
            count -= 1
            remaining -= x1 - x0
            x0 = x1
            self.color_lookup.append(c)
        Grx.set_clip_box(0, y1 + 1, Grx.get_max_x(), Grx.get_max_y())
Beispiel #31
0
def activate(app):
    white = Grx.color_get_white()
    x = Grx.get_width() // 10
    y = Grx.get_height() // 10

    line_opts = Grx.LineOptions()
    line_opts.color = white
    line_opts.width = 3
    line_opts.n_dash_patterns = 2
    line_opts.dash_pattern0 = 6
    line_opts.dash_pattern1 = 4
    line_opts0 = Grx.LineOptions()
    pat = demo.get_checkerboard_pixmap()
    Grx.draw_box(x * 1, y * 1, x * 3, y * 3, white)
    Grx.draw_box_with_options(x * 4, y * 1, x * 6, y * 3, line_opts)
    Grx.draw_box_with_pixmap(x * 7, y * 1, x * 9, y * 3, line_opts0, pat)

    img = demo.get_smiley_pixmap(x * 2, y * 2)
    Grx.draw_filled_box(x * 1, y * 4, x * 3, y * 6, white)
    Grx.draw_filled_box_with_pixmap(x * 4, y * 4, x * 6, y * 6, img)
    Grx.draw_filled_box_with_offset_pixmap(x * 2, y, x * 7, y * 4, x * 9,
                                           y * 6, img)

    frame_colors = Grx.FramedBoxColors()
    frame_colors.background = Grx.color_get(224, 223, 228)
    frame_colors.border_top = Grx.color_get(255, 255, 255)
    frame_colors.border_right = Grx.color_get(155, 157, 154)
    frame_colors.border_bottom = Grx.color_get(110, 110, 100)
    frame_colors.border_left = Grx.color_get(241, 239, 226)
    Grx.draw_framed_box(x * 1, y * 7, x * 3, y * 9, y / 4, frame_colors)
    Grx.draw_rounded_box(x * 4, y * 7, x * 6, y * 9, y / 4, white)
    Grx.draw_filled_rounded_box(x * 7, y * 7, x * 9, y * 9, y / 4, white)