In table cells, make leading spaces nonbreaking

pull/26/head
Catherine Devlin 2015-01-06 20:31:52 -05:00
parent e8002cd219
commit 24a9171d90
3 changed files with 230 additions and 200 deletions

View File

@ -1,5 +1,5 @@
#!wing #!wing
#!version=4.0 #!version=5.0
################################################################## ##################################################################
# Wing IDE project file # # Wing IDE project file #
################################################################## ##################################################################

View File

@ -1,5 +1,5 @@
#!wing #!wing
#!version=4.0 #!version=5.0
################################################################## ##################################################################
# Wing IDE project file : User-specific branch # # Wing IDE project file : User-specific branch #
################################################################## ##################################################################
@ -8,7 +8,7 @@ debug.err-values = {None: {}}
guimgr.overall-gui-state = {'windowing-policy': 'combined-window', guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
'windows': [{'name': 'pl1wewRCfZASfmghIM3JwuU1ss'\ 'windows': [{'name': 'pl1wewRCfZASfmghIM3JwuU1ss'\
'ZVfe0h', 'ZVfe0h',
'size-state': '', 'size-state': 'maximized',
'type': 'dock', 'type': 'dock',
'view': {'area': 'tall', 'view': {'area': 'tall',
'constraint': None, 'constraint': None,
@ -18,25 +18,17 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
'notebook_display': 'normal', 'notebook_display': 'normal',
'notebook_percent': 0.24701670644391405, 'notebook_percent': 0.24701670644391405,
'override_title': None, 'override_title': None,
'pagelist': [('debug-stack', 'pagelist': [('project',
'tall',
1,
{'codeline-mode': 'below'}),
('indent',
'tall',
2,
{}),
('project',
'tall', 'tall',
0, 0,
{'tree-state': {'file-sort-method': 'by name', {'tree-state': {'file-sort-method': 'by name',
'list-files-first': False, 'list-files-first': False,
'tree-states': {'deep': {'column-widths': [1.0], 'tree-states': {'deep': {'expanded-nodes': [(1,),
'expanded-nodes': [(2,), (1,
(3,), 1),
(3, (2,),
1)], (3,)],
'selected-nodes': [(3, 'selected-nodes': [(1,
1, 1,
3)], 3)],
'top-node': (0,)}}, 'top-node': (0,)}},
@ -49,19 +41,26 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
u'django': [], u'django': [],
u'html': [], u'html': [],
u'py': []}}), u'py': []}}),
('source-assistant',
'tall',
2,
{'docstring-during-complete': False,
'wrap-lines': True}),
('browser', ('browser',
'tall', 'tall',
0, 0,
{'all_tree_states': {u'By Module': {'column-w'\ {'all_tree_states': {loc('../cmd2/NEWS.txt'): {''\
'idths': [1.0], 'column-widths': [1.0],
'expanded-nodes': [], 'expanded-nodes': [],
'selected-nodes': [None], 'selected-nodes': [],
'top-node': None}, 'top-node': None},
loc('../cpython/Lib/doctest.py'): {'column-widths': [1.0],
'expanded-nodes': [],
'selected-nodes': [[('generic attribute',
loc('../cpython/Lib/doctest.py'),
'TestResults')]],
'top-node': [('generic attribute',
loc('../cpython/Lib/doctest.py'),
'BLANKLINE_MARKER')]},
u'By Module': {'column-widths': [1.0],
'expanded-nodes': [],
'selected-nodes': [None],
'top-node': None},
loc('../../Dropbox/pillars2/pillars_gdsii_2.py'): {'column-widths': [1.0], loc('../../Dropbox/pillars2/pillars_gdsii_2.py'): {'column-widths': [1.0],
'expanded-nodes': [], 'expanded-nodes': [],
'selected-nodes': [], 'selected-nodes': [],
@ -141,10 +140,6 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
'top-node': [('function def', 'top-node': [('function def',
loc('../../org/mpwfw/ipy/tst.py'), loc('../../org/mpwfw/ipy/tst.py'),
'f')]}, 'f')]},
loc('../cmd2/NEWS.txt'): {'column-widths': [1.0],
'expanded-nodes': [],
'selected-nodes': [],
'top-node': None},
loc('../cmd2/cmd2.py'): {'column-widths': [1.0], loc('../cmd2/cmd2.py'): {'column-widths': [1.0],
'expanded-nodes': [], 'expanded-nodes': [],
'selected-nodes': [], 'selected-nodes': [],
@ -161,14 +156,6 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
'top-node': [('generic attribute', 'top-node': [('generic attribute',
loc('../cmd2/setup.py'), loc('../cmd2/setup.py'),
'install_requires')]}, 'install_requires')]},
loc('../cpython/Lib/doctest.py'): {'column-widths': [1.0],
'expanded-nodes': [],
'selected-nodes': [[('generic attribute',
loc('../cpython/Lib/doctest.py'),
'TestResults')]],
'top-node': [('generic attribute',
loc('../cpython/Lib/doctest.py'),
'BLANKLINE_MARKER')]},
loc('../ipython_doctester/doctester.py'): {'column-widths': [1.0], loc('../ipython_doctester/doctester.py'): {'column-widths': [1.0],
'expanded-nodes': [], 'expanded-nodes': [],
'selected-nodes': [], 'selected-nodes': [],
@ -240,12 +227,24 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
('uses', ('uses',
'tall', 'tall',
0, 0,
{}),
('debug-stack',
'tall',
1,
{'codeline-mode': 'below'}),
('indent',
'tall',
2,
{}),
('source-assistant',
'tall',
2,
{})], {})],
'primary_view_state': {'area': 'wide', 'primary_view_state': {'area': 'wide',
'constraint': None, 'constraint': None,
'current_pages': [11], 'current_pages': [11],
'notebook_display': 'normal', 'notebook_display': 'normal',
'notebook_percent': 0.30332409972299168, 'notebook_percent': 0.3033240997229917,
'override_title': None, 'override_title': None,
'pagelist': [('bookmarks', 'pagelist': [('bookmarks',
'wide', 'wide',
@ -268,56 +267,44 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
('debug-probe', ('debug-probe',
'wide', 'wide',
2, 2,
{'attrib-starts': [], {'active-range': (None,
-1,
-1),
'attrib-starts': [],
'first-line': 0, 'first-line': 0,
'folded-linenos': [], 'folded-linenos': [],
'history': {None: ['uld'], 'history': {u'file:/home/catherine/ve/fec2/bin/rdbms-subsetter': [''\
u'file:/home/catherine/Dropbox/pillars2/pillars_gdsii_2.py': [''\ 'target.exists\n',
'self.matrix\n', 'target.exists(**dict(source_row))\n',
'dir(self_matrix)\n', 'target.db\n',
'dir(self.matrix)\n', 'child_tbl\n',
'( (self.n0 * (2 - (self.rho/self.matrix.big_r_um) ** 2)**0.5\n '\ 'target_parent_row\n',
' - air_index) * self.matrix.lattice_constant_um ** 2'\ 'source_parent_row\n',
')\n\n', 'self\n',
'(self.rho/self.matrix.big_r_um) ** 2\n', 'self.inspector.\n',
'(2 - (self.rho/self.matrix.big_r_um) ** 2)**0.5\n', 'self.inspector.get_primary_keys(target.name)\n',
'self.rho\n', 'args.keys()\n',
'self.xindex\n', "args.force_rows = {'dimcand': [10071936,]}\n",
'self.yindex\n', 'args\n',
'self.matrix.big_r_um\n', 'args.require_children\n',
'self.matrix.x_max_um\n'], 'args.for\n',
u'file:/home/catherine/itninja/database/improve/nltk_data/process.py': [''\ 'args.force\n',
'result\n'], 'args.fraction\n',
u'file:/home/catherine/itninja/database/improve/pos_corpus_auto.py': [''\ 'source_by_pk\n',
'print line\n', 'args.force_rows\n',
'word\n', 'args.force_rows[source_name]\n',
'replacement\n', 'self.db.inspector.get_primary_keys(self.name)\n',
'line\n'], 'pk_name\n',
u'file:/home/catherine/org/mpwfw/ipy/tst.py': [''\ 'pk\n',
'bool(tests)\n', '**{pk_name:pk}\n',
'len(tests)\n', 'print **{pk_name:pk}\n',
'tests[0]\n', 'print **({pk_name:pk})\n',
'test\n', 'print {pk_name: pk}\n',
'dir(test)\n', 'print slct\n',
'test.examples\n', 'source_row\n',
'func\n', 'target\n',
'func.__name__\n', 'source_by_pk(-1)\n']},
'self.lines.splitlines()\n', 'launch-id': None,
'self.lines\n',
'dir(self.lines)\n',
'raw_txt\n',
'print raw_txt\n',
'self.called\n'],
u'file:/home/catherine/proj/ipython_doctester/doctester.py': [''\
'txt\n',
'print txt\n',
'str(captured)\n',
'print captured\n',
'captured\n'],
u'file:/home/catherine/proj/ipython_doctester/tst.py': [''\
'test.globs\n',
't.globs\n',
't\n']},
'sel-line': 0, 'sel-line': 0,
'sel-line-start': 0, 'sel-line-start': 0,
'selection_end': 0, 'selection_end': 0,
@ -341,16 +328,20 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
('os-command', ('os-command',
'wide', 'wide',
1, 1,
{'last-percent': 0.80000000000000004, {'last-percent': 0.8,
'toolbox-percent': 1.0, 'toolbox-percent': 1.0,
'toolbox-tree-sel': ''}), 'toolbox-tree-sel': ''}),
('python-shell', ('python-shell',
'wide', 'wide',
2, 2,
{'attrib-starts': [], {'active-range': (None,
-1,
-1),
'attrib-starts': [],
'first-line': 0, 'first-line': 0,
'folded-linenos': [], 'folded-linenos': [],
'history': {}, 'history': {},
'launch-id': None,
'sel-line': 3, 'sel-line': 3,
'sel-line-start': 130, 'sel-line-start': 130,
'selection_end': 130, 'selection_end': 130,
@ -368,7 +359,7 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
'fMatchCase': False, 'fMatchCase': False,
'fOmitBinary': True, 'fOmitBinary': True,
'fRegexFlags': 46, 'fRegexFlags': 46,
'fReplaceText': '', 'fReplaceText': u'',
'fReverse': False, 'fReverse': False,
'fSearchText': u'.new', 'fSearchText': u'.new',
'fStartPos': 0, 'fStartPos': 0,
@ -401,7 +392,7 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
'fRegexFlags': 46, 'fRegexFlags': 46,
'fReplaceText': u'called', 'fReplaceText': u'called',
'fReverse': False, 'fReverse': False,
'fSearchText': u'sys', 'fSearchText': u'//',
'fStartPos': 0, 'fStartPos': 0,
'fStyle': 'regex', 'fStyle': 'regex',
'fWholeWords': False, 'fWholeWords': False,
@ -433,28 +424,19 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
1, 1,
{'node-states': [], {'node-states': [],
'tree-state': {'column-widths': [0.38426349496797807, 'tree-state': {'column-widths': [0.38426349496797807,
0.61573650503202193], 0.6157365050320219],
'expanded-nodes': [], 'expanded-nodes': [],
'selected-nodes': [], 'selected-nodes': [],
'top-node': (0,)}})], 'top-node': (0,)}})],
'primary_view_state': {'editor_states': {'bookmarks': ([[loc('../../org/mpwfw/disk/ColorWall/run.py'), 'primary_view_state': {'editor_states': ({'bookmarks': ([(loc('../ipython_doctester/ipython_doctester.py'),
{'attrib-starts': [], {'attrib-starts': [],
'first-line': 30, 'first-line': 19,
'folded-linenos': [], 'folded-linenos': [],
'sel-line': 42, 'sel-line': 26,
'sel-line-start': 1437, 'sel-line-start': 696,
'selection_end': 1437, 'selection_end': 724,
'selection_start': 1437}, 'selection_start': 724},
1357513098.9413929], 1358988102.806569),
(loc('../ipython_doctester/ipython_doctester.py'),
{'attrib-starts': [],
'first-line': 19,
'folded-linenos': [],
'sel-line': 26,
'sel-line-start': 696,
'selection_end': 724,
'selection_start': 724},
1358988102.8065691),
[loc('../ipython_doctester/ipython_doctester.py'), [loc('../ipython_doctester/ipython_doctester.py'),
{'attrib-starts': [], {'attrib-starts': [],
'first-line': 19, 'first-line': 19,
@ -463,7 +445,7 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
'sel-line-start': 696, 'sel-line-start': 696,
'selection_end': 724, 'selection_end': 724,
'selection_start': 724}, 'selection_start': 724},
1358988140.2782991], 1358988140.278299],
[loc('../../Dropbox/wof/trough_trial_1.py'), [loc('../../Dropbox/wof/trough_trial_1.py'),
{'attrib-starts': [], {'attrib-starts': [],
'first-line': 0, 'first-line': 0,
@ -490,7 +472,7 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
'sel-line-start': 1397, 'sel-line-start': 1397,
'selection_end': 1418, 'selection_end': 1418,
'selection_start': 1418}, 'selection_start': 1418},
1363624868.1423759), 1363624868.142376),
(loc('../cmd2/NEWS.txt'), (loc('../cmd2/NEWS.txt'),
{'attrib-starts': [], {'attrib-starts': [],
'first-line': 0, 'first-line': 0,
@ -499,7 +481,7 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
'sel-line-start': 206, 'sel-line-start': 206,
'selection_end': 313, 'selection_end': 313,
'selection_start': 313}, 'selection_start': 313},
1363624892.6995621), 1363624892.699562),
[loc('../cmd2/patch.diff'), [loc('../cmd2/patch.diff'),
{'attrib-starts': [], {'attrib-starts': [],
'first-line': 0, 'first-line': 0,
@ -517,7 +499,7 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
'sel-line-start': 361, 'sel-line-start': 361,
'selection_end': 422, 'selection_end': 422,
'selection_start': 422}, 'selection_start': 422},
1363626438.5112541), 1363626438.511254),
(loc('../cmd2/cmd2.py'), (loc('../cmd2/cmd2.py'),
{'attrib-starts': [], {'attrib-starts': [],
'first-line': 38, 'first-line': 38,
@ -535,7 +517,7 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
'sel-line-start': 350, 'sel-line-start': 350,
'selection_end': 370, 'selection_end': 370,
'selection_start': 370}, 'selection_start': 370},
1363626634.4066069), 1363626634.406607),
(loc('../cmd2/NEWS.txt'), (loc('../cmd2/NEWS.txt'),
{'attrib-starts': [], {'attrib-starts': [],
'first-line': 6, 'first-line': 6,
@ -601,7 +583,7 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
'sel-line-start': 1116, 'sel-line-start': 1116,
'selection_end': 1122, 'selection_end': 1122,
'selection_start': 1122}, 'selection_start': 1122},
1364592268.7543321), 1364592268.754332),
[loc('../../itninja/database/improve/condense.py'), [loc('../../itninja/database/improve/condense.py'),
{'attrib-starts': [], {'attrib-starts': [],
'first-line': 15, 'first-line': 15,
@ -610,65 +592,95 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
'sel-line-start': 1116, 'sel-line-start': 1116,
'selection_end': 1122, 'selection_end': 1122,
'selection_start': 1122}, 'selection_start': 1122},
1364592275.5137169], 1364592275.513717],
[loc('src/sql/run.py'), [loc('src/sql/run.py'),
{'attrib-starts': [('run', {'attrib-starts': [('ResultSet',
25)], 68),
'first-line': 13, ('ResultSet.__init__',
74)],
'first-line': 68,
'folded-linenos': [], 'folded-linenos': [],
'sel-line': 29, 'sel-line': 84,
'sel-line-start': 1006, 'sel-line-start': 2635,
'selection_end': 1050, 'selection_end': 2652,
'selection_start': 1050}, 'selection_start': 2652},
1364621577.7297421]], 1419831638.277049],
19), [loc('src/sql/parse.py'),
'current-loc': loc('src/sql/run.py'), {'attrib-starts': [],
'editor-states': {loc('../cmd2/README.txt'): {'attrib-starts': [], 'first-line': 0,
'first-line': 83, 'folded-linenos': [],
'folded-linenos': [], 'sel-line': 0,
'sel-line': 132, 'sel-line-start': 0,
'sel-line-start': 5332, 'selection_end': 0,
'selection_end': 5339, 'selection_start': 0},
'selection_start': 5339}, 1419831640.918957]],
loc('README.rst'): {'attrib-starts': [], 20),
'first-line': 87, 'current-loc': loc('src/sql/parse.py'),
'folded-linenos': [], 'editor-state-list': [(loc('src/sql/parse.py'),
'sel-line': 98, {'attrib-starts': [],
'sel-line-start': 3099, 'first-line': 1,
'selection_end': 3174, 'folded-linenos': [],
'selection_start': 3174}, 'sel-line': 2,
loc('examples/writers.ipynb'): {'attrib-starts': [], 'sel-line-start': 52,
'first-line': 0, 'selection_end': 86,
'folded-linenos': [], 'selection_start': 86}),
'sel-line': 0, (loc('README.rst'),
'sel-line-start': 0, {'attrib-starts': [],
'selection_end': 0, 'first-line': 87,
'selection_start': 0}, 'folded-linenos': [],
loc('setup.py'): {'attrib-starts': [], 'sel-line': 98,
'first-line': 10, 'sel-line-start': 3099,
'folded-linenos': [], 'selection_end': 3174,
'sel-line': 24, 'selection_start': 3174}),
'sel-line-start': 535, (loc('../cmd2/README.txt'),
'selection_end': 568, {'attrib-starts': [],
'selection_start': 568}, 'first-line': 83,
loc('src/sql/run.py'): {'attrib-starts': [('Result'\ 'folded-linenos': [],
'Set', 'sel-line': 132,
6), 'sel-line-start': 5332,
'selection_end': 5339,
'selection_start': 5339}),
(loc('src/sql/run.py'),
{'attrib-starts': [('ResultSet',
68),
('ResultSet.__init__', ('ResultSet.__init__',
7)], 74)],
'first-line': 4, 'first-line': 68,
'folded-linenos': [], 'folded-linenos': [],
'sel-line': 15, 'sel-line': 85,
'sel-line-start': 479, 'sel-line-start': 2645,
'selection_end': 497, 'selection_end': 2652,
'selection_start': 496}}, 'selection_start': 2652}),
'has-focus': True, (loc('setup.py'),
{'attrib-starts': [],
'first-line': 10,
'folded-linenos': [],
'sel-line': 24,
'sel-line-start': 535,
'selection_end': 568,
'selection_start': 568}),
(loc('examples/writers.ipynb'),
{'attrib-starts': [],
'first-line': 0,
'folded-linenos': [],
'sel-line': 0,
'sel-line-start': 0,
'selection_end': 0,
'selection_start': 0})],
'has-focus': False,
'locked': False}, 'locked': False},
[loc('src/sql/parse.py'),
loc('README.rst'),
loc('../cmd2/README.txt'),
loc('src/sql/run.py'),
loc('setup.py'),
loc('examples/writers.ipynb')]),
'open_files': [u'../cmd2/README.txt', 'open_files': [u'../cmd2/README.txt',
u'README.rst', u'README.rst',
u'examples/writers.ipynb', u'examples/writers.ipynb',
u'setup.py', u'setup.py',
u'src/sql/run.py']}, u'src/sql/run.py',
u'src/sql/parse.py']},
'saved_notebook_display': None, 'saved_notebook_display': None,
'split_percents': {}, 'split_percents': {},
'splits': 1, 'splits': 1,
@ -679,11 +691,12 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
'splits': 2, 'splits': 2,
'tab_location': 'left', 'tab_location': 'left',
'user_data': {}}, 'user_data': {}},
'window-alloc': (0, 'window-alloc': (65,
27, 24,
1431, 2495,
813)}]} 1576)}]}
guimgr.recent-documents = [loc('src/sql/run.py')] guimgr.recent-documents = [loc('src/sql/parse.py'),
loc('src/sql/run.py')]
guimgr.visual-state = {loc('../astropy/astropy/table/table.py'): {'attrib-st'\ guimgr.visual-state = {loc('../astropy/astropy/table/table.py'): {'attrib-st'\
'arts': [('Table', 'arts': [('Table',
845), 845),
@ -933,10 +946,11 @@ guimgr.visual-state = {loc('../astropy/astropy/table/table.py'): {'attrib-st'\
proj.build-cmd = {None: ('default', proj.build-cmd = {None: ('default',
None)} None)}
proj.env-vars = {None: ('default', proj.env-vars = {None: ('default',
[''])} [u''])}
proj.pyexec = {None: ('custom', proj.pyexec = {None: ('custom',
'/home/catherine/ve/ipy/bin/python')} u'/home/catherine/ve/ipy3/bin/python')}
search.search-history = [u'sys', search.search-history = [u'//',
u'sys',
u'ip', u'ip',
u'texttable', u'texttable',
u'True', u'True',

View File

@ -6,6 +6,7 @@ import six
from six.moves import cStringIO from six.moves import cStringIO
import codecs import codecs
import os.path import os.path
import re
import sqlalchemy import sqlalchemy
import sqlparse import sqlparse
import prettytable import prettytable
@ -65,11 +66,25 @@ class CsvResultDescriptor(object):
return 'CSV results at %s' % os.path.join(os.path.abspath('.'), self.file_path) return 'CSV results at %s' % os.path.join(os.path.abspath('.'), self.file_path)
def _repr_html_(self): def _repr_html_(self):
return '<a href="%s">CSV results</a>' % os.path.join('.', 'files', self.file_path) return '<a href="%s">CSV results</a>' % os.path.join('.', 'files', self.file_path)
def _nonbreaking_spaces(match_obj):
"""
Make spaces visible in HTML by replacing all `` `` with ``&nbsp;``
Call with a ``re`` match object. Retain group 1, replace group 2
with nonbreaking speaces.
"""
spaces = '&nbsp;' * len(match_obj.group(2))
return '%s%s' % (match_obj.group(1), spaces)
_cell_with_spaces_pattern = re.compile(r'(<td>)( {2,})')
class ResultSet(list, ColumnGuesserMixin): class ResultSet(list, ColumnGuesserMixin):
""" """
Results of a SQL query. Results of a SQL query.
Can access rows listwise, or by string value of leftmost column. Can access rows listwise, or by string value of leftmost column.
""" """
def __init__(self, sqlaproxy, sql, config): def __init__(self, sqlaproxy, sql, config):
@ -94,8 +109,10 @@ class ResultSet(list, ColumnGuesserMixin):
list.__init__(self, []) list.__init__(self, [])
self.pretty = None self.pretty = None
def _repr_html_(self): def _repr_html_(self):
_cell_with_spaces_pattern = re.compile(r'(<td>)( {2,})')
if self.pretty: if self.pretty:
result = self.pretty.get_html_string() result = self.pretty.get_html_string()
result = _cell_with_spaces_pattern.sub(_nonbreaking_spaces, result)
if self.config.displaylimit and len(self) > self.config.displaylimit: if self.config.displaylimit and len(self) > self.config.displaylimit:
result = '%s\n<span style="font-style:italic;text-align:center;">%d rows, truncated to displaylimit of %d</span>' % ( result = '%s\n<span style="font-style:italic;text-align:center;">%d rows, truncated to displaylimit of %d</span>' % (
result, len(self), self.config.displaylimit) result, len(self), self.config.displaylimit)
@ -125,23 +142,23 @@ class ResultSet(list, ColumnGuesserMixin):
return frame return frame
def pie(self, key_word_sep=" ", title=None, **kwargs): def pie(self, key_word_sep=" ", title=None, **kwargs):
"""Generates a pylab pie chart from the result set. """Generates a pylab pie chart from the result set.
``matplotlib`` must be installed, and in an ``matplotlib`` must be installed, and in an
IPython Notebook, inlining must be on:: IPython Notebook, inlining must be on::
%%matplotlib inline %%matplotlib inline
Values (pie slice sizes) are taken from the Values (pie slice sizes) are taken from the
rightmost column (numerical values required). rightmost column (numerical values required).
All other columns are used to label the pie slices. All other columns are used to label the pie slices.
Parameters Parameters
---------- ----------
key_word_sep: string used to separate column values key_word_sep: string used to separate column values
from each other in pie labels from each other in pie labels
title: Plot title, defaults to name of value column title: Plot title, defaults to name of value column
Any additional keyword arguments will be passsed Any additional keyword arguments will be passsed
through to ``matplotlib.pylab.pie``. through to ``matplotlib.pylab.pie``.
""" """
self.guess_pie_columns(xlabel_sep=key_word_sep) self.guess_pie_columns(xlabel_sep=key_word_sep)
@ -149,23 +166,23 @@ class ResultSet(list, ColumnGuesserMixin):
pie = plt.pie(self.ys[0], labels=self.xlabels, **kwargs) pie = plt.pie(self.ys[0], labels=self.xlabels, **kwargs)
plt.title(title or self.ys[0].name) plt.title(title or self.ys[0].name)
return pie return pie
def plot(self, title=None, **kwargs): def plot(self, title=None, **kwargs):
"""Generates a pylab plot from the result set. """Generates a pylab plot from the result set.
``matplotlib`` must be installed, and in an ``matplotlib`` must be installed, and in an
IPython Notebook, inlining must be on:: IPython Notebook, inlining must be on::
%%matplotlib inline %%matplotlib inline
The first and last columns are taken as the X and Y The first and last columns are taken as the X and Y
values. Any columns between are ignored. values. Any columns between are ignored.
Parameters Parameters
---------- ----------
title: Plot title, defaults to names of Y value columns title: Plot title, defaults to names of Y value columns
Any additional keyword arguments will be passsed Any additional keyword arguments will be passsed
through to ``matplotlib.pylab.plot``. through to ``matplotlib.pylab.plot``.
""" """
import matplotlib.pylab as plt import matplotlib.pylab as plt
@ -179,25 +196,25 @@ class ResultSet(list, ColumnGuesserMixin):
plt.title(title or ylabel) plt.title(title or ylabel)
plt.ylabel(ylabel) plt.ylabel(ylabel)
return plot return plot
def bar(self, key_word_sep = " ", title=None, **kwargs): def bar(self, key_word_sep = " ", title=None, **kwargs):
"""Generates a pylab bar plot from the result set. """Generates a pylab bar plot from the result set.
``matplotlib`` must be installed, and in an ``matplotlib`` must be installed, and in an
IPython Notebook, inlining must be on:: IPython Notebook, inlining must be on::
%%matplotlib inline %%matplotlib inline
The last quantitative column is taken as the Y values; The last quantitative column is taken as the Y values;
all other columns are combined to label the X axis. all other columns are combined to label the X axis.
Parameters Parameters
---------- ----------
title: Plot title, defaults to names of Y value columns title: Plot title, defaults to names of Y value columns
key_word_sep: string used to separate column values key_word_sep: string used to separate column values
from each other in labels from each other in labels
Any additional keyword arguments will be passsed Any additional keyword arguments will be passsed
through to ``matplotlib.pylab.bar``. through to ``matplotlib.pylab.bar``.
""" """
import matplotlib.pylab as plt import matplotlib.pylab as plt
@ -208,8 +225,8 @@ class ResultSet(list, ColumnGuesserMixin):
rotation=45) rotation=45)
plt.xlabel(self.xlabel) plt.xlabel(self.xlabel)
plt.ylabel(self.ys[0].name) plt.ylabel(self.ys[0].name)
return plot return plot
def csv(self, filename=None, **format_params): def csv(self, filename=None, **format_params):
"""Generate results in comma-separated form. Write to ``filename`` if given. """Generate results in comma-separated form. Write to ``filename`` if given.
Any other parameterw will be passed on to csv.writer.""" Any other parameterw will be passed on to csv.writer."""
@ -228,8 +245,8 @@ class ResultSet(list, ColumnGuesserMixin):
return CsvResultDescriptor(filename) return CsvResultDescriptor(filename)
else: else:
return outfile.getvalue() return outfile.getvalue()
def interpret_rowcount(rowcount): def interpret_rowcount(rowcount):
if rowcount < 0: if rowcount < 0:
result = 'Done.' result = 'Done.'
@ -253,4 +270,3 @@ def run(conn, sql, config, user_namespace):
#returning only last result, intentionally #returning only last result, intentionally
else: else:
return 'Connected: %s' % conn.name return 'Connected: %s' % conn.name