streamtuner2: api-uikit
Internet radio browser GUI for music/video streams from various directory services.

⌈⌋ branch:  streamtuner2


api-uikit

 
 
uikit

index
streamtuner2/uikit.py

# encoding: UTF-8
# api: python
# type: functions
# title: uikit helper functions
# description: simplify usage of some gtk widgets
# version: 2.0
# author: mario
# license: public domain
#
# Wrappers around gtk methods. The TreeView method .columns() allows
# to fill a treeview. It adds columns and data rows with a mapping
# dictionary (which specifies many options and data positions).
#
# The .tree() method is a trimmed-down variant of that, creates a
# single column, but has threaded entries.
#
# With the methodes .app_state() and .app_restore() named gtk widgets
# can be queried for attributes. The methods return a saveable dict,
# which contain current layout options for a few Widget types. Saving
# and restoring must be handled elsewhere.

 
Modules

      

 
gtk.gdk
base64
copy
gobject
gtk
inspect
os
pygtk
re
sys

 
Classes

      

 
__builtin__.object
AuxiliaryWindow
AboutStreamtuner2
gtk.ComboBox(gtk.Bin, gtk.CellEditable, gtk.CellLayout)
ComboBoxText
uikit

 
class AboutStreamtuner2(AuxiliaryWindow)

   

# Auxiliary window: about dialog
 
 
Method resolution order:
AboutStreamtuner2
AuxiliaryWindow
__builtin__.object

Methods defined here:
__init__(self, parent)

Methods inherited from AuxiliaryWindow:

__getattr__(self, name)

Data descriptors inherited from AuxiliaryWindow:

__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class AuxiliaryWindow(__builtin__.object)

   

# Encapsulates references to gtk objects AND properties in main window,
# which allows to use self. and main. almost interchangably.
#
# This is a kludge to keep gtkBuilder widgets accessible; so just one
# instance has to be built. Also ties main.channels{} or .features{}
# dicts together for feature windows. Used by search, config, streamedit.
 
  Methods defined here:
__getattr__(self, name)
__init__(self, parent)

Data descriptors defined here:

__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class ComboBoxText(gtk.ComboBox)

   

# Text-only dropdown list.
#
# Necessary because gtk.ComboBoxText binding is absent in debian packages
# https://bugzilla.gnome.org/show_bug.cgi?id=660659
#
# This one implements a convenience method `.set_default()` to define the active
# selection by value, rather than by index.
#
# Can use a list[] of entries or a key->value dict{}, where the value becomes
# display text, and the key the internal value.
 
Methods defined here:
__init__(self, entries, no_scroll=1)
get_active_text(self)
# fetch currently selected text entry
no_scroll(self, widget, event, data=None)
# Signal/Event callback to prevent hover scrolling of ComboBox widgets
set_default(self, value)
# activate dropdown of given value

Static methods defined here:

parse_options(opts, sep='|', assoc='=')
# Expand A=a|B=b|C=c option list into (key,value) tuple list, or A|B|C just into a list.

Data and other attributes defined here:

ls = None

 
class uikit

   

# simplified gtk constructors               ---------------------------------------------
 
  Static methods defined here:
add_menu(menuwidget, label, action, insert=None)
# Attach textual menu entry and callback
add_signals(builder, map)
# manual signal binding with a dict of { (widget, signal): callback }
app_bin_check(v)
# return OK or CANCEL depending on availability of app
app_restore(wTree, r=None)
#-- restore window and widget properties
#
# requires only the previously saved widget state dict
app_state(wTree, widgetnames='window1', 'treeview2', 'vbox17')
#-- save window size and widget properties
#
# needs a list of widgetnames
# e.g. pickle.dump(uikit.app_state(...), open(os.environ"HOME"+"/.config/app_winstate", "w"))
bg(w, color='', where='bg', wrap=1)
this method should be called after widget creation, and before .add()ing it to container
columns(widget, datamap=[], entries=None, show_favicons=True, pix_entry=False, fixed_size=24)
#-- fill a treeview
#
# Adds treeviewcolumns/cellrenderers and liststore from a data dictionary.
# Its datamap and the table contents can be supplied in one or two steps.
# When new data gets applied, the columns aren't recreated.
#
# The columns are created according to the datamap, which describes cell
# mapping and layout. Columns can have multiple cellrenderers, but usually
# there is a direct mapping to a data source key from entries.
#
# datamap = [&nbsp;&nbsp;#&nbsp;&nbsp;title&nbsp;&nbsp;&nbsp;width&nbsp;&nbsp;&nbsp;&nbsp;dict-key&nbsp;&nbsp;&nbsp;&nbsp;type,&nbsp;&nbsp;renderer,&nbsp;&nbsp;attrs&nbsp;&nbsp;<br> #&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;["Name",&nbsp;&nbsp;&nbsp;150,&nbsp;&nbsp;["titlerow",&nbsp;&nbsp;&nbsp;str,&nbsp;&nbsp;&nbsp;&nbsp;"text",&nbsp;&nbsp;&nbsp;&nbsp;{}&nbsp;]  ],
#               [False,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0,&nbsp;&nbsp;&nbsp;["interndat",&nbsp;&nbsp;int,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;None,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{}&nbsp;]  ],
#               ["Desc",&nbsp;&nbsp;&nbsp;200,&nbsp;&nbsp;["descriptn",&nbsp;&nbsp;str,&nbsp;&nbsp;&nbsp;&nbsp;"text",&nbsp;&nbsp;&nbsp;&nbsp;{}&nbsp;],  "icon",str,"pixbuf",{}  ],
#
# An according entries list then would contain a dictionary for each row:
#   entries =  {"titlerow":"first", "interndat":123}, {"titlerow":"..."}, 
# Keys not mentioned in the datamap get ignored, and defaults are applied
# for missing cols. All values must already be in the correct type however.
config_treeview(opt, columns='Icon', 'Command')
# Config win table (editable dictionary, two columns w/ executable indicator pixbuf)
do(callback, *args, **kwargs)
# Spool gtk update calls from non-main threads (optional immediate=1 flag to run task next, not last)
hbox(w1, w2, exr=True, spacing=5)
# Wrap two widgets in horizontal box
idle_do()
# Execute UI updating tasks in order
label(text, size=305, markup=0)
# Create GtkLabel
liststore_edit(cell, row, text, user_data)
# Generic Gtk callback to update ListStore when entries get edited.
# where user_data = (liststore, column #id)
msg(text, style=<enum GTK_MESSAGE_INFO of type GtkMessageType>, buttons=<enum GTK_BUTTONS_CLOSE of type GtkButtonsType>, yes=None)
# gtk.messagebox
pixbuf(buf, fmt='png', decode=True, gzip=False)
# Pixbug loader (from inline string, as in `logo.png`, automatic base64 decoding, and gunzipping of raw data)
save_file(title='Save As', parent=None, fn='', formats=None, action=<enum GTK_FILE_CHOOSER_ACTION_SAVE of type GtkFileChooserAction>, action_btn='gtk-save')
save_file_filterchange(c)
# Callback for changed FileFilter, updates current filename extension
tree(widget, entries, title='category', icon='gtk-directory')
#-- treeview for categories
#
# simple two-level treeview display in one column
# with entries = main,[sub,sub, title,...,...]
tree_column(widget, title='Category')
wrap(widgetstore=None, id=None, w=None, label=None, color=None, image=None, align=1, label_size=305, label_markup=0)
# Wrap entries/checkboxes with extra label, background, images, etc.

Data and other attributes defined here:

gtk_position_type_enum = [&lt;enum GTK_POS_LEFT of type GtkPositionType&gt;, &lt;enum GTK_POS_RIGHT of type GtkPositionType&gt;, &lt;enum GTK_POS_TOP of type GtkPositionType&gt;, &lt;enum GTK_POS_BOTTOM of type GtkPositionType&gt;]<enum GTK_POS_LEFT of type GtkPositionType>, <enum GTK_POS_RIGHT of type GtkPositionType>, <enum GTK_POS_TOP of type GtkPositionType>, <enum GTK_POS_BOTTOM of type GtkPositionType>
idle_tasks = []
in_idle = False
save_formats = [('*.pls', '*.pls'), ('*.xspf', '*.xpsf'), ('*.m3u', '*.m3u'), ('*.jspf', '*.jspf'), ('*.asx', '*.asx'), ('*.json', '*.json'), ('*.smil', '*.smil'), ('*.desktop', '*.desktop'), ('*', '*')]('*.pls', '*.pls'), ('*.xspf', '*.xpsf'), ('*.m3u', '*.m3u'), ('*.jspf', '*.jspf'), ('*.asx', '*.asx'), ('*.json', '*.json'), ('*.smil', '*.smil'), ('*.desktop', '*.desktop'), ('*', '*')

 
Functions

      

 
gui_startup(p=0.0, msg='streamtuner2 is starting')
treepath(ls)
# Use a str of "1:2:3" as treepath,
# literally in Gtk2, TreePath-wrapped for Gtk3
treepath_to_str(tp)

 
Data

      

  PY3 = 0
conf = {u'filter_walledgardens': True, u'radionomy_page...e/mario/.config/streamtuner2', u'history': u'20'}
empty_pixbuf = <gtk.gdk.Pixbuf object at 0x7fe51185d820 (GdkPixbuf at 0x18dd190)>
log = <config.log_printer object>
progressbar = None
progresswin = None
ui_xml = u'<?xml version="1.0" encoding="UTF-8"?>\n<!-- Gene... </object>\n </child>\n </object>\n</interface>\n'
ver = 2