I'm having a hard time figuring out how to individually style a cell or group of cells when a certain thing happens. For instance I would like to be able to right-click on a cell and hit something like "tag" and it would change the background color of the cell to something different. I would like to do the same thing with rows, columns, or any random group of selected cells. I also need this change in style to persist even if the cell(s) are moved beyond the viewport layer's view.
If you have a hard time with NatTable, maybe it is worth reading some of our tutorials and documents.
https://www.eclipse.org/nattable/documentation.php?page=styling
http://www.vogella.com/tutorials/NatTable/article.html
In short related to your question. Individual styling is done via config labels on a cell and styles that are registered in the ConfigRegistry for that label. So what you need to do is to implement some sort of label registry based on cell indeces. That label registry then needs to be used by a custom ConfigLabelAccumulator so the labels are attached to the cells with the corresponding indeces.
We have a basic implementation on a column base via the ColumnStyleEditorDialog. This can be seen in the _000_Styled_grid example by clicking on the column header and call "Format cells". Personally I think that feature is not complete, but it should help you in seeing how it works in principle.
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.
Is it possible in an IPython-Notebook cell to get the previous (above) cell content ?
I can see previous output with %capture magic function but I don't find how to get the previous cell content.
%recall jupyter_notebook_cell_number
Should give you the code that was last executed in indicated particular notebook cell, jupyter_notebook_cell_number
I didn't find how to get the previous content cell in a cell.
But I found another solution, creating a custom magic notebook function to capture the cell content and work with that.
The documentation for the input catching system is rather informative.
The returned output (not cell output content) is stored in _oh dictionary and the returned output is added to the page within the .output_area DOM element as a div element with the classes .output_subarea, .output_text and uniquely .output_result. Printed or displayed (IPython.display.display also have the first two classes and print in particular has .output_stream .output_stdout.
_oh is a dictionary and the integer is the same as that you can see on the left of the input (.input_prompt div).
In other words the cell content is rather formatted as expected. And you can in fact add your own HTML.
from IPython.display import display, HTML
display(HTML('<h1>HELLO WORLD</h1>'))
display(HTML(<script>alert("hello world");</script>'))
This shows you can add JS within a Python cells —but this has a big flaw. Likewise, in JS you can execute python code.
IPython.notebook.kernel.execute("python_variable="+JSON.stringify(jsVariable));
However, a JS IPython call is executed when the kernel is idle. Therefore you have to wait for the cell to finish before accessing python_variable. So there's no point doing it all in one cell and regular cell magic works.
Consequently, the following JS magic will give a output dictionary whose keys are cell numbers and values are the content. As mentioned the cell content is formatted, so if you want to change the following based on the class of the element in the cell you can refer to the aforementioned CSS classes.
// querySelectorAll returns a NodeList which lacks most Array functions
// so destructuring into array
const outputs=[...document.querySelectorAll(".cell")].map(
cell=> {
const RawCellN=cell.querySelector(".input_prompt").innerText;
// \xa0 is star. current: skip.
if (RawCellN.match(/\[(\d+)\]/) === null) return null;
const cellN = parseInt(RawCellN.match(/\[(\d+)\]/)[1]);
const outputs= [...cell.querySelectorAll(".output_subarea")].map(
subarea => subarea.innerText.trim());
return [cellN, outputs.filter(out => out.length !== 0)];
}
).filter(value => value !== null); // star cell was skipped.
// pass on the data to python
IPython.notebook.kernel.execute("outputs=dict("+JSON.stringify(outputs)+")")
I'm developsing a debugger plugin in eclipse; i'm trying to write unit tests to grep vars from the variables view and test thier values.
so far I was able to retrieve the variables view object as an IViewPart;
I've extracted the selection provider related to the variables view, by doing this:
ISelectionProvider selProvider = viewPart.getSite().getSelectionProvider();
now i would like to set a selection on the first element in the variables view
how do i get the elements list, or select any of the elements?
Thanks in advance,
Anat
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