def __init__(self, filesnames, parent=None): super(FilesPreviewDialog, self).__init__(parent) self.setWindowTitle('File(s) preview') self.setGeometry(QRect(50, 50, 1000, 600)) self.setLayout(QVBoxLayout()) #a list object has attribute 'insert' filesnames = filesnames if hasattr(filesnames, 'insert') \ else [filesnames] filesPreviewTabWidget = TabWidgetCommon(self) progressManager = ProgressDialogManager(self, label_text="Opening files ...", max_value=len(filesnames)) with progressManager as progress: for filename in filesnames: if (progress.wasCanceled()): break progress.increaseCounter() tab = self.__createFilePreview__(filesPreviewTabWidget, filename) filesPreviewTabWidget.addTab(tab, 'File: ' + filename) closeButton = PushButtonWidget(self, i18n="close", i18n_def="Close") self.connect(closeButton, SIGNAL("clicked()"), self, SLOT("reject()"))
class ApplicationMainWindow(MainWindowWidget): def __init__(self, parent=None, create_menus=True, main_workspace_name=GLOBALS.WORKSPACE_NAME, main_widget_name=GLOBALS.TAB_MAIN_NAME, **params): super(ApplicationMainWindow, self).__init__(parent) self.params = Params(**params) self.setObjectName(GLOBALS.MAIN_WINDOW_NAME) self.setWindowTitle(self.params.window_title) if create_menus == True: menuBuilder = QTMenuBuilder(self) menuBuilder.createMenus() if GLOBALS.START_MENU_ID: if menuBuilder.invokeMenuItem(GLOBALS.START_MENU_ID): sys.exit(0) self.applicationMainTabWidget = None if main_workspace_name: self.applicationMainTabWidget = TabWidgetCommon( self, object_name=main_workspace_name, not_add_widget_to_parent_layout=True) if main_widget_name: self.mainWidget = MainTabItemWindow( self.applicationMainTabWidget) self.applicationMainTabWidget.addTab(self.mainWidget, main_widget_name) self.setCentralWidget(self.applicationMainTabWidget) self.connect(self, ADD_TAB_ITEM_WIDGET_SIGNAL, self.addTabWidget) 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 closeEvent(self, event): for idx in range(self.applicationMainTabWidget.count()): tabWidget = self.applicationMainTabWidget.widget(idx) if hasattr(tabWidget, 'beforeCloseTab'): tabWidget.beforeCloseTab()
class ApplicationMainWindow(MainWindowWidget): def __init__(self, parent=None, create_menus=True, main_workspace_name=GLOBALS.WORKSPACE_NAME, main_widget_name=GLOBALS.TAB_MAIN_NAME, **params): super(ApplicationMainWindow, self).__init__(parent) self.params = Params(**params) self.setObjectName(GLOBALS.MAIN_WINDOW_NAME) self.setWindowTitle(self.params.window_title) if create_menus == True: menuBuilder = QTMenuBuilder(self) menuBuilder.createMenus() if GLOBALS.START_MENU_ID: if menuBuilder.invokeMenuItem(GLOBALS.START_MENU_ID): sys.exit(0) self.applicationMainTabWidget = None if main_workspace_name: self.applicationMainTabWidget = TabWidgetCommon(self, object_name=main_workspace_name, not_add_widget_to_parent_layout=True ) if main_widget_name: self.mainWidget = MainTabItemWindow( self.applicationMainTabWidget) self.applicationMainTabWidget.addTab(self.mainWidget, main_widget_name) self.setCentralWidget(self.applicationMainTabWidget) self.connect(self, ADD_TAB_ITEM_WIDGET_SIGNAL, self.addTabWidget) 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 closeEvent(self, event): for idx in range(self.applicationMainTabWidget.count()): tabWidget = self.applicationMainTabWidget.widget(idx) if hasattr(tabWidget, 'beforeCloseTab'): tabWidget.beforeCloseTab()