Interphase adds interface panel functionality to applications coded with Python and the Pygame multimedia module. Place the interphase folder in the path or within script folder, and use ‘import interphase’. A zip of the interphase folder can also be used with the statement “sys.path.insert(0,’./interphase_zipfile’)” prior to import. Run interphase.py separately for an interface panel demo that is coded in test.py.
To design an interface panel, interphase.Interface can be subclassed. Within the __init__() method call interphase.Interface.__init__(). Interface Object provides several methods to design and utilize an interface panel. Use add() to add controls to panel, place into a method called add_controls(); if added otherwise call activate() after to activate the panel. The Interface class/subclass instance can be added to a pygame sprite group that provides methods update/draw/clear to update the panel. The program maintains the update of the panel including changes through the methods, however panel_update() can be used to force an update if required. If the Interface Object is subclassed, when overriding the update() method call interphase.Interface.update(). Interface interaction can be maintained with the InterfaceState object, that is returned by update() or get_state(), or through pygame event queue checking for event.type interphase.EVENT['controlselect'] and interphase.EVENT['controlinteract'] with the attribute event.state that references the InterfaceState object. To turn the panel off, deactivate() sets state.active to false.
InterfaceState Object:
panel:
– Interface panel (instance panel object)
controls:
– Interface controls (dict {id:object} panel controls object)
panel_active:
– Panel active (bool panel active)
panel_interact:
– Pointer interface interact (bool pointer interact with panel)
control_interact:
– Pointer control interact (‘id’ control interact)
button_interact:
– Pointer button interact (‘id’ button interact)
control:
– Control selected (‘id’ selected control)
button:
– Button selected (‘id’ selected button (‘id’,'id_top’,'id_bottom’))
value:
– Control value (‘value’ current value of selected control)
values:
– Panel control values (dict {‘id’:value} values of all controls)
Interface methods:
add()/add_control(), activate(), deactivate(), is_active(), get_state(), get_value(), get_control(), remove_control(), enable_control(), disable_control(), update(), panel_update(), set_panel_display(), get_id(), set_panel_image(), set_control_image(), set_button_image(), get_panel_image(), get_default_image(), move(), set_moveable(), is_moveable(), set_label_display(), is_label_display(), get_size(), get_position(), move_control(), get_control_move(), set_control_move(), set_control_moveable(), is_control_moveable(), set_tips_display(), is_tips_display(), get_pointer_position(), set_pointer_interact(), set_info_display(), is_info_display(), add_info(), clear_info().
InterfaceControl methods:
get_value(), set_value(), get_list(), set_list(), remove_list(), set_list_icon(), set_control_image(), set_link(), set_link_activated(), set_activated(), is_activated(), set_activated_lock(), is_activated_lock(), set_active(), is_active(), next(), previous(), reset(), get_position(), set_display_text(), set_label_text(), get_tip(), set_tip(), get_id(), set_label(), get_label(), resize_control(), set_enabled(), is_enabled(), get_size(), set_color(), get_list_index(), set_list_index().
Interface Parameters:
Optional Parameters <default>:
identity: ‘id’ panel name <’Interface_Panel’>.
position: (x,y) panel placement on screen <None>.
– values < 1 are %screen.
– None centers on screen.
image: ‘image’ panel image <None>.
– None use default image, ‘none’ suppress default image.
– Image in data folder.
color: (r,g,b) panel color <(0,0,0)>.
size: (w,h) dimension of panel <(350,100)>.
screen: (w,h) dimension of screen <(500,500)>.
moveable: bool panel can move <False>.
position_offset: (x,y) panel move offset <(0,0)>.
move_rate: (x,y) panel move rate pix/s <(200,200)>.
– values < 1 are %position_offset/s.
fixed: bool panel fixed in place <False>.
button_image: ['U','D'] or ‘composite’ control button image <None>.
– None use default image, ‘none’ suppress default image.
– Image in data folder.
control_image: ‘image’ control background image <None>.
– None use default image, ‘none’ suppress default image.
– Image in data folder.
color_key: (r,g,b) image color key transparency <None>.
– transparency set by image alpha value or color_key.
– value -1 color_key from pixel at (0,0).
control_minsize: (x,y) minimum control size <None>.
control_size: ” global control size if control_minsize set <’min’>.
– ‘auto’, ‘auto_width’: fit items.
– ‘min’, ‘min_width’: fit using control_minsize.
– ‘panel’: use exact control_minsize.
button_size: (x,y) button size <(12,12)>.
function_button: placement of buttons of function_select <’left’>.
control_button: placement of buttons of control_select <’right’>.
font_color: (r,g,b) font color of control text <(125,130,135)>.
font_type: [] font type list <None>.
– None: default system font; []: use first font available.
– <control>.set_display_text(info=’system’) gets system fonts.
– ‘file:<font_name>’ path to font file.
font_size: int font size of control text. Size:6,8,10,12,24,32 <10>.
label_display: bool label displayed <False>.
info_display: bool info text displayed <False>.
info_fontsize: int font size used for info text <10>.
info_fontcolor: (r,g,b) font color used for info text <(125,130,135)>.
info_position: (x,y) position of info text <(2,0)>.
tips_display: bool tip text displayed <False>.
tips_fontsize: int font size used for tip text <8>.
tips_fontcolor: (r,g,b) font color used for tip text <(125,130,135)>.
tips_position: (x,y) position offset of tip text <(0,-15)>.
control_response: int control click response (ms) <125>.
pointer_interact: bool pointer interact monitored <False>.
data_folder: ” image data folder <’data’>.
data_zip: ” image data zip <None>.
event: bool interaction generates events <False>.
InterfaceControl Parameters:
Parameters:
panel: obj panel holding control.
– automatically set by panel add() method.
identity: ‘id’ control name.
control_type: ‘type’ control type.
– ‘function_select’, ‘function_toggle’: master control.
– ‘control_select’, ‘control_toggle’: standard control.
– ‘label’: label control.
position: (x,y) control placement on panel. Values < 1 are %panel.
Optional parameters <default>:
size: (w,h) control size override panel specified <None>.
– ‘auto’, ‘auto_width’: fit items.
– ‘min’, ‘min_width’: fit using control_minsize.
– ‘panel’: use exact control_minsize.
color: (r,g,b) control color <(40,80,120)>.
fill: int button edge width, and 0 filled -1 none <1>.
control_outline: display control edge <None>.
control_image: ‘image’ control background image overrides panel <None>.
– ‘none’ suppress image.
– Image in data folder.
font_color: (r,g,b) font color. Overrides panel <None>.
font_type: [] font type list. Overrides panel <None>.
font_size: int font size – 6,8,10,12,24,32. Overrides panel <None>.
split_text: bool split text at space to new line <True>.
control_list: [] list held by control <None>.
– numeric: [0] ‘__numeric’, [1] (start,stop,step).
– alpha: [0] ‘__alpha’, [1] ‘upper’,'lower’,'mixed’.
– alphanumeric: [0] ‘__alphanumeric’ in list[0], [1] ‘upper’,'lower’,'mixed’.
– filelist: [0] ‘__filelist’, [1] path, [2] root, [3] ext.
– ‘item’: Value listing. Leading ‘__’ not display or display available icon.
icon_list: [] control icons <None>.
– replace ‘__item’ in control_list – separate images or a composite image.
icon_size: (w,h) control icon size <None>.
– values < 1 are %control size.
– default use control size.
tip_list: [] tip list – single tip or multiple tip list <None>.
link: [] function control link to activate other controls <None>.
link_activated: bool function control link activated <True>.
activated_color: (r,g,b) highlight color of activated control <(0,120,160)>.
activated_toggle: bool control activated toggle <True>.
– ‘lock’ for activate lock.
label: ” supply label to replace ‘id’ text <None>.
label_display: bool control label displayed <True>.
active: bool control active state <True>.
control_response: int control response (ms). Overrides panel <None>.
hold_response: int hold (ms) before control response quicken <1000>.
– 0 no response change.
delay_response: int initial delay (ms) before control response <0>.
loop: bool option list loop <False>.
reverse: bool control switches reversed <False>.
event: bool interaction generates events. Overrides panel <None>.
Interface Methods:
- __init__(self, identity=’Interface_Panel’, position=None, image=None, color=(0, 0, 0), size=(350, 100), screen=(500, 500), moveable=False, position_offset=(0, 0), move_rate=(200, 200), fixed=False, button_image=None, control_image=None, color_key=None, control_minsize=None, control_size=’min’, button_size=(12, 12), function_button=’left’, control_button=’right’, font_color=(125, 130, 135), font_type=None, font_size=10, label_display=False, info_display=False, info_fontsize=10, info_fontcolor=(125, 130, 135), info_position=(2, 0), tips_display=False, tips_fontsize=8, tips_fontcolor=(125, 130, 135), tips_position=(0, -15), control_response=125, pointer_interact=False, data_folder=’data’, data_zip=None, event=False)
- activate(self, activate_panel=True)
- Panel activation.
- add(self, identity, control_type, position, **parameters)
- Add control to panel.
- add_control(self, identity, control_type, position, **parameters)
- Add control to panel.
- add_controls(self)
- Method to overide in subclass for adding controls.
- add_info(self, *message_append)
- Add text to info.
- clear_info(self)
- Clear text from info.
- deactivate(self)
- Panel deactivation.
- disable_control(self, *control)
- Set control disabled.
- enable_control(self, *control)
- Set control enabled.
- get_control(self, *control)
- Retrieve control object. Multiple controls return a dictionary of control objects, and if no parameter given return dictionary of all control objects.
- get_control_move(self)
- Return selected control to move.
- get_default_image(self, mode=None, path=None)
- Get or save default images.
- get_id(self)
- Get panel identity
- get_panel_image(self, change=False)
- Get panel image to modify. Parameter Change - True: mod permanent, False: mod transitory.
- get_pointer_position(self)
- Get position of pointer determined at latest update.
- get_position(self)
- Retrieve panel position.
- get_size(self)
- Retrieve panel size.
- get_state(self)
- Get the state object of the panel.
- get_value(self, *control)
- Retrieve current value of control. Multiple controls return a dictionary of values, and if no parameter given return dictionary of all values.
- is_active(self)
- Check whether panel is active.
- is_control_moveable(self)
- Check whether control is moveable.
- is_info_display(self)
- Check whether info is displayed.
- is_label_display(self)
- Check whether label is displayed.
- is_moveable(self, setting=None)
- Check whether panel is moveable.
- is_tips_display(self)
- Check whether tips are displayed.
- move(self, x, y)
- Move panel to new position x,y.
- move_control(self, control=None, position=None, offset=None)
- Move selected control. If no position supplied, use position of mouse pointer.
- panel_update(self, force_update=True)
- Update control panel, determines interaction, does control action.
- remove_control(self, *control)
- Remove control from panel.
- set_button_image(self, button_image=None, data_folder=None, data_zip=None, file_obj=None, color_key=None, surface=None)
- Set image used for buttons.
- set_control_image(self, control_image=None, data_folder=None, data_zip=None, file_obj=None, color_key=None, surface=None)
- Set image used for control.
- set_control_move(self, control=None, mouse_visible=True)
- Select control to move.
- set_control_moveable(self, setting=’Toggle’)
- Set control moveable.
- set_info_display(self, setting=’Toggle’)
- Set info display setting.
- set_label_display(self, setting=’Toggle’)
- Set label display setting.
- set_moveable(self, setting=’Toggle’, position_offset=None, move_rate=None)
- Set panel moveable setting.
- set_panel_display(self, setting=’Toggle’)
- Set whether panel display toggled with pointer interaction.
- set_panel_image(self, image=None, data_folder=None, data_zip=None, file_obj=None, color_key=None, surface=None)
- Set image used for panel.
- set_pointer_interact(self, setting=’Toggle’)
- Set pointer interact monitoring.
- set_tips_display(self, setting=’Toggle’)
- Set tips display setting.
- update(self)
- Update control panel. If overriding in interface subclass, call Interface.update(self).
InterfaceControl Methods:
- __init__(self, panel, identity, control_type, position, size=None, color=(40, 80, 120), fill=1, control_outline=None, control_image=None, font_color=None, font_type=None, font_size=None, split_text=True, control_list=None, icon_list=None, icon_size=None, tip_list=None, link=None, link_activated=True, activated_color=(0, 120, 160), activated_toggle=True, label=None, label_display=True, active=True, control_response=None, hold_response=1000, delay_response=0, loop=False, reverse=False, event=None)
- get_id(self)
- Get control identity
- get_label(self)
- Get control label.
- get_list(self)
- Return control listing.
- get_list_index(self, item=None)
- Get the current place in control listing, or index of first occurrence of item.
- get_position(self)
- Retrieve control position.
- get_size(self)
- Retrieve control size.
- get_tip(self, item=None)
- Get the tip for a control item, or list of tips if no parameter given. Parameter: item:str
- get_value(self)
- Get the value of a control.
- is_activated(self)
- Check whether control is activated.
- is_activated_lock(self)
- Check control activate lock.
- is_active(self)
- Check whether a control is active.
- is_enabled(self)
- Check whether control is enabled.
- next(self)
- Set value to next in control list.
- previous(self)
- Set value to previous in control list.
- remove_list(self, items=None, index=None)
- Remove specified items (or item at index) from control listing, including corresponding tips and links. Passing no parameter removes complete control list.
- reset(self, change_index=True)
- Reset value to start of control list.
- resize_control(self, size)
- Resize control.
- set_activated(self, setting=’Toggle’)
- Set control activated.
- set_activated_lock(self, setting=’Toggle’)
- Set control activate lock.
- set_active(self, setting=’Toggle’)
- Set control active setting.
- set_color(self, color=None, activated_color=None, fill=None)
- Set control color.
- set_control_image(self, control_image=None, data_folder=None, data_zip=None, file_obj=None, color_key=None, surface=None)
- Set image of control.
- set_display_text(self, font_color=None, font_bgcolor=None, font_type=None, font_size=None, split_text=None, size=None, info=False)
- Set display text properties.
- set_enabled(self, setting=’Toggle’)
- Set control enabled setting.
- set_label(self, label=None)
- Set control label.
- set_label_text(self, font_color=None, font_bgcolor=None, font_type=None, font_size=None, split_text=None)
- Set label text properties.
- set_link(self, control, link)
- Set linked controls. Parameters: control:str, link:[].
- set_link_activated(self, setting=’Toggle’)
- Set whether linked control active immediately or upon control button activation.
- set_list(self, control_list, icon_list=None, size=None, icon_size=None, case=False, data_folder=None, data_zip=None, file_obj=None, color_key=None, surface=None, append=False, index=None, keep_link=True, keep_tip=True)
- Set control listing of a control.
- set_list_icon(self, control_list, icon_list=None, data_folder=None, data_zip=None, file_obj=None, color_key=None, surface=None, icon_size=None)
- Set control listing icon of a control, changing if item in listing or appending new item.
- set_list_index(self, index)
- Set the place in control listing.
- set_tip(self, *tip)
- Set tip for a control item. Parameters: tip:str/[] single control tip or tip list for control list items; or tuple item:str,tip:str tip for control list item.
- set_value(self, value, change_index=True)
- Set the value of a control. Parameters: value - control value; change_index - True change list index to first available value, False to leave index position unchanged, index number for specific index if is value.
