INSTRUCTION stringlengths 1 46.3k | RESPONSE stringlengths 75 80.2k |
|---|---|
Add a vod, with one input.
@param p_instance: the instance.
@param psz_name: the name of the new vod media.
@param psz_input: the input MRL.
@param i_options: number of additional options.
@param ppsz_options: additional options.
@param b_enabled: boolean for enabling the new vod.
@param psz... | def libvlc_vlm_add_vod(p_instance, psz_name, psz_input, i_options, ppsz_options, b_enabled, psz_mux):
'''Add a vod, with one input.
@param p_instance: the instance.
@param psz_name: the name of the new vod media.
@param psz_input: the input MRL.
@param i_options: number of additional options.
@p... |
Delete a media (VOD or broadcast).
@param p_instance: the instance.
@param psz_name: the media to delete.
@return: 0 on success, -1 on error. | def libvlc_vlm_del_media(p_instance, psz_name):
'''Delete a media (VOD or broadcast).
@param p_instance: the instance.
@param psz_name: the media to delete.
@return: 0 on success, -1 on error.
'''
f = _Cfunctions.get('libvlc_vlm_del_media', None) or \
_Cfunction('libvlc_vlm_del_media', (... |
Enable or disable a media (VOD or broadcast).
@param p_instance: the instance.
@param psz_name: the media to work on.
@param b_enabled: the new status.
@return: 0 on success, -1 on error. | def libvlc_vlm_set_enabled(p_instance, psz_name, b_enabled):
'''Enable or disable a media (VOD or broadcast).
@param p_instance: the instance.
@param psz_name: the media to work on.
@param b_enabled: the new status.
@return: 0 on success, -1 on error.
'''
f = _Cfunctions.get('libvlc_vlm_set_... |
Set the output for a media.
@param p_instance: the instance.
@param psz_name: the media to work on.
@param psz_output: the output MRL (the parameter to the "sout" variable).
@return: 0 on success, -1 on error. | def libvlc_vlm_set_output(p_instance, psz_name, psz_output):
'''Set the output for a media.
@param p_instance: the instance.
@param psz_name: the media to work on.
@param psz_output: the output MRL (the parameter to the "sout" variable).
@return: 0 on success, -1 on error.
'''
f = _Cfunction... |
Set a media's input MRL. This will delete all existing inputs and
add the specified one.
@param p_instance: the instance.
@param psz_name: the media to work on.
@param psz_input: the input MRL.
@return: 0 on success, -1 on error. | def libvlc_vlm_set_input(p_instance, psz_name, psz_input):
'''Set a media's input MRL. This will delete all existing inputs and
add the specified one.
@param p_instance: the instance.
@param psz_name: the media to work on.
@param psz_input: the input MRL.
@return: 0 on success, -1 on error.
... |
Set a media's loop status.
@param p_instance: the instance.
@param psz_name: the media to work on.
@param b_loop: the new status.
@return: 0 on success, -1 on error. | def libvlc_vlm_set_loop(p_instance, psz_name, b_loop):
'''Set a media's loop status.
@param p_instance: the instance.
@param psz_name: the media to work on.
@param b_loop: the new status.
@return: 0 on success, -1 on error.
'''
f = _Cfunctions.get('libvlc_vlm_set_loop', None) or \
_C... |
Set a media's vod muxer.
@param p_instance: the instance.
@param psz_name: the media to work on.
@param psz_mux: the new muxer.
@return: 0 on success, -1 on error. | def libvlc_vlm_set_mux(p_instance, psz_name, psz_mux):
'''Set a media's vod muxer.
@param p_instance: the instance.
@param psz_name: the media to work on.
@param psz_mux: the new muxer.
@return: 0 on success, -1 on error.
'''
f = _Cfunctions.get('libvlc_vlm_set_mux', None) or \
_Cfun... |
Seek in the named broadcast.
@param p_instance: the instance.
@param psz_name: the name of the broadcast.
@param f_percentage: the percentage to seek to.
@return: 0 on success, -1 on error. | def libvlc_vlm_seek_media(p_instance, psz_name, f_percentage):
'''Seek in the named broadcast.
@param p_instance: the instance.
@param psz_name: the name of the broadcast.
@param f_percentage: the percentage to seek to.
@return: 0 on success, -1 on error.
'''
f = _Cfunctions.get('libvlc_vlm_... |
Return information about the named media as a JSON
string representation.
This function is mainly intended for debugging use,
if you want programmatic access to the state of
a vlm_media_instance_t, please use the corresponding
libvlc_vlm_get_media_instance_xxx -functions.
Currently there are no ... | def libvlc_vlm_show_media(p_instance, psz_name):
'''Return information about the named media as a JSON
string representation.
This function is mainly intended for debugging use,
if you want programmatic access to the state of
a vlm_media_instance_t, please use the corresponding
libvlc_vlm_get_me... |
Get vlm_media instance position by name or instance id.
@param p_instance: a libvlc instance.
@param psz_name: name of vlm media instance.
@param i_instance: instance id.
@return: position as float or -1. on error. | def libvlc_vlm_get_media_instance_position(p_instance, psz_name, i_instance):
'''Get vlm_media instance position by name or instance id.
@param p_instance: a libvlc instance.
@param psz_name: name of vlm media instance.
@param i_instance: instance id.
@return: position as float or -1. on error.
... |
Get vlm_media instance time by name or instance id.
@param p_instance: a libvlc instance.
@param psz_name: name of vlm media instance.
@param i_instance: instance id.
@return: time as integer or -1 on error. | def libvlc_vlm_get_media_instance_time(p_instance, psz_name, i_instance):
'''Get vlm_media instance time by name or instance id.
@param p_instance: a libvlc instance.
@param psz_name: name of vlm media instance.
@param i_instance: instance id.
@return: time as integer or -1 on error.
'''
f =... |
Get libvlc_event_manager from a vlm media.
The p_event_manager is immutable, so you don't have to hold the lock.
@param p_instance: a libvlc instance.
@return: libvlc_event_manager. | def libvlc_vlm_get_event_manager(p_instance):
'''Get libvlc_event_manager from a vlm media.
The p_event_manager is immutable, so you don't have to hold the lock.
@param p_instance: a libvlc instance.
@return: libvlc_event_manager.
'''
f = _Cfunctions.get('libvlc_vlm_get_event_manager', None) or ... |
(INTERNAL) Convert 'i.i.i[.i]' str to int. | def _dot2int(v):
'''(INTERNAL) Convert 'i.i.i[.i]' str to int.
'''
t = [int(i) for i in v.split('.')]
if len(t) == 3:
t.append(0)
elif len(t) != 4:
raise ValueError('"i.i.i[.i]": %r' % (v,))
if min(t) < 0 or max(t) > 255:
raise ValueError('[0..255]: %r' % (v,))
i = t.... |
Example callback, useful for debugging. | def debug_callback(event, *args, **kwds):
'''Example callback, useful for debugging.
'''
l = ['event %s' % (event.type,)]
if args:
l.extend(map(str, args))
if kwds:
l.extend(sorted('%s=%s' % t for t in kwds.items()))
print('Debug callback (%s)' % ', '.join(l)) |
Register an event notification.
@param eventtype: the desired event type to be notified about.
@param callback: the function to call when the event occurs.
@param args: optional positional arguments for the callback.
@param kwds: optional keyword arguments for the callback.
@ret... | def event_attach(self, eventtype, callback, *args, **kwds):
"""Register an event notification.
@param eventtype: the desired event type to be notified about.
@param callback: the function to call when the event occurs.
@param args: optional positional arguments for the callback.
... |
Unregister an event notification.
@param eventtype: the event type notification to be removed. | def event_detach(self, eventtype):
"""Unregister an event notification.
@param eventtype: the event type notification to be removed.
"""
if not isinstance(eventtype, EventType):
raise VLCException("%s required: %r" % ('EventType', eventtype))
k = eventtype.value
... |
Create a new MediaPlayer instance.
@param uri: an optional URI to play in the player. | def media_player_new(self, uri=None):
"""Create a new MediaPlayer instance.
@param uri: an optional URI to play in the player.
"""
p = libvlc_media_player_new(self)
if uri:
p.set_media(self.media_new(uri))
p._instance = self
return p |
Create a new Media instance.
If mrl contains a colon (:) preceded by more than 1 letter, it
will be treated as a URL. Else, it will be considered as a
local path. If you need more control, directly use
media_new_location/media_new_path methods.
Options can be specified as suppl... | def media_new(self, mrl, *options):
"""Create a new Media instance.
If mrl contains a colon (:) preceded by more than 1 letter, it
will be treated as a URL. Else, it will be considered as a
local path. If you need more control, directly use
media_new_location/media_new_path meth... |
Create a new MediaList instance.
@param mrls: optional list of MRL strings | def media_list_new(self, mrls=None):
"""Create a new MediaList instance.
@param mrls: optional list of MRL strings
"""
l = libvlc_media_list_new(self)
# We should take the lock, but since we did not leak the
# reference, nobody else can access it.
if mrls:
... |
Enumerate the defined audio output devices.
@return: list of dicts {name:, description:, devices:} | def audio_output_enumerate_devices(self):
"""Enumerate the defined audio output devices.
@return: list of dicts {name:, description:, devices:}
"""
r = []
head = libvlc_audio_output_list_get(self)
if head:
i = head
while i:
i = i.c... |
Sets the application name. LibVLC passes this as the user agent string
when a protocol requires it.
@param name: human-readable application name, e.g. "FooBar player 1.2.3".
@param http: HTTP User Agent, e.g. "FooBar/1.2.3 Python/2.6.0".
@version: LibVLC 1.1.1 or later. | def set_user_agent(self, name, http):
'''Sets the application name. LibVLC passes this as the user agent string
when a protocol requires it.
@param name: human-readable application name, e.g. "FooBar player 1.2.3".
@param http: HTTP User Agent, e.g. "FooBar/1.2.3 Python/2.6.0".
@... |
Sets some meta-information about the application.
See also L{set_user_agent}().
@param id: Java-style application identifier, e.g. "com.acme.foobar".
@param version: application version numbers, e.g. "1.2.3".
@param icon: application icon name, e.g. "foobar".
@version: LibVLC 2.1... | def set_app_id(self, id, version, icon):
'''Sets some meta-information about the application.
See also L{set_user_agent}().
@param id: Java-style application identifier, e.g. "com.acme.foobar".
@param version: application version numbers, e.g. "1.2.3".
@param icon: application ic... |
Create a media with custom callbacks to read the data from.
@param open_cb: callback to open the custom bitstream input media.
@param read_cb: callback to read data (must not be NULL).
@param seek_cb: callback to seek, or NULL if seeking is not supported.
@param close_cb: callback to clo... | def media_new_callbacks(self, open_cb, read_cb, seek_cb, close_cb, opaque):
'''Create a media with custom callbacks to read the data from.
@param open_cb: callback to open the custom bitstream input media.
@param read_cb: callback to read data (must not be NULL).
@param seek_cb: callback... |
Add a broadcast, with one input.
@param psz_name: the name of the new broadcast.
@param psz_input: the input MRL.
@param psz_output: the output MRL (the parameter to the "sout" variable).
@param i_options: number of additional options.
@param ppsz_options: additional options.
... | def vlm_add_broadcast(self, psz_name, psz_input, psz_output, i_options, ppsz_options, b_enabled, b_loop):
'''Add a broadcast, with one input.
@param psz_name: the name of the new broadcast.
@param psz_input: the input MRL.
@param psz_output: the output MRL (the parameter to the "sout" va... |
Add a vod, with one input.
@param psz_name: the name of the new vod media.
@param psz_input: the input MRL.
@param i_options: number of additional options.
@param ppsz_options: additional options.
@param b_enabled: boolean for enabling the new vod.
@param psz_mux: the mux... | def vlm_add_vod(self, psz_name, psz_input, i_options, ppsz_options, b_enabled, psz_mux):
'''Add a vod, with one input.
@param psz_name: the name of the new vod media.
@param psz_input: the input MRL.
@param i_options: number of additional options.
@param ppsz_options: additional ... |
Set the output for a media.
@param psz_name: the media to work on.
@param psz_output: the output MRL (the parameter to the "sout" variable).
@return: 0 on success, -1 on error. | def vlm_set_output(self, psz_name, psz_output):
'''Set the output for a media.
@param psz_name: the media to work on.
@param psz_output: the output MRL (the parameter to the "sout" variable).
@return: 0 on success, -1 on error.
'''
return libvlc_vlm_set_output(self, str_t... |
Set a media's input MRL. This will delete all existing inputs and
add the specified one.
@param psz_name: the media to work on.
@param psz_input: the input MRL.
@return: 0 on success, -1 on error. | def vlm_set_input(self, psz_name, psz_input):
'''Set a media's input MRL. This will delete all existing inputs and
add the specified one.
@param psz_name: the media to work on.
@param psz_input: the input MRL.
@return: 0 on success, -1 on error.
'''
return libvlc_... |
Add a media's input MRL. This will add the specified one.
@param psz_name: the media to work on.
@param psz_input: the input MRL.
@return: 0 on success, -1 on error. | def vlm_add_input(self, psz_name, psz_input):
'''Add a media's input MRL. This will add the specified one.
@param psz_name: the media to work on.
@param psz_input: the input MRL.
@return: 0 on success, -1 on error.
'''
return libvlc_vlm_add_input(self, str_to_bytes(psz_na... |
Set a media's vod muxer.
@param psz_name: the media to work on.
@param psz_mux: the new muxer.
@return: 0 on success, -1 on error. | def vlm_set_mux(self, psz_name, psz_mux):
'''Set a media's vod muxer.
@param psz_name: the media to work on.
@param psz_mux: the new muxer.
@return: 0 on success, -1 on error.
'''
return libvlc_vlm_set_mux(self, str_to_bytes(psz_name), str_to_bytes(psz_mux)) |
Edit the parameters of a media. This will delete all existing inputs and
add the specified one.
@param psz_name: the name of the new broadcast.
@param psz_input: the input MRL.
@param psz_output: the output MRL (the parameter to the "sout" variable).
@param i_options: number of a... | def vlm_change_media(self, psz_name, psz_input, psz_output, i_options, ppsz_options, b_enabled, b_loop):
'''Edit the parameters of a media. This will delete all existing inputs and
add the specified one.
@param psz_name: the name of the new broadcast.
@param psz_input: the input MRL.
... |
Get media descriptor's elementary streams description
Note, you need to call L{parse}() or play the media at least once
before calling this function.
Not doing this will result in an empty array.
The result must be freed with L{tracks_release}.
@version: LibVLC 2.1.0 and later. | def tracks_get(self):
"""Get media descriptor's elementary streams description
Note, you need to call L{parse}() or play the media at least once
before calling this function.
Not doing this will result in an empty array.
The result must be freed with L{tracks_release}.
@v... |
Add media instance to media list.
The L{lock} should be held upon entering this function.
@param mrl: a media instance or a MRL.
@return: 0 on success, -1 if the media list is read-only. | def add_media(self, mrl):
"""Add media instance to media list.
The L{lock} should be held upon entering this function.
@param mrl: a media instance or a MRL.
@return: 0 on success, -1 if the media list is read-only.
"""
if isinstance(mrl, basestring):
... |
Set the MRL to play.
Warning: most audio and video options, such as text renderer,
have no effects on an individual media. These options must be
set at the vlc.Instance or vlc.MediaPlayer instanciation.
@param mrl: The MRL
@param options: optional media option=value strings
... | def set_mrl(self, mrl, *options):
"""Set the MRL to play.
Warning: most audio and video options, such as text renderer,
have no effects on an individual media. These options must be
set at the vlc.Instance or vlc.MediaPlayer instanciation.
@param mrl: The MRL
@param opt... |
Get the video size in pixels as 2-tuple (width, height).
@param num: video number (default 0). | def video_get_size(self, num=0):
"""Get the video size in pixels as 2-tuple (width, height).
@param num: video number (default 0).
"""
r = libvlc_video_get_size(self, num)
if isinstance(r, tuple) and len(r) == 2:
return r
else:
raise VLCException(... |
Set a Win32/Win64 API window handle (HWND).
Specify where the media player should render its video
output. If LibVLC was built without Win32/Win64 API output
support, then this has no effects.
@param drawable: windows handle of the drawable. | def set_hwnd(self, drawable):
"""Set a Win32/Win64 API window handle (HWND).
Specify where the media player should render its video
output. If LibVLC was built without Win32/Win64 API output
support, then this has no effects.
@param drawable: windows handle of the dr... |
Get the mouse pointer coordinates over a video as 2-tuple (x, y).
Coordinates are expressed in terms of the decoded video resolution,
B{not} in terms of pixels on the screen/viewport. To get the
latter, you must query your windowing system directly.
Either coordinate may be negative o... | def video_get_cursor(self, num=0):
"""Get the mouse pointer coordinates over a video as 2-tuple (x, y).
Coordinates are expressed in terms of the decoded video resolution,
B{not} in terms of pixels on the screen/viewport. To get the
latter, you must query your windowing system directly... |
Set callbacks and private data to render decoded video to a custom area
in memory.
Use L{video_set_format}() or L{video_set_format_callbacks}()
to configure the decoded format.
@param lock: callback to lock video memory (must not be NULL).
@param unlock: callback to unlock video ... | def video_set_callbacks(self, lock, unlock, display, opaque):
'''Set callbacks and private data to render decoded video to a custom area
in memory.
Use L{video_set_format}() or L{video_set_format_callbacks}()
to configure the decoded format.
@param lock: callback to lock video me... |
Set decoded video chroma and dimensions.
This only works in combination with L{video_set_callbacks}(),
and is mutually exclusive with L{video_set_format_callbacks}().
@param chroma: a four-characters string identifying the chroma (e.g. "RV32" or "YUYV").
@param width: pixel width.
... | def video_set_format(self, chroma, width, height, pitch):
'''Set decoded video chroma and dimensions.
This only works in combination with L{video_set_callbacks}(),
and is mutually exclusive with L{video_set_format_callbacks}().
@param chroma: a four-characters string identifying the chro... |
Set callbacks and private data for decoded audio.
Use L{audio_set_format}() or L{audio_set_format_callbacks}()
to configure the decoded audio format.
@param play: callback to play audio samples (must not be NULL).
@param pause: callback to pause playback (or NULL to ignore).
@par... | def audio_set_callbacks(self, play, pause, resume, flush, drain, opaque):
'''Set callbacks and private data for decoded audio.
Use L{audio_set_format}() or L{audio_set_format_callbacks}()
to configure the decoded audio format.
@param play: callback to play audio samples (must not be NULL... |
Set decoded audio format.
This only works in combination with L{audio_set_callbacks}(),
and is mutually exclusive with L{audio_set_format_callbacks}().
@param format: a four-characters string identifying the sample format (e.g. "S16N" or "FL32").
@param rate: sample rate (expressed in Hz... | def audio_set_format(self, format, rate, channels):
'''Set decoded audio format.
This only works in combination with L{audio_set_callbacks}(),
and is mutually exclusive with L{audio_set_format_callbacks}().
@param format: a four-characters string identifying the sample format (e.g. "S16N... |
Take a snapshot of the current video window.
If i_width AND i_height is 0, original size is used.
If i_width XOR i_height is 0, original aspect-ratio is preserved.
@param num: number of video output (typically 0 for the first/only one).
@param psz_filepath: the path where to save the scr... | def video_take_snapshot(self, num, psz_filepath, i_width, i_height):
'''Take a snapshot of the current video window.
If i_width AND i_height is 0, original size is used.
If i_width XOR i_height is 0, original aspect-ratio is preserved.
@param num: number of video output (typically 0 for ... |
Configures an explicit audio output device.
If the module paramater is NULL, audio output will be moved to the device
specified by the device identifier string immediately. This is the
recommended usage.
A list of adequate potential device strings can be obtained with
L{audio_out... | def audio_output_device_set(self, module, device_id):
'''Configures an explicit audio output device.
If the module paramater is NULL, audio output will be moved to the device
specified by the device identifier string immediately. This is the
recommended usage.
A list of adequate ... |
Do or redo the action | def do(self):
'Do or redo the action'
self._runner = self._generator(*self.args, **self.kwargs)
rets = next(self._runner)
if isinstance(rets, tuple):
self._text = rets[0]
return rets[1:]
elif rets is None:
self._text = ''
r... |
Decorator which creates a new undoable action type.
This decorator should be used on a generator of the following format::
@undoable
def operation(*args):
do_operation_code
yield 'descriptive text'
undo_operator_code | def undoable(generator):
''' Decorator which creates a new undoable action type.
This decorator should be used on a generator of the following format::
@undoable
def operation(*args):
do_operation_code
yield 'descriptive text'
undo_operator_code
... |
Redo the last undone action.
This is only possible if no other actions have occurred since the
last undo call. | def redo(self):
''' Redo the last undone action.
This is only possible if no other actions have occurred since the
last undo call.
'''
if self.canredo():
undoable = self._redos.pop()
with self._pausereceiver():
try:
... |
Undo the last action. | def undo(self):
''' Undo the last action. '''
if self.canundo():
undoable = self._undos.pop()
with self._pausereceiver():
try:
undoable.undo()
except:
self.clear()
raise
... |
Clear the undo list. | def clear(self):
''' Clear the undo list. '''
self._undos.clear()
self._redos.clear()
self._savepoint = None
self._receiver = self._undos |
Add a undoable to the stack, using ``receiver.append()``. | def append(self, action):
''' Add a undoable to the stack, using ``receiver.append()``. '''
if self._receiver is not None:
self._receiver.append(action)
if self._receiver is self._undos:
self._redos.clear()
self.docallback() |
Returns bounding box (xmin, xmax, ymin, ymax) | def get_bbox(self):
"""Returns bounding box (xmin, xmax, ymin, ymax)"""
x_min = self.x
x_max = x_min + self.width
y_min = self.y
y_max = self.y + self.height
return x_min, x_max, y_min, y_max |
Returns False iif bounding boxed of self and other intersect | def is_bbox_not_intersecting(self, other):
"""Returns False iif bounding boxed of self and other intersect"""
self_x_min, self_x_max, self_y_min, self_y_max = self.get_bbox()
other_x_min, other_x_max, other_y_min, other_y_max = other.get_bbox()
return \
self_x_min > other_x... |
Returns True iif point is inside the rectangle (border included)
Parameters
----------
* pt_x: Number
\tx-value of point
* pt_y: Number
\ty-value of point | def is_point_in_rect(self, pt_x, pt_y):
"""Returns True iif point is inside the rectangle (border included)
Parameters
----------
* pt_x: Number
\tx-value of point
* pt_y: Number
\ty-value of point
"""
x_min, x_max, y_min, y_max = self.get_bb... |
Returns bounding box (xmin, xmax, ymin, ymax) | def get_bbox(self):
"""Returns bounding box (xmin, xmax, ymin, ymax)"""
width = self.width
height = self.height
cos_angle = cos(self.angle)
sin_angle = sin(self.angle)
x_diff = 0.5 * width
y_diff = 0.5 * height
# self rotates around (0, 0).
c_x... |
Returns False iif any edge excludes all vertices of other. | def is_edge_not_excluding_vertices(self, other):
"""Returns False iif any edge excludes all vertices of other."""
c_a = cos(self.angle)
s_a = sin(self.angle)
# Get min and max of other.
other_x_min, other_x_max, other_y_min, other_y_max = other.get_bbox()
self_x_diff ... |
Returns collision with axis aligned rect | def collides(self, other):
"""Returns collision with axis aligned rect"""
angle = self.angle
width = self.width
height = self.height
if angle == 0:
return other.collides(Rect(-0.5 * width,
-0.5 * height, width, height))
... |
Returns vector from left to right | def get_vec_lr(self):
"""Returns vector from left to right"""
return self.width * self.cos_a(), -self.width * self.sin_a() |
Returns vector from top to bottom | def get_vec_tb(self):
"""Returns vector from top to bottom"""
return self.height * self.sin_a(), self.height * self.cos_a() |
Returns rectangle center | def get_center(self):
"""Returns rectangle center"""
lr_x, lr_y = self.get_vec_lr()
tb_x, tb_y = self.get_vec_tb()
center_x = self.x + (lr_x + tb_x) / 2.0
center_y = self.y + (lr_y + tb_y) / 2.0
return center_x, center_y |
Returns 2-tuples for each edge
top_left
top_right
bottom_left
bottom_right | def get_edges(self):
"""Returns 2-tuples for each edge
top_left
top_right
bottom_left
bottom_right
"""
lr_x, lr_y = self.get_vec_lr()
tb_x, tb_y = self.get_vec_tb()
top_left = self.x, self.y
top_right = self.x + lr_x, self.y + lr_y
... |
Returns collision with axis aligned other rect | def collides_axisaligned_rect(self, other):
"""Returns collision with axis aligned other rect"""
# Shift both rects so that self is centered at origin
self_shifted = RotoOriginRect(self.width, self.height, -self.angle)
s_a = self.sin_a()
c_a = self.cos_a()
center_x = ... |
Returns tuple of theme, icon, action and toggle paths | def get_paths(self, theme, icon_size):
"""Returns tuple of theme, icon, action and toggle paths"""
_size_str = "x".join(map(str, icon_size))
theme_path = get_program_path() + "share" + os.sep + "icons" + os.sep
icon_path = theme_path + theme + os.sep + _size_str + os.sep
action... |
Adds custom images to Artprovider | def CreateBitmap(self, artid, client, size):
"""Adds custom images to Artprovider"""
if artid in self.extra_icons:
return wx.Bitmap(self.extra_icons[artid], wx.BITMAP_TYPE_ANY)
else:
return wx.ArtProvider.GetBitmap(artid, client, size) |
Sets class state from kwargs attributes, pops extra kwargs | def set_initial_state(self, kwargs):
"""Sets class state from kwargs attributes, pops extra kwargs"""
self.main_window = kwargs.pop("main_window")
try:
statustext = kwargs.pop("statustext")
except KeyError:
statustext = ""
try:
self.total_l... |
Next that shows progress in statusbar for each <freq> cells | def next(self):
"""Next that shows progress in statusbar for each <freq> cells"""
self.progress_status()
# Check abortes state and raise StopIteration if aborted
if self.aborted:
statustext = _("File loading aborted.")
post_command_event(self.main_window, self.... |
Write that shows progress in statusbar for each <freq> cells | def write(self, *args, **kwargs):
"""Write that shows progress in statusbar for each <freq> cells"""
self.progress_status()
# Check abortes state and raise StopIteration if aborted
if self.aborted:
statustext = _("File saving aborted.")
post_command_event(self.m... |
Displays progress in statusbar | def progress_status(self):
"""Displays progress in statusbar"""
if self.line % self.freq == 0:
text = self.statustext.format(nele=self.line,
totalele=self.total_lines)
if self.main_window.grid.actions.pasting:
try:
... |
Sets aborted state if escape is pressed | def on_key(self, event):
"""Sets aborted state if escape is pressed"""
if self.main_window.grid.actions.pasting and \
event.GetKeyCode() == wx.WXK_ESCAPE:
self.aborted = True
event.Skip() |
Plots histogram | def hist(data):
"""Plots histogram"""
win = CurveDialog(edit=False, toolbar=True, wintitle="Histogram test")
plot = win.get_plot()
plot.add_item(make.histogram(data))
win.show()
win.exec_() |
Returns list of table nodes from ods object | def _get_tables(self, ods):
"""Returns list of table nodes from ods object"""
childnodes = ods.spreadsheet.childNodes
qname_childnodes = [(s.qname[1], s) for s in childnodes]
return [node for name, node in qname_childnodes if name == u"table"] |
Returns rows from table | def _get_rows(self, table):
"""Returns rows from table"""
childnodes = table.childNodes
qname_childnodes = [(s.qname[1], s) for s in childnodes]
return [node for name, node in qname_childnodes
if name == u'table-row'] |
Returns rows from row | def _get_cells(self, row):
"""Returns rows from row"""
childnodes = row.childNodes
qname_childnodes = [(s.qname[1], s) for s in childnodes]
return [node for name, node in qname_childnodes
if name == u'table-cell'] |
Updates code in code_array | def _ods2code(self):
"""Updates code in code_array"""
ods = ODSReader(self.ods_file, clonespannedcolumns=True)
tables = ods.sheets
for tab_id, table in enumerate(tables):
for row_id in xrange(len(table)):
for col_id in xrange(len(table[row_id])):
... |
Holds application main loop | def pyspread(S=None):
"""Holds application main loop"""
# Initialize main application
app = MainApplication(S=S, redirect=False)
app.MainLoop() |
Returns a a tuple (options, filename)
options: The command line options
filename: String (defaults to None)
\tThe name of the file that is loaded on start-up | def parse(self):
"""
Returns a a tuple (options, filename)
options: The command line options
filename: String (defaults to None)
\tThe name of the file that is loaded on start-up
"""
options, args = self.parser.parse_args()
# If one dimension is 0 then... |
Init class that is automatically run on __init__ | def OnInit(self):
"""Init class that is automatically run on __init__"""
# Get command line options and arguments
cmdp = Commandlineparser()
options, filename = cmdp.parse()
kwargs = {
"title": "pyspread",
"S": self.S
}
# Store command l... |
Reads a sheet in the sheet dictionary
Stores each sheet as an array (rows) of arrays (columns) | def readSheet(self, sheet):
"""Reads a sheet in the sheet dictionary
Stores each sheet as an array (rows) of arrays (columns)
"""
name = sheet.getAttribute("name")
rows = sheet.getElementsByType(TableRow)
arrRows = []
# for each row
for row in rows:
... |
Sniffs CSV dialect and header info from csvfilepath
Returns a tuple of dialect and has_header | def sniff(filepath):
"""
Sniffs CSV dialect and header info from csvfilepath
Returns a tuple of dialect and has_header
"""
with open(filepath, "rb") as csvfile:
sample = csvfile.read(config["sniff_size"])
sniffer = csv.Sniffer()
dialect = sniffer.sniff(sample)()
has_header = ... |
Returns List of first line items of file filepath | def get_first_line(filepath, dialect):
"""Returns List of first line items of file filepath"""
with open(filepath, "rb") as csvfile:
csvreader = csv.reader(csvfile, dialect=dialect)
for first_line in csvreader:
break
return first_line |
Returns list of digested values in line | def digested_line(line, digest_types):
"""Returns list of digested values in line"""
digested_line = []
for i, ele in enumerate(line):
try:
digest_key = digest_types[i]
except IndexError:
digest_key = digest_types[0]
digest = Digest(acceptable_types=[digest... |
Generator of digested values from csv file in filepath
Parameters
----------
filepath:String
\tFile path of csv file to read
dialect: Object
\tCsv dialect
digest_types: tuple of types
\tTypes of data for each col | def csv_digest_gen(filepath, dialect, has_header, digest_types):
"""Generator of digested values from csv file in filepath
Parameters
----------
filepath:String
\tFile path of csv file to read
dialect: Object
\tCsv dialect
digest_types: tuple of types
\tTypes of data for each col
... |
Generator of row, col, value tuple from iterable of iterables
it: Iterable of iterables
\tMatrix that shall be mapped on target grid
shape: Tuple of Integer
\tShape of target grid
topleft: 2-tuple of Integer
\tTop left cell for insertion of it | def cell_key_val_gen(iterable, shape, topleft=(0, 0)):
"""Generator of row, col, value tuple from iterable of iterables
it: Iterable of iterables
\tMatrix that shall be mapped on target grid
shape: Tuple of Integer
\tShape of target grid
topleft: 2-tuple of Integer
\tTop left cell for inser... |
Encodes all Unicode strings in line to encoding
Parameters
----------
line: Iterable of Unicode strings
\tDate to be encoded
encoding: String, defaults to "utf-8"
\tTarget encoding | def encode_gen(line, encoding="utf-8"):
"""Encodes all Unicode strings in line to encoding
Parameters
----------
line: Iterable of Unicode strings
\tDate to be encoded
encoding: String, defaults to "utf-8"
\tTarget encoding
"""
for ele in line:
if isinstance(ele, types.Uni... |
Generator of values in a csv line | def _get_csv_cells_gen(self, line):
"""Generator of values in a csv line"""
digest_types = self.digest_types
for j, value in enumerate(line):
if self.first_line:
digest_key = None
digest = lambda x: x.decode(self.encoding)
else:
... |
Writes values from iterable into CSV file | def write(self, iterable):
"""Writes values from iterable into CSV file"""
io_error_text = _("Error writing to file {filepath}.")
io_error_text = io_error_text.format(filepath=self.path)
try:
with open(self.path, "wb") as csvfile:
csv_writer = csv.writer(cs... |
Get an Excel index from | def color2idx(self, red, green, blue):
"""Get an Excel index from"""
xlwt_colors = [
(0, 0, 0), (255, 255, 255), (255, 0, 0), (0, 255, 0), (0, 0, 255),
(255, 255, 0), (255, 0, 255), (0, 255, 255), (0, 0, 0),
(255, 255, 255), (255, 0, 0), (0, 255, 0), (0, 0, 255),
... |
Writes shape to xls file
Format: <rows>\t<cols>\t<tabs>\n | def _shape2xls(self, worksheets):
"""Writes shape to xls file
Format: <rows>\t<cols>\t<tabs>\n
"""
__, __, tabs = self.code_array.shape
if tabs > self.xls_max_tabs:
tabs = self.xls_max_tabs
for tab in xrange(tabs):
worksheet = self.workbook.ad... |
Updates shape in code_array | def _xls2shape(self):
"""Updates shape in code_array"""
sheets = self.workbook.sheets()
nrows = 1
ncols = 1
for sheet in sheets:
nrows = max(nrows, sheet.nrows)
ncols = max(ncols, sheet.ncols)
ntabs = len(sheets)
self.code_array.shape = n... |
Writes code to xls file
Format: <row>\t<col>\t<tab>\t<code>\n | def _code2xls(self, worksheets):
"""Writes code to xls file
Format: <row>\t<col>\t<tab>\t<code>\n
"""
code_array = self.code_array
xls_max_shape = self.xls_max_rows, self.xls_max_cols, self.xls_max_tabs
for key in code_array:
if all(kele < mele for kele, ... |
Updates code in xls code_array | def _xls2code(self, worksheet, tab):
"""Updates code in xls code_array"""
def xlrddate2datetime(xlrd_date):
"""Returns datetime from xlrd_date"""
try:
xldate_tuple = xlrd.xldate_as_tuple(xlrd_date,
self.workboo... |
Returns xlwt.Font for pyspread style | def _get_font(self, pys_style):
"""Returns xlwt.Font for pyspread style"""
# Return None if there is no font
if "textfont" not in pys_style:
return
font = xlwt.Font()
font.name = pys_style["textfont"]
if "pointsize" in pys_style:
font.height = ... |
Returns xlwt.Alignment for pyspread style | def _get_alignment(self, pys_style):
"""Returns xlwt.Alignment for pyspread style"""
# Return None if there is no alignment
alignment_styles = ["justification", "vertical_align", "angle"]
if not any(astyle in pys_style for astyle in alignment_styles):
return
def ang... |
Returns xlwt.pattern for pyspread style | def _get_pattern(self, pys_style):
"""Returns xlwt.pattern for pyspread style"""
# Return None if there is no bgcolor
if "bgcolor" not in pys_style:
return
pattern = xlwt.Pattern()
pattern.pattern = xlwt.Pattern.SOLID_PATTERN
bgcolor = wx.Colour()
b... |
Returns xlwt.Borders for pyspread style | def _get_borders(self, pys_style, pys_style_above, pys_style_left):
"""Returns xlwt.Borders for pyspread style"""
# Return None if there is no border key
border_keys = [
"borderwidth_right",
"borderwidth_bottom",
"bordercolor_right",
"bordercolor_... |
Gets XFStyle for cell key | def _get_xfstyle(self, worksheets, key):
"""Gets XFStyle for cell key"""
row, col, tab = key
dict_grid = self.code_array.dict_grid
dict_grid.cell_attributes._update_table_cache()
pys_style = dict_grid.cell_attributes[key]
pys_style_above = dict_grid.cell_attributes[row ... |
Appends to cell_attributes with checks | def _cell_attribute_append(self, selection, tab, attributes):
"""Appends to cell_attributes with checks"""
cell_attributes = self.code_array.cell_attributes
thick_bottom_cells = []
thick_right_cells = []
# Does any cell in selection.cells have a larger bottom border?
... |
Updates attributes in code_array | def _xls2attributes(self, worksheet, tab):
"""Updates attributes in code_array"""
# Merged cells
for top, bottom, left, right in worksheet.merged_cells:
attrs = {"merge_area": (top, left, bottom - 1, right - 1)}
selection = Selection([(top, left)], [(bottom - 1, right - ... |
Writes row_heights to xls file
Format: <row>\t<tab>\t<value>\n | def _row_heights2xls(self, worksheets):
"""Writes row_heights to xls file
Format: <row>\t<tab>\t<value>\n
"""
xls_max_rows, xls_max_tabs = self.xls_max_rows, self.xls_max_tabs
dict_grid = self.code_array.dict_grid
for row, tab in dict_grid.row_heights:
if... |
Updates row_heights in code_array | def _xls2row_heights(self, worksheet, tab):
"""Updates row_heights in code_array"""
for row in xrange(worksheet.nrows):
try:
height_points = worksheet.rowinfo_map[row].height / 20.0
height_inches = height_points / 72.0
height_pixels = height_i... |
Returns xls width from given pyspread width | def pys_width2xls_width(self, pys_width):
"""Returns xls width from given pyspread width"""
width_0 = get_default_text_extent("0")[0]
# Scale relative to 12 point font instead of 10 point
width_0_char = pys_width * 1.2 / width_0
return int(width_0_char * 256.0) |
Writes col_widths to xls file
Format: <col>\t<tab>\t<value>\n | def _col_widths2xls(self, worksheets):
"""Writes col_widths to xls file
Format: <col>\t<tab>\t<value>\n
"""
xls_max_cols, xls_max_tabs = self.xls_max_cols, self.xls_max_tabs
dict_grid = self.code_array.dict_grid
for col, tab in dict_grid.col_widths:
if co... |
Updates col_widths in code_array | def _xls2col_widths(self, worksheet, tab):
"""Updates col_widths in code_array"""
for col in xrange(worksheet.ncols):
try:
xls_width = worksheet.colinfo_map[col].width
pys_width = self.xls_width2pys_width(xls_width)
self.code_array.col_widths[... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.