Get tab status using pyforms - pyforms

I'm working with pyforms to create a tab widget and I want to get and set the current active tab. Consider this example:
self.formset = [{
'Person A': ['_firstname', '_lastname'],
'Person B': ['_firstname', '_lastname'] }]
so we get 2 tabs Person A and Person B. If I switch between them I would like to be informed with something similar to PyQt function currentIndex(). So far I havn't been able to find a method in the pyforms documentation, is there a way to accomplish this just using pyforms?

The main issue in getting or setting the current index of your tab widget is to get access to the QTabWidget created by pyforms when the layout is generated. Once you have access to it, you simply call the setCurrentIndex(int)/currentIndex() of the widget.
A (dirty) quick fix to this is to modify the BaseWidget.py located in the pyforms module files which can be <VIRTUALENV_DIR>/lib/python3.6/site-packages/pyforms/gui when using virtualenv.
def generate_tabs(self, formsetdict):
"""
Generate QTabWidget for the module form
#param formset: Tab form configuration
#type formset: dict
"""
tabs = QTabWidget(self)
for key, item in sorted(formsetdict.items()):
ctrl = self.generate_panel(item)
tabs.addTab(ctrl, key[key.find(':') + 1:])
self.tabs = tabs
return tabs
Note the additional :
self.tabs = tabs
Then in the code of your widget/app (subclass of BasicWidget) :
>>> _t = self.tabs
>>> _t.setCurrentIndex(3) # activate the 4th tab
>>> print(_t.currentIndex())
3

Related

Typo3 Content Elements missing in wizard

I have some content elements in a site package which I want to show up in the content element wizard as explained here:
https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ApiOverview/ContentElements/ContentElementsWizard.html
Basically I have done the same as shown in the section "Create a new tab"
Configuration\TsConfig\Page\ContentElement\All.tsconfig is looking like this:
mod.wizards.newContentElement.wizardItems.mci.header = MCI
mod.wizards.newContentElement.wizardItems.mci {
elements {
mci_home_banner {
iconIdentifier = home-banner
title = Home-Banner
description = Banner der Startseite
tt_content_defValues.CType = mci_home_banner
}
mci_home_banner_element {
iconIdentifier = home-banner-element
title = Home Banner Element
description = Element im Starseitenbanner
tt_content_defValues.CType = mci_home_banner_element
}
}
show := addToList(mci_home_banner, mci_home_banner_element)
}
I reduced the code to just 2 elements. They are not shown at all, but are available over the dropdown, so I can switch to one of them after choosing another element.
This didn't work when created in 9.5 and still does not work after switching to version 11.5.10
What am I missing?
#user414873 Did you try to add your custom elements to the "common" tab instead of your new one "mci"?
And did you try to use an existing icon identifier (e.g. "content-image" or an other one - see https://typo3.github.io/TYPO3.Icons/)? Just to make sure that there is no problem with your custom icons that prevents the elements from being displayed.
Does this minimal example work for you:
mod.wizards.newContentElement.wizardItems.common {
elements {
mci_home_banner {
iconIdentifier = content-image
title = Home-Banner
description = Banner der Startseite
tt_content_defValues.CType = mci_home_banner
}
}
show := addToList(mci_home_banner)
}
And I would doubt this:
I guess otherwise the content elements wouldn't be available at all.
I suggest you check it's correctly included by using the "Info" module in your TYPO3 main menu. Then select the page where the content element should be included and switch the dropdown on top of the content area to "View TSconfig fields content". Now you can search for "wizards" and check if your element is included.

Accordion dropdown filtering through ion search bar

Hi I just created the ionic accordion dropdowns by following a tutorial blog link which used widgets for creating an accordion dropdowns, Below is the link of that blog.
http://masteringionic.com/blog/2019-01-27-creating-a-simple-accordion-widget-in-ionic-4/
updated: here is the my project demo link https://stackblitz.com/github/dSaif/search-accordion
Everything is working perfect, but i want to add Ion-searchbar at the top of the accordions sothat the dropdowns gets filter by inputing text.
please assist me how can i do that. Thank you.
You are going to have to create a variable in your homepage to store your filtered results. Then you need to have a filter function that will take the input from the search bar and filter your master list. Keep in mind you should not set the new variable to the master list, this could cause issues due to object referencing.
So you should have something like
in your html
<ion-searchbar placeholder="Search a name." [(ngModel)]="searchValue" (ionChange)="filterList()"></ion-searchbar>
In your ts file
searchValue: string = '';
filteredList: Array<{ name: string, description: string, image: string }> = this.technologies;
// function called in the html whenever you change the ion searchbar value
private filterList(){
//Make a variable so as to avoid any flashing on the screen if you set it to an empty array
const localFilteredList = []
this.technologies.forEach(currentItem => {
//here goes your search criteria, in the if statement
if(currentItem.name && currentItem.name.toLowerCase().includes(this.searchValue.toLowerCase())) {
localFilteredList.push(currentItem);
}
});
//finally set the global filter list to your newly filtered list
this.filteredList = localFilteredList;
}
You also need to make sure to reference the filterList variable instead of the current one you are referencing.

$ionicHistory.goBack() not working correctly with ion tabs

My page contains 3 tabs, if i forward to next page from tab3 and then coming back from that page using $ionicHistory.goBack() it redirects to tab1. how to make it redirects to tab3 itself
function sample($scope,$ionicHistory){
$ionicHistory.goBack();
};
}
I'm not sure it's possible to do that just through $state. I'm new to Ionic myself as I had my first peek back in December (2016). However, I happened to have this exact scenario. This is how I solved it.
In my case, I was not using tabs. Instead, I had three different DIVs that were visible depending on the "tab number". When initializing the view, I set it to "1" and used the property to control what code is executed.
I'm guessing that the control you're using has a property like that to identify and set the particular tab you need, as this is the most likely way to change tabs on tab-click. Consider putting the value of that property "tab #" into the appropriate service used by the controller. This is a stripped-down version of actual code in one of my services defined via Factory.
YourService.js:
// controllers are instances. When navigating away, state is lost. This
// tracks the tab we wish to view when we load the home page.
var activeHomePageTab = 1;
var service = {
getActiveTab: getActiveTab,
setActiveTab: setActiveTab,
...
};
return service;
////////////////
function getActiveTab() { return activeHomePageTab; }
function setActiveTab(num) { activeHomePageTab = num; }
...
Here, the functions are private. In your controller, when you set your tab, also set this property. As a singleton, this will remain in effect as long as your application is running.
Next, in your init() routine, when the controller is loaded, check for this property and set the tab if it is defined:
function init() {
var tab = YourService.getActiveTab();
if (tab !== undefined) {
setTab(tab);
} else {
setTab(1)
}
...
}
Of course, there are other ways - maybe using Value or a property on a Constant object.

Neos 2.0 Breadcrumb menu: How to skip first two levels?

I need to display a breadcrumb menu where the first two levels are skipped.
Menus of type Menu have a property entryLevel to control where the menu starts, but it seems that is not the case for Breadcrumb. (At least it has no effect.)
Is there a way to accomplish this in Neos?
Breadcrumb is defined in TYPO3.Neos/Resources/Private/TypoScript/Prototypes/Breadcrumb.ts2 and you can overwrite values from there in Root.ts2 in your site package. So you can change templatePath and handle it using iterator in f:for or even better just limit (slice) items you pass to template on TS2 level. Translating it to code, you have Your.Site.Package/Resources/Private/TypoScript/Root.ts2 and there your page definition, just change Breadcrumb part:
page = Page {
...
body {
templatePath = 'resource://Your.Site.Package/Private/Templates/Page/Default.html'
sectionName = 'body'
parts {
menu = Menu
breadcrumb = Breadcrumb {
# replace items with itemCollection if you're using BreadcrumbMenu (Neos 2+)
items = ${q(node).add(q(node).parents('[instanceof TYPO3.Neos:Document]')).slice(0, -2).get()}
}
}
...

Whats the best way to programatically open a pane inside Dijit AccordionContainer

I am trying open & close accordion panes programatically. Here is the simplified version of my code. Even though I set the first pane's selected to false and and second pane's selected to true, only the first pane opens when it loads on the browser (FF3).
var accordionContainer = new dijit.layout.AccordionContainer().placeAt("test");
var accordPane = new dijit.layout.ContentPane({"title": "test", "content":"hello"});
var accordPane2 = new dijit.layout.ContentPane({"title": "test1", "content":"hello1"});
accordionContainer.addChild(accordPane);
accordionContainer.addChild(accordPane2, 1);
accordPane.startup();
accordPane2.startup();
//accordionContainer.selectChild(accordPane2);
accordionContainer.startup();
accordPane.selected = false;
accordPane2.selected = true;
You can do it like this:
accordionContainer.selectChild( accordPane2 );
Assuming you are using dojo 1.3.
dijit.layout.AccordionContainer is a subclass of dijit.layout.StackContainer, which has selectChild defined.
I set up a demo page where you can see this code in action
If you were calling selectChild before startup, that could cause the error you were seeing since the widget wasn't in a 'complete' state. (Sorry, missed the commneted out code before I posted original answer)