Esempio n. 1
0
    def __init__(self, context):
        """
        Initializes the Plugin
        """
        
        super(ArniGuiDetail, self).__init__(context)
        self.setObjectName('arni_gui_detail')

        # Process standalone plugin command-line arguments
        from argparse import ArgumentParser

        parser = ArgumentParser()
        # Add argument(s) to the parser.
        parser.add_argument("-q", "--quiet", action="store_true",
                            dest="quiet",
                            help="Put plugin in silent mode")
        args, unknowns = parser.parse_known_args(context.argv())
        if not args.quiet:
            print 'arguments: ', args
            print 'unknowns: ', unknowns

        self.__model = ROSModel()

        self.__selection_widget = SelectionWidget(self.__model)
        context.add_widget(self.__selection_widget)

        self.__tree_widget = TreeWidget(self.__model, self.__selection_widget, self)
        context.add_widget(self.__tree_widget)
        self.__tree_widget.connect_slots()
        self.__tree_widget.show_erroneous_check_box.setCheckState(0)

        self.__selection_widget.connect_slots()
        
        #: is handeld here for the widget communication
        self.__tree_widget.item_tree_view.clicked.connect(self.__on_item_in_item_tree_view_clicked)
Esempio n. 2
0
    def init_ui(self):
        logging.debug("MainWindow::init_ui")
        self.setCentralWidget(self.wapp)
        # self.setWindowTitle(title)

        dockWidget = QtGui.QDockWidget(project_dock_name, self)
        # dockWidget.setAllowedAreas(QtCore.Qt.LeftDockWidgetArea | QtCore.Qt.RightDockWidgetArea)
        self.wproject = TreeWidget()
        self.wproject.parent_type = "file"  # configure the treeViewItem scan
        self.wproject.ext = self.project_ext  # configure the treeView scan extension

        dockWidget.setWidget(self.wproject)
        self.addDockWidget(QtCore.Qt.LeftDockWidgetArea, dockWidget)

        dockWidget = QtGui.QDockWidget(log_dock_name, self)
        # dockWidget.setAllowedAreas(QtCore.Qt.BottomDockWidgetArea | QtCore.Qt.RightDockWidgetArea)
        self.wlog = LogWidget()
        dockWidget.setWidget(self.wlog)
        self.addDockWidget(QtCore.Qt.BottomDockWidgetArea, dockWidget)

        dockWidget = QtGui.QDockWidget(files_dock_name, self)
        # dockWidget.setAllowedAreas(QtCore.Qt.BottomDockWidgetArea | QtCore.Qt.RightDockWidgetArea)
        self.wfiles = FilesWidget()
        dockWidget.setWidget(self.wfiles)
        # self.addDockWidget(QtCore.Qt.RightDockWidgetArea, dockWidget)
        self.addDockWidget(QtCore.Qt.BottomDockWidgetArea, dockWidget)

        logging.debug("MainWindow::create actions")
        self.create_actions()
        logging.debug("MainWindow::create menu")
        self.create_menu()
        self.statusBar().showMessage("Ready")

        try:
            version = "%s v.%s" % (self.wapp.__project__, self.wapp.__version__)
            self.statusBar().addPermanentWidget(QtGui.QLabel(version))
        except:
            pass

        try:
            self.setWindowIcon((QtGui.QIcon(os.path.join(_module_path(), "static", "icon.png"))))
            self.led_red_pixmap = QtGui.QPixmap(os.path.join(_module_path(), "static", "led-red.png"))
            self.led_green_pixmap = QtGui.QPixmap(os.path.join(_module_path(), "static", "led-green.png"))
            self.led_grey_pixmap = QtGui.QPixmap(os.path.join(_module_path(), "static", "led-grey.png"))
            self.led_blue_pixmap = QtGui.QPixmap(os.path.join(_module_path(), "static", "led-blue.png"))

            self.processWidget = QtGui.QLabel()
            self.processWidget.setPixmap(self.led_grey_pixmap)
            self.statusBar().addPermanentWidget(self.processWidget)
            # use_LCD
            self.statusbar_timer = QtGui.QLCDNumber()
            self.statusBar().addPermanentWidget(self.statusbar_timer)
            # use_ToolLED
            # self.toolLED=QtGui.QLabel()
            # self.toolLED.setPixmap(self.led_grey_pixmap)
            # self.statusBar().addPermanentWidget(self.toolLED)
        except:
            pass  # should do something
Esempio n. 3
0
    def __init__(self, context):
        """
        Initializes the Plugin
        """

        super(ArniGuiDetail, self).__init__(context)
        self.setObjectName('arni_gui_detail')

        # Process standalone plugin command-line arguments
        from argparse import ArgumentParser

        parser = ArgumentParser()
        # Add argument(s) to the parser.
        parser.add_argument("-q",
                            "--quiet",
                            action="store_true",
                            dest="quiet",
                            help="Put plugin in silent mode")
        args, unknowns = parser.parse_known_args(context.argv())
        if not args.quiet:
            print 'arguments: ', args
            print 'unknowns: ', unknowns

        self.__model = ROSModel()

        self.__selection_widget = SelectionWidget(self.__model)
        context.add_widget(self.__selection_widget)

        self.__tree_widget = TreeWidget(self.__model, self.__selection_widget,
                                        self)
        context.add_widget(self.__tree_widget)
        self.__tree_widget.connect_slots()
        self.__tree_widget.show_erroneous_check_box.setCheckState(0)

        self.__selection_widget.connect_slots()

        #: is handeld here for the widget communication
        self.__tree_widget.item_tree_view.clicked.connect(
            self.__on_item_in_item_tree_view_clicked)
Esempio n. 4
0
    def __init__(self, parent=None):
        QtWidgets.QGraphicsView.__init__(self, parent)
        self.scene = QtWidgets.QGraphicsScene(self)
        self.scene.setSceneRect(0, 0, 700, 500)

        # self.simple_group = QtWidgets.QGraphicsItemGroup()
        # self.simple_group.addToGroup(self.simple_entity_widget)
        # self.simple_group.addToGroup(self.simple_entity_widget2)
        # self.simple_group.addToGroup(self.simple_arrow)
        # self.simple_group.setFlag(QtWidgets.QGraphicsItem.ItemIsMovable)
        # self.simple_group.setFlag(QtWidgets.QGraphicsItem.ItemIsSelectable)
        # self.scene.addItem(self.simple_group)

        e = EntityExtractor()
        # C:\PythonProjects\CppDesignViewer\EntityRepo
        repo = e.search_classes('../EntityRepo/test_simple_file.cpp')
        entity_tree = EntityTrees()
        entity_tree.form_trees_from_repository(repo)
        roots = entity_tree.get_root_nodes()
        tree_widget_list = list()

        prev_widget_x = 10
        prev_widget_y = 0

        for root in roots:
            tree_widget_list.append(TreeWidget(root))
            tree_widget_list[-1].setPos(QPointF(prev_widget_x, prev_widget_y))
            h = tree_widget_list[-1].sizeHint(Qt.SizeHint.PreferredSize).height()
            prev_widget_y += h + 5
            self.scene.addItem(tree_widget_list[-1])

        print("sizeHint = ", tree_widget_list[0].sizeHint(Qt.SizeHint.MinimumSize)) #, QtCore.QSizeF(100, 100)
        print("sizeHint = ", tree_widget_list[0].sizeHint(Qt.SizeHint.MaximumSize))
        print("sizeHint = ", tree_widget_list[0].sizeHint(Qt.SizeHint.PreferredSize))



        # tree = TestTreeWidget().combine_trees((3, "left tree"), (2, "center tree"), (2, "right tree"))
        # tree_widget = TreeWidget()
        # tree_widget.build_from_root(tree)
        # self.scene.addItem(tree_widget)

        self.setScene(self.scene)
        self.timer = QtCore.QTimer()
        self.timer.setInterval(1000)
        self.timer.timeout.connect(self.timeout_slot)
        # self.timer.start()
        self.time_counter = 0
        self.time_increment = 1
Esempio n. 5
0
class ArniGuiDetail(Plugin):
    """
    The ArniGuiDetail-Plugin
    """
    def __init__(self, context):
        """
        Initializes the Plugin
        """

        super(ArniGuiDetail, self).__init__(context)
        self.setObjectName('arni_gui_detail')

        # Process standalone plugin command-line arguments
        from argparse import ArgumentParser

        parser = ArgumentParser()
        # Add argument(s) to the parser.
        parser.add_argument("-q",
                            "--quiet",
                            action="store_true",
                            dest="quiet",
                            help="Put plugin in silent mode")
        args, unknowns = parser.parse_known_args(context.argv())
        if not args.quiet:
            print 'arguments: ', args
            print 'unknowns: ', unknowns

        self.__model = ROSModel()

        self.__selection_widget = SelectionWidget(self.__model)
        context.add_widget(self.__selection_widget)

        self.__tree_widget = TreeWidget(self.__model, self.__selection_widget,
                                        self)
        context.add_widget(self.__tree_widget)
        self.__tree_widget.connect_slots()
        self.__tree_widget.show_erroneous_check_box.setCheckState(0)

        self.__selection_widget.connect_slots()

        #: is handeld here for the widget communication
        self.__tree_widget.item_tree_view.clicked.connect(
            self.__on_item_in_item_tree_view_clicked)

    def __on_item_in_item_tree_view_clicked(self, index):
        """
        Handels the click action and opens the clicked item in the SelectionWidget

        :param item: the clicked item
        :type item: QModelIndex
        """
        # the index comes from the proxy_model so it has to be converted but not here
        self.__selection_widget.set_selected_item(index)

    def shutdown_plugin(self):
        pass

    def save_settings(self, plugin_settings, instance_settings):
        instance_settings.set_value("tab_widget",
                                    self.__selection_widget.get_current_tab())
        instance_settings.set_value(
            "range_combo_box",
            self.__selection_widget.get_range_combo_box_index())
        instance_settings.set_value(
            "show_nodes_check_box",
            self.__tree_widget.show_nodes_check_box.checkState())
        instance_settings.set_value(
            "hide_debug_check_box",
            self.__tree_widget.hide_debug_check_box.checkState())
        instance_settings.set_value(
            "show_topics_check_box",
            self.__tree_widget.show_topics_check_box.checkState())
        instance_settings.set_value(
            "show_connections_check_box",
            self.__tree_widget.show_connections_check_box.checkState())
        instance_settings.set_value(
            "also_show_subscribers_check_box",
            self.__tree_widget.also_show_subscribers_check_box.checkState())
        instance_settings.set_value(
            "show_erroneous_check_box",
            self.__tree_widget.show_erroneous_check_box.checkState())
        instance_settings.set_value(
            "relative_font_size", self.__tree_widget.get_relative_font_size())

    def restore_settings(self, plugin_settings, instance_settings):
        tab_value = instance_settings.value("tab_widget")
        combo_box_value = instance_settings.value("range_combo_box")
        show_nodes_check_box = instance_settings.value("show_nodes_check_box")
        hide_debug_check_box = instance_settings.value("hide_debug_check_box")
        show_topics_check_box = instance_settings.value(
            "show_topics_check_box")
        show_erroneous_check_box = instance_settings.value(
            "show_erroneous_check_box")
        show_connections_check_box = instance_settings.value(
            "show_connections_check_box")
        also_show_subscribers_check_box = instance_settings.value(
            "also_show_subscribers_check_box")
        relative_font_size = instance_settings.value("relative_font_size")

        self.__selection_widget.set_current_tab(
            0 if tab_value is None else int(tab_value))

        self.__selection_widget.set_range_combo_box_index(
            0 if combo_box_value is None else int(combo_box_value))

        state = 2 if show_nodes_check_box is None else int(
            show_nodes_check_box)
        self.__tree_widget.show_nodes_check_box.setCheckState(state)
        self.__tree_widget.show_nodes_check_box.stateChanged.emit(state)

        state = 2 if hide_debug_check_box is None else int(
            hide_debug_check_box)
        self.__tree_widget.hide_debug_check_box.setCheckState(state)
        self.__tree_widget.hide_debug_check_box.stateChanged.emit(state)

        state = 2 if show_topics_check_box is None else int(
            show_topics_check_box)
        self.__tree_widget.show_topics_check_box.setCheckState(state)
        self.__tree_widget.show_topics_check_box.stateChanged.emit(state)

        state = 2 if show_connections_check_box is None else int(
            show_connections_check_box)
        self.__tree_widget.show_connections_check_box.setCheckState(state)
        self.__tree_widget.show_connections_check_box.stateChanged.emit(state)

        state = 2 if also_show_subscribers_check_box is None else int(
            also_show_subscribers_check_box)
        self.__tree_widget.also_show_subscribers_check_box.setCheckState(state)
        self.__tree_widget.also_show_subscribers_check_box.stateChanged.emit(
            state)

        state = 0 if show_erroneous_check_box is None else int(
            show_erroneous_check_box)
        self.__tree_widget.show_erroneous_check_box.setCheckState(state)
        self.__tree_widget.show_erroneous_check_box.stateChanged.emit(state)

        self.__tree_widget.set_relative_font_size(
            0 if relative_font_size is None else int(relative_font_size))
Esempio n. 6
0
class MainWindow(QtGui.QMainWindow):
    def __init__(self, app_widget, parent=None):
        super(MainWindow, self).__init__()
        self.wapp = app_widget
        # self.wproject.parent_type='file'      #configure the treeViewItem scan
        self.project_ext = ["*.*"]  # configure the treeView scan extension
        # self.init_ui()
        self.config = Config()
        self.parent = parent

    def init_ui(self):
        logging.debug("MainWindow::init_ui")
        self.setCentralWidget(self.wapp)
        # self.setWindowTitle(title)

        dockWidget = QtGui.QDockWidget(project_dock_name, self)
        # dockWidget.setAllowedAreas(QtCore.Qt.LeftDockWidgetArea | QtCore.Qt.RightDockWidgetArea)
        self.wproject = TreeWidget()
        self.wproject.parent_type = "file"  # configure the treeViewItem scan
        self.wproject.ext = self.project_ext  # configure the treeView scan extension

        dockWidget.setWidget(self.wproject)
        self.addDockWidget(QtCore.Qt.LeftDockWidgetArea, dockWidget)

        dockWidget = QtGui.QDockWidget(log_dock_name, self)
        # dockWidget.setAllowedAreas(QtCore.Qt.BottomDockWidgetArea | QtCore.Qt.RightDockWidgetArea)
        self.wlog = LogWidget()
        dockWidget.setWidget(self.wlog)
        self.addDockWidget(QtCore.Qt.BottomDockWidgetArea, dockWidget)

        dockWidget = QtGui.QDockWidget(files_dock_name, self)
        # dockWidget.setAllowedAreas(QtCore.Qt.BottomDockWidgetArea | QtCore.Qt.RightDockWidgetArea)
        self.wfiles = FilesWidget()
        dockWidget.setWidget(self.wfiles)
        # self.addDockWidget(QtCore.Qt.RightDockWidgetArea, dockWidget)
        self.addDockWidget(QtCore.Qt.BottomDockWidgetArea, dockWidget)

        logging.debug("MainWindow::create actions")
        self.create_actions()
        logging.debug("MainWindow::create menu")
        self.create_menu()
        self.statusBar().showMessage("Ready")

        try:
            version = "%s v.%s" % (self.wapp.__project__, self.wapp.__version__)
            self.statusBar().addPermanentWidget(QtGui.QLabel(version))
        except:
            pass

        try:
            self.setWindowIcon((QtGui.QIcon(os.path.join(_module_path(), "static", "icon.png"))))
            self.led_red_pixmap = QtGui.QPixmap(os.path.join(_module_path(), "static", "led-red.png"))
            self.led_green_pixmap = QtGui.QPixmap(os.path.join(_module_path(), "static", "led-green.png"))
            self.led_grey_pixmap = QtGui.QPixmap(os.path.join(_module_path(), "static", "led-grey.png"))
            self.led_blue_pixmap = QtGui.QPixmap(os.path.join(_module_path(), "static", "led-blue.png"))

            self.processWidget = QtGui.QLabel()
            self.processWidget.setPixmap(self.led_grey_pixmap)
            self.statusBar().addPermanentWidget(self.processWidget)
            # use_LCD
            self.statusbar_timer = QtGui.QLCDNumber()
            self.statusBar().addPermanentWidget(self.statusbar_timer)
            # use_ToolLED
            # self.toolLED=QtGui.QLabel()
            # self.toolLED.setPixmap(self.led_grey_pixmap)
            # self.statusBar().addPermanentWidget(self.toolLED)
        except:
            pass  # should do something
        # self.show()

    def create_actions(self):
        self.addProjectAct = QtGui.QAction(QtGui.QIcon("add.png"), "&Add", self)
        self.addProjectAct.triggered.connect(self.addProject)
        self.deleteProjectAct = QtGui.QAction(QtGui.QIcon("delete.png"), "&Delete", self)  # delete selected if any
        self.deleteProjectAct.triggered.connect(self.deleteProject)

        # self.addProjectAct.triggered.connect(self.wproject.add_item)
        self.connect(
            self.wproject.treeWidget, QtCore.SIGNAL("customContextMenuRequested(const QPoint &)"), self.menuContextTree
        )
        self.connect(self.wproject.treeWidget, QtCore.SIGNAL("itemSelectionChanged()"), self.setProjectFromTreeView)

    def create_menu(self):
        # self.projectMenu = self.menuBar().addMenu("&Project")
        # self.projectMenu.addAction(self.addProjectAct)
        # self.projectMenu.addAction(self.deleteProjectAct)
        # self.viewMenu=self.menuBar().addMenu("&About")
        workspaceGroup = QtGui.QActionGroup(self)
        import functools

        for item in self.config.workspace:
            name, value = item
            act = QtGui.QAction(name, self, checkable=True)
            act.triggered.connect(functools.partial(self.setProject, name, value))  # not!
            self.wproject.add_item(value, name=name)
            # workspaceGroup.addAction(act)
            # self.projectMenu.addAction(act)

    """
  def update_ui(self):
    for item in range(self.wproject.treeWidget.topLevelItemCount()):
      #print self.wproject.treeWidget.topLevelItemCount()
      logging.info('remove item %s' %item)
      self.wproject.treeWidget.takeTopLevelItem(item)
    #self.wproject=TreeWidget()
    #self.wproject.parent_type='file'      #configure the treeViewItem scan
    #self.wproject.ext=['*.*']   
    workspaceGroup = QtGui.QActionGroup(self)
    import functools
    for item in self.wapp.config.workspace:
      name, value = item
      act = QtGui.QAction(name, self, checkable=True)
      act.triggered.connect(functools.partial(self.setProject, name, value)) #not!
      self.wproject.add_item(value,name=name)
      workspaceGroup.addAction(act)
    self.setCentralWidget(self.wapp)

  def setAppWidget(self,widget):
    logging.debug('MainWindow::setAppWidget %s' %repr(widget))
    self.wapp=widget
    self.update_ui()
  """

    def setLog(self, logfilepath):
        logging.debug("AppMainWindow::setLog %s" % logfilepath)
        self.wlog.set_path(logfilepath)

    def setFileView(self, path):
        logging.debug("AppMainWindow::setFileView %s" % path)
        self.wfiles.set_path(path)

    # --------  Project Management
    def addProject(self):
        logging.debug("MainWindow::addProject")
        dialog = QtGui.QFileDialog(self)
        dialog.setFileMode(QtGui.QFileDialog.DirectoryOnly)
        dirname = dialog.getExistingDirectory(self, "Select project folder!", os.path.abspath(os.getcwd()))
        # if not os.path.isfile(os.path.join(dirname, configfilename)):
        #  QtGui.QMessageBox.information(self, title, unicode('%s not found. Create one.' %configfilename))
        # self.wapp.createNewAppConf(dirname)
        _name, _bool = QtGui.QInputDialog.getText(self, "New Workspace", "label/name")

        # update widget
        if _bool == True:
            self.wproject.add_item(dirname, name=_name)
            self.config.create(_name, dirname)  # addWorkspace

    def setProjectFromTreeView(self):
        # print self.wproject.treeWidget.currentIndex()
        i = self.wproject.treeWidget.currentIndex().row()
        logging.debug("MainWindow::setProjectFromTreeView index %s" % str(i))
        _name, path = self.config.workspace[i]
        self.setProject(_name, path)

    def setProject(self, name, path):
        logging.debug("MainWindow::setProject : %s" % name)
        if self.parent != None:
            print self.parent
            if hasattr(self.parent, setProject):  # exposed method!
                print "call parent"
                self.parent.setProject(name, path)

        # self.wapp.setWorkspace(name,path)
        # self.setWorkspace(name,path)  #WARNING

        # if on per-project based
        # logfiles=os.path.join(path,logfilename)
        # self.wlog.set_path(logfiles)
        # report_path=os.path.join(self.currentWorkspace,report_path)
        # self.wfiles.set_path(report_path)

    def deleteProject(self):
        logging.debug("MainWindow::delete TreeWidgetItem %s" % self.wproject.treeWidget.currentIndex().row())
        i = self.wproject.treeWidget.currentIndex().row()
        logging.debug("delete item  %s" % i)
        self.wproject.treeWidget.takeTopLevelItem(i)
        del self.wproject.items[i]

        print type(self.config.workspace)
        logging.info("MainWindow:: delete from list %s" % repr(self.config.workspace[i]))
        del self.config.workspace[i]
        self.config.write()

    def menuContextTree(self, point):  # projectContextMenuHandler
        item = self.wproject.treeWidget.itemAt(point)
        logging.debug("%s " % item)
        logging.debug(self.wproject.treeWidget.currentIndex())
        menu = QtGui.QMenu()
        addAction = menu.addAction(self.addProjectAct)
        deleteAction = menu.addAction(self.deleteProjectAct)
        menu.exec_(QtGui.QCursor.pos())
        # self.connnect(self.treeWidget, ,addAction)

    # --------  TOOL LED
    def startToolProcess(self):
        try:
            self.toolLED.setPixmap(self.led_blue_pixmap)
        except:
            pass

    def endToolProcess(self):
        try:
            self.toolLED.setPixmap(self.led_grey_pixmap)
        except:
            pass

    # -------- process Timer & LED
    def startProcessTimer(self):
        self.timer = QtCore.QTimer(self)
        self.connect(self.timer, QtCore.SIGNAL("timeout()"), self.updateProcessTimer)
        self.ptime = 0
        self.timer.start(1000)
        try:
            self.processWidget.setPixmap(self.led_green_pixmap)
        except:
            pass
        # if hasattr(self.parent,onStartProcess):
        # parent.onStartProcess()

    def stopProcessTimer(self):
        self.timer.stop()
        try:
            self.processWidget.setPixmap(self.led_grey_pixmap)
        except:
            pass

    def updateProcessTimer(self):
        self.ptime += 1
        self.statusbar_timer.display(self.ptime)
Esempio n. 7
0
class ArniGuiDetail(Plugin):
    """
    The ArniGuiDetail-Plugin
    """
    
    def __init__(self, context):
        """
        Initializes the Plugin
        """
        
        super(ArniGuiDetail, self).__init__(context)
        self.setObjectName('arni_gui_detail')

        # Process standalone plugin command-line arguments
        from argparse import ArgumentParser

        parser = ArgumentParser()
        # Add argument(s) to the parser.
        parser.add_argument("-q", "--quiet", action="store_true",
                            dest="quiet",
                            help="Put plugin in silent mode")
        args, unknowns = parser.parse_known_args(context.argv())
        if not args.quiet:
            print 'arguments: ', args
            print 'unknowns: ', unknowns

        self.__model = ROSModel()

        self.__selection_widget = SelectionWidget(self.__model)
        context.add_widget(self.__selection_widget)

        self.__tree_widget = TreeWidget(self.__model, self.__selection_widget, self)
        context.add_widget(self.__tree_widget)
        self.__tree_widget.connect_slots()
        self.__tree_widget.show_erroneous_check_box.setCheckState(0)

        self.__selection_widget.connect_slots()
        
        #: is handeld here for the widget communication
        self.__tree_widget.item_tree_view.clicked.connect(self.__on_item_in_item_tree_view_clicked)




    def __on_item_in_item_tree_view_clicked(self, index):
        """
        Handels the click action and opens the clicked item in the SelectionWidget

        :param item: the clicked item
        :type item: QModelIndex
        """
        # the index comes from the proxy_model so it has to be converted but not here
        self.__selection_widget.set_selected_item(index)

    def shutdown_plugin(self):
        pass


    def save_settings(self, plugin_settings, instance_settings):
        instance_settings.set_value("tab_widget", self.__selection_widget.get_current_tab())
        instance_settings.set_value("range_combo_box", self.__selection_widget.get_range_combo_box_index())
        instance_settings.set_value("show_nodes_check_box", self.__tree_widget.show_nodes_check_box.checkState())
        instance_settings.set_value("hide_debug_check_box", self.__tree_widget.hide_debug_check_box.checkState())
        instance_settings.set_value("show_topics_check_box", self.__tree_widget.show_topics_check_box.checkState())
        instance_settings.set_value("show_connections_check_box", self.__tree_widget.show_connections_check_box.checkState())
        instance_settings.set_value("also_show_subscribers_check_box", self.__tree_widget.also_show_subscribers_check_box.checkState())
        instance_settings.set_value("show_erroneous_check_box", self.__tree_widget.show_erroneous_check_box.checkState())
        instance_settings.set_value("relative_font_size", self.__tree_widget.get_relative_font_size())


    def restore_settings(self, plugin_settings, instance_settings):
        tab_value = instance_settings.value("tab_widget")
        combo_box_value = instance_settings.value("range_combo_box")
        show_nodes_check_box = instance_settings.value("show_nodes_check_box")
        hide_debug_check_box = instance_settings.value("hide_debug_check_box")
        show_topics_check_box = instance_settings.value("show_topics_check_box")
        show_erroneous_check_box = instance_settings.value("show_erroneous_check_box")
        show_connections_check_box = instance_settings.value("show_connections_check_box")
        also_show_subscribers_check_box = instance_settings.value("also_show_subscribers_check_box")
        relative_font_size = instance_settings.value("relative_font_size")

        self.__selection_widget.set_current_tab(0 if tab_value is None else int(tab_value))

        self.__selection_widget.set_range_combo_box_index(0 if combo_box_value is None else int(combo_box_value))

        state = 2 if show_nodes_check_box is None else int(show_nodes_check_box)
        self.__tree_widget.show_nodes_check_box.setCheckState(state)
        self.__tree_widget.show_nodes_check_box.stateChanged.emit(state)

        state = 2 if hide_debug_check_box is None else int(hide_debug_check_box)
        self.__tree_widget.hide_debug_check_box.setCheckState(state)
        self.__tree_widget.hide_debug_check_box.stateChanged.emit(state)

        state = 2 if show_topics_check_box is None else int(show_topics_check_box)
        self.__tree_widget.show_topics_check_box.setCheckState(state)
        self.__tree_widget.show_topics_check_box.stateChanged.emit(state)

        state = 2 if show_connections_check_box is None else int(show_connections_check_box)
        self.__tree_widget.show_connections_check_box.setCheckState(state)
        self.__tree_widget.show_connections_check_box.stateChanged.emit(state)

        state = 2 if also_show_subscribers_check_box is None else int(also_show_subscribers_check_box)
        self.__tree_widget.also_show_subscribers_check_box.setCheckState(state)
        self.__tree_widget.also_show_subscribers_check_box.stateChanged.emit(state)

        state = 0 if show_erroneous_check_box is None else int(show_erroneous_check_box)
        self.__tree_widget.show_erroneous_check_box.setCheckState(state)
        self.__tree_widget.show_erroneous_check_box.stateChanged.emit(state)

        self.__tree_widget.set_relative_font_size(0 if relative_font_size is None else int(relative_font_size))
Esempio n. 8
0
 def setUp(self):
     self.tree_widget = TreeWidget()
Esempio n. 9
0
class TestTreeWidget(TestCase):
    def setUp(self):
        self.tree_widget = TreeWidget()

    def appendToTree(self, base_tree, child_index, tree_to_append):
        child = base_tree.childAt(child_index)
        for c in tree_to_append.get_children_generator():
            child.append_a_child(c)
        EntityTrees().update_subtree_width(base_tree)

    def createSimpleTree(self, child_count, tree_name="base"):
        root = EntityTreeNode(EntityStructure(tree_name))
        for i in range(child_count):
            child = EntityTreeNode(EntityStructure("child {0} ({1})".format(i, tree_name)))
            root.append_a_child(child)
        EntityTrees().update_subtree_width(root)
        return root

    def changeChildWidth(self, tree, child_index, new_width):
        tree.childAt(child_index).node_width_in_units = new_width
        EntityTrees().update_subtree_width(tree)
        pass

    def combine_trees(self, *args):
        '''
        :param args: (tree_size_in_child_count, tree_name) ..
        :return: combined tree
        '''
        base_tree = self.createSimpleTree(len(args), "base tree")
        child_index = 0
        for i in args:
            self.appendToTree(base_tree, child_index, self.createSimpleTree(i[0], i[1]))
            child_index += 1
        return base_tree


    def test_build_tree_from_one_node(self):
        node = EntityTreeNode(EntityStructure("Test name"))
        self.tree_widget.build_from_root(node)
        node_name = node.get_name()
        root_name = self.tree_widget.get_root_widget().name
        self.assertEqual(node_name, root_name)

    def test_two_children_split_by_one_column(self):
        node_with_two_children = self.createSimpleTree(2)
        self.tree_widget.build_from_root(node_with_two_children)
        root = self.tree_widget.get_root_widget()
        first_child = root.get_next_child()
        second_child = root.get_next_child()
        self.assertEqual(root.row_col_tuple, (0, 1))
        self.assertEqual(first_child.row_col_tuple, (1, 0))
        self.assertEqual(second_child.row_col_tuple, (1, 2))

    def test_three_children_split_by_one_column(self):
        node_with_three_children = self.createSimpleTree(3)
        self.tree_widget.build_from_root(node_with_three_children)
        root = self.tree_widget.get_root_widget()
        first_child = root.get_next_child()
        second_child = root.get_next_child()
        third_child = root.get_next_child()
        self.assertEqual(root.row_col_tuple, (0, 2))
        self.assertEqual(first_child.row_col_tuple, (1, 0))
        self.assertEqual(second_child.row_col_tuple, (1, 2))
        self.assertEqual(third_child.row_col_tuple, (1, 4))

    def test_three_children_with_different_size(self):
        node_with_three_children = self.createSimpleTree(3)
        self.changeChildWidth(node_with_three_children, 1, 2)
        self.tree_widget.build_from_root(node_with_three_children)

        root = self.tree_widget.get_root_widget()
        first_child = root.get_next_child()
        second_child = root.get_next_child()
        third_child = root.get_next_child()
        # 0 1 2 * 4 5 6 (ceil(7/2)-1)
        # * 1 2 * 4 5 *
        self.assertEqual(root.row_col_tuple,        (0, 3))
        self.assertEqual(first_child.row_col_tuple, (1, 0))
        self.assertEqual(second_child.row_col_tuple,(1, 3))
        self.assertEqual(third_child.row_col_tuple, (1, 6))

    def test_binary_tree_with_three_levels(self):
        base_tree = self.combine_trees((2, "left tree"), (2, "right tree"))

        self.tree_widget.build_from_root(base_tree)
        root = self.tree_widget.get_root_widget()
        c0 = root.get_next_child()
        c00 = c0.get_next_child()
        c01 = c0.get_next_child()
        c1 = root.get_next_child()
        c10 = c1.get_next_child()
        c11 = c1.get_next_child()
        #012*456
        #0*234*6
        #*1*3*5*
        self.assertEqual(root.row_col_tuple,(0, 3))
        self.assertEqual(c0.row_col_tuple,  (1, 1))
        self.assertEqual(c1.row_col_tuple,  (1, 5))
        self.assertEqual(c00.row_col_tuple, (2, 0))
        self.assertEqual(c01.row_col_tuple, (2, 2))
        self.assertEqual(c10.row_col_tuple, (2, 4))
        self.assertEqual(c11.row_col_tuple, (2, 6))

    def test_three_branch_tree_with_three_levels(self):
        base_tree = self.combine_trees((2, "left tree"), (2, "center tree"), (2, "right tree"))

        self.tree_widget.build_from_root(base_tree)
        root = self.tree_widget.get_root_widget()
        c_left = root.get_next_child()
        c_left_left = c_left.get_next_child()
        c_left_right = c_left.get_next_child()

        c_center = root.get_next_child()
        c_center_left  = c_center.get_next_child()
        c_center_right = c_center.get_next_child()

        c_right = root.get_next_child()
        c_right_left = c_right.get_next_child()
        c_right_right = c_right.get_next_child()
        # 0 1 2 3 4 * 6 7 8 9 10 11 (ceil(12/2)-1)
        # 0 * 2 3 4 * 6 7 8 * 10 11
        # * 1 * 3 * 5 * 7 * 9 *  11
        self.assertEqual(root.row_col_tuple,    (0, 5))
        self.assertEqual(c_left.row_col_tuple,  (1, 1))
        self.assertEqual(c_center.row_col_tuple,(1, 5))
        self.assertEqual(c_right.row_col_tuple, (1, 9))
        self.assertEqual(c_left_left.row_col_tuple,     (2, 0))
        self.assertEqual(c_left_right.row_col_tuple,    (2, 2))
        self.assertEqual(c_center_left.row_col_tuple,   (2, 4))
        self.assertEqual(c_center_right.row_col_tuple,  (2, 6))
        self.assertEqual(c_right_left.row_col_tuple,    (2, 8))
        self.assertEqual(c_right_right.row_col_tuple,   (2, 10))

    def test_three_branch_tree_with_different_size(self):
        base_tree = self.combine_trees((2, "left tree"), (3, "center tree"), (2, "right tree"))

        self.tree_widget.build_from_root(base_tree)
        root = self.tree_widget.get_root_widget()
        c_left = root.get_next_child()
        c_left_left = c_left.get_next_child()
        c_left_right = c_left.get_next_child()

        c_center = root.get_next_child()
        c_center_left  = c_center.get_next_child()
        c_center_center = c_center.get_next_child()
        c_center_right = c_center.get_next_child()

        c_right = root.get_next_child()
        c_right_left = c_right.get_next_child()
        c_right_right = c_right.get_next_child()
        # 0 1 2 3 4 5 * 7 8 9 10 11 12
        # 0 * 2 3 4 5 * 7 8 9 10  * 12
        # * 1 * 3 * 5 * 7 * 9  * 11  *
        self.assertEqual(root.row_col_tuple,    (0, 6))
        self.assertEqual(c_left.row_col_tuple,  (1, 1))
        self.assertEqual(c_center.row_col_tuple,(1, 6))
        self.assertEqual(c_right.row_col_tuple, (1, 11))
        self.assertEqual(c_left_left.row_col_tuple,     (2, 0))
        self.assertEqual(c_left_right.row_col_tuple,    (2, 2))
        self.assertEqual(c_center_left.row_col_tuple,   (2, 4))
        self.assertEqual(c_center_center.row_col_tuple, (2, 6))
        self.assertEqual(c_center_right.row_col_tuple,  (2, 8))
        self.assertEqual(c_right_left.row_col_tuple,    (2, 10))
        self.assertEqual(c_right_right.row_col_tuple,   (2, 12))