Is it possible to view only "out" cells in iPython Notebook? - ipython

Sometimes i don't need code and just want to see the report in iPython. Is it possible to view only "out" cells in iPython Notebook?

Yes. Install ipython-notebook-extensions. These extensions provide many features, including runtools, which allows you to
Hide or show input (i.e. the source code) of marked code cells
Hide or show output of marked code cells
If you are using ipython3.x, you can install from an ipython notebook via the following:
import IPython.html.nbextensions as nb
ext= 'https://github.com/ipython-contrib/IPython-notebook-extensions/archive/3.x.zip'
nb.install_nbextension(ext)
Load runtools extension
from IPython.html.services.config import ConfigManager
ip = get_ipython()
cm = ConfigManager(parent=ip, profile_dir=ip.profile_dir.location)
cm.update('notebook', {"load_extensions": {"IPython-notebook-extensions-3.x/usability/runtools/main": True}})
From a normal notebook, below,
you can mark a cell (or all cells) and
either view or hide input and output.

Related

TreeView multiple selection does not work correctly after changing selection without UI

This is potentially a bug, though perhaps I'm misunderstanding something.
Brief description
Basically, I have found that using "Shift+Arrows" to do multiple selection in a Gtk.TreeView does not work correctly after changing the selection using Gtk.TreeSelection.select_iter. On the other hand, if you change the selection by clicking on a row and then pressing "Shift+Arrows", the selection behaves as one would expect.
I should note that if you change the selected row by calling Gtk.TreeSelection.select_iter, the UI updates as you would expect and calling Gtk.TreeSelection.get_selected_rows() returns the rows it should. It's only when you then try to select multiple rows using the arrow keys that you get strange behavior.
This is perhaps best illustrated in this self contained example, which I've tried to make as simple as possible:
Code
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
class TreeViewBug(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self)
self.connect('destroy', Gtk.main_quit)
# Create model consisting of row path and a name
self.treeModel = Gtk.ListStore(int, str)
self.treeModel.append([0, 'alice'])
self.treeModel.append([1, 'bob'])
self.treeModel.append([2, 'chad'])
self.treeModel.append([3, 'dan'])
self.treeModel.append([4, 'emma'])
self.treeView = Gtk.TreeView()
self.treeView.append_column(Gtk.TreeViewColumn('path', Gtk.CellRendererText(), text=0))
self.treeView.append_column(Gtk.TreeViewColumn('name', Gtk.CellRendererText(), text=1))
self.treeView.set_model(self.treeModel)
# Allow for multiple selection
self.treeView.get_selection().set_mode(Gtk.SelectionMode.MULTIPLE)
self.add(self.treeView)
def run(self):
self.show_all()
# Focus the TreeView so we can test multiple select via keyboard without clicking on a row
self.treeView.grab_focus()
# Manually change the selected row to the row with "chad"
chadIter = self.treeModel[2].iter
self.treeView.get_selection().select_iter(chadIter)
print('Press "Shift+Down" and see what happens')
print(' it should select "chad, dan", but instead it selects "bob, chad"')
print('Afterwards, try clicking on "chad" and then pressing Shift+Down. It should behave normally')
Gtk.main()
if __name__ == '__main__':
tv = TreeViewBug()
tv.run()
Things I've tried
I initially encountered the bug when my code changed the selected row via Gtk.TreeSelection.select_iter in response to a button click.
I've also tried:
adding a custom select function (Gtk.TreeSelection.set_select_function)
clearing the selection before changing it (Gtk.TreeSelection.unselect_all)
changing the selection asynchronously (GLib.idle_add).
redrawing TreeView after changing selection
Speculations
I'm guessing that TreeView/TreeViewSelection has some internal state variable tracking selection and row that, for some reason, isn't getting properly updated when TreeSelection.select_iter is called. These variables are probably related to UI features, because TreeSelection.get_selected_rows still works properly. Also it makes sense the UI would need additional state information since the UI logic of multiple selection depends on previous UI interaction (Shift+Down behaves differently when extending a selection depending on whether you initially selected upwards or downwards)
Because a Gtk.TreeView uses MVC, you actually need to set the cursor of the treeview. This may affect the rest of the program, depending on what you are doing. Example:
#chadIter = self.treeModel[2].iter
#self.treeView.get_selection().select_iter(chadIter)
path = 2
column = self.treeView.get_column(0)
edit = False
self.treeView.set_cursor(path, column, edit)

Modify cell's metadata

I want to store the values of my IPython.html.widgets in my ipython notebook somehow.
Is there a way to modify the metadata of the current cell from the code within the cell itself?
I don't know how to do this from within the notebook, but I found a way to do it with a custom preprocessor and nbconvert.
You can create a class that extends nbconvert.preprocessors.ExecutePreprocessor. In the preprocess (or preprocess_cell) method, add logic for storing the relevant output in the cell metadata.
Something like:
class MyExecutePreprocessor(ExecutePreprocessor):
def preprocess_cell(self, cell, resources, index):
# Execute the cell normally
cell, resources = super().preprocess_cell(cell, resources, index)
# Add your magic here
cell.metadata['widgets'] = {'stuff':'that is cool'}
return cell, resources
You can then execute this preprocessor programatically, or as an argument to nbconvert.
If I understand what you are looking for:
from the Cell Toolbar (top right of the ipython notebook toolbar), select Edit Metadata from the drop-down list.

Access debug variables from within the code

It's about debugging in eclipse,
While debugging, I can see Variables window containing the variable names and their values, how can I access those variables and get their values from within the code or (expression) window?
For example can I write something like this:
print cash.dbname
or
x=cr.IN_MAX
or
s = _pool._serialized
(See the picture)
There's a very complex tree of variables, can I also access this variable tree reaching the branches and leaves?
Open the Display view; there you can enter code snippets that execute within the current stack frame selected in the Debug view. Code completion works, too.
You can select part or all of the contents of the Display view, right-click, and choose to Display, Inspect, or Execute it. Very powerful for exploring application state when debugging.
See also the Eclipse Help page about Display View.

convert ipython notebook to presentation with cells contents hidden

Is it possible currently to convert IPython notebook to presentation so only output of each cell is visible on the slide? e.g. if I want to show plot, but don't want to show lines of code for plotting it?
Thanks!
Update:
It seems that adding
div.input.hbox, div.prompt.output_prompt {
display: none;
}
to customs.css does the trick.
I wonder if it possible to hide these items on slide-basis.
Making this on slide-basis implies write an extension to make it possible...

Creating columns with editable cells in Gtk treeview using Glade

I am trying to create a simple GUI with table containing x and y coordinates of samples. I use treeview, and I want the cells of the table to be editable by user. Is it possible to specify if the cells should be editable directly in Glade in cellrenderer properties, or do I have to specify it in my code? I use Glade 3.6.1
I have just found out that unticking box "Editable" in the Tree View Editor when editing my treeview, enables me to specify whether the cells shall be editable or not, because if the box is unticked, the cells editable property is no longer connected with the model.
But if I run the program, cells are editable, but the value that I write inside disappears. How can I fix that? Why doesn't the cell store the value I type inside?
Thanks for any hint
For anyone dealing with a similar problem, I have solved it - whenever a cell is edited, appropriate record in the model needs to be changed, example code in Python:
cell.connect("edited", self.text_edited, model, column)
def text_edited( self, w, row, new_text, model, column)
model[row][column] = new_text
I found I had to do something just a little different, but I am also using Ubuntu's Quickly development environment. I did have to go into Glade and uncheck the "Editable" box in my cellrenderer, which then brought up a toggable "Yes/No" button. Then my code looks like:
#psuedo-code function definition
cellcolumn_widget.connect("edited", self.function, list_or_treestore, columnnumber)
#actual code, editing second column so column is passed as 1
self.builder.get_object("cellrenderer_chapter").connect("edited", self.cell_edited, self.builder.get_object("liststore_chapters"),1)
def cell_edited(self, widget, row, new_text, model, column):
model.set_value(model.get_iter(row),column,new_text)
for python GTK, by default, text in Gtk.CellRendererText widgets is not editable, you can change this by setting the value of the “editable” property to True:
renderer = Gtk.CellRendererText();
renderer.set_property("editable", True);
then you can connect to the “edited” signal and update your Gtk.TreeModel and/or database accordingly:
renderer.connect("edited", self.entry_edited);
def entry_edited(self, widget, path, text):
self.listStore[path][number_of_row] = text; # put the number_of_row to be edited
check this tutorial for more information python gtk 3 tutorial - CellRendererText