Skip to content

Commit

Permalink
Improved the docs for show_toolbar and added support for setting it a…
Browse files Browse the repository at this point in the history
…s a default option.
  • Loading branch information
Tim Shawver committed Mar 6, 2016
1 parent f432ac8 commit 275f415
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 26 deletions.
30 changes: 19 additions & 11 deletions qgrid/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,27 @@ def __init__(self):
'editable': True,
'autoEdit': False
}
self._show_toolbar = False
self._remote_js = False
self._precision = None # Defer to pandas.get_option

def set_grid_option(self, optname, optvalue):
self._grid_options[optname] = optvalue

def set_defaults(self, remote_js=None, precision=None, grid_options=None):
def set_defaults(self, show_toolbar=None, remote_js=None, precision=None, grid_options=None):
if show_toolbar is not None:
self._show_toolbar = show_toolbar
if remote_js is not None:
self._remote_js = remote_js
if precision is not None:
self._precision = precision
if grid_options is not None:
self._grid_options = grid_options

@property
def show_toolbar(self):
return self._show_toolbar

@property
def grid_options(self):
return self._grid_options
Expand All @@ -79,7 +86,7 @@ def precision(self):
defaults = _DefaultSettings()


def set_defaults(remote_js=None, precision=None, grid_options=None):
def set_defaults(show_toolbar=None, remote_js=None, precision=None, grid_options=None):
"""
Set the default qgrid options. The options that you can set here are the
same ones that you can pass into ``show_grid``. See the documentation
Expand All @@ -98,7 +105,7 @@ def set_defaults(remote_js=None, precision=None, grid_options=None):
show_grid :
The function whose default behavior is changed by ``set_defaults``.
"""
defaults.set_defaults(remote_js, precision, grid_options)
defaults.set_defaults(show_toolbar, remote_js, precision, grid_options)


def set_grid_option(optname, optvalue):
Expand All @@ -124,13 +131,18 @@ def set_grid_option(optname, optvalue):
defaults.grid_options[optname] = optvalue


def show_grid(data_frame, remote_js=None, precision=None, grid_options=None,
show_toolbar=False):
def show_grid(data_frame, show_toolbar=None, remote_js=None, precision=None, grid_options=None):
"""
Main entry point for rendering DataFrames as SlickGrids.
Parameters
----------
show_toolbar : bool
Whether to show a toolbar with options for adding/removing rows and
exporting the widget to a static view. Adding/removing rows only works with
DataFrames that have an integer index. The export feature is used to
generate a copy of the grid that will be mostly functional when rendered in
nbviewer.jupyter.org or when exported to html via the notebook's File menu.
remote_js : bool
Whether to load slickgrid.js from a local filesystem or from a
remote CDN. Loading from the local filesystem means that SlickGrid
Expand All @@ -144,12 +156,6 @@ def show_grid(data_frame, remote_js=None, precision=None, grid_options=None,
grid_options : dict
Options to use when creating javascript SlickGrid instances. See the Notes section below for
more information on the available options, as well as the default options that qgrid uses.
show_toolbar : bool
*EXPERIMENTAL* - Whether to show a toolbar with options for adding/removing rows and
exporting the widget to a static view. This feature is marked as experimental because
add/remove rows is not fully functional yet. The export feature should work fine,
so it's technically not experimental. Most people will have no need for it though, so
I don't mind keeping it buried here under the experimental label.
Notes
-----
Expand All @@ -176,6 +182,8 @@ def show_grid(data_frame, remote_js=None, precision=None, grid_options=None,
set_grid_option : Permanently set individual SlickGrid options.
"""

if show_toolbar is None:
show_toolbar = defaults.show_toolbar
if remote_js is None:
remote_js = defaults.remote_js
if precision is None:
Expand Down
21 changes: 6 additions & 15 deletions qgrid_demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
"collapsed": false
},
"outputs": [],
"source": [
Expand Down Expand Up @@ -165,10 +165,10 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### 3. Now render with qgrid again, and set some options\n",
"### 4. Now render with qgrid again, and set some options\n",
"The `show_grid` function takes a number of optional parameters to allow you to configure the behavior of the grid it generates. In the following example we use a couple of these optional parameters:\n",
"\n",
"* Setting `show_toolbar` to True causes some buttons to be shown above the grid. These buttons allow you to add and remove rows, as well as export a version of qgrid that will be functional when rendered by [nbviewer](http://nbviewer.jupyter.org/).\n",
"* Setting `show_toolbar` to True causes some buttons to be shown above the grid. These buttons allow you to add and remove rows, as well as export a version of qgrid that will be functional when rendered by [nbviewer](http://nbviewer.jupyter.org/). Note that these buttons won't be visible on nbviewer.jupyter.org, only when qgrid is running within a jupyter notebook.\n",
"* `grid_options` takes a dict and allows you to pass any of the \"grid options\" listed in [SlickGrid's documentation](https://github.com/mleibman/SlickGrid/wiki/Grid-Options). In this example we make use of two of these options, `forceFitColumns` and `defaultColumnWidth`, to improve qgrid's ability to handle a large number of columns\n",
"\n",
"You can read about these and the rest of the optional parameters for the `show_grid` function in our [API documentation](http://qgrid.readthedocs.org/en/latest/#qgrid.show_grid). \n",
Expand All @@ -191,7 +191,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"*The same 'spy' DataFrame rendered as a qgrid again, this time some options tweaked. Precision has been decreased to 2, the columns are wider, and a horizontal scroll bar has appeared.*"
"*The same 'spy' DataFrame rendered as a qgrid again, this time some options tweaked. The toolbar buttons are visible, the columns are wider, and a horizontal scroll bar has appeared.*"
]
},
{
Expand Down Expand Up @@ -248,7 +248,7 @@
"metadata": {},
"source": [
"### 3. Render the DataFrame again, this time using the QGridWidget class directly\n",
"The ``show_grid`` function is just a convenience function which internally constructs an instance of QGridWidget and renders it with jupyter notebook's ``display`` function. If you're an advanced user you might be interested in constructing the QGridWidget directly, so that you can retrieve or update the DataFrame it uses internally."
"The ``show_grid`` function is just a convenience function which internally constructs an instance of QGridWidget and renders it with jupyter notebook's ``display`` function. The following code shows how to construct a QGridWidget directly, so that you can retrieve or update the DataFrame it uses internally."
]
},
{
Expand All @@ -268,7 +268,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### 3. Get the DataFrame back from the QGridWidget and render it without qgrid\n",
"### 4. Get the DataFrame back from the QGridWidget and render it without qgrid\n",
"If you make edits to the data using the grid above, they will be reflected in the DataFrame that is returned by ``grid.df``."
]
},
Expand All @@ -282,15 +282,6 @@
"source": [
"grid.df"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down

0 comments on commit 275f415

Please sign in to comment.