jguvc_eip.basic_io

Functions

  • start(): This function opens the io window and we can start interacting with it.

  • draw_line(): Draw a line on the currently active image.

  • draw_circle(): Draw a circle on the currently active image.

  • draw_ellipse(): Draw an axis-aligned ellipse on the currently active image.

  • draw_rectangle(): Draw a rectangle on the currently active image.

  • draw_polygon(): Draw a polygon on the currently active image.

  • draw_text(): Draws text at an arbitrary position on the currently active image.

  • draw_pixel(): Changes the color of a single pixel in the active buffer

  • read_pixel(): Reads the color of the specified pixel from the active buffer.

  • load_image(): Loads an image into an internal image database from an external file.

  • draw_image(): Draws an image to the screen (more precisely, the active buffer).

  • draw_object(): Draws a (potentially complex/composite) image object onto the screen.

  • clear_image(): This image clears the active image, overwriting all pixels with a fixed color.

  • set_active_image(): This command chooses which image the draw commands are directed to (which image to draw on).

  • set_visible_image(): This command chooses which image is currently visible.

  • copy_image(): This command copies the content of an image from one buffer to another.

  • resize_image(): This image clears the active image, overwriting all pixels with a fixed color.

  • get_last_key_pressed_event(): This function handles “buffered” keyboard input

  • clear_key_pressed_event_buffer(): Clears the buffer of all key press events recorded so far.

  • get_current_keys_down(): This function handles “unbuffered” keyboard input.

  • get_current_mouse_position(): Queries the current mouse position.

  • print_message(): Prints a message on the message console of the basic_io window (default: lower part of the window),

  • print_html(): Prints a message on the message console of the basic_io window (default: lower part of the window),

  • input_string(): This command opens a small edit box and asks for text to be entered. The result is returned as a string.

  • wait_close(): This command waits until the window is closed.

  • close_and_exit(): Closes the io window and exits the main process, too (stops the currently running program immediately).

jguvc_eip.basic_io.start()

This function opens the io window and we can start interacting with it.

This should be the first statement in your code. Starting is done implicitly, if needed, but it is cleaner to open the window explicitly.

Return type

None

jguvc_eip.basic_io.draw_line(start_x, start_y, end_x, end_y, color=(0, 0, 0), thickness=1)

Draw a line on the currently active image.

Parameters
  • start_x (int) – start of the line (x-coordinate) [pixel]

  • start_y (int) – start of the line (y-coordinate) [pixel]

  • end_x (int) – end of the line (x-coordinate) [pixel]

  • end_y (int) – end of the line (y-coordinate) [pixel]

  • color (Tuple[int, int, int]) – color of the line (default: black) [0..255]³

  • thickness (int) – line thickness, default 1 [pixel]

Return type

None

jguvc_eip.basic_io.draw_circle(x, y, radius, fill_color=(0, 0, 0), border_color=(0, 0, 0), border_thickness=1)

Draw a circle on the currently active image.

Parameters
  • x (int) – center of the ellipse, x-coordinate [pixel]

  • y (int) – center of the ellipse, y-coordinate [pixel]

  • radius (int) – radius of the circle [pixel]

  • fill_color (Optional[Tuple[int, int, int]]) – the color for filling the polygon. can be set to None (then, shape is not filled) [0…255]³

  • border_color (Optional[Tuple[int, int, int]]) – the color for the border of the polygon. can be set to None (then, shape is not filled) [0…255]³

  • border_thickness (int) – the thickness of the border (a value of zero also turns off borders) [pixel]

Return type

None

jguvc_eip.basic_io.draw_ellipse(x, y, radius_x, radius_y, fill_color=(0, 0, 0), border_color=(0, 0, 0), border_thickness=1)

Draw an axis-aligned ellipse on the currently active image.

Parameters
  • x (int) – center of the ellipse, x-coordinate

  • y (int) – center of the ellipse, y-coordinate

  • radius_x (int) – radius in x-direction

  • radius_y (int) – radius in y-direction

  • fill_color (Optional[Tuple[int, int, int]]) – the color for filling the polygon. can be set to None (then, shape is not filled) [0…255]³

  • border_color (Optional[Tuple[int, int, int]]) – the color for the border of the polygon. can be set to None (then, shape is not filled) [0…255]³

  • border_thickness (int) – the thickness of the border (a value of zero also turns off borders) [pixel]

Return type

None

jguvc_eip.basic_io.draw_rectangle(x, y, width, height, fill_color=(0, 0, 0), border_color=(0, 0, 0), border_thickness=1)

Draw a rectangle on the currently active image.

Parameters
  • x (int) – x-coordinate of upper left corner [pixel]

  • y (int) – y-coordinate of upper left corner [pixel]

  • width (int) – width of the rectangle [pixel]

  • height (int) – height of the rectangle [pixel]

  • fill_color (Optional[Tuple[int, int, int]]) – the color for filling the polygon. can be set to None (then, shape is not filled) [0…255]³

  • border_color (Optional[Tuple[int, int, int]]) – the color for the border of the polygon. can be set to None (then, shape is not filled) [0…255]³

  • border_thickness (int) – the thickness of the border (a value of zero also turns off borders) [pixel]

Return type

None

jguvc_eip.basic_io.draw_polygon(points, fill_color=(0, 0, 0), border_color=(0, 0, 0), border_thickness=1)

Draw a polygon on the currently active image.

Parameters
  • points (List[Tuple[int, int]]) – a list of tuples (x:int, y:int) of x- and y-coordinates of the points of the polygon to be drawn ([pixel] x [pixel])^num_points

  • fill_color (Optional[Tuple[int, int, int]]) – the color for filling the polygon. can be set to None (then, shape is not filled) [0…255]³

  • border_color (Optional[Tuple[int, int, int]]) – the color for the border of the polygon. can be set to None (then, shape is not filled) [0…255]³

  • border_thickness (int) – the thickness of the border (a value of zero also turns off borders) [pixel]

Return type

None

jguvc_eip.basic_io.draw_text(x, y, text, color=(0, 0, 0), background_color=None, font_height=16)

Draws text at an arbitrary position on the currently active image.

Parameters
  • x (int) – x coordinate where the text starts (upper-left corner) [pixel]

  • y (int) – y coordinate where the text starts (upper-left corner) [pixel]

  • text (str) – text to be printed [string]

  • color (Tuple[int, int, int]) – the color to be used (optional, default=BLACK) [0…255]³

  • background_color (Optional[Tuple[int, int, int]]) – optional argument that specifies the background fill color [0…255]³

  • font_height (int) – the height of the characters in pixel (optional, default=16 pixel) [pixel]

Return type

None

jguvc_eip.basic_io.draw_pixel(x, y, color=(0, 0, 0))

Changes the color of a single pixel in the active buffer

Parameters
  • x (int) – x coordinate of the pixel

  • y (int) – y coordinate of the pixel

  • color (Tuple[int, int, int]) – the color to be used (optional, default=BLACK) [0…255]³

Return type

None

jguvc_eip.basic_io.read_pixel(x, y)

Reads the color of the specified pixel from the active buffer.

Parameters
  • x (int) – x coordinate of the pixel

  • y (int) – y coordinate of the pixel

Result

An RGB Tuple from {0,1,2,…,255}^3 or (-1, -1, -1) if something went wrong (in particular, if the specified pixel coordinate was outside the buffer)

Return type

Tuple[int, int, int]

jguvc_eip.basic_io.load_image(filename)

Loads an image into an internal image database from an external file.

Parameters

filename (str) – the filename of the image file. The function accepts both png and jpg files. png-files with transparency are rendered correctly (with transparent pixels / using the alpha-channel). This can be used for defining sprites for games or icons for UIs or the similar.

Return type

int

Returns

an integer index under which the image has been stored internally. In case of errors (such as “file not found”), index -1 is returned. Images can only have positive indices 0,1,2,3,… Thus, -1 is always an invalid image (and cannot be used to draw on the screen)

jguvc_eip.basic_io.draw_image(x, y, index)

Draws an image to the screen (more precisely, the active buffer).

Parameters
  • x (int) – x-coordinate of top-left pixel of the image to be drawn

  • y (int) – y-coordinate of the top-left pixel of the image to be drawn

  • index (int) – index of the image in the internal database. Invalid indices will be ignored (no action taken).

Return type

None

jguvc_eip.basic_io.draw_object(obj, x=0, y=0)

Draws a (potentially complex/composite) image object onto the screen. See module :module: image_objects.py for choices.

Parameters
  • obj (ImageObject) – The image object to be drawn.

  • x (int) – (optional) offset in x-direction; by default, the shape is drawn in the top left corner (x-offset 0)

  • y (int) – (optional) offset in y-direction; by default, the shape is drawn in the top left corner (y-offset 0)

Return type

None

jguvc_eip.basic_io.clear_image(color=(255, 255, 255))

This image clears the active image, overwriting all pixels with a fixed color. By default, the color is white.

Parameters

color (Tuple[int, int, int]) – the color with which the image is overwritten. Defaults to WHITE if not given.

Return type

None

jguvc_eip.basic_io.set_active_image(buffer)

This command chooses which image the draw commands are directed to (which image to draw on).

basic_io provides 10 “buffers”, indexed by 0 to 9. Numbers smaller than 0 or larger than 9 cause an exception. If the buffer does not yet exist, it will be automatically created (with the default size of 640x480 pixel). By default, buffer 0 is active and visible.

Parameters

buffer (int) – index of the buffer to draw to in the future

Return type

None

jguvc_eip.basic_io.set_visible_image(buffer)

This command chooses which image is currently visible.

By default, this is the same as the active image, that we are drawing on. In general, visible and active image can be different (for example, to implement double buffering to avoid flicker). basic_io provides 10 “buffers”, indexed by 0 to 9. Numbers smaller than 0 or larger than 9 cause an exception. If the buffer does not yet exist, it will be automatically created (with the default size of 640x480 pixel, initialized with a white background). By default, buffer 0 is active and visible.

Parameters

buffer (int) – index of the buffer that will be visible from now on.

Return type

None

jguvc_eip.basic_io.copy_image(from_buffer, to_buffer)

This command copies the content of an image from one buffer to another.

The width/height of the destination will be set to that of the source.

Parameters
  • from_buffer (int) – source buffer [0,1,…,9]

  • to_buffer (int) – destination buffer [0,1,…,9]

Return type

None

jguvc_eip.basic_io.resize_image(width, height, color=(255, 255, 255))

This image clears the active image, overwriting all pixels with a fixed color.

By default, the color is white.

Parameters
  • width (int) – new width of the image in pixel, must be in range [1,2,…,10000]

  • height (int) – new height of the image in pixel, must be in range [1,2,…,10000]

  • color (Tuple[int, int, int]) – the color with which the image is overwritten. Defaults to WHITE if not given.

Return type

None

jguvc_eip.basic_io.get_last_key_pressed_event()

This function handles “buffered” keyboard input

It works as follows: Whenever a key is pressed on the keyboard, it will be recorded and placed in a list sorted by time of pressing. This function returns the earliest key-press event that is found in this list, and removes it from the list. Hence, keyboard events arrive in the order of being pressed. Events are also recorded while the program is doing other things - you do not need to call this function at the time of the key being pressed down for the event to be recorded - it will be reported at a later time when the function is called. In case no key had been pressed, an empty string is returned.

Scope/limitations:
  • Currently, only ascii-characters ‘a’-‘z’, ‘A’-‘Z’ and numbers ‘0’-‘9’ are reported, all other letters are ignored

  • Special/control keys: only the space bar ‘ ‘, return key ‘backslash-n’ , and the cursor keys are reported. cursor keys appear as ‘cursor_left’, ‘cursor_right’, ‘cursor_up’, ‘cursor_down’

  • A mouse click onto the current image is also recognized and reported as ‘left_mouse_button’ or ‘right_mouse_button’.

Return type

str

Returns

a string containing a single character (’ ‘,’a’…’z’,’A’,…,’Z’,’0’…,’9’) or the string ‘backslash-n’ (single character) for the return-key a code for a cursor key (‘cursor_left’, ‘cursor_right’, ‘cursor_up’, ‘cursor_down’) or ‘left_mouse_button’, ‘right_mouse_button’ for mouse clicks, or ‘’ if nothing has happened (empty buffer)

jguvc_eip.basic_io.clear_key_pressed_event_buffer()

Clears the buffer of all key press events recorded so far.

Return type

None

jguvc_eip.basic_io.get_current_keys_down()

This function handles “unbuffered” keyboard input.

It returns a list of all keys that are pressed down at the instance in time when this function is being called (more precisely: when the window process receives the request from this call).

Any call to ‘get_current_keys_down()’ also clears the buffer for the “buffered” input of get_last_key_pressed_event()” to avoid chaos / mixing up events.

Scope/limitations:
  • Currently, only ascii-characters ‘a’-‘z’, ‘A’-‘Z’ and numbers ‘0’-‘9’ are reported, all other letters are ignored

  • Special/control keys: only the space bar ‘ ‘, return key ‘backslash-n’, and the cursor keys are reported. cursor keys appear as ‘cursor_left’, ‘cursor_right’, ‘cursor_up’, ‘cursor_down’

  • A mouse click onto the current image is also recognized and reported as ‘left_mouse_button’ or ‘right_mouse_button’.

Return type

List[str]

Returns

A list of pressed keys. Each key is encoded as a a string containing a single character (’ ‘,’a’…’z’,’A’,…,’Z’,’0’…,’9’) or the string ‘backslash-n’ (single character) for the return-key a code for a cursor key (‘cursor_left’, ‘cursor_right’, ‘cursor_up’, ‘cursor_down’) or ‘left_mouse_button’, ‘right_mouse_button’ for mouse clicks. If no key is currently pressed, the return value is an empty list ([]).

jguvc_eip.basic_io.get_current_mouse_position()

Queries the current mouse position.

Mouse positions are only recorded while the mouse is residing over the currently visible image; afterwards, the last event might remain. Clicks on the image (mouse button down) ‘capture’ the mouse, i.e., even values outside the image boundaries are tracked (negative coordinates or coordinates larger than width-1, height-1 are now possible. This is useful for interaction with the mouse such as click & draw on images).

Return type

Tuple[int, int]

Returns

The current mouse position as Tuple of (x,y) with pixel coordinates for x- and y-axis

jguvc_eip.basic_io.print_message(text)

Prints a message on the message console of the basic_io window (default: lower part of the window), not on the active image/main screen!

This makes sure the message will be visible (useful for diagnostics, debugging, etc.)

Parameters

text (str) – a string with the message to be printed

Return type

None

jguvc_eip.basic_io.print_html(text)

Prints a message on the message console of the basic_io window (default: lower part of the window), not on the active image/main screen!

This makes sure the message will be visible (useful for diagnostics, debugging, etc.) The string will be interpreted as HTML code and displayed formatted accordingly. Note: The html-output is not very stable (most likely due to QT limitations). Use with caution…

Parameters

text (str) – a string with the message to be printed

Return type

None

jguvc_eip.basic_io.input_string(question)

This command opens a small edit box and asks for text to be entered. The result is returned as a string. Entering is concluded by pressing the Ok-Button (or by pressing return, i.e., results are on-liners).

Parameters

question (str) – the message in front of the command-prompt

Result

the string entered (might be empty)

Return type

str

jguvc_eip.basic_io.wait_close()

This command waits until the window is closed.

This should typically be the last statement in your program.

Return type

None

jguvc_eip.basic_io.close_and_exit()

Closes the io window and exits the main process, too (stops the currently running program immediately).

Return type

None