PyGObject and Gtk.TreeStore / TreeView - How do I acces the parent element? - gtk3

I'm working with PyGObject and I successfully setup a TreeStore and a corresponding TreeView. It is just a simple one-column view. It lists all accounts as parents and then you can click the little triangle and it shows the folders. The code looks like this:
accounts_tree_store = Gtk.TreeStore(str)
treeview_accounts = self.builder.get_object("treeview_accounts")
treeview_accounts.set_model(accounts_tree_store)
renderer = Gtk.CellRendererText()
account_iter = accounts_tree_store.append(None, ["Account1"])
accounts_tree_store.append(account_iter, ["Folder1"])
accounts_tree_store.append(account_iter, ["Folder2"])
accounts_tree_store.append(account_iter, ["Folder3"])
accounts_tree_store.append(account_iter, ["Folder4"])
accounts_tree_store.append(account_iter, ["Folder5"])
Then I added this so I can get a selection:
selected_tree = treeview_accounts.get_selection()
selected_tree.connect("changed", Handler().on_tree_select_change)
And my function handler looks like this:
def on_tree_select_change(self, widget, *args):
model, iter = widget.get_selected()
if iter:
print((model[iter][0]))
Now all this works just fine. But I want to also print out the parent of the element that is selected. Something like: "Folder2 for Account4". The question is: How can I access the parent? Is there some sort of "get_parent()" function? I didn't find anything in the docs. Does anyone know how to do this?
Thanks in advance!!

This fuction is called iter_parent and will return parent if iter has one. It's a model's method.
model, iter = widget.get_selected()
parent = model.iter_parent (iter)

Related

QgsField won't accept parameter typeName

I'm trying to create new vector layer with the same fields as contained in original layer.
original_layer_fields_list = original_layer.fields().toList()
new_layer = QgsVectorLayer("Point", "new_layer", "memory")
pr = new_layer.dataProvider()
However, when I try:
for fld in original_layer_fields_list:
type_name = fld.typeName()
pr.addAttributes([QgsField(name = fld.name(), typeName = type_name)])
new_layer.updateFields()
QgsProject.instance().addMapLayer(new_layer)
I get a layer with no fields in attribute table.
If I try something like:
for fld in original_layer_fields_list:
if fld.type() == 2:
pr.addAttributes([QgsField(name = fld.name(), type = QVariant.Int)])
new_layer.updateFields()
QgsProject.instance().addMapLayer(new_layer)
... it works like charm.
Anyway ... I'd rather like the first solution to work in case if one wants to automate the process and not check for every field type and then find an appropriate code. Besides - I really am not able to find any documentation about codes for data types. I managed to find this post https://gis.stackexchange.com/questions/353975/get-only-fields-with-datatype-int-in-pyqgis where in comments Kadir pointed on this sourcecode (https://codebrowser.dev/qt5/qtbase/src/corelib/kernel/qvariant.h.html#QVariant::Type).
I'd really be thankful for any kind of direction.

SAPUI5 List Item context binding, get the next path

I have a table of list items (questions) and I want to be able to re-arrange them. See screenshot.
Currently, on the button down press, I can get the current binding context and I am getting that sequence property (001). What I want to be able to do is also be able to get the path of the next list items binding context (002 in this case).
Current code...
// Move Question Down
onQuestionMoveDown: function (oEvent) {
// Get binding context
var source = oEvent.getSource().getBindingContext("view");
var path = source.getPath();
var object = source.getModel().getProperty(path);
var currentQuestionSequence = object.Sequence;
MessageToast.show("Current # " + currentQuestionSequence);
}
Then once I have that I can sort my updates logic.
A possible solution could be that you have an order value on your model and you update that order when the user clicks on the button.
If the list is sorted by that value you will achieve what you're looking for.
The items should be bound to the table via list binding, and so the data set would be an Array, the path for each line will be like ".../itemSet/0, .../itemSet/1, ...". So possible solution could be:
function getNextItem(oItem){
var oContext = oItem.getBindingContext("view"), // assumpe the model name is view
sPath = oContext.getPath(),
sSetPath = sPath.substr(0, sPath.lastIndexOf("/")),
iMaxLen = oContext.getProperty(sSetPath).length,
iCurIndex = parseInt(sPath.substr(sPath.lastIndexOf("/")+1));
// If it's already reach to be bottom, return undefined
return iCurIndex < iMaxLen -1 ? oContext.getProperty(sSetPath + "/" + ++iCurIndex) : undefined;
}
Regards,
Marvin

Can not add CURDify menu to sitemap in lift

I have sitemap code like that:
object Site {
val booksMenus = Book.menus
val authorsMenus = Author.menus
val publishersMenus = Publisher.menus
def sitemap = SiteMap(
home >> LocGroup("lg1"),
static,
}
I want to add LocGroup to my menus and add them to sitemap
for example booksMenus is List[Menu] doing that as first answer suggested
booksMenus.map(_ >>LockGroup("lb"))
can not be possible because appending Loc only for Menuable not Menu type
There is anyway to do that?
value >> is not a member of List[net.liftweb.sitemap.Menu]
That means you should assign "group markers" to menu members, not to list of them. For example, smth like this:
booksMenus.map(x=> x >> LogGroup("lg1"))

How to display content of an ArrayController inside a CollectionView

I am trying to understand how Ember.CollectionView works and I am having a basic issue with displaying the content of my ArrayController in the DOM. Here is my little jsfiddle experiment so you can see for yourself. Here is the coffeescript:
window.App = Ember.Application.create()
window.App.initialize()
App.Item = Em.View.create
tagName:'li'
willInsertElement: () ->
console.log "I **WILL** indert the element", this.$()
didInsertElement: () ->
console.log "I **DID** insert the element", this.$()
template: Ember.Handlebars.compile("~~ {{view.content.title}} ~~")
App.items = Em.ArrayController.create()
App.items.set('content',[
Em.Object.create({title:"AN"}),
Em.Object.create({title:"Epic"}),
Em.Object.create({title:"View"})
])
App.epicView = Ember.CollectionView.create
classNames: ['epic-view']
contentBinding: 'App.items'
itemViewClass: 'App.Item'
App.epicView.appendTo('body')
As you can see in the output of that fiddle, I have not been able to figure out how to access and display the title of objects in the list. When I append the view to body using the call to App.epicView.appendTo('body') it seems to iterate over the three objects but does not print anything.
Any ideas what am I missing here?
ps: I am using Ember 1.0pre
I would simply do something like this: http://jsfiddle.net/Sly7/nevW2/67/
Declare your views (with extend) instead of instantiate them (with create)

Call TYPO3 plugin from other plugin's body

I need to call typo3 plugin from other plugin's body and pass its result to template. This is pseudo-code that describes what I want to achieve doing this:
$data['###SOME_VARIABLE###'] = $someOtherPlugin->main();
$this->cObj->substituteMarkerArray($someTemplate, $data);
Is it possible?
Thanks!
It doenst work if you use the whole pi construct, e.g. for links, marker function etc, and the TSFE Data can be corrupted.
Dmitry said:
http://lists.typo3.org/pipermail/typo3-english/2008-August/052259.html
$cObjType = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_rgsmoothgallery_pi1'];
$conf = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_rgsmoothgallery_pi1.'];
$cObj = t3lib_div::makeInstance('tslib_cObj');
$cObj->start(array(), '_NO_TABLE');
$conf['val'] = 1;
$content = $cObj->cObjGetSingle($cObjType, $conf); //calling the main method
You should use t3lib_div:makeInstance method.
There is a working example from TYPO3's "powermail" extension.
function getGeo() {
// use geo ip if loaded
if (t3lib_extMgm::isLoaded('geoip')) {
require_once( t3lib_extMgm::extPath('geoip').'/pi1/class.tx_geoip_pi1.php');
$this->media = t3lib_div::makeInstance('tx_geoip_pi1');
if ($this->conf['geoip.']['file']) { // only if file for geoip is set
$this->media->init($this->conf['geoip.']['file']); // Initialize the geoip Ext
$this->GEOinfos = $this->media->getGeoIP($this->ipOverride ? $this->ipOverride : t3lib_div::getIndpEnv('REMOTE_ADDR')); // get all the infos of current user ip
}
}
}
The answer of #mitchiru is nice and basically correct.
If you have created your outer extension with Kickstarter and you are using pi_base then there is already an instance of tslib_cObj and the whole construct becomes simpler:
// get type of inner extension, eg. USER or USER_INT
$cObjType = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_innerextension_pi1'];
// get configuration array of inner extension
$cObjConf = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_innerextension_pi1.'];
// add own parameters to configuration array if needed - otherwise skip this line
$cObjConf['myparam'] = 'myvalue';
// call main method of inner extension, using cObj of outer extension
$content = $this->cObj->cObjGetSingle($cObjType, $cObjConf);
Firstly, you have to include your plugin class, before using, or outside your class:
include_once(t3lib_extMgm::extPath('myext').'pi1/class.tx_myext_pi1.php');
Secondly in your code (in the main as example)
$res = tx_myext_pi1::myMethod();
This will work for sure (I've checked this): http://lists.typo3.org/pipermail/typo3-english/2008-August/052259.html.
Probably Fedir's answer is correct too but I didn't have a chance to try it.
Cheers!