示例#1
0
    def __init__(self, spine, toc=None):
        QStandardItemModel.__init__(self)
        self.current_query = {'text': '', 'index': -1, 'items': ()}
        if toc is None:
            toc = MTOC()
        self.all_items = depth_first = []
        for t in toc:
            self.appendRow(TOCItem(spine, t, 0, depth_first))

        for x in depth_first:
            possible_enders = [
                t for t in depth_first
                if t.depth <= x.depth and t.starts_at >= x.starts_at
                and t is not x and t not in x.ancestors
            ]
            if possible_enders:
                min_spine = min(t.starts_at for t in possible_enders)
                possible_enders = {
                    t.fragment
                    for t in possible_enders if t.starts_at == min_spine
                }
            else:
                min_spine = len(spine) - 1
                possible_enders = set()
            x.ends_at = min_spine
            x.possible_end_anchors = possible_enders

        self.currently_viewed_entry = None
示例#2
0
    def update_usb_devices(self):
        model = QStandardItemModel()
        bus = dbus.SystemBus()
        self.iface = 'org.freedesktop.DBus.ObjectManager'
        #bus.add_signal_receiver(self.callback_function, signal, iface)
        proxy = bus.get_object("org.freedesktop.UDisks2",
                               "/org/freedesktop/UDisks2")
        self.iface = dbus.Interface(proxy, "org.freedesktop.UDisks2")

        self.iface.connect_to_signal('DeviceAdded', self.device_added_callback)
        self.iface.connect_to_signal('DeviceRemoved',
                                     self.device_removed_callback)
        self.iface.connect_to_signal('InterfacesAdded',
                                     self.device_changed_callback)

        dev1 = get_usb()
        items = get_usb()

        #for text, checked in items:
        for text in sorted(items):

            text_item = QStandardItem(text)
            #checked_item = QStandardItem()
            #checked_item.setData(QVariant(checked), Qt.CheckStateRole)
            model.appendRow(text_item)  #([text_item, checked_item])

        view = QTreeView()
        view.header().hide()
        view.setRootIsDecorated(False)

        combo = self.ui.comboBox_device
        combo.setView(view)
        combo.setModel(model)
        combo.show()
示例#3
0
    def projeto_branco(self):
        """Função responsável por reiniciar um projeto novo em branco"""

        self.dirProject = {}
        """
       Criação da variável que armazenará as informações da interface responsável pela árvore de projetos e listas
       """
        self.ui.treeView.setHeaderHidden(True)
        self.ui.treeView.setEditTriggers(
            QtWidgets.QAbstractItemView.NoEditTriggers)
        treeModel = QStandardItemModel()
        self.ui.treeView.setModel(treeModel)
        self.rootNode = treeModel.invisibleRootItem()

        self.ui.treeView.setExpandsOnDoubleClick(False)

        self.ui.actionSalvarProjeto.setEnabled(False)
        self.ui.salvarListaButton.setEnabled(False)
        self.ui.salvarProjetoButton.setEnabled(False)

        try:
            subwindow = self.ui.mdiArea.currentSubWindow()
            subwindow.close()
        except AttributeError:
            pass
示例#4
0
    def __init__(self, member_list, contacts, parent=None):
        super(MemberListWidget, self).__init__(parent)
        self.setMinimumSize(200, 600)
        self.user_home = os.path.expanduser('~')
        #self.setAcceptDrops(True)
        self.app_home = self.user_home + '/.wechat/'
        self.head_home = ("%s/heads" % (self.app_home))
        self.cache_home = ("%s/cache/" % (self.app_home))
        self.cache_image_home = "%s/image/" % (self.cache_home)
        self.contact_head_home = ("%s/contact/" % (self.head_home))
        self.default_head_icon = './resource/images/default.png'
        self.default_member_icon = './resource/images/webwxgeticon.png'
        self.members = member_list
        self.contacts = contacts
        #self.setWindowFlags(Qt.FramelessWindowHint)#|Qt.Popup
        self.membersTable = QTableView()
        self.membersTable.verticalHeader().setDefaultSectionSize(60)
        self.membersTable.verticalHeader().setVisible(False)
        self.membersTable.horizontalHeader().setDefaultSectionSize(60)
        self.membersTable.horizontalHeader().setVisible(False)
        #More
        self.more = QPushButton(wechatutil.unicode('顯示更多'))
        self.verticalSpacer = QSpacerItem(20, 20, QSizePolicy.Minimum,
                                          QSizePolicy.Expanding)

        self.membersTableModel = QStandardItemModel(0, 4)
        self.initinal_member_list_widget(self.members)
        mainLayout = QVBoxLayout()
        mainLayout.addWidget(self.membersTable)
        mainLayout.addWidget(self.more)
        mainLayout.addItem(self.verticalSpacer)
        self.setLayout(mainLayout)
示例#5
0
    def initialise (self, univers):
        model = QStandardItemModel (3,1)
    
        i = 0
        for faction in univers.faction_list :
            item = QStandardItem(faction.name)
            item.setFlags(QtCore.Qt.ItemIsUserCheckable | QtCore.Qt.ItemIsEnabled);
            item.setData(QtCore.Qt.Unchecked, QtCore.Qt.CheckStateRole);

            model.setItem(i, 0, item)
            i = i + 1

        combo = QComboBox()
        combo.setModel(model)

        list_v = QListView()
        list_v.setModel(model)

        table = QTableView()
        table.setModel(model)

        container = QWidget()
        containerLayout = QVBoxLayout()
        container.setLayout(containerLayout)
        containerLayout.addWidget(combo)
        containerLayout.addWidget(list_v)
        containerLayout.addWidget(table)
 def displaysql(self):
     db = pymysql.connect("localhost",
                          "root",
                          "123456",
                          "flowdata",
                          charset="UTF8")
     cursor = db.cursor()
     cursor.execute("SELECT *FROM ANOMALYTYPE")
     rows = cursor.fetchall()
     if rows != ():
         row = cursor.rowcount  # 取得记录个数,用于设置表格的行数
         vol = len(rows[0])  # 取得字段数,用于设置表格的列数
         cursor.close()
         db.close()
         self.model = QStandardItemModel()
         self.model.setHorizontalHeaderLabels(
             ['异常发生时间', '异常流量源地址', '异常流量目的地址', '异常流量类型'])
         self.tableView.horizontalHeader().setStretchLastSection(True)
         self.tableView.horizontalHeader().setSectionResizeMode(
             QHeaderView.Stretch)
         for i in range(row):
             for j in range(vol):
                 temp_data = rows[i][j]
                 data = QStandardItem("%s" % (str(temp_data)))
                 self.model.setItem(i, j, data)
         self.tableView.setModel(self.model)
     else:
         cursor.close()
         db.close()
示例#7
0
    def __init__(self, id_dict: dict, name_dict: dict, parent=None):
        """
        Supers QComboBox, but also creates class references to the categories dictionaries.

        Args:
            id_dict: Categories dictionary with id numbers as keys.
            name_dict: Categories dictionary with names as keys.
            parent: Widget parent.
        """
        super().__init__()
        self.id_dict = id_dict
        self.name_dict = name_dict
        cat_list = sorted(list(self.name_dict.keys()))
        self.fill_combo(cat_list)

        model = QStandardItemModel()
        for i, word in enumerate(cat_list):
            item = QStandardItem(word)
            model.setItem(i, 0, item)

        self.setModel(model)
        self.setModelColumn(0)

        if parent is not None:
            self.setParent(parent)
示例#8
0
 def __init__(self,member_list,parent = None):
     super(ContactListWindow,self).__init__(parent)
     self.setModal(True)
     self.user_home = os.path.expanduser('~')
     self.app_home = self.user_home + '/.wechat/'
     self.head_home = ("%s/heads"%(self.app_home))
     self.cache_home = ("%s/cache/"%(self.app_home))
     self.cache_image_home = "%s/image/"%(self.cache_home)
     self.contact_head_home = ("%s/contact/"%(self.head_home))
     self.default_head_icon = './resource/images/default.png'
     self.members = member_list
     self.membersTable = QTableView()
     self.membersTable.horizontalHeader().setStretchLastSection(True)
     self.membersTable.verticalHeader().setDefaultSectionSize(60)
     #self.membersTable.horizontalHeader().setDefaultSectionSize(60)
     self.membersTable.setColumnWidth(0, 10);
     self.membersTable.setColumnWidth(1, 60);
     self.membersTable.verticalHeader().setVisible(False)
     self.membersTable.horizontalHeader().setVisible(False)
     #confirm
     self.confirm = QPushButton(wechatutil.unicode("確定"),self)
     self.membersTableModel = QStandardItemModel(0,2)
     self.membersTableModel.itemChanged.connect(self.itemChanged)
     self.initinal_member_list_widget()
     mainLayout=QVBoxLayout()
     mainLayout.addWidget(self.membersTable)
     mainLayout.addWidget(self.confirm)
     self.setLayout(mainLayout)
     #self.membersTable.clicked.connect(self.contact_item_clicked)
     self.confirm.clicked.connect(self.do_confirm)
     self.selectedRowCount = 0
示例#9
0
 def init_topic_tracklist(self):
     self.topic_tracklist = QListView()
     self.topic_tracklist_label = QLabel("Topic Track List")
     self.topic_tracklist_model = QStandardItemModel()
     self.topic_tracklist.setModel(self.topic_tracklist_model)
     topic_tracklist_buttons = QWidget()
     topic_tracklist_buttons_layout = QHBoxLayout()
     topic_tracklist_buttons_layout.setSpacing(0)
     topic_tracklist_buttons_layout.setContentsMargins(0, 0, 0, 0)
     topic_tracklist_buttons.setLayout(topic_tracklist_buttons_layout)
     self.topic_tracklist_add_button = QPushButton("+")
     self.topic_tracklist_del_button = QPushButton("-")
     self.topic_tracklist_conf_button = QPushButton("confirm")
     self.topic_analyze_button = QPushButton("analyze")
     topic_tracklist_buttons_layout.addWidget(
         self.topic_tracklist_add_button)
     topic_tracklist_buttons_layout.addWidget(
         self.topic_tracklist_del_button)
     topic_tracklist_buttons_layout.addStretch(20)
     topic_tracklist_buttons_layout.addWidget(
         self.topic_tracklist_conf_button)
     topic_tracklist_buttons_layout.addWidget(self.topic_analyze_button)
     topic_tracklist_buttons_layout.setStretch(0, 6)
     topic_tracklist_buttons_layout.setStretch(1, 6)
     topic_tracklist_buttons_layout.setStretch(2, 6)
     topic_tracklist_buttons_layout.setStretch(3, 6)
     self.topic_tracklist_widget = QWidget()
     topic_tracklist_layout = QVBoxLayout()
     self.topic_tracklist_widget.setLayout(topic_tracklist_layout)
     topic_tracklist_layout.addWidget(self.topic_tracklist_label)
     topic_tracklist_layout.addWidget(self.topic_tracklist)
     topic_tracklist_layout.addWidget(topic_tracklist_buttons)
示例#10
0
    def __init__(self, obj_map):
        self.obj_map = obj_map
        super().__init__()
        self.setWindowTitle("Object File Browser")
        self.childen_windows = []
        layout = QVBoxLayout()
        monospaced_font = get_monospaced_font()

        layout.addWidget(QLabel("Browse object files by dgo..."))

        # Set up the tree view
        self.tree = QTreeView()
        self.tree_model = QStandardItemModel()
        self.tree_root = self.tree_model.invisibleRootItem()
        for dgo_name, dgo in obj_map.dgo_files.items():
            dgo_entry = QStandardItem(dgo_name)
            dgo_entry.setFont(monospaced_font)
            dgo_entry.setEditable(False)
            for obj_name, obj in dgo.obj_files.items():
                obj_entry = QStandardItem(obj_name)
                obj_entry.setFont(monospaced_font)
                obj_entry.setEditable(False)
                dgo_entry.appendRow(obj_entry)
            self.tree_root.appendRow(dgo_entry)

        self.tree.setModel(self.tree_model)
        self.tree.clicked.connect(self.handle_tree_click)
        self.tree.doubleClicked.connect(self.handle_tree_double_click)
        layout.addWidget(self.tree)

        # Set up the Search Box
        layout.addWidget(QLabel("Or search for object (regex):"))
        self.search_box = QLineEdit()
        self.search_box.textChanged.connect(self.handle_search_change)
        layout.addWidget(self.search_box)

        # Set up Search Results
        self.search_result = QListView()
        layout.addWidget(self.search_result)
        self.search_result.clicked.connect(self.handle_search_result_click)
        self.search_result.doubleClicked.connect(
            self.handle_search_result_double_click)
        self.search_result.setMaximumHeight(200)

        # Set up the info box at the bottom
        self.text_box = QPlainTextEdit()
        self.text_box.setReadOnly(True)
        self.text_box.setFont(monospaced_font)
        layout.addWidget(self.text_box)
        self.text_box.setMaximumHeight(100)
        self.text_box.setPlainText(
            "Select an object file to see details. Double click to open.")

        # add it to the window!
        widget = QWidget()
        widget.setLayout(layout)
        self.setCentralWidget(widget)
    def __init__(self, spine, book_title):
        QStandardItemModel.__init__(self)
        toc = []

        self.base_path = os.path.split(spine[0])[0]
        self.book_title = book_title
        self._spine_list = spine
        ## now populate the current notes 
        self.update_current_annotation_list()
    def __init__(self, spine, book_title):
        QStandardItemModel.__init__(self)
        toc = []

        self.base_path = os.path.split(spine[0])[0]
        self.book_title = book_title
        self._spine_list = spine
        ## now populate the current notes
        self.update_current_annotation_list()
示例#13
0
	def __init__(self, *args, **kwargs):
		super().__init__(*args, **kwargs)
		self.setupUi(self)

		self.materiallist = list()
		self.title = ['印刷材料', '印刷单价', '印刷数量']
		self.totalprice = 0
		self.model = QStandardItemModel()
		self.comboBox.addItems(['银行转账'])
		self.showTable()
示例#14
0
    def __init__(self):
        super().__init__()

        self.app_state = AppState()
        self.app_state.addAddItemListener(self._addItemListener)

        self.model = QStandardItemModel()
        self.model.setHeaderData(self._ITEM_NAME, Qt.Horizontal, "Name")
        self.model.setHeaderData(self._OPERATIONS, Qt.Horizontal, "Operations")
        self.model.itemChanged.connect(self._renameListener)
        self.initUI()
示例#15
0
    def handle_search_change(self, text):
        objs = self.obj_map.get_objs_matching_regex(text)
        model = QStandardItemModel()
        root = model.invisibleRootItem()
        monospaced_font = get_monospaced_font()

        for x in objs:
            entry = QStandardItem(x)
            entry.setFont(monospaced_font)
            entry.setEditable(False)
            root.appendRow(entry)
        self.search_result.setModel(model)
示例#16
0
 def __init__(self, toc=None):
     QStandardItemModel.__init__(self)
     self.current_query = {'text':'', 'index':-1, 'items':()}
     self.all_items = depth_first = []
     normal_font = QApplication.instance().font()
     emphasis_font = QFont(normal_font)
     emphasis_font.setBold(True), emphasis_font.setItalic(True)
     if toc:
         for t in toc['children']:
             self.appendRow(TOCItem(t, 0, depth_first, normal_font, emphasis_font))
     self.node_id_map = {x.node_id: x for x in self.all_items}
     self.currently_viewed_entry = None
示例#17
0
    def __init__(self, tree):
        self.tree = tree

        self.model = QStandardItemModel()
        self.rootNode = self.model.invisibleRootItem()

        self.tree.setModel(self.model)
        self.tree.setHeaderHidden(True)
        self.tree.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)

        self.tree.clicked.connect(lambda: self.oneClickedEvent())
        self.tree.customContextMenuRequested.connect(self.openTreeMenu)
示例#18
0
文件: __init__.py 项目: aaronschif/sp
    def __init__(self):
        super().__init__()

        model = QStandardItemModel()

        for x in range(10):
            item = QStandardItem('Foo' + str(x))
            item.setChild(0, QStandardItem('Zoo'))
            model.insertRow(0, item)

        # model.setItem(2, 2, QStandardItem('Bar'))
        self.setModel(model)
        self.setHeaderHidden(True)
示例#19
0
    def initUI(self):
        layout = QGridLayout()
        layout.setSpacing(10)
        self.loginLabel = QLabel("邮箱:")
        self.loginLabel.setAlignment(Qt.AlignRight)
        self.loginLabel.setStyleSheet("color:rgb(20,20,20,255);font-size:16px;font-weight:bold:text")

        self.loginTxt = QLineEdit()
        self.loginTxt.setText("admin")
        self.loginTxt.setPlaceholderText("User Name")
        self.loginTxt.setClearButtonEnabled(True)
        self.loginTxt.textChanged.connect(self.on_loginTxt_textChanged)  # 绑定槽函数
        self.m_model = QStandardItemModel(0, 1, self)
        m_completer = QCompleter(self.m_model, self)
        self.loginTxt.setCompleter(m_completer)
        m_completer.activated[str].connect(self.onTxtChoosed)

        self.pwdLabel = QLabel("密码:")
        self.pwdLabel.setAlignment(Qt.AlignRight)
        self.pwdTxt = QLineEdit()
        self.pwdTxt.setContextMenuPolicy(Qt.NoContextMenu)  # 禁止复制粘贴
        self.pwdTxt.setPlaceholderText("Password")
        self.pwdTxt.setText("admin")
        self.pwdTxt.setEchoMode(QLineEdit.Password)
        self.pwdTxt.setClearButtonEnabled(True)
        self.registeredBtn = QPushButton("注册")
        self.loginBtn = QPushButton("登陆")

        self.headLabel = QLabel("用户登陆")
        self.headLabel.resize(300, 30)
        self.headLabel.setAlignment(Qt.AlignCenter)
        self.headLabel.setStyleSheet("color:rgb(10,10,10,255);font-size:25px;font-weight:bold;font-family:Roman times;")

        self.headLabel.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        layout.addWidget(self.headLabel, 0, 0, 1, 2)
        policy = self.headLabel.sizePolicy()
        print(policy.verticalPolicy())
        policy.setVerticalPolicy(1)
        print(policy.verticalPolicy())
        # policy.setVerticalPolicy(1)
        layout.addWidget(self.loginLabel, 1, 0)
        layout.addWidget(self.loginTxt, 1, 1)
        layout.addWidget(self.pwdLabel, 2, 0)
        layout.addWidget(self.pwdTxt, 2, 1)
        layout.addWidget(self.registeredBtn, 3, 0)
        layout.addWidget(self.loginBtn, 3, 1)

        frame = QFrame(self)
        frame.setLayout(layout)
        self.setCentralWidget(frame)
        self.resize(300, 150)
示例#20
0
 def create_data_model(self, parent):
     model = QStandardItemModel(0, 4, parent)
     model.setHeaderData(self.CB, Qt.Horizontal, "1")
     model.setHeaderData(self.ONE, Qt.Horizontal, "2")
     model.setHeaderData(self.TWO, Qt.Horizontal, "3")
     model.setHeaderData(self.THREE, Qt.Horizontal, "4")
     return model
示例#21
0
    def initUI(self):
        self.setWindowTitle("标注工具")
        self.label_log.setText("")

        from mylabel import MyLabel, SemiLabel

        # 将响应函数绑定在按钮上
        self.btn_open.clicked.connect(self.on_open_dir)
        self.btn_next.clicked.connect(self.on_next_image)
        self.btn_pre.clicked.connect(self.on_pre_image)
        self.btn_save.clicked.connect(self.on_save)

        # 目录树
        self.model = QStandardItemModel(0, 1, self)
        self.model.setHeaderData(0, Qt.Horizontal, "文件路径")
        self.treeView.setModel(self.model)
        self.treeView.clicked.connect(self.tree_clicked)

        # 全手动
        self.lb = MyLabel(self.tab_manu)
        self.lb.setGeometry(QRect(10, 10, 760, 540))
        self.radio_poly.setChecked(True)
        self.button_group = QtWidgets.QButtonGroup(self)
        self.button_group.addButton(self.radio_rect)
        self.button_group.addButton(self.radio_poly)

        # 半自动
        self.mylabel_rgb_semi = SemiLabel(self.tab_semi)
        self.mylabel_rgb_semi.setGeometry(QRect(30, 150, 320, 240))
        self.label_rgb_semi.setText("")
        self.label_mask_semi.setText("")
        self.label_curmarker_semi.setText("current_marker: " + "1")

        # 全自动
        self.label_rgbtfusion_auto.setText("")
        self.label_registered_auto.setText("")
        self.label_mask_auto.setText("")
        self.mylabel_registered_auto = SemiLabel(self.tab_auto)
        self.mylabel_registered_auto.setGeometry(QRect(40, 290, 320, 240))
        self.label_curmarker_auto.setText("current_marker: " + "1")
        self.boundary_points = []

        # self.radio_semi_auto.setChecked(True)
        # self.group_auto = QtWidgets.QButtonGroup(self)
        # self.group_auto.addButton(self.radio_semi_auto)
        # self.group_auto.addButton(self.radio_auto_auto)

        self.cur_img_ann = {}
        self.show()
示例#22
0
class StandardTree(ABC):
    def __init__(self, tree):
        self.tree = tree

        self.model = QStandardItemModel()
        self.rootNode = self.model.invisibleRootItem()

        self.tree.setModel(self.model)
        self.tree.setHeaderHidden(True)
        self.tree.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)

        self.tree.clicked.connect(lambda: self.oneClickedEvent())
        self.tree.customContextMenuRequested.connect(self.openTreeMenu)

    @abstractmethod
    def oneClickedEvent(self):
        pass

    def openTreeMenu(self, point):
        __index = self.tree.selectionModel().currentIndex()
        menu = QtWidgets.QMenu()
        with open("static/qcss/styleMenu.css", "r") as f:
            menu.setStyleSheet(f.read())
        self.checkMenu(__index, menu)
        menu.exec(self.tree.viewport().mapToGlobal(point))

    @abstractmethod
    def checkMenu(self, index, menu):
        pass
示例#23
0
    def updatePhpVersionsTreeView(self):
        if len(self.availableReleases):
            data = self.loadingObj.groupByMinorRelease(
                self.availableReleases, self.latestPatchcheckBox.isChecked())
            treeModel = QStandardItemModel()
            rootNode = treeModel.invisibleRootItem()

            for name, group in data.items():
                version = StandardItem("PHP " + name)
                version.setSelectable(False)
                rootNode.appendRow(version)

                for n, v in group:
                    r = StandardItem(n)
                    version.appendRow(r)

            self.phpVersionsTreeView.setModel(treeModel)
示例#24
0
    def createmtSettingPanel(self):
        UUIDdelegate = toolbox.UUIDLineEditDelegate(
            self.translate("InboundMtPanel", "Gerate UUID"))

        self.model = QStandardItemModel(0, 3)
        self.tableViewInMtUser = tableViewUser = QTableView(self)
        tableViewUser.setModel(self.model)
        self.model.setHorizontalHeaderLabels(self.labelUsermtPanel)
        tableViewUser.setSelectionMode(QAbstractItemView.SingleSelection)
        tableViewUser.setSelectionBehavior(QAbstractItemView.SelectRows)

        tableViewUser.setItemDelegateForColumn(2, UUIDdelegate)

        self.btnInMtNew = QPushButton(
            self.translate("InboundMtPanel", "New"), self)
        self.btnInMtDelete = QPushButton(
            self.translate("InboundMtPanel", "Delete"), self)
        
        self.btnGroup = QButtonGroup()
        self.btnGroup.addButton(self.btnInMtNew)
        self.btnGroup.addButton(self.btnInMtDelete)
        
        vboxBtn = QVBoxLayout()
        vboxBtn.addWidget(QLabel())
        vboxBtn.addWidget(QLabel())
        vboxBtn.addWidget(QLabel())
        vboxBtn.addWidget(self.btnInMtNew)
        vboxBtn.addWidget(self.btnInMtDelete)
        
        hbox = QHBoxLayout()
        hbox.addWidget(tableViewUser)
        hbox.addLayout(vboxBtn)
        
        self.groupInboudnMtPanel = QGroupBox(
            self.translate("InboundMtPanel", "MTProto"), self)
        self.groupInboudnMtPanel.setLayout(hbox)
        
        self.createInboundMtPanelSignals()

        if (v2rayshellDebug):
            self.__debugBtn = QPushButton("__debugTest", self)
            vboxBtn.addWidget(self.__debugBtn)
            self.__debugBtn.clicked.connect(self.__debugTest)
            self.settingInboundMtPanelFromJSONFile(self.mtJSONFile, True)
        
        return self.groupInboudnMtPanel
示例#25
0
class ItemList(QWidget):

    _ITEM_NAME, _OPERATIONS = range(2)

    def __init__(self):
        super().__init__()

        self.app_state = AppState()
        self.app_state.addAddItemListener(self._addItemListener)

        self.model = QStandardItemModel()
        self.model.setHeaderData(self._ITEM_NAME, Qt.Horizontal, "Name")
        self.model.setHeaderData(self._OPERATIONS, Qt.Horizontal, "Operations")
        self.model.itemChanged.connect(self._renameListener)
        self.initUI()

    def initUI(self):
        grid = QGridLayout()
        self.setLayout(grid)

        self.tree_view = QTreeView()
        self.tree_view.setModel(self.model)
        self.tree_view.clicked.connect(self._selectedItemListener)

        grid.addWidget(self.tree_view, 0, 0, 19, 1)

        self.load_data_button = QPushButton('Load Data')
        self.load_data_button.clicked.connect(self._loadDatauttonListener)
        grid.addWidget(self.load_data_button, 20, 0, 1, 1)

    #Private
    def _getItemKey(self, item):
        return self.model.itemData(item)[257]

    #Event Handlers
    def _selectedItemListener(self, event):
        key = self._getItemKey(self.tree_view.currentIndex())
        self.app_state.setCurrentItem(key)

    def _loadDatauttonListener(self):
        file_path, file_types = QFileDialog.getOpenFileName(
            self, 'Open file', os.path.expanduser("~"))
        if (len(file_path) <= 0):
            return

        item_data = Loader.load(file_path)
        self.app_state.addItem(item_data)

    #Called when a new item is added to the AppState
    def _addItemListener(self, key, item_data):
        item = QStandardItem(item_data.name)
        item.setData(key)  # Set my custom index as a payload
        item.setSelectable(True)
        item.setEditable(True)
        self.model.appendRow(item)

    def _renameListener(self, item):
        key = item.data()
        self.app_state.renameItemAt(key, item.text())
示例#26
0
    def create_model(self, data):
        def addItems(parent, elements, t=""):
            for xref, name in elements:
                item = QStandardItem(name)
                data = xref
                item.setData(data)
                parent.appendRow(item)

        model = QStandardItemModel(self)
        addItems(model, data)
        self.setModel(model)
示例#27
0
    def createFieldsUI(self):
        # Button
        buttons = QtWidgets.QHBoxLayout()
        new = QtWidgets.QPushButton("New")
        new.setMaximumWidth(100)
        new.clicked.connect(self.newField)

        delete = QtWidgets.QPushButton("Delete")
        delete.setMaximumWidth(100)
        delete.clicked.connect(self.deleteFieldSelected)
        buttons.addWidget(new)

        buttons.addWidget(delete)
        self.Fields.addLayout(buttons)

        # Model
        self.FieldsModel = QStandardItemModel()
        self.FieldsModel.setHorizontalHeaderLabels(
            ["Name", "R/W", "bitStart", "bitEnd", "type", "Title", "Description", "Register"])
        self.FieldsModel.itemChanged.connect(self.FieldsItemChanged)
        self.FieldsTreeRoot = self.FieldsModel.invisibleRootItem()

        # TreeView
        self.FieldTree = QtWidgets.QTreeView()
        self.FieldTree.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
        self.FieldTree.setModel(self.FieldsModel)
        self.FieldTree.setUniformRowHeights(True)
        self.FieldTree.setColumnWidth(0, 200)
        self.FieldTree.setColumnWidth(1, 70)
        self.FieldTree.setColumnWidth(2, 70)
        self.FieldTree.setColumnWidth(3, 70)

        self.FieldTree.setItemDelegateForColumn(1,FieldReadWriteDelegate(self.FieldTree))
        self.FieldTree.setItemDelegateForColumn(2,FieldBitStartDelegate(self.FieldTree))
        self.FieldTree.setItemDelegateForColumn(3,FieldBitEndDelegate(self.FieldTree))
        self.FieldTree.setItemDelegateForColumn(4,FieldTypeDelegate(self.FieldTree))


        self.FieldTree.setItemDelegateForColumn(7,FieldRegisterDelegate(self.FieldTree, self.getRegisterNames))

        self.Fields.addWidget(self.FieldTree)
示例#28
0
    def createRegistersUI(self):
        #Button
        buttons = QtWidgets.QHBoxLayout()
        new = QtWidgets.QPushButton("New")
        new.setMaximumWidth(100)
        new.clicked.connect(self.newRegister)
        edit = QtWidgets.QPushButton("Edit")
        edit.setMaximumWidth(100)
        edit.clicked.connect(self.editRegisterSelected)
        delete = QtWidgets.QPushButton("Delete")
        delete.setMaximumWidth(100)
        delete.clicked.connect(self.deleteRegisterSelected)
        buttons.addWidget(new)
        buttons.addWidget(edit)
        buttons.addWidget(delete)
        self.Registers.addLayout(buttons)

        #Model
        self.RegistersModel = QStandardItemModel()
        self.RegistersModel.setHorizontalHeaderLabels(["Name", "Address", "Length", "Signed", "R/W", "Title", "Description"])
        self.RegistersModel.itemChanged.connect(self.RegistersItemChanged)
        self.RegistersTreeRoot = self.RegistersModel.invisibleRootItem()


        # TreeView
        self.RegisterTree = QtWidgets.QTreeView()
        self.RegisterTree.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
        self.RegisterTree.setModel(self.RegistersModel)
        self.RegisterTree.setUniformRowHeights(True)
        self.RegisterTree.setColumnWidth(0, 200)
        self.RegisterTree.setColumnWidth(1, 70)
        self.RegisterTree.setColumnWidth(2, 70)
        self.RegisterTree.setColumnWidth(3, 70)
        self.RegisterTree.setColumnWidth(4, 70)

        self.RegisterTree.setItemDelegateForColumn(1,RegisterAddressDelegate(self.RegisterTree))
        self.RegisterTree.setItemDelegateForColumn(2,RegisterLengthDelegate(self.RegisterTree))
        self.RegisterTree.setItemDelegateForColumn(3, RegisterSignedDelegate(self.RegisterTree))
        self.RegisterTree.setItemDelegateForColumn(4, RegisterReadWriteDelegate(self.RegisterTree))

        self.Registers.addWidget(self.RegisterTree)
示例#29
0
    def abrir_projeto(self):
        """Função responsável por abrir um novo projeto na janela principal.
        """
        """
        Todas informações atuais da árvore são apagadas para abrir o arquivo desejado
        """
        treeModel = QStandardItemModel()
        self.ui.treeView.setModel(treeModel)
        self.rootNode = treeModel.invisibleRootItem()

        # As informações antigas do dicionário de projetos são removidas

        # A variável 'fileinfo' armazena o caminho do arquivo que deseja-se abrir
        fileinfo, _ = QtWidgets.QFileDialog.getOpenFileName(
            self, 'Abrir', '', '*.xml')
        if not fileinfo:
            return
        filename = os.path.basename(fileinfo)
        filepath = os.path.dirname(fileinfo)

        # Se o usuário clicou escolheu um arquivo, a função carrega_xml da classe XMLFile é chamada para então carregar
        # o arquivo .xml selecionado com os seus respectivos projetos, listas e linhas criadas pelo usuário
        # A variável 'flag' é utiliza para verificar se o arquivo .xml é consistente, retornando -1 caso seja inválido e
        # retornando 1 caso seja válido.
        flag = XMLFile.carrega_xml(self, filename, filepath)

        if flag == -1:
            QtWidgets.QMessageBox.warning(self, "Aviso", "XML Inválido")
        else:
            self.ui.actionSalvarProjeto.setEnabled(True)
            self.ui.salvarListaButton.setEnabled(True)
            self.ui.salvarProjetoButton.setEnabled(True)

            # A nova árvore aberta então é expandida e qualquer projeto antigo aberto é fechado
            self.ui.treeView.expandAll()

            try:
                subwindow = self.ui.mdiArea.currentSubWindow()
                subwindow.close()
            except AttributeError:
                pass
示例#30
0
    def update_filename_box(self):
        doing_multiple = self.doing_multiple

        model = QStandardItemModel()
        self.filename_box.setModel(model)
        self.icon_file_names.sort(key=sort_key)
        if doing_multiple:
            item = QStandardItem(_('Open to see checkboxes'))
            item.setIcon(QIcon(I('blank.png')))
        else:
            item = QStandardItem('')
        item.setFlags(Qt.ItemFlag(0))
        model.appendRow(item)

        for i, filename in enumerate(self.icon_file_names):
            item = QStandardItem(filename)
            if doing_multiple:
                item.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled)
                item.setData(Qt.Unchecked, Qt.CheckStateRole)
            else:
                item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable)
            icon = QIcon(
                QPixmap(os.path.join(self.icon_folder, filename)).scaled(
                    self.filenamebox_view.iconSize(),
                    transformMode=Qt.SmoothTransformation))
            item.setIcon(icon)
            model.appendRow(item)
示例#31
0
    def init_weibo_tracklist(self):
        self.weibo_tracklist = QListView()
        self.weibo_tracklist_label = QLabel("Weibo Track List")
        self.weibo_tracklist_model = QStandardItemModel()
        self.weibo_tracklist.setModel(self.weibo_tracklist_model)
        weibo_tracklist_buttons = QWidget()
        weibo_tracklist_buttons_layout = QHBoxLayout()
        weibo_tracklist_buttons_layout.setSpacing(0)
        weibo_tracklist_buttons_layout.setContentsMargins(0, 0, 0, 0)
        weibo_tracklist_buttons.setLayout(weibo_tracklist_buttons_layout)
        self.weibo_tracklist_add_button = QPushButton("+")
        self.weibo_tracklist_del_button = QPushButton("-")
        self.weibo_tracklist_conf_button = QPushButton("confirm")
        self.weibo_analyze_button = QPushButton("analyze")
        weibo_tracklist_buttons_layout.addWidget(
            self.weibo_tracklist_add_button)
        weibo_tracklist_buttons_layout.addWidget(
            self.weibo_tracklist_del_button)
        weibo_tracklist_buttons_layout.addStretch(20)
        weibo_tracklist_buttons_layout.addWidget(
            self.weibo_tracklist_conf_button)
        weibo_tracklist_buttons_layout.addWidget(self.weibo_analyze_button)
        weibo_tracklist_buttons_layout.setStretch(0, 6)
        weibo_tracklist_buttons_layout.setStretch(1, 6)
        weibo_tracklist_buttons_layout.setStretch(2, 6)
        weibo_tracklist_buttons_layout.setStretch(3, 6)

        self.weibo_sentiment_checkbox = QCheckBox("Comment Sentimnet")
        weibo_analyze_options = QWidget()
        weibo_analyze_options_layout = QHBoxLayout()
        weibo_analyze_options.setLayout(weibo_analyze_options_layout)
        weibo_analyze_options_layout.addWidget(self.weibo_sentiment_checkbox)

        self.weibo_tracklist_widget = QWidget()
        weibo_tracklist_layout = QVBoxLayout()
        self.weibo_tracklist_widget.setLayout(weibo_tracklist_layout)
        weibo_tracklist_layout.addWidget(self.weibo_tracklist_label)
        weibo_tracklist_layout.addWidget(self.weibo_tracklist)
        weibo_tracklist_layout.addWidget(weibo_tracklist_buttons)
        weibo_tracklist_layout.addWidget(weibo_analyze_options)
示例#32
0
    def update_filename_box(self):
        doing_multiple = self.doing_multiple

        model = QStandardItemModel()
        self.filename_box.setModel(model)
        self.icon_file_names.sort(key=sort_key)
        if doing_multiple:
            item = QStandardItem(_('Open to see checkboxes'))
        else:
            item = QStandardItem('')
        model.appendRow(item)

        for i,filename in enumerate(self.icon_file_names):
            item = QStandardItem(filename)
            if doing_multiple:
                item.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled)
                item.setData(Qt.Unchecked, Qt.CheckStateRole)
            else:
                item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable)
            icon = QIcon(os.path.join(self.icon_folder, filename))
            item.setIcon(icon)
            model.appendRow(item)
示例#33
0
 def set_tableView(self):
     """
     设置表格格式
     :return:
     """
     # 设置数据层次结构,4行4列
     self.model = QStandardItemModel(0, 4)
     # 设置水平方向四个头标签文本内容
     self.model.setHorizontalHeaderLabels(
         ['编号', '重量(g)', '单价(元/g)', '金额(元)'])
     self.tableView.setModel(self.model)
     # 水平方向标签拓展剩下的窗口部分,填满表格
     self.tableView.horizontalHeader().setStretchLastSection(True)
     self.tableView.horizontalHeader().setSectionResizeMode(
         QHeaderView.Stretch)  # 水平方向,表格大小拓展到适当的尺寸
     # self.tableView.setRowHeight(0,60) #设置行高
     self.tableView.setShowGrid(False)  #不显示网格
     # self.tableView.setEnabled(False)
     self.tableView.setSelectionBehavior(
         QAbstractItemView.SelectRows)  #设置点击选择一整行
     self.tableView.verticalHeader().hide()  #隐藏行头
     self.tableView.setEditTriggers(
         QAbstractItemView.NoEditTriggers)  #单元格不可编辑
示例#34
0
文件: toc.py 项目: Cykooz/calibre
    def __init__(self, spine, toc=None):
        QStandardItemModel.__init__(self)
        if toc is None:
            toc = MTOC()
        self.all_items = depth_first = []
        for t in toc:
            self.appendRow(TOCItem(spine, t, 0, depth_first))

        for x in depth_first:
            possible_enders = [t for t in depth_first if t.depth <= x.depth
                    and t.starts_at >= x.starts_at and t is not x and t not in
                    x.ancestors]
            if possible_enders:
                min_spine = min(t.starts_at for t in possible_enders)
                possible_enders = {t.fragment for t in possible_enders if
                        t.starts_at == min_spine}
            else:
                min_spine = len(spine) - 1
                possible_enders = set()
            x.ends_at = min_spine
            x.possible_end_anchors = possible_enders

        self.currently_viewed_entry = None
示例#35
0
    def update_filename_box(self):
        doing_multiple = self.doing_multiple

        model = QStandardItemModel()
        self.filename_box.setModel(model)
        self.icon_file_names.sort(key=sort_key)
        if doing_multiple:
            item = QStandardItem(_('Open to see checkboxes'))
            item.setIcon(QIcon(I('blank.png')))
        else:
            item = QStandardItem('')
        item.setFlags(Qt.ItemFlag(0))
        model.appendRow(item)

        for i,filename in enumerate(self.icon_file_names):
            item = QStandardItem(filename)
            if doing_multiple:
                item.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled)
                item.setData(Qt.Unchecked, Qt.CheckStateRole)
            else:
                item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable)
            icon = QIcon(QPixmap(os.path.join(self.icon_folder, filename)).scaled(self.filenamebox_view.iconSize(), transformMode=Qt.SmoothTransformation))
            item.setIcon(icon)
            model.appendRow(item)
示例#36
0
 def init_crawl_widget(self):
     self.llayout = QVBoxLayout()
     self.crawl_widget.setLayout(self.llayout)
     self.log_label = QLabel("Log")
     self.log_list = QTableView()
     self.log_model = QStandardItemModel()
     self.log_model.setColumnCount(3)
     self.log_model.setHorizontalHeaderLabels(["Status", "Time", "Message"])
     self.log_list.setModel(self.log_model)
     self.log_list.horizontalHeader().setSectionResizeMode(
         QHeaderView.Stretch)
     self.log_list.horizontalHeader().setSectionResizeMode(
         0, QHeaderView.ResizeToContents)
     self.log_list.horizontalHeader().setSectionResizeMode(
         1, QHeaderView.ResizeToContents)
     self.log_list.horizontalHeader().setSectionResizeMode(
         2, QHeaderView.ResizeToContents)
     log_widget = QWidget()
     log_layout = QVBoxLayout()
     log_layout.addWidget(self.log_label)
     log_layout.addWidget(self.log_list)
     log_widget.setLayout(log_layout)
     self.rule_label = QLabel("Rule")
     self.rule_edit = QTextEdit()
     rule_widget = QWidget()
     rule_layout = QVBoxLayout()
     rule_layout.addWidget(self.rule_label)
     rule_layout.addWidget(self.rule_edit)
     rule_widget.setLayout(rule_layout)
     self.crawl_button = QPushButton('Crawl')
     self.llayout.addWidget(log_widget)
     self.llayout.addWidget(rule_widget)
     self.llayout.addWidget(self.crawl_button)
     self.llayout.setStretch(0, 15)
     self.llayout.setStretch(1, 6)
     self.llayout.setStretch(2, 1)
    def update_view(self, problems_data):
        """
        Update QTableView model and proxy filter

        :param problems_data: problems found in database
        :type problems_data: dict
        :return: proxy filter to connect with line edit
        :rtype: QSortFilterProxyModel
        """

        problems_model = QStandardItemModel()
        problems_model.setRowCount(len(problems_data['problems']))
        problems_model.setColumnCount(len(self.headers_list))

        if problems_data['problems']:
            for row, item in enumerate(problems_data['problems']):
                problems_model.setItem(row, 0, self.get_tableitem(item))
                problems_model.setItem(row, 1, self.get_output_tableitem(item))

        else:
            tableitem = QStandardItem('No problem to report.')

            icon = QIcon(settings.get_image('checked'))
            tableitem.setIcon(icon)
            tableitem.setTextAlignment(Qt.AlignCenter)
            problems_model.setItem(0, 0, tableitem)

        proxy_filter = QSortFilterProxyModel()
        proxy_filter.setFilterCaseSensitivity(Qt.CaseInsensitive)
        proxy_filter.setSourceModel(problems_model)

        problems_model.setHorizontalHeaderLabels(self.headers_list)

        self.setModel(proxy_filter)

        self.setColumnWidth(0, 500)
        self.setColumnWidth(1, 300)

        return proxy_filter