"""Common abstract base classes for various backends.
There are three different types of backends.
- GraphicsBackendBase: Everything graphical - windows, canvas objects, labels, interactors.
- AudioBackendBase: Everything auditory - creating and playing sounds.
- ConsoleBackendBase: Everything textual - fonts and lines.
The Tk backend is a graphical backend only. The Java backend is all three.
Other implementations of `ConsoleBackendBase` have been spun out into their own
library `popup-console`.
These abstract base classes are provided for backend developers to see which
methods their backend will need to support. It is considered under development
and can change at any time.
"""
import abc
[docs]class GraphicsBackendBase(abc.ABC):
"""Interface for graphical backends."""
# TODO(sredmond): Decorate all of these classes with @abc.abstractmethod.
# For now, the interlaced decorators make the interface too hard to read.
# GWindow lifecycle.
[docs] def gwindow_constructor(self, gwindow, width, height, top_compound, visible=True): pass
[docs] def gwindow_close(self, gwindow): pass
[docs] def gwindow_delete(self, gwindow): pass
[docs] def gwindow_set_exit_on_close(self, gwindow, exit_on_close): pass
[docs] def gwindow_exit_graphics(self): pass
# GWindow drawing.
[docs] def gwindow_clear(self, gwindow): pass
[docs] def gwindow_clear_canvas(self, gwindow): pass
[docs] def gwindow_repaint(self, gwindow): pass
[docs] def gwindow_draw(self, gwindow, gobject): pass
# GWindow attributes.
[docs] def gwindow_request_focus(self, gwindow): pass
[docs] def gwindow_set_visible(self, gwindow, flag): pass
[docs] def gwindow_set_window_title(self, gwindow, title): pass
[docs] def gwindow_get_width(self): pass
[docs] def gwindow_get_height(self): pass
# GWindow geometry.
[docs] def gwindow_add_to_region(self, gwindow, gobject, region): pass
[docs] def gwindow_remove_from_region(self, gwindow, gobject, region): pass
[docs] def gwindow_set_region_alignment(self, gwindow, region, align): pass
# Shared GObject operations.
[docs] def gobject_set_location(self, gobject, x, y): pass
[docs] def gobject_set_filled(self, gobject, flag): pass
[docs] def gobject_remove(self, gobject): pass
[docs] def gobject_set_color(self, gobject, color): pass
[docs] def gobject_set_fill_color(self, gobject, color): pass
[docs] def gobject_send_forward(self, gobject): pass
[docs] def gobject_send_to_front(self, gobject): pass
[docs] def gobject_send_backward(self, gobject): pass
[docs] def gobject_send_to_back(self, gobject): pass
[docs] def gobject_set_size(self, gobject, width, height): pass
[docs] def gobject_get_size(self, gobject): pass
[docs] def gobject_get_bounds(self, gobject): pass
[docs] def gobject_set_line_width(self, gobject, line_width): pass
[docs] def gobject_contains(self, gobject, x, y): pass
[docs] def gobject_set_visible(self, gobject, flag): pass
[docs] def gobject_scale(self, gobject, sx, sy): pass
[docs] def gobject_rotate(self, gobject, theta): pass
# Rectangular regions
[docs] def grect_constructor(self, grect): pass
[docs] def groundrect_constructor(self, gobject, width, height, corner): pass
[docs] def g3drect_constructor(self, gobject, width, height, raised): pass
[docs] def g3drect_set_raised(self, gobject, raised): pass
# Elliptical regions
[docs] def goval_constructor(self, goval): pass
[docs] def garc_constructor(self, garc): pass
[docs] def garc_set_start_angle(self, garc, angle): pass
[docs] def garc_set_sweep_angle(self, garc, angle): pass
[docs] def garc_set_frame_rectangle(self, garc, x, y, width, height): pass
# GLines
[docs] def gline_constructor(self, gline): pass
[docs] def gline_set_start_point(self, gline, x, y): pass
[docs] def gline_set_end_point(self, gline, x, y): pass
# Compounds
[docs] def gcompound_constructor(self, gobject): pass
[docs] def gcompound_add(self, compound, gobject): pass
# Fonts
[docs] def gfont_default_attributes(self): pass
[docs] def gfont_attributes_from_system_name(self, font_name): pass
[docs] def gfont_get_font_metrics(self, gfont): pass
[docs] def gfont_measure_text_width(self, gfont, text): pass
# Labels
[docs] def glabel_constructor(self, glabel): pass
[docs] def glabel_set_font(self, glabel, gfont): pass
[docs] def glabel_set_label(self, glabel, text): pass
# Polygons
[docs] def gpolygon_constructor(self, gpolygon): pass
[docs] def gpolygon_add_vertex(self, gpolygon, x, y): pass
# Timers
[docs] def gtimer_constructor(self, timer): pass
[docs] def gtimer_delete(self, timer): pass
[docs] def gtimer_start(self, timer): pass
[docs] def gtimer_pause(self, timer, millis): pass
[docs] def gtimer_stop(self, timer): pass
# Images
[docs] def image_find(self, filename): pass
[docs] def image_load(self, filename): pass
[docs] def gimage_constructor(self, gimage, filename): pass
[docs] def gimage_blank(self, gimage, width, height): pass
[docs] def gimage_get_pixel(self, gimage, row, col): pass
[docs] def gimage_set_pixel(self, gimage, row, col, rgb): pass
[docs] def gimage_preview(self, gimage): pass
[docs] def gbufferedimage_constructor(self, gobject, x, y, width, height): pass
[docs] def gbufferedimage_fill(self, gobject, rgb): pass
[docs] def gbufferedimage_fill_region(self, gobject, x, y, width, height, rgb): pass
[docs] def gbufferedimage_load(self, gobject, filename): pass
[docs] def gbufferedimage_resize(self, gobject, width, height, retain): pass
[docs] def gbufferedimage_save(self, gobject, filename): pass
[docs] def gbufferedimage_set_rgb(self, gobject, x, y, rgb): pass
[docs] def gbufferedimage_update_all_pixels(self, gobject, base64): pass
# Events
[docs] def set_action_command(self, gobject, cmd): pass
[docs] def get_next_event(self, mask): pass
[docs] def wait_for_event(self, mask): pass
[docs] def event_add_keypress_handler(self, event, handler): pass
[docs] def event_generate_keypress(self, event): pass
[docs] def event_add_mouse_handler(self, event, handler): pass
[docs] def event_generate_mouse(self, event): pass
[docs] def event_pump_one(self): pass
[docs] def event_add_window_changed_handler(self, handler): pass
[docs] def event_set_window_closed_handler(self, handler): pass
# TODO(sredmond): Rename these backend events for consistency.
[docs] def timer_pause(self, event): pass
[docs] def timer_schedule(self, function, delay_ms): pass
# Interactors
[docs] def gcheckbox_constructor(self, gcheckbox): pass
[docs] def gcheckbox_is_selected(self, gcheckbox): pass
[docs] def gcheckbox_set_selected(self, gcheckbox, state): pass
[docs] def gslider_constructor(self, gslider, min, max, value): pass
[docs] def gslider_get_value(self, gslider): pass
[docs] def gslider_set_value(self, gslider, value): pass
[docs] def gtextfield_constructor(self, gtextfield, num_chars): pass
[docs] def gtextfield_get_text(self, gtextfield): pass
[docs] def gtextfield_set_text(self, gtextfield, text): pass
[docs] def gchooser_constructor(self, gchooser): pass
[docs] def gchooser_add_item(self, gchooser, item): pass
[docs] def gchooser_get_selected_item(self, gchooser): pass
[docs] def gchooser_set_selected_item(self, gchooser, item): pass
# Dialogs
[docs] def gfilechooser_show_open_dialog(self, current_dir, file_filter): pass
[docs] def gfilechooser_show_save_dialog(self, current_dir, file_filter): pass
[docs] def goptionpane_show_confirm_dialog(self, message, title, confirm_type): pass
[docs] def goptionpane_show_message_dialog(self, message, title, message_type): pass
[docs] def goptionpane_show_option_dialog(self, message, title, options, initially_selected): pass
[docs] def goptionpane_show_text_file_dialog(self, message, title, rows, cols): pass
[docs]class ConsoleBackendBase(abc.ABC):
"""Interface for console backends."""
[docs] @abc.abstractmethod
def clear_console(self): pass
[docs] @abc.abstractmethod
def set_console_font(self, font): pass
[docs] @abc.abstractmethod
def set_console_size(self, console_size): pass
[docs] @abc.abstractmethod
def get_console_line(self): pass
[docs] @abc.abstractmethod
def put_console(self, line, stderr=False): pass
[docs] @abc.abstractmethod
def echo_console(self): pass
[docs] @abc.abstractmethod
def end_line_console(self): pass
[docs]class AudioBackendBase(abc.ABC):
"""Interface for audio backends."""
# Sounds
[docs] @abc.abstractmethod
def create_sound(self, sound, *args): pass
[docs] @abc.abstractmethod
def delete_sound(self, sound, *args): pass
[docs] @abc.abstractmethod
def play_sound(self, sound, *args): pass
# Notes
[docs] @abc.abstractmethod
def play_note(self, note, repeat): pass