Пример #1
0
    def createWidget(self, class_name, parent=None, name=''):
        """Function that is called for each widget defined in ui file,
        overridden here to populate baseinstance instead.
        """

        if parent is None and self.baseinstance:
            # supposed to create the top-level widget, return the base instance
            # instead
            return self.baseinstance
        else:
            if class_name in self.availableWidgets():
                # create a new widget for child widgets
                widget = QUiLoader.createWidget(self, class_name, parent, name)
            else:
                # if not in the list of availableWidgets, must be a custom widget
                # this will raise KeyError if the user has not supplied the
                # relevant class_name in the dictionary, or TypeError, if
                # customWidgets is None
                try:
                    widget = self.customWidgets[class_name](parent)
                except (TypeError, KeyError) as e:
                    raise Exception(
                        'No custom widget ' + class_name +
                        ' found in customWidgets param of UiLoader __init__.')

            if self.baseinstance:
                # set an attribute for the new child widget on the base
                # instance, just like PyQt4.uic.loadUi does.
                setattr(self.baseinstance, name, widget)

            return widget
Пример #2
0
            def createWidget(self, class_name, parent=None, name=""):
                """Called for each widget defined in ui file

                Overridden here to populate `baseinstance` instead.

                """

                if parent is None and self.baseinstance:
                    # Supposed to create the top-level widget,
                    # return the base instance instead
                    return self.baseinstance

                # For some reason, Line is not in the list of available
                # widgets, but works fine, so we have to special case it here.
                if class_name in self.availableWidgets() + ["Line"]:
                    # Create a new widget for child widgets
                    widget = QUiLoader.createWidget(self, class_name, parent,
                                                    name)
                elif class_name in self.custom_widgets:
                    widget = self.custom_widgets[class_name](parent)
                else:
                    raise Exception("Custom widget '%s' not supported" %
                                    class_name)

                if self.baseinstance:
                    # Set an attribute for the new child widget on the base
                    # instance, just like PyQt5.uic.loadUi does.
                    setattr(self.baseinstance, name, widget)

                return widget
Пример #3
0
    def createWidget(self, class_name, parent=None, name=''):
        """
        Overrides QUiLoader to createWidget in current window rather than a new one
        ``class_name:`` The class we want to create  
        ``parent:`` The parent widget  
        ``name:`` The name of the widget we'll create  
        """

        if class_name is QMainWindow.__name__:
            return self.window

        if parent is None and self.window:
            return self.window
        else:
            if class_name in self.availableWidgets():
                widget = QUiLoader.createWidget(self, class_name, parent, name)
                widget.show()
            else:
                try:
                    widget = self.customWidgets[class_name](parent)
                except (TypeError, KeyError) as e:
                    raise Exception(
                        class_name,
                        'was not found are you sure it was promoted?')

            if self.window:
                setattr(self.window, name, widget)

            return widget
Пример #4
0
 def createWidget(self, className, parent=None, name=""):
     widget = QUiLoader.createWidget(self, className, parent, name)
     self._widgets.append(widget)
     if parent is None:
         return self.baseinstance
     else:
         setattr(self.baseinstance, name, widget)
         return widget
Пример #5
0
 def createWidget(self, className, parent=None, name=""):
     widget = QUiLoader.createWidget(self, className, parent, name)
     self._widgets.append(widget)
     if parent is None:
         return self.baseinstance
     else:
         setattr(self.baseinstance, name, widget)
         return widget
Пример #6
0
 def createWidget(self, inClassName, inParent = None, inName = ''):
     if inParent is None and self.mTarget:
         return self.mTarget
     else:
         widget = QUiLoader.createWidget(self, inClassName, inParent, inName)
         if self.mTarget:
             setattr(self.mTarget, inName, widget)
         return widget
Пример #7
0
 def createWidget(self, className, parent=None, name=""):
     if className == "QCustomPlot":
         return QCustomPlot(parent)
     if parent is None:
         return self.baseinstance
     else:
         widget = QUiLoader.createWidget(self, className, parent, name)
         setattr(self.baseinstance, name, widget)
         return widget
Пример #8
0
 def createWidget(self, class_name, parent=None, name=''):
     if parent is None and self.base_instance:
         return self.base_instance
     else:
         # create a new widget for child widgets
         widget = QUiLoader.createWidget(self, class_name, parent, name)
         if self.base_instance:
             setattr(self.base_instance, name, widget)
         return widget
Пример #9
0
 def createWidget(self, class_name, parent=None, name=''):
     if parent is None and self.baseinstance:
         # supposed to create the top-level widget, return the base instance
         # instead
         return self.baseinstance
     else:
         # create a new widget for child widgets
         widget = QUiLoader.createWidget(self, class_name, parent, name)
         if self.baseinstance:
             # set an attribute for the new child widget on the base
             # instance, just like PyQt4.uic.loadUi does.
             setattr(self.baseinstance, name, widget)
         return widget
Пример #10
0
 def createWidget(self, class_name, parent=None, name=''):
     if parent is None and self.baseinstance:
         return self.baseinstance
     else:
         if class_name in self.availableWidgets():
             widget = QUiLoader.createWidget(self, class_name, parent, name)
         else:
             try:
                 widget = self.customWidgets[class_name](parent)
             except (TypeError, KeyError) as e:
                 raise Exception(
                     'No custom widget ' + class_name +
                     ' found in customWidgets param of UiLoader __init__.')
         if self.baseinstance:
             setattr(self.baseinstance, name, widget)
         return widget
Пример #11
0
            def createWidget(self, class_name, parent=None, name=''):
                # don't create the top-level widget, if a base instance is set
                if self._base_instance and not parent:
                    return self._base_instance

                if class_name in self._custom_widgets:
                    widget = self._custom_widgets[class_name](parent)
                else:
                    widget = QUiLoader.createWidget(self, class_name, parent, name)

                if str(type(widget)).find(self.class_aliases.get(class_name, class_name)) < 0:
                    sys.modules['QtCore'].qDebug(str('PySide.loadUi(): could not find widget class "%s", defaulting to "%s"' % (class_name, type(widget))))

                if self._base_instance:
                    setattr(self._base_instance, name, widget)

                return widget
Пример #12
0
    def createWidget(self, class_name, parent=None, name=''):
        """
        Function that is called for each widget defined in ui file,
        overridden here to populate baseinstance instead.
        """

        if parent is None and self.baseinstance:
            # supposed to create the top-level widget, return the base instance
            # instead
            return self.baseinstance

        else:
            if class_name in self.availableWidgets():
                # create a new widget for child widgets
                widget = QUiLoader.createWidget(self, class_name, parent, name)

            else:
                # if not in the list of availableWidgets,
                # must be a custom widget
                # this will raise KeyError if the user has not supplied the
                # relevant class_name in the dictionary, or TypeError, if
                # customWidgets is None
                if class_name not in self.customWidgets:
                    raise Exception('No custom widget ' + class_name +
                                    ' found in customWidgets param of' +
                                    'UiFile %s.' % self.uifile)
                try:
                    widget = self.customWidgets[class_name](parent)
                except Exception:
                    _logger.error("Fail to instanciate widget %s from file %s",
                                  class_name, self.uifile)
                    raise

            if self.baseinstance:
                # set an attribute for the new child widget on the base
                # instance, just like PyQt*.uic.loadUi does.
                setattr(self.baseinstance, name, widget)

                # this outputs the various widget names, e.g.
                # sampleGraphicsView, dockWidget, samplesTableView etc.
                # print(name)

            return widget
            def createWidget(self, class_name, parent=None, name=''):
                # don't create the top-level widget, if a base instance is set
                if self._base_instance and not parent:
                    return self._base_instance

                if class_name in self._custom_widgets:
                    widget = self._custom_widgets[class_name](parent)
                else:
                    widget = QUiLoader.createWidget(self, class_name, parent, name)

                if str(type(widget)).find(self.class_aliases.get(class_name, class_name)) < 0:
                    sys.modules['QtCore'].qDebug(
                        'PySide.loadUi(): could not find widget class "%s", defaulting to "%s"' %
                        (class_name, type(widget)))

                if self._base_instance:
                    setattr(self._base_instance, name, widget)

                return widget
Пример #14
0
        def createWidget(self, class_name, parent=None, name=""):
            if self.toplevel_instance is not None and parent is None:
                widget = self.toplevel_instance
            elif name in self._promotions:
                widget = self._promotions[name](parent)
                if parent is None:
                    # widgets with no parents must be saved or else Python crashes
                    self._store.append(widget)
            elif class_name in self._custom_widgets:
                widget = self._custom_widgets[class_name](parent)
            else:
                if class_name in self.availableWidgets():
                    widget = QUiLoader.createWidget(self, class_name, parent,
                                                    name)
                else:
                    raise UiLoaderUnknownWidgetException(
                        "Widget '%s' has unknown class '%s'" %
                        (name, class_name))

            return widget
Пример #15
0
        def createWidget(self, class_name, parent=None, name=''):
            """
            Function that is called for each widget defined in ui file,
            overridden here to populate baseinstance instead.
            """

            if parent is None and self.baseinstance:
                # supposed to create the top-level widget, return the base
                # instance instead
                return self.baseinstance

            else:

                # For some reason, Line is not in the list of available
                # widgets, but works fine, so we have to special case it here.
                if class_name in self.availableWidgets(
                ) or class_name == 'Line':
                    # create a new widget for child widgets
                    widget = QUiLoader.createWidget(self, class_name, parent,
                                                    name)

                else:
                    # If not in the list of availableWidgets, must be a custom
                    # widget. This will raise KeyError if the user has not
                    # supplied the relevant class_name in the dictionary or if
                    # customWidgets is empty.
                    try:
                        widget = self.customWidgets[class_name](parent)
                    except KeyError:
                        raise Exception('No custom widget ' + class_name + ' '
                                        'found in customWidgets')

                if self.baseinstance:
                    # set an attribute for the new child widget on the base
                    # instance, just like PyQt4.uic.loadUi does.
                    setattr(self.baseinstance, name, widget)

                return widget
Пример #16
0
 def createWidget(self, class_name, parent=None, name=''):
     if class_name == 'QWidget':
         w = QWidget(parent)
         w.setObjectName(name)
         return w
     return QUiLoader.createWidget(self, class_name, parent, name)