Main GUI class

class discopygal.gui.gui.GUI

The RMP GUI class, handles all the boilerplate code for having GUI capable Qt projects

Any GUI application should derive from this class, and set somewhere in the layout the property ‘graphicsView’ to a QGraphicsView. The function you should override in this case is setupUi()

add_circle_segment(radius: float, center_x: float, center_y: float, start_angle: float, end_angle: float, clockwise, fill_color=19, line_color=2)

Add a circle segment to the scene and return the object associated with it

Parameters:
  • radius (float) – radius of circle

  • center_x (float) – x position of circle center

  • center_y (float) – y position of circle center

  • start_angle (float) – start angle of circle segment

  • end_angle (float) – end angle of circle segment

  • clockwise (bool) – draw from start to end clockwise or counter-clockwise

  • fill_color (QtGui.QColor) – color of the interior of circle

  • line_color (QtGui.QColor) – color of the circle segment

Returns:

circle segment

Return type:

RCircleSegment

add_disc(r, x, y, fill_color=2, line_color=2)

Add a disc to the scene with radius r centered at (x, y) and return the object associated with it

Parameters:
  • r (float) – radius of disc

  • x (float) – x position of center of disc

  • y (float) – y position of center of disc

  • fill_color (QtGui.QColor) – color of the interior of disc

  • line_color (QtGui.QColor) – color of the boundary of disc

Returns:

disc

Return type:

RDisc

add_disc_robot(r, x, y, text='', fill_color=2, line_color=2)

Add a disc robot to the scene with radius r centered at (x, y) and return the object associated with it

Parameters:
  • r (float) – radius of disc

  • x (float) – x position of center of disc

  • y (float) – y position of center of disc

  • text (str) – label of the robot

  • fill_color (QtGui.QColor) – color of the interior of disc

Returns:

disc robot

Return type:

RDiscRobot

add_polygon(points, fill_color=2, line_color=2, text='', pos=None)

Add a polygon to the scene and return the object associated with it

Parameters:
  • points (list<(float, float)>) – list of points of polygon

  • fill_color (QtGui.QColor) – color of the interior of polygon

  • line_color (QtGui.QColor) – color of the boundary of polygon

  • pos (QtCore.QPointF) – initial position of polygon (used for animation). If none first vertex is chosen.

Returns:

polygon

Return type:

RPolygon

add_polygon_with_holes(points, holes, fill_color=2, line_color=19)

Add a polygon with holes to the scene and return the object associated with it

Parameters:
  • points (list<(float, float)>) – list of points of polygon

  • holes (list<list<(float, float)>>) – list of holes, each hole is a list of points

  • fill_color (QtGui.QColor) – color of the interior of polygon

  • line_color (QtGui.QColor) – color of the boundary of polygon

Returns:

polygon

Return type:

RPolygonWithHoles

add_segment(x1, y1, x2, y2, line_color=2, opacity=1.0)

Add a segment to the scene and return the object associated with it

Parameters:
  • x1 (float) – x1 position of start endpoint

  • y1 (float) – y1 position of start endpoint

  • x2 (float) – x2 position of end endpoint

  • y2 (float) – y2 position of end endpoint

  • line_color (QtGui.QColor) – color of the segment

  • opacity (float) – opacity of the segment

Returns:

segment

Return type:

RSegment

add_segment_angle(x1, y1, length, angle, line_color=2)

Add an angled segment to the scene and return the object associated with it

Parameters:
  • x1 (float) – x1 position of start endpoint

  • y1 (float) – y1 position of start endpoint

  • length (float) – length of segment

  • angle (float) – angle (in radians) of segment

  • line_color (QtGui.QColor) – color of the segment

Returns:

angled segment

Return type:

RSegment_angle

add_text(text, x, y, size, color=2)

Add a text label to the scene and return the object associated with it

Parameters:
  • text (str) – text label

  • x (float) – x position of text label

  • y (float) – y position of text label

  • size (int) – size of label

  • color (QtGui.QColor) – color of the label

Returns:

text label

Return type:

RText

animation_finished()

Function that is called when the ‘finished’ signal is fired Empties the queue and calls the finished action defined by the program

animation_finished_action()

Function reference that is called when animation is finished

base_line_width = 3.5

Base (default) line width

base_text_size = 2.0

Base (default) text size

clear_scene()

Clear the scene of all objects

empty_queue()

Empty the animation queue

get_field(key)

Get the text of field with key <key> in the GUI

Parameters:

key (str) – key of line edit

Returns:

text of selected line edit

Return type:

str

graphicsView = None

QGraphicsView widget where everything is drawn

height = 1000

Screen height

is_queue_paused()

Return true if the queue is paused.

Returns:

True if paused

Return type:

bool

is_queue_playing()

Return true if the queue is paused.

Returns:

True if paused

Return type:

bool

labels = {}

Dictionary of all UI labels

lineEdits = {}

Dictionary of all UI line inputs

linear_translation_animation(obj, ix, iy, x, y, duration=1000)

Create a new linear translation animation for obj starting at ix, iy and ending at x, y

Parameters:
  • obj (QObject) – object to animate

  • ix (float) – x position of start

  • iy (float) – y position of start

  • x (float) – x position of end

  • y (float) – y position of end

  • duration (int) – duration of animation

Returns:

animation object

Return type:

QPropertyAnimation

mainWindow = None

MainWindowPlus main window

parallel_animation(*animations)

Create an animation from a set of animations that will run in parallel

Parameters:

*animations (QPropertyAnimation, QPropertyAnimation, …) – the animations we want to run in parallel

Returns:

parallel animation group object

Return type:

QParallelAnimationGroup

pause_animation(duration=1000)

Create an animation that does nothing

Parameters:

duration (int) – duration of animation

Returns:

animation object

Return type:

QPropertyAnimation

pause_queue()

Pause an animation

play_queue()

Play (and empty) the animation queue (Either play from start or resume a paused animation)

progressBars = {}

Dictionary of all UI progress bars

pushButtons = {}

Dictionary of all UI push buttons

queue_animation(*animations)

Add an animation to the animation queue

Parameters:

*animations (QPropertyAnimation, QPropertyAnimation, …) – the animations we want to add to queue

redraw()

Redraw the scene with updated parameters

scene = None

GraphicsScenePlus scene that contains all the objects

segment_angle_animation(obj, ix, iy, ia, x, y, a, clockwise, duration=2000)

Create an animation for angle segment starting at ix, iy with angle ia ending at x, y, angle a

Parameters:
  • obj (QObject) – object to animate

  • ix (float) – x position of start segment

  • iy (float) – y position of start segment

  • ia (float) – rotation of the start segment

  • x (float) – x position of end segment

  • y (float) – y position of end segment

  • a (float) – rotation of the end segment

  • clockwise (bool) – rotate the segment clocwise

  • duration (int) – duration of animation

Returns:

animation object

Return type:

QPropertyAnimation

sequence = None

QSequentialAnimationGroup sequence of animation

set_animation_finished_action(action)

Set the function to be called when the animation finishes playing

Parameters:

action (function<()->()>) – action to be called when animation finished

set_button_text(key, s)

Set the text of the button with key <key> in the GUI

Parameters:
  • key (str) – key of the pushbutton

  • s (str) – new label of pushbutton

set_field(key, s)

Set the text of field with key <key> in the GUI

Parameters:
  • key (str) – key of line edit

  • s (str) – new text for line edit

set_label(key, s, color=2)

Set the text of label with key <key> in the GUI

Parameters:
  • key (str) – key of label

  • s (str) – new label text

  • color (QColor) – color of label

set_logic(key, logic)

Set the function to be called when the button with key <key> in the GUI is pressed

Parameters:
  • key (str) – key of pushbutton

  • logic (function<()->()>) – function that is connected to the button

set_program_name(s)

Set the program’s name (title of the window)

Parameters:

s (str) – new window title

set_progressbar_value(key, n: int)

Set the value of the progressBar with key <key>

Parameters:
  • key (str) – key of the progress bar

  • n (int) – value of the progress bar

setupUi()

Setup the UI layout of the application. Should be overridded by any GUI application and define a custom layout.

stop_queue()

Stop (and empty) the animation queue

text_animation(obj, text: int)

Create an animation that changes the text of an object

Parameters:
  • obj (QObject) – object to animate

  • text (int) – the new label we want to set

Returns:

animation object

Return type:

QPropertyAnimation

translation_animation(obj, func, duration=1000)

Create a general translation animation for obj. func is path from the unit interval I to R^2

Parameters:
  • obj (QObject) – object to animate

  • func (function <I -> R^2>) – a function representing a path from unit interal I to R^2

  • duration (int) – duration of animation

Returns:

animation object

Return type:

QPropertyAnimation

value_animation(obj, v_begin, v_end, duration=1000)

Create an animation that changes the value of an object

Parameters:
  • obj (QObject) – object to animate

  • v_begin (object) – the start value of the object

  • v_end (object) – the end value of the object

  • duration (int) – duration of animation

Returns:

animation object

Return type:

QPropertyAnimation

visibility_animation(obj, visible)

Create an animation the changes the visibility of an object

Parameters:
  • obj (QObject) – object to animate

  • visible (bool) – the visibility we wat to set

Returns:

animation object

Return type:

QPropertyAnimation

width = 1600

Screen width

zoom = 1.0

View zoom