configwindow.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:dxf2gcode 作者: cnc-club 项目源码 文件源码
def createWidgetFromDefinitionDict(self):
        """
        Automatically build a widget, based on dict definition of the items.
        @return: a QWidget containing all the elements of the configuration window
        """
        logger.info('Creating configuration window')
        tab_widget = QTabWidget()
        definition = self.cfg_window_def

        #Create a dict with the sections' titles if not already defined. This dict contains sections' names as key and tabs' titles as values
        if '__section_title__' not in definition:
            definition['__section_title__'] = {}

        #Compute all the sections
        for section in sorted(definition):
            #skip the special section __section_title__
            if section == '__section_title__':
                continue

            #Create the title for the section if it doesn't already exist
            if section not in definition['__section_title__']:
                #The title for this section doesn't exist yet
                if isinstance(definition[section], dict) and '__section_title__' in definition[section]:
                    #The title for this section is defined into the section itself => we add the title to the dict containing all the titles
                    definition['__section_title__'][section] = definition[section]['__section_title__']
                else:
                    #The title for this section is not defined anywhere, so we use the section name itself as a title
                    definition['__section_title__'][section] = section.replace('_', ' ')

            #Create the tab (and the widget) for the current section, if it doesn't exist yet
            widget = None
            for i in range(tab_widget.count()):
                if definition['__section_title__'][section] == tab_widget.tabText(i):
                    widget = tab_widget.widget(i)
                    break

            if widget is None:
                widget = QWidget()
                tab_widget.addTab(widget, definition['__section_title__'][section])

            #Create the tab content for this section
            self.createWidgetSubSection(definition[section], widget)
            #Add a separator at the end of this subsection
            if widget.layout() is not None:
                separator = QFrame()
                separator.setFrameShape(QFrame.HLine)
                widget.layout().addWidget(separator)
                widget.layout().addStretch()

        #Add a QSpacer at the bottom of each widget, so that the items are placed on top of each tab
        for i in range(tab_widget.count()):
            if tab_widget.widget(i).layout() is not None:
                tab_widget.widget(i).layout().addStretch()

        return tab_widget
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号