Beispiel #1
0
def test_standarditemmodel():
    model = gui.StandardItemModel()
    model.add("test")
    for item in model:
        pass
    with open("data.pkl", "wb") as jar:
        pickle.dump(model, jar)
    with open("data.pkl", "rb") as jar:
        model = pickle.load(jar)
    model += gui.StandardItem("Item")
    model[0]
    assert len(model.find_items("test")) == 1
    with pytest.raises(InvalidParamError):
        model.find_items("test", mode="wrong_mode")
    del model[0]
    model.add_item(
        "Test",
        icon="mdi.timer",
        data={1: "Test"},
        foreground=gui.Brush(),
        background=gui.Brush(),
        font=gui.Font(),
        selectable=True,
        status_tip="test",
        tool_tip="test",
        whats_this="test",
        checkstate="unchecked",
        size_hint=core.Size(10, 10),
        is_user_type=True,
    )
Beispiel #2
0
def test_standarditem():
    item = gui.StandardItem()
    with open("data.pkl", "wb") as jar:
        pickle.dump(item, jar)
    with open("data.pkl", "rb") as jar:
        item = pickle.load(jar)

    # item[constants.USER_ROLE] = "test"
    # assert item[constants.USER_ROLE] == "test"
    item.set_icon("mdi.timer")
    item.set_checkstate("unchecked")
    with pytest.raises(InvalidParamError):
        item.set_checkstate("test")
    assert item.get_checkstate() == "unchecked"
    item.get_background()
    item.get_foreground()
    item.get_font()
    item.get_icon()
    bytes(item)
    item.clone()
    item.add_item(
        "Test",
        icon="mdi.timer",
        data={1: "Test"},
        foreground=gui.Brush(),
        background=gui.Brush(),
        font=gui.Font(),
        selectable=True,
        status_tip="test",
        tool_tip="test",
        whats_this="test",
        checkstate="unchecked",
        size_hint=core.Size(10, 10),
        is_user_type=True,
    )
Beispiel #3
0
def test_standarditem():
    s = gui.StandardItem()
    with open("data.pkl", "wb") as jar:
        pickle.dump(s, jar)
    with open("data.pkl", "rb") as jar:
        s = pickle.load(jar)
    repr(s)
    s.set_icon("mdi.timer")
Beispiel #4
0
def test_standarditemmodel():
    model = gui.StandardItemModel()
    model.add("test")
    for item in model:
        pass
    with open("data.pkl", "wb") as jar:
        pickle.dump(model, jar)
    with open("data.pkl", "rb") as jar:
        model = pickle.load(jar)
    model += gui.StandardItem("Item")
Beispiel #5
0
 def add_item(
     self,
     name: str = "",
     icon: types.IconType = None,
     data: dict | None = None,
     foreground: QtGui.QBrush | None = None,
     background: QtGui.QBrush | None = None,
     font: QtGui.QFont | None = None,
     selectable: bool = True,
     enabled: bool = True,
     editable: bool = False,
     status_tip: str | None = None,
     tool_tip: str | None = None,
     whats_this: str | None = None,
     # text_alignment: Optional[str] = None,
     checkstate: constants.StateStr | None = None,
     flags: QtCore.Qt.ItemFlags | None = None,
     size_hint: types.SizeType | None = None,
     is_user_type: bool = False,
 ) -> gui.StandardItem:
     item = gui.StandardItem(name)
     if icon is not None:
         icon = iconprovider.get_icon(icon)
         item.setIcon(icon)
     if data is not None:
         for k, v in data.items():
             item.setData(v, k)
     if foreground is not None:
         item.setForeground(foreground)
     if background is not None:
         item.setBackground(background)
     if font is not None:
         item.setFont(font)
     if flags is not None:
         item.setFlags(flags)
     if enabled:
         item.setEnabled(enabled)
     if editable:
         item.setEditable(editable)
     if selectable:
         item.setSelectable(selectable)
     if status_tip:
         item.setStatusTip(status_tip)
     if tool_tip:
         item.setToolTip(tool_tip)
     if whats_this:
         item.setWhatsThis(whats_this)
     if size_hint is not None:
         item.set_size_hint(size_hint)
     if checkstate is not None:
         item.set_checkstate(checkstate)
     self.appendRow([item])
     return item
Beispiel #6
0
def test_standarditemmodel():
    model = gui.StandardItemModel()
    model.add("test")
    for item in model:
        pass
    with open("data.pkl", "wb") as jar:
        pickle.dump(model, jar)
    with open("data.pkl", "rb") as jar:
        model = pickle.load(jar)
    model += gui.StandardItem("Item")
    model[0]
    assert len(model.find_items("test")) == 1
    with pytest.raises(ValueError):
        model.find_items("test", mode="wrong_mode")
Beispiel #7
0
 def add(self, *item: str | QtGui.QStandardItem):
     for i in item:
         if isinstance(i, str):
             i = gui.StandardItem(i)
         self.appendRow([i])
Beispiel #8
0
        if whats_this:
            item.setWhatsThis(whats_this)
        if size_hint is not None:
            item.set_size_hint(size_hint)
        if checkstate is not None:
            item.set_checkstate(checkstate)
        self.appendRow([item])
        return item


if __name__ == "__main__":
    import pickle

    from prettyqt import widgets

    model = gui.StandardItemModel()
    model.add("test")
    app = widgets.app()
    w = widgets.ListView()
    w.set_model(model)
    model += gui.StandardItem("Item")
    for item in model:
        pass
    with open("data.pkl", "wb") as jar:
        pickle.dump(model, jar)
    with open("data.pkl", "rb") as jar:
        model = pickle.load(jar)
    model += gui.StandardItem("Item2")
    w.show()
    app.main_loop()
Beispiel #9
0
def test_standarditem():
    s = gui.StandardItem()
    with open("data.pkl", "wb") as jar:
        pickle.dump(s, jar)
    with open("data.pkl", "rb") as jar:
        s = pickle.load(jar)
 def add(self, item) -> int:
     if isinstance(item, str):
         item = gui.StandardItem(item)
     self.appendRow(item)
     return self.rowCount()
Beispiel #11
0
 def add_item(self, label):
     item = gui.StandardItem(label)
     self.appendRow(item)