def addTabWidget(self, _tab_widget_name, _tab_widget_classname, _model, _reuse): if self.applicationMainTabWidget == None: InformationWindow(message="Main tab widget wasn't created!") return _class_object = get_class_object(_tab_widget_classname) tabWidget = _class_object(parent=self.applicationMainTabWidget, model=_model) #get all tab titles titles = [ str(self.applicationMainTabWidget.tabText(idx)) for idx in range(self.applicationMainTabWidget.count()) ] #get list of true/false of matching titles to _tab_widget_name #with an optional number pattern = _tab_widget_name + ' \[[0-9]*\]' matches = [ re.match(pattern, title) or title == _tab_widget_name for title in titles ] #reuse means we have to delete all matching tab widgets if _reuse == True: map(self.applicationMainTabWidget.removeTab, any_indexes(matches)) #if have to be created a tab widget and there is #at least one, with the same title, already elif _reuse == False and any(matches) == True: #get a maximum number of existing tabs, if there is no number #attached to any tabs then the default is 1 max_num = get_max_number_between_signs(titles, from_end=True, default=1) #add next number to the tab title _tab_widget_name = '%s [%d]' % (_tab_widget_name, max_num + 1) self.applicationMainTabWidget.addTab(tabWidget, _tab_widget_name) self.applicationMainTabWidget.setCurrentWidget(tabWidget)
def addTabWidget(self, _tab_widget_name, _tab_widget_classname, _model, _reuse): if self.applicationMainTabWidget == None: InformationWindow(message="Main tab widget wasn't created!") return _class_object = get_class_object(_tab_widget_classname) tabWidget = _class_object(parent=self.applicationMainTabWidget, model=_model) #get all tab titles titles = [str(self.applicationMainTabWidget.tabText(idx)) for idx in range(self.applicationMainTabWidget.count())] #get list of true/false of matching titles to _tab_widget_name #with an optional number pattern = _tab_widget_name + ' \[[0-9]*\]' matches = [re.match(pattern, title) or title == _tab_widget_name for title in titles] #reuse means we have to delete all matching tab widgets if _reuse == True: map(self.applicationMainTabWidget.removeTab, any_indexes(matches)) #if have to be created a tab widget and there is #at least one, with the same title, already elif _reuse == False and any(matches) == True: #get a maximum number of existing tabs, if there is no number #attached to any tabs then the default is 1 max_num = get_max_number_between_signs(titles, from_end=True, default=1) #add next number to the tab title _tab_widget_name = '%s [%d]' % (_tab_widget_name, max_num + 1) self.applicationMainTabWidget.addTab(tabWidget, _tab_widget_name) self.applicationMainTabWidget.setCurrentWidget(tabWidget)
def getNextTitle(self, title): titles = [_t for _t in self.getTabsTitles() if _t.startswith(title)] max_num = -1 if len(titles) == 0 else \ get_max_number_between_signs(titles, from_end=True, default=0) return title if max_num == -1 else '%s [%d]' % (title, max_num + 1)