bdedit package

Submodules

bdedit.Icons module

bdedit.Icons.qCleanupResources()
bdedit.Icons.qInitResources()

bdedit.block module

class bdedit.block.Block(scene, window, name='Unnamed Block', pos=(0, 0))

Bases: bdedit.interface_serialize.Serializable

The Block Class extends the Serializable Class from BdEdit, and defines how a block is represented, and has all the necessary methods for creating, manipulating and interacting with a block.

This class includes information about the blocks’:

  • name;

  • type;

  • appearance;

  • on-screen positioning;

  • parameters, and their values;

  • number of inputs and outputs.

__init__(scene, window, name='Unnamed Block', pos=(0, 0))

This method initializes an instance of the Block Class. It maps the following internal parameters of the block, initializing them to their defaults values. These are overwritten when an instance of the grandchild block is created. The parameters are defined as:

  • title: the name of the Block. This defaults to the name of the name of the grandchild class, and is incremented if an instance with the same default name already exists.

  • type: the type of Block. This defaults to the type of the grandchild class, and is determined through calling blockname(self.__class__) when a grandchild class is created.

  • icon: the icon for this Block. This is a locally referenced string filepath, defined within the grandchild class.

  • inputs: a list of containing input Sockets relating to this Block. The number of input sockets is restricted to 0 or n based on the inputsNum variable defined within the child class.

  • outputs: a list of containing output Sockets relating to this Block. The number of output sockets is restricted to 0 or n based on the outputsNum variable defined within the child class.

  • parameters: a list of editable parameters relating to this Block. This defaults to the list defined within the grandchild class, but follows the following structure of being a list of lists, where each ‘lists’ is a list defining the parameter as below:

    • parameters = [“name”, type, value, [restrictions]] e.g. parameters = [[“Gain”, float, gain, []], [“Premul”, bool, premul, []]]

    • name: is the name of the variable as a string

    • type: is the required type the variable should be (e.g. int, str, float)

    • value: is the default value the variable is set to should one not be provided

    • restrictions: is a list (can be list of lists) containing further restrictions applied to the parameter. These restrictions follow the following structure, of being a list with a string as the first list element, followed by a list of conditions being applied to the parameter as the second list element:

      • restriction = [“restriction name”, [condition(s)]]

      • restriction name: can be only one of the following “keywords”, “range”, “type” or “signs”.

      • condition(s): differ based on the restriction name used, and will be of the following format:

        • for keywords: a list of string words the parameter must exactly match to, e.g. [“keywords”, [“sine”, “square”, “triangle”]]

        • for range: a list containing a min and max allowable value for this parameter, e.g. [“range”, [0, 1000]] or [“range”, [-math.inf, math.inf]]

        • for type: a list containing alternative types, with the last value repeating the initial type required for this parameter, e.g. [“type”, [type(None), tuple]] (initial type = tuple) or [“type”, [type(None), bool]] (initial type = bool)

        • for signs: a list containing each allowable character this parameter can match, e.g. [“signs”, [“*”, “/”]] or [“signs”, [“+”, “-“]] currently this is used for drawing signs along certain input sockets, so only these characters are supported,

Parameters
  • scene (Scene, required) – a scene (or canvas) in which the Block is stored and shown (or painted into). Provided by the Interface.

  • window (QGridLayout, required) – layout information of where all Widgets are located in the bdedit window. Provided by the Interface.

  • name (str, optional) – set to grandchild class’s default name “__class__.__name__ Block” when it is created

  • pos (tuple of 2-ints, optional) – (x,y) coordinates of the block’s positioning within the Scene, defaults to (0,0)

closeParamWindow()

This method closes the ParamWindow of this Block

deserialize(data, hashmap={})

This method is called to reconstruct a Block when loading a saved JSON file containing all relevant information to recreate the Scene with all its items.

Parameters
  • data (OrderedDict, required) – a Dictionary of essential information for reconstructing a Block

  • hashmap (Dict, required) – a Dictionary for directly mapping the essential block parameters to this instance of Block, without having to individually map each parameter

Returns

True when completed successfully

Return type

Boolean

getSocketPosition(index, position)

This method is called to determine the coordinates of where a given Socket should be positioned on the sides of the this Block. The returned coordinates are in reference to the coordinates of this Block.

Parameters
  • index (int, required) – the index of this Socket in the list of sockets for this Block

  • position – the (LEFT(1) or RIGHT(3)) side of the block this socket

should be displayed on. :type position: enumerate, required :return: the [x,y] coordinates at which to place this Socket instance. :rtype: list of int, int

makeInputSockets(inputs, position, socketType=1)

This method is called to create a number of input Sockets for this Block.

Parameters
  • inputs (int, required) – number of input sockets to create

  • position – an enum representing the position of where to place

the Socket on the Block currently only supports LEFT (1), or RIGHT (3). :type position: enumerate, required :param socketType: an enum representing the type of Socket to create. This is used for the graphics of the socket, but was also intended to be used to reduce two methods for creating input and output sockets, to a single method. :type socketType: enumerate, optional, defaults to INPUT(1)

makeOutputSockets(outputs, position, socketType=2)

This method is called to create a number of outputs Sockets for this Block.

Parameters
  • outputs (int, required) – number of output sockets to create

  • position – an enum representing the position of where to place

the Socket on the Block currently only supports LEFT (1), or RIGHT (3). :type position: enumerate, required :param socketType: an enum representing the type of Socket to create. This is used for the graphics of the socket, but was also intended to be used to reduce two methods for creating input and output sockets, to a single method. :type socketType: enumerate, optional, defaults to OUTPUT(2)

property pos

This method is called to access the positional coordinates of this Block in terms of where it is displayed within the Scene

Returns

the (x,y) coordinates of this Block

Return type

tuple (int, int)

remove()

This method is called to remove:

  • the selected Block instance;

  • any sockets associated with this Block;

  • any wires that were connected to this Blocks’ sockets; and

  • the parameter window associated with this Block (if one existed).

removeSockets(type)

This method removes all sockets of given type, associated with this Block.

Parameters

type – the type of Socket to remove (“Input” for input type,

“Output” for output type) :type type: str, required

serialize()

This method is called to create an ordered dictionary of all of this Blocks’ parameters - necessary for the reconstruction of this Block - as key-value pairs. This dictionary is later used for writing into a JSON file.

Returns

an OrderedDict of [keys, values] pairs of all essential Block parameters.

Return type

OrderedDict ([keys, values]*)

setDefaultTitle(name, increment=None)

This method is called to give a block a generic name, and if that name already exists, to increment it by 1.

Parameters
  • name (str, required) – the generic name to be given to this Block

  • increment – the number to display next to the generic name, to make

it unique. Defaults to None if this is the first instance of this block type. :type increment: int, optional

setFocusOfBlocks()

This method sends all Block instances within the Scene to back and then sends the currently selected Block instance to front.

setPos(x, y)

This method is called to set the positional coordinates of this Block in terms of where it is displayed within the Scene

Parameters
  • x (int, required) – the x coordinate of this Block

  • y (int, required) – the y coordinate of this Block

setTitle(name=None)

This method is called to determine if a this Block can be named with the provided name. It applies logic to check if the given name of type str, and if no other Block instance already has the given name. If either of these conditions are not met, the user will be notified to provide a different name.

Parameters

name – given name to be set for this Block, defaults to None if

not provided :type name: str, optional :return: - nothing (if name successfully set);

  • [duplicate error message, given name] (if duplicate found);

  • invalid type error message (if name is not of type str).

Return type

  • nothing (if name successfully set);

  • list of [str, str] (if duplicate found);

  • str (if name is not of type str).

toggleParamWindow()

This method toggles the visibility of the ParamWindow of this Block

static tuple_decoder(obj)

This method is called when deserializing a JSON file to generate a saved copy of the Scene with all the Blocks, Sockets and Wires. It’s purpose is for decoding an encoded representation for a tuple (encoded with the TupleEncoder Class) when the JSON file was written. This decoder/encoder combination is required as JSON does not support saving under type tuple, and instead saves that information as a type list.

This code has been adapted from: https://stackoverflow.com/a/15721641

Parameters

obj (Union [int, slice], required) – the string object being decoded

Returns

the string object wrapped as a tuple (if decoded to have a __tuple__ key)

the string object (otherwise) :rtype: - tuple (if decoded to have a __tuple__ key); - any (otherwise)

updateConnectedEdges()

This method calls for any and all Wire instances that are connected to a Socket instance, to update where it is drawn TO and FROM.

updateSocketPositions()

This method updates flips the position (LEFT or RIGHT) of where the input and output sockets needs to be placed within this Block. After the positions of all the Blocks’ sockets are updated, the updateConnectedEdges method is called to update the locations for where the wires connect to.

updateSocketSigns()

As some Blocks - namely the PROD and SUM Blocks - have additional logic for drawing signs (+,-,*,/) alongside the input sockets, this method updates these signs of the socket, if the block type is a PROD or SUM Block

class bdedit.block.DiscreteBlock(scene, window, name='Unnamed Discrete Block', pos=(0, 0))

Bases: bdedit.block.Block

The DiscreteBlock Class is a subclass of Block, and referred to as a child class of Block. It inherits all the methods and parameters of its parent class and controls the number of input or output Sockets any subclass (referred to as a grandchild class of Block) that inherits it has.

__init__(scene, window, name='Unnamed Discrete Block', pos=(0, 0))

This method initializes an instance of the DiscreteBlock Class.

Parameters
  • scene (Scene, required) – inherited through Block

  • window (QGridLayout, required) – inherited through Block

  • name – overwritten to the name of grandchild class’s block name,

defaults to “Unnamed Discrete Block” :type name: str, optional :param pos: inherited through Block :type pos: tuple of 2-ints, optional

numInputs()

This method returns the number of input sockets this Block has.

Returns

number of input sockets associated with this Block.

Return type

int

numOutputs()

This method returns the number of output sockets this Block has.

Returns

number of input sockets associated with this Block.

Return type

int

class bdedit.block.FunctionBlock(scene, window, name='Unnamed Function Block', pos=(0, 0))

Bases: bdedit.block.Block

The FunctionBlock Class is a subclass of Block, and referred to as a child class of Block. It inherits all the methods and parameters of its parent class and controls the number of input or output Sockets any subclass (referred to as a grandchild class of Block) that inherits it has.

__init__(scene, window, name='Unnamed Function Block', pos=(0, 0))

This method initializes an instance of the FunctionBlock Class.

Parameters
  • scene (Scene, required) – inherited through Block

  • window (QGridLayout, required) – inherited through Block

  • name – overwritten to the name of grandchild class’s block name,

defaults to “Unnamed Function Block” :type name: str, optional :param pos: inherited through Block :type pos: tuple of 2-ints, optional

numInputs()

This method returns the number of input sockets this Block has.

Returns

number of input sockets associated with this Block.

Return type

int

numOutputs()

This method returns the number of output sockets this Block has.

Returns

number of input sockets associated with this Block.

Return type

int

class bdedit.block.INPORTBlock(scene, window, name='Unnamed INPORT Block', pos=(0, 0))

Bases: bdedit.block.Block

The INPORTBlock Class is a subclass of Block, and referred to as a child class of Block. It inherits all the methods and parameters of its parent class and controls the number of input or output Sockets any subclass (referred to as a grandchild class of Block) that inherits it has.

__init__(scene, window, name='Unnamed INPORT Block', pos=(0, 0))

This method initializes an instance of the INPORTBlock Class.

Parameters
  • scene (Scene, required) – inherited through Block

  • window (QGridLayout, required) – inherited through Block

  • name (str, optional) – overwritten to the name of grandchild class’s block name, defaults to “Unnamed INPORT Block”

  • pos (tuple of 2-ints, optional) – inherited through Block

numInputs()

This method returns the number of input sockets this Block has.

Returns

number of input sockets associated with this Block.

Return type

int

numOutputs()

This method returns the number of output sockets this Block has.

Returns

number of input sockets associated with this Block.

Return type

int

class bdedit.block.OUTPORTBlock(scene, window, name='Unnamed OUTPORT Block', pos=(0, 0))

Bases: bdedit.block.Block

The OUTPORTBlock Class is a subclass of Block, and referred to as a child class of Block. It inherits all the methods and parameters of its parent class and controls the number of input or output Sockets any subclass (referred to as a grandchild class of Block) that inherits it has.

__init__(scene, window, name='Unnamed OUTPORT Block', pos=(0, 0))

This method initializes an instance of the OUTPORTBlock Class.

Parameters
  • scene (Scene, required) – inherited through Block

  • window (QGridLayout, required) – inherited through Block

  • name – overwritten to the name of grandchild class’s block name,

defaults to “Unnamed OUTPORT Block” :type name: str, optional :param pos: inherited through Block :type pos: tuple of 2-ints, optional

numInputs()

This method returns the number of input sockets this Block has.

Returns

number of input sockets associated with this Block.

Return type

int

numOutputs()

This method returns the number of output sockets this Block has.

Returns

number of input sockets associated with this Block.

Return type

int

class bdedit.block.SUBSYSTEMBlock(scene, window, name='Unnamed SUBSYSTEM Block', pos=(0, 0))

Bases: bdedit.block.Block

The SUBSYSTEMBlock Class is a subclass of Block, and referred to as a child class of Block. It inherits all the methods and parameters of its parent class and controls the number of input or output Sockets any subclass (referred to as a grandchild class of Block) that inherits it has.

__init__(scene, window, name='Unnamed SUBSYSTEM Block', pos=(0, 0))

This method initializes an instance of the SUBSYSTEMBlock Class.

Parameters
  • scene (Scene, required) – inherited through Block

  • window (QGridLayout, required) – inherited through Block

  • name – overwritten to the name of grandchild class’s block name,

defaults to “Unnamed SUBSYSTEM Block” :type name: str, optional :param pos: inherited through Block :type pos: tuple of 2-ints, optional

numInputs()

This method returns the number of input sockets this Block has.

Returns

number of input sockets associated with this Block.

Return type

int

numOutputs()

This method returns the number of output sockets this Block has.

Returns

number of input sockets associated with this Block.

Return type

int

class bdedit.block.SinkBlock(scene, window, name='Unnamed Sink Block', pos=(0, 0))

Bases: bdedit.block.Block

The SinkBlock Class is a subclass of Block, and referred to as a child class of Block. It inherits all the methods and parameters of its parent class and controls the number of input or output Sockets any subclass (referred to as a grandchild class of Block) that inherits it has.

__init__(scene, window, name='Unnamed Sink Block', pos=(0, 0))

This method initializes an instance of the SinkBlock Class.

Parameters
  • scene (Scene, required) – inherited through Block

  • window (QGridLayout, required) – inherited through Block

  • name – overwritten to the name of grandchild class’s block name,

defaults to “Unnamed Sink Block” :type name: str, optional :param pos: inherited through Block :type pos: tuple of 2-ints, optional

numInputs()

This method returns the number of input sockets this Block has.

Returns

number of input sockets associated with this Block.

Return type

int

numOutputs()

This method returns the number of output sockets this Block has.

Returns

number of input sockets associated with this Block.

Return type

int

class bdedit.block.SourceBlock(scene, window, name='Unnamed Source Block', pos=(0, 0))

Bases: bdedit.block.Block

The SourceBlock Class is a subclass of Block, and referred to as a child class of Block. It inherits all the methods and parameters of its parent class and controls the number of input or output Sockets any subclass (referred to as a grandchild class of Block) that inherits it has.

__init__(scene, window, name='Unnamed Source Block', pos=(0, 0))

This method initializes an instance of the SourceBlock Class.

Parameters
  • scene (Scene, required) – inherited through Block

  • window (QGridLayout, required) – inherited through Block

  • name – overwritten to the name of grandchild class’s block name,

defaults to “Unnamed Source Block” :type name: str, optional :param pos: inherited through Block :type pos: tuple of 2-ints, optional

numInputs()

This method returns the number of input sockets this Block has.

Returns

number of input sockets associated with this Block.

Return type

int

numOutputs()

This method returns the number of output sockets this Block has.

Returns

number of input sockets associated with this Block.

Return type

int

class bdedit.block.TransferBlock(scene, window, name='Unnamed Transfer Block', pos=(0, 0))

Bases: bdedit.block.Block

The TransferBlock Class is a subclass of Block, and referred to as a child class of Block. It inherits all the methods and parameters of its parent class and controls the number of input or output Sockets any subclass (referred to as a grandchild class of Block) that inherits it has.

__init__(scene, window, name='Unnamed Transfer Block', pos=(0, 0))

This method initializes an instance of the TransferBlock Class.

Parameters
  • scene (Scene, required) – inherited through Block

  • window (QGridLayout, required) – inherited through Block

  • name – overwritten to the name of grandchild class’s block name,

defaults to “Unnamed Transfer Block” :type name: str, optional :param pos: inherited through Block :type pos: tuple of 2-ints, optional

numInputs()

This method returns the number of input sockets this Block has.

Returns

number of input sockets associated with this Block.

Return type

int

numOutputs()

This method returns the number of output sockets this Block has.

Returns

number of input sockets associated with this Block.

Return type

int

class bdedit.block.TupleEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)

Bases: json.encoder.JSONEncoder

This Class inherits JSONEncoder from the json library, and is used to encode user-editable parameters associated with a Block which need to be stored as a type tuple. This code is necessary as JSON does not support storing data as tuples. After the encoder has been used to serialize (save) the Block parameter data, when the Block is deserialized (loaded), this encoded representation of a tuple will be decoded and stored as a tuple.

This code is adapted from: https://stackoverflow.com/a/15721641

encode(item)

This method determines whether a given user-editable block parameter is of type tuple, and converts it to a dictionary with a “__tuple__” key with value True (signifying this parameter should be represented as a tuple), and an “item’s” key with value item (this being the value of the user-editable parameter).

Parameters

item (any) – the user-editable parameter’s value

Returns

  • a Dictionary defined as above (if item is tuple);

  • the item (otherwise)

Return type

  • Dict (if item is tuple);

  • any (otherwise)

bdedit.block.block(cls)

This method is called whenever a grandchild class of the Block is called, adding it to a list of usable blocks.

This code has been adapted from: https://github.com/petercorke/bdsim/blob/bdedit/bdsim/components.py

Parameters

cls (Class, required) – the class of the Block Class’s grandchild block Class.

bdedit.block.blockname(cls)

This method strips any underscores from a grandchild Class of the Block Class, and capitalizes the Class.__name__ to be used as the the Class’s name.

This code has been adapted from: https://github.com/petercorke/bdsim/blob/bdedit/bdsim/bdsim.py

Parameters

cls (Class, required) – the class of the Block Class’s grandchild block Class.

Returns

a reformatted string of the block’s class name

Return type

str

bdedit.block_graphics_block module

class bdedit.block_graphics_block.GraphicsBlock(block, parent=None)

Bases: PyQt5.QtWidgets.QGraphicsItem

The GraphicsBlock Class extends the QGraphicsItem Class from PyQt5. This class is responsible for graphically drawing Blocks within the GraphicsScene. Using the provided Block dimensions, it specifies the Blocks’ shape and colour.

__init__(block, parent=None)

This method initializes an instance of the GraphicsBlock Class. It inherits the dimensions of its Block, and defines its shape and colour.

Parameters
  • block (Block, required) – the Block this GraphicsBlock instance relates to

  • parent (NoneType, optional, defaults to None) – the parent widget this class instance belongs to (None)

boundingRect()

This is an inbuilt method of QGraphicsItem, that is overwritten by GraphicsBlock which returns the area within which the GraphicsBlock can be interacted with. When a mouse click event is detected within this area, this will trigger logic that relates to a Block (that being, selecting/deselecting, moving, deleting, flipping or opening a parameter window).

Returns

a rectangle within which the Block can be interacted with

Return type

QRectF

checkBlockHeight()

This method checks if the current height of the Block is enough to fit all the Sockets that are to be drawn, while following the set socket spacing. It also handles the resizing of the Block (if there isn’t enough space for all the sockets), ensuring the sockets are evenly spaced while following the set socket spacing.

checkMode()

This method checks the mode of the GraphicsScene’s background (Light, Dark) and updates the colour mode of the pens and brushes used to paint this Block.

getTitle()

This method returns the current title of this Block.

Returns

Block title

Return type

str

initTitle()

This method initializes a QGraphicsTextItem which will graphically represent the title (name) of this Block.

initUI()

This method sets flags to allow for this Block to be movable and selectable.

mouseMoveEvent(event)

This is an inbuilt method of QGraphicsItem, that is overwritten by GraphicsBlock to detect, and assign logic to mouse movement.

Currently, the following logic is applied to the Block on mouse movement:

  • a detected mouse move event on this GraphicsBlock will enforce grid-snapping on the selected GraphicsBlock (making it move only in increments of the same size as the smaller grid squares of the background).

  • the selected GraphicsBlock will be prevented from moving outside the maximum zoomed out border of the work area (the GraphicsScene).

  • the connection points of any wires connected to the selected block AND any other block it is connected to, will be updated, as the block is moved around.

Parameters

event (QMouseMoveEvent, automatically recognized by the inbuilt function) – a mouse movement event

mousePressEvent(event)

This is an inbuilt method of QGraphicsItem, that is overwritten by GraphicsBlock to detect, and assign logic to a right mouse press event.

Currently a detected mouse press event on the GraphicsBlock will select or deselect it.

  • If selected, the GraphicsBlock will be sent to front and will appear on top of other blocks.

  • Additionally, if the right mouse button is pressed and a GraphicsBlock is selected, a parameter window will be toggled for this Block.

Parameters

event (QMousePressEvent, automatically recognized by the inbuilt function) – a mouse press event (Left, Middle or Right)

paint(painter, style, widget=None)

This is an inbuilt method of QGraphicsItem, that is overwritten by GraphicsBlock. This method is automatically called by the GraphicsView Class whenever even a slight user-interaction is detected within the Scene.

Before drawing, the dimensions of the Block are checked, to ensure they can hold all the necessary Sockets. Then the following are drawn in order:

  • the title of the block

  • the fill of the block (a rounded rectangle)

  • the outline of the block (a rounded rectangle)

  • the icon of the block (if one exists)

Parameters
  • painter (QPainter, automatically recognized and overwritten from this method) – a painter (paint brush) that paints and fills the shape of this GraphicsBlock

  • style (QStyleOptionGraphicsItem, automatically recognized from this method) – style of the painter (isn’t used but must be defined)

  • widget (NoneType, optional, defaults to None) – the widget this class is being painted on (None)

setTitle()

This method updates this Blocks’ graphical title to the stored title of the Block.

titleLength()

This method calculates and returns the length of this Blocks’ title in pixels.

Returns

the pixel length of this Blocks’ title

Return type

int

updateMode(value)

This method updates the mode of the Block to the provided value (should only ever be “Light”, “Dark” or “Off”).

Parameters

value (str, required) – current mode of the GraphicsScene’s background (“Light”, “Dark”, “Off”)

class bdedit.block_graphics_block.GraphicsSocketBlock(block, parent=None)

Bases: PyQt5.QtWidgets.QGraphicsItem

The GraphicsSocketBlock Class extends the QGraphicsItem Class from PyQt5. This class is responsible for graphically drawing Connector Blocks within the GraphicsScene.

__init__(block, parent=None)

This method initializes an instance of the GraphicsSocketBlock Class (otherwise known as the Graphics Class of the Connector Block).

Parameters
  • block (Connector Block) – the Connector Block this GraphicsSocketBlock instance relates to

  • parent (NoneType, optional, defaults to None) – the parent widget this class instance belongs to (None)

boundingRect()

This is an inbuilt method of QGraphicsItem, that is overwritten by GraphicsSocketBlock which returns the area within which the GraphicsSocketBlock can be interacted with. When a mouse click event is detected within this area, this will trigger logic that relates to a Block (that being, selecting/deselecting, moving, deleting, flipping or opening a parameter window. Or if its Sockets are clicked on, this will trigger a wire to be created or ended).

Returns

a rectangle within which the Block can be interacted with

Return type

QRectF

initUI()

This method sets flags to allow for this Connector Block to be movable and selectable.

mouseMoveEvent(event)

This is an inbuilt method of QGraphicsItem, that is overwritten by GraphicsSocketBlock to detect, and assign logic to mouse movement.

Currently, the following logic is applied to the Connector Block on mouse movement:

  • a detected mouse move event on this GraphicsSocketBlock will enforce grid-snapping on the selected GraphicsSocketBlock (making it move only in increments of the same size as the smaller grid squares of the background).

  • the selected GraphicsSocketBlock will be prevented from moving outside the maximum zoomed out border of the work area (the GraphicsScene).

  • the connection points of any wires connected to the selected Connector Block AND any other block it is connected to, will be updated, as the block is moved around.

Parameters

event (QMouseMoveEvent, automatically recognized by the inbuilt function) – a mouse movement event

mousePressEvent(event)

This is an inbuilt method of QGraphicsItem, that is overwritten by GraphicsSocketBlock to detect, and assign logic to a right mouse press event.

Currently a detected mouse press event on the GraphicsSocketBlock will select or deselect it.

Additionally if selected, the GraphicsBlock will be sent to front and will appear on top of other blocks.

Parameters

event (QMousePressEvent, automatically recognized by the inbuilt function) – a mouse press event (Left, Middle or Right)

paint(painter, style, widget=None)

This is an inbuilt method of QGraphicsItem, that is overwritten by GraphicsSocketBlock (otherwise referred to as the Graphics Class of the Connector Block. This method is automatically called by the GraphicsView Class whenever even a slight user-interaction is detected within the Scene.

When the Connector Block is selected, this method will draw an orange outline around the Connector Block, within which it can be interacted with.

:param painter:a painter (paint brush) that paints and fills the shape of this GraphicsSocketBlock :type painter: QPainter, automatically recognized and overwritten from this method :param style: style of the painter (isn’t used but must be defined) :type style: QStyleOptionGraphicsItem, automatically recognized from this method :param widget: the widget this class is being painted on (None) :type widget: NoneType, optional, defaults to None

bdedit.block_graphics_socket module

class bdedit.block_graphics_socket.GraphicsSocket(socket)

Bases: PyQt5.QtWidgets.QGraphicsItem

The GraphicsSocket Class extends the QGraphicsItem Class from PyQt5. This class is responsible for graphically drawing Sockets on Blocks. It specifies the shape, colour, style and dimensions of the Socket and also implements the logic for drawing signs alongside the input sockets of PROD and SUM` Blocks.

__init__(socket)

This method initializes an instance of the GraphicsSocket Class. It defines the shapes and sizes for a given input or output Socket. Depending on the socket_type, stored within the provided Socket, the shape and colour of the given Socket is decided.

Parameters

socket (Socket) – the Socket this GraphicsSocket instance relates to

boundingRect()

This is an inbuilt method of QGraphicsItem, that is overwritten by GraphicsSocket which returns the area within which the GraphicsSocket can be interacted with. When a mouse click event is detected within this area, this will trigger logic that relates to a Socket (that being, the generating or completion of a Wire).

Returns

a rectangle within which the Socket can be interacted with

Return type

QRectF

getSignPath(sign, multi)

This method determines and returns what method should be called to paint the sign (+,-,*,/) next to an input socket (for PROD and SUM blocks only).

Parameters
  • sign (str, required) – the sign associated with the current Socket (can be ‘+’,’-‘,’*’, or ‘/’)

  • multi (int, required, 1 or -1) – internal variable (1 when default orientation, -1 when flipped)

Returns

the relevant painter path method for drawing the desired sign

Return type

QPainterPath

paint(painter, style, widget=None)

This is an inbuilt method of QGraphicsItem, that is overwritten by GraphicsSocket. This method is automatically called by the GraphicsView Class whenever even a slight user-interaction is detected within the Scene.

It dictates how both input and output Sockets are painted on their relating Block. The position at which to draw the Socket is determined internally by the Socket class, so when the GraphicsSocket class paints the Socket, it is painted with respects to the point where the Socket should be.

Parameters
  • painter (QPainter, automatically recognized and overwritten from this method) – a painter (paint brush) that paints and fills the shape of this GraphicsSocket

  • style (QStyleOptionGraphicsItem, automatically recognized from this method) – style of the painter (isn’t used but must be defined)

  • widget (NoneType, optional, Defaults to None) – the widget this class is being painted on (None)

paintDivide(multi)

This method creates a painter path for drawing a divide sign character next to an input socket.

Parameters

multi (int, required, 1 or -1) – internal variable (1 when default orientation, -1 when flipped)

Returns

the painter path to draw this sign

Return type

QPainterPath

paintMinus(multi)

This method creates a painter path for drawing the ‘-‘ character next to an input socket.

Parameters

multi (int, required, 1 or -1) – internal variable (1 when default orientation, -1 when flipped)

Returns

the painter path to draw this sign

Return type

QPainterPath

paintMultiply(multi)

This method creates a painter path for drawing the ‘x’ character next to an input socket.

Parameters

multi (int, required, 1 or -1) – internal variable (1 when default orientation, -1 when flipped)

Returns

the painter path to draw this sign

Return type

QPainterPath

paintPlus(multi)

This method creates a painter path for drawing the ‘+’ character next to an input socket.

Parameters

multi (int, required, 1 or -1) – internal variable (1 when default orientation, -1 when flipped)

Returns

the painter path to draw this sign

Return type

QPainterPath

bdedit.block_graphics_wire module

class bdedit.block_graphics_wire.GraphicsWire(wire)

Bases: PyQt5.QtWidgets.QGraphicsPathItem

The GraphicsWire Class extends the QGraphicsPathItem Class from PyQt5. This class is responsible for graphically drawing Wires between Sockets.

This class takes a Wire as an input and then looks for the coordinates of the start and end socket defined within it. Then based on these coordinates, connects them with a Wire of the selected type. It is also used to redraw the wires when they are moved around, and if a wire is selected it will redraw the wire thicker and in a different colour.

__init__(wire)

This method initializes an instance of the GraphicsWire Class. It initially specifies the starting and ending sockets as being None, sets the Wire to always be drawn underneath other items within the GraphicsScene, and defines the colors with which the wire can be drawn.

Parameters

wire (Wire) – the Wire Class instance this GraphicsWire relates to

paint(painter, style, widget=None)

This is an inbuilt method of QGraphicsItem, that is overwritten by GraphicsWire. This method is automatically called by the GraphicsView Class whenever even a slight user-interaction is detected within the Scene.

It sets up the painter object and draws the line based on the path that will be set by the specific implementation of GraphicsWire that is calling paint. Then the painter will select the way the wire will be drawn depending on whether or not the wire is selected.

Parameters
  • painter (QPainter, automatically recognized and overwritten from this method) – a painter that paints the path (line) of this GraphicsWire

  • style (QStyleOptionGraphicsItem, automatically recognized from this method) – style of the painter (isn’t used but must be defined)

  • widget (NoneType, optional, Defaults to None) – the widget this class is being painted on (None)

setDestination(x, y)

This method sets the point of where the Wire will end. This is based on the position of the end Socket.

Parameters
  • x (int, required) – x coordinate of the end Socket

  • y (int, required) – y coordinate of the end Socket

setDestinationOrientation(orientation)

This method sets the orientation (position) of the destination (end) Socket - in terms of where it is drawn on the block (LEFT/RIGHT) - to the provided orientation.

Parameters

orientation (enumerate, required) – where on the Block the end Socket is drawn (LEFT(1) or RIGHT(2))

setSource(x, y)

This method sets the point from where the Wire will start. This is based on the position of the start Socket.

Parameters
  • x (int, required) – x coordinate of the start Socket

  • y (int, required) – y coordinate of the start Socket

setSourceOrientation(orientation)

This method sets the orientation (position) of the source (start) Socket - in terms of where it is drawn on the block (LEFT/RIGHT) - to the provided orientation.

Parameters

orientation (enumerate, required) – where on the Block the start Socket is drawn (LEFT(1) or RIGHT(2))

updateLineSegments()

This method uses the coordinates of the points this wire goes through, to determine the coordinates that make up the horizontal and vertical line segments of this wire (this logic is only applicable to GraphicsWireStep).

updatePath()

This method is inherited and overwritten (currently) by the GraphicsWireDirect, GraphicsWireBezier or GraphicsWireStep classes, which dictate the pathing logic of the wire between the start and end socket.

updateWireCoordinates(new_coordinates)

This method checks if the list of coordinate points this wire passes through, has changed and needs to be updated. This method reduces the computational resources required to otherwise re-write the list of coordinate points for this wire, every time a user-interaction is detected within the GraphicsView.

Parameters

new_coordinates (list) – proposed coordinate points for this Wire

class bdedit.block_graphics_wire.GraphicsWireBezier(wire)

Bases: bdedit.block_graphics_wire.GraphicsWire

The GraphicsWireBezier Class extends the GraphicsWire Class from BdEdit. This class is responsible for providing a bezier painter path that the GraphicsWire class should follow when drawing the Wire. This wire type option looks good in the first direction it is drawn (e.g. left-to-right) but will not wrap logically when blocks are flipped or moved past each other (e.g. such that the wire would now be right-to-left).

updatePath()

This method creates a painter path that connects two points (start/end sockets) with a bezier line. This line is drawn as a cubic (think sine wave).

class bdedit.block_graphics_wire.GraphicsWireDirect(wire)

Bases: bdedit.block_graphics_wire.GraphicsWire

The GraphicsWireDirect Class extends the GraphicsWire Class from BdEdit. This class is responsible for providing a straight painter path that the GraphicsWire class should follow when drawing the Wire. This wire type will draw a straight line between two Sockets. It will take the shortest distance between these two points, and will go through other Blocks to do so.

updatePath()

This method creates a painter path that connects two points (start/end sockets) with a straight line.

class bdedit.block_graphics_wire.GraphicsWireStep(wire)

Bases: bdedit.block_graphics_wire.GraphicsWire

The GraphicsWireStep Class extends the GraphicsWire Class from BdEdit. This class is responsible for providing a stepped painter path that the GraphicsWire class should follow when drawing the Wire. This is the default wire style used within BdEdit, and has the most supporting logic built around it.

This wire option draws a straight line between two sockets when the two blocks side by side at equal heights, are connected with a wire in the middle.

Otherwise if the two blocks are at varying heights, a stepped line will be drawn from the starting socket, with 90 degree bends at each point the wire must turn to reach the end socket.

updatePath()

This method creates a painter path that connects two points (start/end sockets) with a stepped line. This path is returned as a straight line if two blocks at equal heights, are connected with a wire on the inside of each of the blocks. Otherwise the path is returned as a stepped line with 90 degree bends at each point the wire must turn.

The logic for when this wire should turn is calculated internally. Please refer to the technical document accompanying the BdEdit code for visual explanations for how this logic is determined.

bdedit.block_param_window module

class bdedit.block_param_window.ParamWindow(block, parent=None)

Bases: PyQt5.QtWidgets.QWidget

The ParamWindow Class extends the QWidget Class from PyQt5. The ParamWindow Class controls:

  • how the parameter window appears visually,

  • where it is located within the BdEdit application window,

  • the displayed parameters from the Block the parameter window is related to,

  • sanity checking on user-edits to the Block parameters,

  • pop-up user feedback for successful or unsuccessful Block parameter edits.

__init__(block, parent=None)

This method initializes an instance of the ParamWindow Class.

Parameters
  • block (Block) – the Block this ParamWindow instance relates to

  • parent (None, optional) – the parent widget this ParamWindow belongs to (should be None)

buildParamWindow()

This method handles the building of the ParamWindow instance. These instances will always look exactly the same in terms of the information they contain, however the Block parameters and the block type will vary depending on the Block this ParamWindow relates to.

The ParamWindow is built by adding items into the QWidget that represents this parameter window. For each item added into the QWidget, a label is displayed on the left-hand-side, and either the non-editable value (label) is displayed on the right-hand-side, or an editable line is displayed and populated with the respective parameters’ current value.

The ParamWindow is populated by, first, adding a non-editable line displaying the selected Blocks’ type. Next, the Blocks’ current title is added with an editable line. Following this, each Block parameter looped through and added with an editable line in which the current value of the Block parameter is populated. Changing this value will prompt the sanity checking of the value entered, which is handled by the updateBlockParameters() method.

closeQMessageBox()

This method closes a pop-up user-feedback message if one already exists within the parameter window. This prevents multiple messages from being displayed at the same time, and ensure the message the user sees, is the most relevant one.

displayPopUpMessage(title, text, messageType)

This method displays a pop-up user-feedback message within the parameter window, notifying them of either a successful or unsuccessful update to the Blocks’ parameters. This method will also trigger the message to auto-close, after 1.5 seconds for a successful update, and after 5 seconds for an unsuccessful update. If at any point the user updates the Block parameters before this time is elapsed, the current (old) message will be removed and replaced by the most relevant message. An unsuccessful update attempt will also issue an error sound when the message is opened.

Parameters
  • title (str) – the title of the message box displayed

  • text (str) – the text that fills the body of the displayed message box

  • messageType (str) – variable that calls what type of message to display (“Success”, “Error”)

static getSafeValue(inputValue, requiredType, requiredOptions)

This method takes an input value (which is the value a parameter is being checked if it can be updated to), and checks whether it matches an allowable type that has been defined for that parameter within the grandchild Block Class. If the input value doesn’t match the required type, an invalid type str will be returned. If the input value does match the required type, it is further checked, whether it matches any further restrictions placed onto that parameter from within the grandchild Block Class. If the value doesn’t meet the criteria of the restrictions, a bad input str will be returned. If the input does match the criteria of the restriction, it will be converted to the type it must be in and returned.

Parameters
  • inputValue (str) – the value which the parameter would be updated to

  • requiredType (type, determined by the grandchild Block Class) – the value type which is required for this parameter

  • requiredOptions (list) – a list of restrictions placed onto this parameter

Returns

  • str (if incompatible type or restriction criteria not met),

  • requiredType (if compatible type and restrictions are met)

Return type

type, determined by the grandchild Block Class

initUI()

This method adds a ‘Parameter Window’ label to the ParamWindow, sets the alignment of items within the parameter window, sets the background to auto fill, and finally, sets the layout manager of the ParamWindow.

updateBlockParameters()

This method calls for each of the parameters within the parameter window to be sanity checked by the getSafeValue() method, which determines whether or not a provided value is compatible with the parameter type (defined in the Block Class) and is safe to override the current value. If that check is returned to be safe, this method will handle the updating of the Block parameters, as well as triggering a successful update attempt message.

If the check is returned as not safe, meaning the given value is not compatible, an unsuccessful update attempt error message will be prompted, notifying the user of the incompatible parameter value they have set, and either what the compatible types or values are. This logic also applies when a user changes the blocks’ title to one that already exists, which will cause a duplicate error message to display.

Some parameters values directly affect the GraphicsBlock of the Block they relate to. For example, blocks that can have multiple input or output sockets, will have a parameter that controls how many of these sockets the block has. And once edited, this method will trigger an appropriate number of sockets to be created or deleted. This parameter can also affect the GraphicsBlock when too many sockets are created, requiring the block to be resized. The triggering of this resizing will also be issued from within this method.

bdedit.block_socket module

class bdedit.block_socket.Socket(node, index=0, position=1, socket_type=1, multi_wire=True)

Bases: bdedit.interface_serialize.Serializable

The Socket Class extends the Serializable Class from BdEdit, and defines how a socket is represented, and has all the necessary methods for creating, manipulating and interacting with a socket. This class allows for Wires to be connected to Blocks, while also controlling where on the Block the Sockets are drawn, and how they appear.

This class includes information about the sockets’:

  • type;

  • index;

  • position;

  • appearance;

  • parent Block; and

  • connected wire(s).

__init__(node, index=0, position=1, socket_type=1, multi_wire=True)

This method initializes an instance of the Socket Class.

Parameters
  • node (Block, required) – the associated Block this Socket relates to

  • index (int, optional, defaults to 0) – the height (along the side of the Block) this Socket should be drawn at

  • position (enumerate, optional, defaults to LEFT(1)) – the side ( LEFT(1) or RIGHT(3) ) this Socket should be drawn on

  • socket_type (enumerate, optional, defaults to INPUT(1)) – this Socket’s type (INPUT(1) or OUTPUT(2))

  • multi_wire (bool, optional, defaults to True) – boolean of whether this Socket has multiple wires

deserialize(data, hashmap={})

This method is called to reconstruct a Socket when loading a saved JSON file containing all relevant information to recreate the Scene with all its items.

Parameters
  • data (OrderedDict, required) – a Dictionary of essential information for reconstructing a Socket

  • hashmap (Dict, required) – a Dictionary for directly mapping the essential socket variables to this instance of Socket, without having to individually map each variable

Returns

True when completed successfully

Return type

Boolean

getSocketPosition()

This method retrieves and returns the [x,y] coordinates for where the current Socket should be drawn.

Returns

the [x,y] coordinates at which to place this Socket.

Return type

list of int, int

hasEdge()

This method returns True if the current Socket has Wires connected to it, and False if no Wires are connected to it.

Returns

  • True (If wires are connected to this Socket)

  • False (If no wires are connected to this Socket)

Return type

bool

isInputSocket()

This method returns True if the current Socket is an input socket.

Returns

  • True (If current Socket is an input Socket)

  • False (If current Socket is not an input Socket)

Return type

bool

isOutputSocket()

This method returns True if the current Socket is an output socket.

Returns

  • True (If current Socket is an output Socket)

  • False (If current Socket is not an output Socket)

Return type

bool

removeAllWires()

This method removes all Wires connected to this Socket.

removeSockets(type)

This method removes all of the input or output Sockets, relating to this Block, as specified by the type.

This method removes all sockets of given type, associated with this Block.

Parameters

type (str, required) – the type of Socket to remove (“Input” or “Output”)

removeWire(wire)

This method removes the given Wire from the list of Wires connected to this Socket, if it is connected to this Socket.

Parameters

wire (Wire, required) – the wire to be removed

serialize()

This method is called to create an ordered dictionary of all of this Sockets’ parameters - necessary for the reconstruction of this Socket - as key-value pairs. This dictionary is later used for writing into a JSON file.

Returns

an OrderedDict of [keys, values] pairs of all essential Socket parameters.

Return type

OrderedDict ([keys, values]*)

setConnectedEdge(wire)

This method adds the given wire to the list of Wires that are connected to this Socket.

Parameters

wire (Wire, required) – the wire connecting to this Socket

bdedit.block_socket_block module

class bdedit.block_socket_block.Connector(scene, window, name='Unnamed Connector Block', pos=(0, 0))

Bases: bdedit.block.Block

The Connector Class is a subclass of Block, and referred to as a child class of Block. It inherits all the methods and variables of its parent class to behave as a Block. It allows for wires to be more neatly redirected, acting as a node through which the wires can be moved around more freely within the work area.

The idea of this Connector block was for it to be a single socket which allows a wire to be redirected through it, however currently it works by mimicking a Block that only has 1 input and 1 output socket. The same socket logic that applies to a Block, also applies to the Connector Block.

That being:

  • an input: can only have 1 Wire connecting into it

  • an output: can have n Wires connecting into it

__init__(scene, window, name='Unnamed Connector Block', pos=(0, 0))

This method initializes an instance of the Connector Block Class.

Parameters
  • scene (Scene, required) – inherited through Block

  • window (QGridLayout, required) – inherited through Block

  • name (str, optional) – defaults to “Unnamed Connector Block”

  • pos (tuple of 2-ints, optional) – inherited through Block

bdedit.block_wire module

class bdedit.block_wire.Wire(scene, start_socket=None, end_socket=None, wire_type=3)

Bases: bdedit.interface_serialize.Serializable

The Wire Class extends the Serializable Class from BdEdit, and defines how a wire is represented, and has all the necessary methods for creating, manipulating and interacting with a wire. This class connects start and end sockets to a created wire. The style of wire being drawn is also controlled by this Class:

  • a straight wire will have type DIRECT(1),

  • a curved or wave-like wire will have type BEZIER(2),

  • a stepped wire will have type STEP(3)

This class includes information about the wires’:

  • style;

  • end_socket;

  • start_socket;

  • point-to-point coordinates;

  • horizontal and vertical line segments;

  • intersection points with other wires (has been disabled).

__init__(scene, start_socket=None, end_socket=None, wire_type=3)

This method initializes an instance of the Wire Class.

Parameters
  • scene (Scene, required) – a scene (or canvas) in which the Wire is stored and shown (or painted into). Provided by the Interface.

  • start_socket (Socket, optional, defaults to None (automatically set)) – the start Socket of this Wire

  • end_socket (Socket, optional, defaults to None (automatically set)) – the end Socket of this Wire

  • wire_type (enumerate, optional, defaults to STEP(3) (automatically set)) – the wire style of this Wire (DIRECT(1), BEZIER(2), STEP(3))

checkIntersections()

This method checks all active wires in the scene for intersections with other wires. This method will be called any time a mouse movement is detected in the GraphicsView class, which will cause the GraphicsScene to draw points at these intersections to separate the wires.

To reduce computation for finding these intersection points, only vertical line segments of wires are checked for intersections. This is because an intersection point can only occur when a horizontal line segment of one wire meets a vertical line segment of another wire, and every single wire has a horizontal segment (as sockets are drawn on the LEFT or RIGHT sides of a Block).

When this method is called, the current intersection points are deleted, as all wires are checked against in this method, and as such, any new (or previous) intersection points will be appended into a list of intersection points that is stored within the GraphicsScene Class.

deserialize(data, hashmap={})

This method is called to reconstruct a Wire when loading a saved JSON file containing all relevant information to recreate the Scene with all its items.

Parameters
  • data (OrderedDict, required) – a Dictionary of essential information for reconstructing a Wire

  • hashmap (Dict, required) – a Dictionary for directly mapping the essential wire variables to this instance of Wire, without having to individually map each variable

Returns

True when completed successfully

Return type

Boolean

property end_socket

This method is a decorate that gets the end socket of this Wire.

Returns

the end Socket of this Wire

Return type

Socket

remove()

This method will remove the selected Wire from the Scene, un-assign the Sockets that related to it, and remove the Wire from these Sockets.

remove_from_sockets()

This method will un-assign the start and end sockets of this Wire.

serialize()

This method is called to create an ordered dictionary of all of this Wires’ parameters - necessary for the reconstruction of this Wire - as key-value pairs. This dictionary is later used for writing into a JSON file.

Returns

an OrderedDict of [keys, values] pairs of all essential Wire parameters.

Return type

OrderedDict, ([keys, values]*)

property start_socket

This method is a decorate that gets the start socket of this Wire.

Returns

the start Socket of this Wire

Return type

Socket

updatePositions()

This method grabs the new positions of sockets on blocks as they are moved around within the scene, in order to determine the positions which the wire should connect. The redrawing of the wire to these positions will also be handled within this method.

property wire_type

This method is a decorate that gets the wire type (or style) of this Wire.

Returns

the style of this Wire (DIRECT(1), BEZIER(2), STEP(3))

Return type

enumerate

bdedit.interface module

class bdedit.interface.Interface(resolution, parent=None)

Bases: PyQt5.QtWidgets.QWidget

The Interface Class extends the QWidget Class from PyQt5, and houses the necessary methods for controlling how the application appears. It also connects the other Classes to allow for Block Diagrams to be constructed.

This class includes information about the:

  • toolbar, its buttons and their connections

  • library Browser menu, its buttons and their connections

  • scene, its appearance (Background and Foreground) and its items (Blocks, Sockets, Wires)

  • application layout, in terms of where the toolbar, library Browser, scene and parameter window is displayed.

Note, the toolbar, library Browser, scene and parameter window will be referred to as application components.

__init__(resolution, parent=None)

This method initializes an instance of the Interface.

Parameters
  • resolution (PyQt5.QtCore.QRect(0, 0, screen_width, screen_height), required) – the desktop screen resolution of the user

  • parent (None, optional) – the parent widget this interface belongs to (should be None)

initUI(resolution)

This method is responsible for controlling the size of the application window. It is also responsible for each application component, in terms of:

  • setting its dimensions ;

  • setting its position within the application layout;

  • creating its relevant buttons and connecting them to desired actions;

  • populating it with the created buttons; and

  • spacing out these buttons within the application component itself.

Parameters

resolution (PyQt5.QtCore.QRect(0, 0, screen_width, screen_height), required) – the desktop screen resolution of the user

Returns

a QWidget that is displayed within the application from bdEdit.py

Return type

QWidget

loadFromFile()

This method opens a QFileDialog window, prompting the user to select a file to load from.

on_click(scene)

This method creates a Wire instance from the Socket that was clicked on, to the mouse pointer.

Parameters

scene (Scene, required) – the scene within which the Block and Socket are located

resizeEvent(event)

This is an inbuilt method of QWidget, that is overwritten by Interface to update the dimensions of the Scene when the application window has been resized.

Parameters

event (QResizeEvent, automatically recognized by the inbuilt function) – an interaction event that has occurred with this QWidget

saveAsToFile()

This method opens a QFileDialog window, prompting the user to enter a name under which the current file will be saved. This file will automatically be given a .json file type.

saveToFile()

This method calls the method from within the Scene to save a copy of the current Scene, with all its items under a file with the current filename. If this is the first time a user is saving their file, they will be prompted to name the file and to choose where it will be saved.

save_image(picture_name)

This method takes a filename and saves a snapshot of all the items within the Scene into it. Currently the resolution of this image is set to 4K resolution (3840 x 2160).

Parameters

picture_name (str, required) – the name under which the image will be saved

toggleCanvasItems()

This method toggles hiding/expanding all Canvas related Items. Currently these include only the Connector Block.

toggleDiscreteBlocks()

This method toggles hiding/expanding all Discrete Blocks. These depend on the Blocks defined within the auto-imported files.

toggleFunctionBlocks()

This method toggles hiding/expanding all Function Blocks. These depend on the Blocks defined within the auto-imported files.

toggleSinkBlocks()

This method toggles hiding/expanding all Sink Blocks. These depend on the Blocks defined within the auto-imported files.

toggleSourceBlocks()

This method toggles hiding/expanding all Source Blocks. These depend on the Blocks defined within the auto-imported files.

toggleSubSystemBlocks()

This method toggles hiding/expanding all SubSystem Blocks. These depend on the Blocks defined within the auto-imported files.

toggleTransferBlocks()

This method toggles hiding/expanding all Transfer Blocks. These depend on the Blocks defined within the auto-imported files.

updateColorMode()

This method is called to update the color mode with which the Scene background should be displayed. The options are:

  • Light: light gray grid lines, with dark outlines for blocks

  • Dark: dark gray grid lines, with light outlines for blocks

  • Off: no grid lines, with dark outlines for blocks

updateSceneDimensions()

This method updates the dimensions of the scene based on current window size (will change as the application window is resized).

bdedit.interface.importBlocks()

This method is called at the beginning of an Interface instance, to auto import all grandchild Classes of the Block class from a locally referenced dictionary called Block_Classes.

This code is adapted from: https://github.com/petercorke/bdsim/blob/bdedit/bdsim/bdsim.py

Returns

a list of imported blocks

Return type

list

bdedit.interface_graphics_scene module

class bdedit.interface_graphics_scene.GraphicsScene(scene, parent=None)

Bases: PyQt5.QtWidgets.QGraphicsScene

The GraphicsScene Class extends the QGraphicsScene Class from PyQt5, and controls the basic appearance of the Scene it belongs to. The things it controls include its background, and foreground.

__init__(scene, parent=None)

This method creates an QGraphicsScene instance and associates it to this GraphicsScene instance. The GraphicsScene dictates how all items within the Scene are visually represented.

Parameters
  • scene (Scene, required) – the Scene to which this GraphicsScene belongs to

  • parent (None, optional) – the parent widget this GraphicsScene belongs to (should be None)

checkMode()

This method updates the colors used for painting the background of the GraphicsScene.

drawBackground(painter, rect)

This is an inbuilt method of QGraphicsScene, that is overwritten by GraphicsScene to draw a grid background, or a plain background, depending on what grid mode is chosen. This background is drawn behind all other items within the GraphicsScene.

Parameters
  • painter (QPainter, automatically recognized and overwritten from this method) – a painter (paint brush) that paints the background of this GraphicsScene

  • rect (QRect, automatically recognized by the inbuilt function) – a rectangle that defines the dimensions of this GraphicsScene

drawForeground(painter, rect)

This is an inbuilt method of QGraphicsScene, that is overwritten by GraphicsScene to draw additional logic for intersection points between wires. This logic is drawn overtop of all other items within the GraphicsScene apart from Blocks. Intersection points are drawn as a circle (same fill color as the background) to create a separation between the wires, then redraws a vertical section of the wire overtop.

Parameters
  • painter (QPainter, automatically recognized and overwritten from this method) – a painter (paint brush) that paints the foreground of this GraphicsScene

  • rect (QRect, automatically recognized by the inbuilt function) – a rectangle that defines the dimensions of this GraphicsScene

mouseMoveEvent(event)

This is an inbuilt method of QGraphicsScene, that is overwritten by GraphicsScene to update the start-end points of where the wires are drawn to, as items are moved around within the GraphicsScene.

Parameters

event (QMouseEvent, automatically recognized by the inbuilt function) – a mouse movement event that has occurred with this GraphicsScene

setGrScene(width, height)

This method sets the dimensions of the GraphicsScene.

Parameters
  • width (int, required) – width of the GraphicsScene

  • height (int, required) – height of the GraphicsScene

updateMode(value)

This method updates the background mode for the GraphicsScene, depending on what option was chosen in the toolbar drop down menu next to grid mode.

Parameters

value (str, required) – the color mode of the background (“Light”, “Dark”, “Off”)

bdedit.interface_graphics_view module

class bdedit.interface_graphics_view.GraphicsView(grScene, parent=None)

Bases: PyQt5.QtWidgets.QGraphicsView

The GraphicsView Class extends the QGraphicsView Class from PyQt5, and handles most of the user interactions with the Interface, through press/scroll/click/scroll/key events. It also contains the logic for what Wire should be drawn and what Sockets it connects to. Here mouse click events are used to drag the wires from a start to a end socket, when click is dragged from a socket, the mode == MODE_WIRE_DRAG will be set to True and a Wire will follow the mouse until a end socket is set or mode == MODE_WIRE_DRAG is False and the Wire will be deleted.

__init__(grScene, parent=None)

This method creates an QGraphicsView instance and associates it to this GraphicsView instance.

Parameters
  • grScene (GraphicsScene, required) – the GraphicsScene to which this GraphicsView belongs to

  • parent (None, optional) – the parent widget this GraphicsView belongs to (should be None)

closeParamWindows()

This method will close the parameter window used for changing the user-editable block variables.

deleteSelected()

This method removes the selected Block or Wire from the scene.

dist_click_release(event)

This method checks how for the cursor has moved. This is be used when the Wire is dragged, to check that wire has been dragged away from the start socket, so that when it is released on a socket we know its not the start socket.

Parameters

event (QMouseEvent, automatically recognized by the inbuilt function) – a mouse release event that has occurred with this GraphicsView

Returns

  • True (if mouse has been released more than an defined distance from the start_socket)

  • False (if mouse has been released too close too the start_socket)

Return type

bool

edgeDragEnd(item)

This method is used for setting the end socket of the Wire. The place where the wire has been released will be checked, and if it is a GraphicSocket and is not the start socket then a Wire is completed.

Next some check will be made to see that inputs are not connected to inputs and outputs are not connected to outputs. Additionally, Block Sockets will be checked to prevent multiple Wires from connecting to a single input socket. No such restriction is placed on the output sockets. This same logic is applied to Connector Blocks.

If these conditions are met, the wire that was dragged will be deleted, and a new Wire will be created with the start socket from the block the wire drag started at, and the end socket being from the socket of the block the Wire was dragged to.

If the above-mentioned conditions not met, the wire is simply removed.

Parameters

item – should be the socket that has been clicked on (however could

be one of the following: GraphicsBlock, GraphicsSocket, GraphicsWireStep or NoneType) :type item: GraphicsSocket, required :return: False (if the the Wire has been successfully drawn between Blocks) :rtype: bool

edgeDragStart(item)

This method starts drawing a Wire between two Blocks. It will construct a new Wire and set the start socket to the socket that has been clicked on, and the end socket to None. The end socket will be set when either another socket is clicked, or the mouse button is released over another socket. If neither happen, the wire will be deleted.

Parameters

item (GraphicsSocket, required) – the socket that has been clicked on

flipBlockSockets()

This method flips the selected Block so that the input and output Sockets change sides.

getItemAtClick(event)

This method returns the object at the click location. It is used when checking what item within the GraphicsView has been clicked when starting to drag a wire.

Parameters

event (QMouseEvent, automatically recognized by the inbuilt function) – a mouse click event that has occurred with this GraphicsView

Returns

the item that has been clicked on (can be GraphicsBlock, GraphicsSocket, GraphicsWireStep, NoneType), required

Return type

GraphicsBlock, GraphicsSocket, GraphicsWireStep or NoneType

initUI()

This method initializes the GraphicsScene with additional settings to make things draw smoother

intersectionTest()

This method initiates the checking of all Wires within the Scene for intersection points where they overlap.

keyPressEvent(event)

This is an inbuilt method of QGraphicsView, that is overwritten by GraphicsView to detect, and assign actions to the following key presses.

  • DEL or BACKSPACE: removes selected item from the Scene

  • F: flips the sockets on a Block or Connector Block

  • CTRL + S: previously connected to saving the Scene

  • CTRL + L: previously connected to loading a Scene file

The saving and loading of a file using keys has since been disabled, as it used an old method for saving/loading JSON files which has since been overwritten in the Interface Class. However these key checks are still connected if future development should take place.

Parameters

event (QKeyPressEvent, automatically recognized by the inbuilt function) – key(s) press(es) that have been detected

leftMouseButtonPress(event)

This method handles the logic associate with the Left mouse button press. It will always run the getItemAtClick method to return the item that has been clicked on.

  • If a GraphicsSocket is pressed on, then a draggable Wire will be started.

  • If a GraphicWire is pressed, then the active draggable Wire will be ended (when the wire is draggable, clicking off at a Socket, will register the clicked item as a GraphicsWire).

Alternatively, the following logic is applied for selecting items.

  • If an empty space within the GraphicsView is pressed, a draggable net will appear, within which all items will be selected.

  • If left clicking while holding the SHIFT or CTRL key, this will incrementally select an item from within the GraphicsView. The items that are selectable are GraphicsBlock, GraphicsWire or GraphicsSocketBlock (which is the Connector Block).

Otherwise nothing is done with the left mouse press.

Parameters

event (QMousePressEvent, required) – a Left mouse button press

Returns

None to exit the method

Return type

NoneType

leftMouseButtonRelease(event)

This method handles the logic associate with the Left mouse button release. It will always run the getItemAtClick method to return the item that the mouse has been released from.

  • If a Wire was the item being dragged, it will check how far the Wire has moved, then an attempt to complete the Wire onto a Socket will be made. If no Socket is found, the Wire will be ended.

Alternatively, the following logic is applied for selecting items.

  • If an empty space within the GraphicsView is released, if a draggable net was active, all items within that net will be selected.

  • If left clicking while holding the SHIFT or CTRL key, this will incrementally select an item from within the GraphicsView. The items that are selectable are GraphicsBlock, GraphicsWire or GraphicsSocketBlock (which is the Connector Block).

Parameters

event (QMouseReleaseEvent, required) – a Left mouse button release

Returns

None to exit the method

Return type

NoneType

middleMouseButtonPress(event)

This method handles the logic associate with the Middle mouse button press (perhaps more intuitively understood as pressing the scroll wheel). When the scroll wheel is pressed, the mouse cursor will appear as a hand that pinches the GraphicsView, allowing the canvas to be dragged around.

Parameters

event (QMousePressEvent, required) – the detected middle mouse press event

middleMouseButtonRelease(event)

This method handles the logic associate with the Middle mouse button release (perhaps more intuitively understood as releasing the scroll wheel). When the scroll wheel is releasing, the mouse cursor will change back from appearing as a hand to the default mouse cursor (pointer arrow on Windows).

Parameters

event (QMouseReleaseEvent, required) – the detected middle mouse release event

mouseMoveEvent(event)

This is an inbuilt method of QGraphicsView, that is overwritten by GraphicsView to assign logic to detected mouse movement.

  • If the wire is in dragging mode, the position the wire is drawn to will be updated to the mouse cursor as it is moved around.

  • Additionally, the code to check for intersection amongst wires will be run, and subsequently, if any are found, they will be automatically marked within the GraphicsScene Class.

Parameters

event (QMouseMoveEvent, automatically recognized by the inbuilt function) – the detected mouse movement event

mousePressEvent(event)

This is an inbuilt method of QGraphicsView, that is overwritten by GraphicsView to detect, and direct the Left, Middle and Right mouse button presses to methods that handle their associated logic.

Additionally, when the Left mouse button is pressed anywhere in the GraphicsView, any currently ParamWindow that relates to an active Block within the Scene will be closed.

Parameters

event (QMousePressEvent, automatically recognized by the inbuilt function) – a mouse press event (Left, Middle or Right)

mouseReleaseEvent(event)

This is an inbuilt method of QGraphicsView, that is overwritten by GraphicsView to detect, and direct the Left, Middle and Right mouse button releases to methods that handle their associated logic.

Parameters

event (QMouseReleaseEvent, required) – a mouse release event (Left, Middle or Right)

rightMouseButtonPress(event)

This method handles the logic associate with the Right mouse button press. Currently no logic is linked to a right mouse press.

Parameters

event (QMousePressEvent, required) – the detected right mouse press event

Returns

the mouse press event is returned

Return type

QMousePressEvent

rightMouseButtonRelease(event)

This method handles the logic associate with the Right mouse button release. Currently no logic is linked to a right mouse release.

Parameters

event (QMousePressEvent, required) – the detected right mouse release event

Returns

the mouse release event is returned

Return type

QMouseReleaseEvent

wheelEvent(event)

This is an inbuilt method of QGraphicsView, that is overwritten by GraphicsView to assign logic to detected scroll wheel movement.

  • As the scroll wheel is moved up, this will make the zoom in on the work area of the GraphicsScene.

  • As the scroll wheel is moved down, this will make the zoom out of the work area of the GraphicsScene.

Parameters

event (QWheelEvent, automatically recognized by the inbuilt function) – the detected scroll wheel movement

bdedit.interface_scene module

class bdedit.interface_scene.Scene(resolution, window)

Bases: bdedit.interface_serialize.Serializable

The Scene Class extends the Serializable Class from BdEdit, and holds the information of all the Block and Wire instances that are within it. It also handles the storage of intersection points of the wires.

This class includes information about the:

  • blocks, a list containing all Block instances

  • wires, a list containing all Wire instances

  • intersection points, a list containing all intersection points between Wires

__init__(resolution, window)

This method initializes an instance of the Scene Class.

Parameters
  • resolution (PyQt5.QtCore.QRect(0, 0, screen_width, screen_height), required) – the desktop screen resolution of the user

  • window (QGridLayout, required) – the application’s layer manager

addBlock(block)

This method adds a Block to the Scene's list of blocks.

addWire(wire)

This method adds a Wire to the Scene's list of wires.

checkForDuplicates(name)

This method checks if the given name would be a duplicate of an existing block name.

Parameters

name (str, required) – the desired name for a Block

Returns

  • False (if given name is not a duplicate)

  • True (if given name is a duplicate)

Return type

bool

clear()

This method removes all blocks from the list of blocks within the Scene. This will subsequently remove any and all wires between these blocks.

deserialize(data, hashmap={})

This method is called to reconstruct a Scene and all its items when loading a saved JSON.

Parameters
  • data (OrderedDict, required) – a Dictionary of essential information for reconstructing a Scene

  • hashmap (Dict, required) – a Dictionary for directly mapping the essential scene variables to this instance of Scene, without having to individually map each variable

Returns

True when completed successfully

Return type

bool

displayMessage()

This method displays a ‘File saved successfully!’ pop-up message, providing the user with feedback that their was saved. This pop-up message will disappear on its own after 1 second.

getSceneHeight()

This method returns the current height of the Scene.

getSceneWidth()

This method returns the current width of the Scene.

initUI()

This method creates an GraphicsScene instance and associates it to this Scene instance. The GraphicsScene dictates how all items within the Scene are visually represented.

loadFromFile(filename)

This method loads the contents of a saved JSON file with the given filename into an instance of the Scene.

This method will call upon the self.deserialize() method which will subsequently call the self.deserialize() method within each item that should be reconstructed for the Scene (these being the Block, Wire and Socket).

Parameters

filename (str) – name of the file to load from

removeBlock(block)

This method removes a Block to the Scene's list of blocks.

removeWire(wire)

This method removes a Wire to the Scene's list of wires.

saveToFile(filename)

This method saves the contents of the Scene instance into a JSON file under the given filename. This method will call upon the self.serialize() method which will subsequently call the self.serialize() method within each item displayed in the Scene (these being the Block, Wire and Socket).

Parameters

filename (str, required) – name of the file to save into

serialize()

This method is called to create an ordered dictionary of all of this Scenes’ parameters - necessary for the reconstruction of this Scene - as key-value pairs. This dictionary is later used for writing into a JSON file.

Returns

an OrderedDict of [keys, values] pairs of all essential Scene parameters.

Return type

OrderedDict ([keys, values]*)

setSceneHeight(height)

This method sets the current height of the Scene, to the given height.

setSceneWidth(width)

This method sets the current width of the Scene, to the given width.

updateSceneDimensions()

This method sets the dimensions of the Scene to the currently set scene_width and scene_height.

bdedit.interface_serialize module

class bdedit.interface_serialize.Serializable

Bases: object

The Serializable class provides three essential methods for: ensuring uniqueness amongst necessary data (1), saving (2) and loading (3) of this data that is needed for the reconstruction of a Block Diagram.

__init__()

This method extracts the unique identification number of the class instance that calls this method, and stores it as a variable within that class instance.

deserialize(data, hashmap={})

This method is inherited and overwritten by all classes that have graphical components related to them (Scene, Block, Socket and Wire). This allows those classes to un-package (load) the data stored within the saved JSON file in order to reconstruct the respective class instance.

Parameters
  • data (OrderedDict, required) – a Dictionary of essential data for reconstructing a Block Diagram

  • hashmap – a Dictionary for of the same data, but used for simpler mapping

of variables to class instances :type hashmap: Dict, required

serialize()

This method is inherited and overwritten by all classes that have graphical components related to them (Scene, Block, Socket and Wire). This allows those classes to package (save) essential variables necessary for the later reconstruction of those class instances, into a JSON file.

Module contents