Exemplo n.º 1
0
 def deep_create_tree(came_from: QTreeWidgetItem,
                      collections_tree: dict):
     for single_name in collections_tree:
         single_value = collections_tree[single_name]
         qtree = QTreeWidgetItem(came_from, 'zame')
         qtree.setText(0, single_name)
         deep_create_tree(qtree, single_value)
Exemplo n.º 2
0
    def btn_add(self):
        """
        Add a new child for the time varying parameters
        """

        items = self.ui.tree.selectedItems()
        if not items:
            return
        item: QTreeWidgetItem = items[0]

        key = item.text(0)
        # Only for time varying parameters
        if key and key not in self.vr3.get_varying():
            return

        # If select toplevel item
        if key:
            parent = item
        # If its a child
        else:
            parent = item.parent()

        # Add item at the end
        new = QTreeWidgetItem(parent)
        new.setText(1, "0")
        new.setText(2, "0")
        new.setText(3, "0")
        new.setFlags(new.flags() | Qt.ItemIsEditable)
        parent.addChild(new)

        self.set_buttons_state()
Exemplo n.º 3
0
 def add_dir(self, dir_path, parent):
     sorted_list = sorted(self.list_dir(dir_path),
                          key=lambda x:
                          (x[0] not in self.dirs, x[0].lower()))
     for path, mtime in sorted_list:
         basename = os.path.basename(path)
         if len(basename) == 0:
             continue
         item = QTreeWidgetItem()
         item.setText(0, basename)
         self.index[item] = path
         parent.setFlags(parent.flags() | Qt.ItemIsTristate
                         | Qt.ItemIsUserCheckable)
         item.setFlags(item.flags() | Qt.ItemIsUserCheckable)
         item.setCheckState(
             0, Qt.Checked
             if parent.checkState(0) == Qt.Checked else Qt.Unchecked)
         parent.addChild(item)
         item.setText(
             1, time.strftime("%b %d %Y %I:%M:%S %p",
                              time.localtime(mtime)))
         if path in self.dirs and len(self.list_dir(path)) != 0:
             sub_item = QTreeWidgetItem()
             self.hidden[item] = sub_item
             item.addChild(sub_item)
             item.setIcon(0, QIcon(get_resource_path("images/folder.png")))
Exemplo n.º 4
0
 def onAddOptionGroup(self):
     text, ok = QInputDialog.getText(self.backtest, "请输入期权组名称", "名称",
                                     QLineEdit.Normal)
     current_item = self.backtest_tree.currentItem()
     # parent_item = current_item.parent()
     current_item_text = current_item.text(0)
     # parent_item_text = parent_item.text(0)
     if ok and text:
         node = QTreeWidgetItem(current_item)
         node.setText(0, text)
         node.setCheckState(0, Qt.Unchecked)
         node.setWhatsThis(0, "option_group")
         node.setIcon(0, QtGui.QIcon("../icon/group.png"))
         self.backtest_tree.expandItem(self.backtest_tree.currentItem())
         group_dict = {
             "name": text,
             "enable": 1,
             "contracts": [],
             "signal": {
                 "type": "list",
                 "value": 0,
                 "list": []
             },
             "ratio": {
                 "type": "float",
                 "value": 0,
             },
         }
         for underlying in self.config["options"]["underlyings"]:
             if underlying.get("name") == current_item_text:
                 underlying["groups"].append(group_dict)
def add_tree_item(item_parent,
                  tree_value,
                  tree_class_text,
                  tree_text,
                  tree_col_num=0,
                  tree_top=False):
    '''在目录树上添加节点

    在目录树上添加节点

    @参数说明: 
        item_parent:此节点的父节点
        tree_value:节点相对应的值
        tree_class_text:
        tree_text:设置节点文字
        tree_col_num:节点的行号
        tree_top:是否为首节点

    @返回值: 
        tree_item:返回此节点

    @注意: 
        无
    '''
    tree_item = QTreeWidgetItem(tree_value)  # 创建 QTreeWidgetItem 类
    text = QCoreApplication.translate(tree_class_text, tree_text)
    tree_item.setText(tree_col_num, text)  # 设置节点文字
    # 首节点判定
    if (tree_top == False):
        item_parent.addChild(tree_item)
    else:
        item_parent.addTopLevelItem(tree_item)
    return tree_item
Exemplo n.º 6
0
    def add_tivo(self, name, ip_address):
        item = QTreeWidgetItem()
        item.setText(0, name)
        item.setText(1, ip_address)

        self.tivo_listings.addTopLevelItem(item)
        self.tivos_found.append(item)
Exemplo n.º 7
0
 def update_node_data(self,
                      child_node: QTreeWidgetItem,
                      item: Union[JenkinsJob, JenkinsFolder]):
     icon = "job.png" if isinstance(item, JenkinsJob) else "folder.png"
     child_node.setText(0, item.name)
     child_node.setIcon(0, get_icon(icon))
     child_node.setCheckState(0, as_qt_selection(item.selected))
Exemplo n.º 8
0
    def _map_treeitems(self, rootnode):
        """ rootnode: yorick_service.Nodes.Node """

        # PyQt4 is designed to add top level item alone
        rootitem = QTreeWidgetItem(self.widget)
        rootitem.setText(0, rootnode.node_name)
        self.widget.addTopLevelItem(rootitem)

        # add children widget items recursively
        def gen_child(parent, node):
            child = QTreeWidgetItem(parent)
            child.setText(0, node.node_name)

            self.item_to_node[child] = node
            node.listitem = child

            # partial to generate gen_child recurse
            list(map(partial(gen_child, child), node.children))
            return child

        # ignite recursion
        self.item_to_node.clear()
        self.item_to_node[rootitem] = rootnode

        rootitem.addChildren(
            list(map(partial(gen_child, rootitem), rootnode.children)))
Exemplo n.º 9
0
        def build_menu_by_recursive(root: QTreeWidgetItem, menu_dict: dict):
            for key in menu_dict:
                item = QTreeWidgetItem()

                item_font = QFont()
                item_font.setPointSize(
                    self.config.getint('master', 'master_item_font_size'))
                try:
                    text = str(menu_dict[key]['text'])
                    item.setText(0, text)
                    item.setFont(0, item_font)
                except KeyError:
                    pass
                try:
                    descript = str(menu_dict[key]['descript'])
                    item.setToolTip(0, descript)
                except KeyError:
                    pass
                try:
                    scl = str(menu_dict[key]['scl'])
                    item.setText(2, scl)
                except KeyError:
                    pass
                try:
                    children = menu_dict[key]['children']
                    build_menu_by_recursive(item, children)
                except KeyError:
                    pass
                try:
                    expanded = menu_dict[key]['expanded']
                    item.setExpanded(expanded)
                except KeyError:
                    pass

                root.addChild(item)
Exemplo n.º 10
0
 def treeItems():
     categories = Categories().data
     for key in categories:
         parent = QTreeWidgetItem(tree)
         parent.setText(0, key)
         for item in categories[key]:
             child = QTreeWidgetItem(parent)
             child.setText(0, item)
Exemplo n.º 11
0
 def __add_words_to_speech_part(self, speech_part_item: QTreeWidgetItem,
                                words: list):
     """
     Adds words as a QTreeWidgetItem objects to the specified speech part item
     """
     for word in words:
         word_item = QTreeWidgetItem(word)
         word_item.setText(self.DEFAULT_COLUMN, word)
         speech_part_item.addChild(word_item)
Exemplo n.º 12
0
 def __add_aspect_type(self, aspect_type: str) -> QTreeWidgetItem:
     """
     Adds a QTreeWidgetItem with specified text aspect tree
     :return: added QTreeWidgetItem item
     """
     item = QTreeWidgetItem()
     item.setText(self.DEFAULT_COLUMN, aspect_type)
     self.addTopLevelItem(item)
     return item
Exemplo n.º 13
0
 def add_root_path(self, path):
     root = QTreeWidgetItem()
     root.setText(0, path)
     root.setCheckState(0, Qt.Unchecked)
     root.setIcon(0, QIcon(get_resource_path("images/folder.png")))
     self.index[root] = path
     self.expanded.add(path)
     self.snapshot_tree_widget.addTopLevelItem(root)
     self.add_dir(path, root)
Exemplo n.º 14
0
 def __add_speech_part(self, speech_part: str,
                       aspect_item: QTreeWidgetItem) -> QTreeWidgetItem:
     """
     Adds a QTreeWidgetItem with specified text to the aspect item
     :return: added QTreeWidgetItem item
     """
     item = QTreeWidgetItem()
     item.setText(self.DEFAULT_COLUMN, speech_part)
     aspect_item.addChild(item)
     return item
Exemplo n.º 15
0
        def gen_child(parent, node):
            child = QTreeWidgetItem(parent)
            child.setText(0, node.node_name)

            self.item_to_node[child] = node
            node.listitem = child

            # partial to generate gen_child recurse
            list(map(partial(gen_child, child), node.children))
            return child
Exemplo n.º 16
0
    def create_root(self, parent, name, value):
        root = QTreeWidgetItem(parent)
        root.setText(0, name)
        root.setText(1, value)
        root.setTextColor(0, QColor('#ffffff'))
        root.setTextColor(1, QColor('#ffffff'))
        root.setBackgroundColor(0, QColor('#0066cc'))
        root.setBackgroundColor(1, QColor('#0066cc'))

        return root
Exemplo n.º 17
0
 def on_addSoftwareButton_clicked(self):
     index = len(self.software_list)
     software = SoftwareProgram(index)
     self.software_list.append(software)
     self.CATALOG.add_software(software)
     item = QTreeWidgetItem()
     item.setText(0, "".join([str(software.index), ". New Software"]))
     self.insertChildren(item, software)
     self.ui.softwareTreeWidget.addTopLevelItem(item)
     self.open_edit_window(item)
Exemplo n.º 18
0
    def add_address_to_list(qtreelist: QTreeWidget, addr):
        for i in range(qtreelist.topLevelItemCount()):
            item = qtreelist.topLevelItem(i)  # type: QTreeWidgetItem
            if int(item.text(0), 16) == addr:
                return None # deduplicate

        item = QTreeWidgetItem(qtreelist)
        item.setText(0, "%#x" % addr)
        item.setFlags(item.flags() | Qt.ItemIsUserCheckable)
        item.setData(0, Qt.CheckStateRole, Qt.Checked)
        return item
Exemplo n.º 19
0
    def create_from_dict(self, d):
        for category in d:
            category_item = QTreeWidgetItem()
            category_item.setText(0, category)

            for elem_name in d[category]:
                it = QTreeWidgetItem()
                it.setText(0, elem_name)
                category_item.addChild(it)

            self.addTopLevelItem(category_item)
Exemplo n.º 20
0
        def items(lists):
            item_ = QTreeWidgetItem()

            for idx_, i_ in enumerate(lists):
                try:
                    item_.setText(idx_, str(i_))
                except ValueError:
                    item_.setText(idx_, i_[::20])  # it's too long, so str.
                # this str-to-everyone might cause overhead.
                # maybe I need to only apply str to lineProcess's few form items.
            return item_
Exemplo n.º 21
0
 def insertItemsIntoTree(self, item, tree):
     for i in item:
         print(i)
         subitem = QTreeWidgetItem(tree)
         subitem.setText(0, i)
         if type(item[i]) == dict:
             print(item[i])
             self.insertItemsIntoTree(item[i], subitem)
         # else:
         #     self.insertItemsIntoTree(item[i], tree)
     return
Exemplo n.º 22
0
    def create_child(self, name, value):
        """Create child item of the tree"""
        root = QTreeWidgetItem()
        root.setText(0, name)
        root.setText(1, value)
        root.setTextColor(0, QColor('#0066cc'))
        root.setTextColor(1, QColor('#0066cc'))
        root.setBackgroundColor(0, QColor('#ccffff'))
        root.setBackgroundColor(1, QColor('#ccffff'))

        return root
Exemplo n.º 23
0
    def onAddOptionUnderlying(self):

        text, ok = QInputDialog.getText(self.backtest, "请输入期权标的名称", "名称",
                                        QLineEdit.Normal)
        if ok and text:
            node = QTreeWidgetItem(self.backtest_tree.currentItem())
            node.setText(0, text)
            node.setCheckState(0, Qt.Unchecked)
            node.setWhatsThis(0, "option_underlying")
            self.backtest_tree.expandItem(self.backtest_tree.currentItem())
            ids = [
                i.btId for i in self.mdi_area.subWindowList()
                if hasattr(i, "btType")
                and i.btType in ["option_underlying", "excel", "csv"]
            ]
            group_dict = {
                "name": text,
                "enable": 0,
                "ratio": {
                    "type": "int",
                    "value": 0,
                },
                "id": {
                    "type":
                    "list",
                    "value":
                    0,
                    "list":
                    ids,
                    "data":
                    getattr(
                        self.parent.getSubWindowByAttribute("btId", ids[0]),
                        "btData")
                },
                "signal": {
                    "type": "list",
                    "value": 0,
                    "list": []
                },
                "option_side": {
                    "type": "list",
                    "value": 0,
                    "list": [u"买入"]
                },
                "volume": {
                    "type": "int",
                    "value": 0,
                },
                "groups": [],
                "contracts": [],
            }
            self.config["options"]["underlyings"].append(group_dict)
Exemplo n.º 24
0
    def onLoadFunctionDialogTab(self, index, function_ui, data,
                                hidden_columns):
        if index == 0:
            self.cal_list1 = function_ui.findChild(QListWidget, "cal_list1")
            self.cal_list2 = function_ui.findChild(QListWidget, "cal_list2")
            self.function_box = function_ui.findChild(QComboBox,
                                                      "function_box")
            self.list_items = [
                i for i in list(data.columns) if i not in hidden_columns
            ]
            self.cal_list1.clear()
            self.cal_list2.clear()
            for item in self.list_items:
                self.cal_list1.addItem(item)
            for item in self.list_items:
                self.cal_list2.addItem(item)
            self.function_box.currentIndexChanged.connect(
                self.onFunctionCalculateBox)
        elif index == 1:
            self.rel_list1 = function_ui.findChild(QListWidget, "rel_list1")
            self.rel_list2 = function_ui.findChild(QListWidget, "rel_list2")
            self.function_box = function_ui.findChild(QComboBox, "rel_box")
            self.list_items = [
                i for i in list(data.columns) if i not in hidden_columns
            ]
            self.rel_list1.clear()
            self.rel_list2.clear()
            for item in self.list_items:
                self.rel_list1.addItem(item)
            for item in self.list_items:
                self.rel_list2.addItem(item)
            self.function_box.currentIndexChanged.connect(
                self.onFunctionCalculateBox)
        elif index == 2:
            self.search_tec_function = function_ui.findChild(
                QLineEdit, "search_input")
            self.tec_tree = function_ui.findChild(QTreeWidget, "tec_tree")
            talib_groups = talib.get_function_groups()

            for key in talib_groups.keys():
                node = QTreeWidgetItem(self.tec_tree)
                node.setText(0, key)
                for value in talib_groups[key]:
                    sub_node = QTreeWidgetItem(node)
                    sub_node.setText(0, value)

            self.tec_tree.itemClicked.connect(
                lambda event1, event2: self.onFunctionTecTree(
                    event1, event2, function_ui, data, hidden_columns))
            self.search_tec_function.textEdited.connect(
                lambda event: self.onTecFunctionSearched(function_ui))
Exemplo n.º 25
0
        def add_leaves(parent, path):
            global files_count, dir_count, project_name_

            files = sorted(
                filter(lambda f: os.path.isfile(os.path.join(path, f)),
                       os.listdir(path)))
            dirs = sorted(
                filter(lambda f: os.path.isdir(os.path.join(path, f)),
                       os.listdir(path)))

            for file in dirs:
                if file == '__pycache__':
                    continue

                if file.startswith('.'):
                    continue

                if file.endswith('.ipynb'):
                    continue

                if file.endswith('.png'):
                    continue

                if file == BCIFR_FILE:
                    continue

                tree = QTreeWidgetItem(parent)
                tree.setText(0, file)
                tree.path = os.path.join(path, file)
                tree.previous_name = file
                add_leaves(tree, os.path.join(path, file))
                dir_count += 1

                # print(file)

            for file in files:

                if file.startswith('.'):
                    continue

                tree = QTreeWidgetItem(parent)
                tree.setText(0, file)
                tree.path = os.path.join(path, file)
                tree.previous_name = file
                # if 'main.py' == file:
                # self.open_script(tree)

                tree.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEditable
                              | Qt.ItemIsUserCheckable | Qt.ItemIsEnabled)

                files_count += 1
Exemplo n.º 26
0
    def setup_possible_locations_tree(self):
        """
        Creates the possible_locations_tree with all worlds, areas and nodes.
        """
        self.possible_locations_tree.itemDoubleClicked.connect(
            self._on_tree_node_double_clicked)

        # TODO: Dark World names
        for world in self.game_description.world_list.worlds:
            world_item = QTreeWidgetItem(self.possible_locations_tree)
            world_item.setText(0, world.name)
            world_item.setExpanded(True)
            self._asset_id_to_item[world.world_asset_id] = world_item

            for area in world.areas:
                area_item = QTreeWidgetItem(world_item)
                area_item.area = area
                area_item.setText(0, area.name)
                area_item.setHidden(True)
                self._asset_id_to_item[area.area_asset_id] = area_item

                for node in area.nodes:
                    node_item = QTreeWidgetItem(area_item)
                    if isinstance(node, TranslatorGateNode):
                        node_item.setText(
                            0, "{} ({})".format(node.name, node.gate))
                    else:
                        node_item.setText(0, node.name)
                    node_item.node = node
                    if node.is_resource_node:
                        node_item.setFlags(node_item.flags()
                                           & ~Qt.ItemIsUserCheckable)
                    self._node_to_item[node] = node_item
Exemplo n.º 27
0
    def create_item(self, text, parent, index):
        after = None

        if index != 0:
            after = self.child_at(parent, index - 1)

        if parent is not None:
            item = QTreeWidgetItem(parent, after)
        else:
            item = QTreeWidgetItem(self, after)

        item.setText(0, text)
        item.setFlags(item.flags() | Qt.ItemIsEditable)
        return item
Exemplo n.º 28
0
    def onClickedFunctionButton(self):
        loader = QUiLoader()
        function_ui = loader.load('function_description.ui',
                                  parentWidget=self.python_editor)
        function_ui.setWindowTitle("函数说明")
        function_ui.show()

        self.tree = function_ui.findChild(QTreeWidget)
        self.demo = function_ui.findChild(QTextEdit)

        talib_groups = talib.get_function_groups()

        for key in talib_groups.keys():
            node = QTreeWidgetItem(self.tree)
            node.setText(0, key)
            for value in talib_groups[key]:
                sub_node = QTreeWidgetItem(node)
                sub_node.setText(0, value)
        names = functions.functions_name
        for key in names.keys():
            node = QTreeWidgetItem(self.tree)
            node.setText(0, key)
            for name in names[key].keys():
                sub_node = QTreeWidgetItem(node)
                sub_node.setText(0, name)
        self.tree.itemClicked.connect(
            lambda event1, event2: self.onFunctionTreeItemClicked(
                event1, event2))
        self.tree.itemDoubleClicked.connect(
            lambda event1, event2: self.onFunctionTreeItemDoubleClicked(
                event1, event2))
        return
Exemplo n.º 29
0
    def __init__(self):
        super().__init__()
        self.setHeaderHidden(True)

        self.addTopLevelItem(QTreeWidgetItem(["Library"]))

        for i in range(10):
            group = QTreeWidgetItem()
            group.setText(0, "Group" + str(1))
            group.setIcon(0, QIcon("images/count.png"))
            self.addTopLevelItem(group)

            content = QTreeWidgetItem()
            group.addChild(content)
            self.setItemWidget(content, 0, ExpandedList(self))
Exemplo n.º 30
0
def update_hierarchy_tree(fname):
    global netlist
    with open(fname) as f:
        netlist = json.load(f)
    modules = netlist['modules']
    top_module = list(modules.items())[0][0]
    for k, v in modules.items():
        attrs = v.get('attributes', {})
        if 'top' in attrs:
            top_module = k
    window.treeWidget.clear()
    root_item = QTreeWidgetItem(window.treeWidget)
    root_item.setText(0, top_module)
    root_item.full_name = top_module
    root_item.model = modules[top_module]
    walk_module(modules[top_module], root_item, top_module)
    window.treeWidget.expandAll()