Ejemplo n.º 1
0
class RadioButtonWidget(QtWidgets.QWidget):

    state = Binder()
    state.picked = ""

    def __init__(self):
        super(RadioButtonWidget, self).__init__()
        self.initialize()

    def initialize(self):
        layout = QtWidgets.QVBoxLayout()
        self.setLayout(layout)

        groupBox = QtWidgets.QGroupBox("Exclusive Radio Buttons")
        self.rb1 = QtWidgets.QRadioButton("One")
        self.rb2 = QtWidgets.QRadioButton("Two")

        h_layout = QtWidgets.QVBoxLayout()
        h_layout.addWidget(self.rb1)
        h_layout.addWidget(self.rb2)
        groupBox.setLayout(h_layout)

        self.label = QtWidgets.QLabel()
        layout.addWidget(groupBox)
        layout.addWidget(self.label)

        self.label.setText(lambda: "CheckedNames %s" % self.state.picked)

        for rb in groupBox.findChildren(QtWidgets.QRadioButton):
            rb.toggled.connect(self.updateRB)

    def updateRB(self, check):
        rb = self.sender()
        self.state.picked = rb.text()
Ejemplo n.º 2
0
class ListWidgetTest(QtWidgets.QWidget):

    state = Binder()
    state.selected = []

    def __init__(self):
        super(ListWidgetTest, self).__init__()
        self.initialize()

    def initialize(self):
        layout = QtWidgets.QVBoxLayout()
        self.setLayout(layout)

        self.listWidget = QtWidgets.QListWidget()
        self.listWidget.setSelectionMode(
            QtWidgets.QListWidget.ExtendedSelection)
        self.listWidget.addItems(["A", "B", "C"])

        self.label = QtWidgets.QLabel()
        layout.addWidget(self.listWidget)
        layout.addWidget(self.label)

        self.label.setText(lambda: "Selected: %s" % self.state.selected)

        self.listWidget.itemSelectionChanged.connect(self.update)

    def update(self):
        self.state.selected = [
            item.text() for item in self.listWidget.selectedItems()
        ]
Ejemplo n.º 3
0
class TodoItem(QtWidgets.QWidget):

    state = Binder()

    @inject(state)
    def __init__(self):
        super(TodoItem, self).__init__()

        # NOTE disable auto load feature
        dumper = self.state("dumper")
        dumper.set_auto_load(False)
        self.state.text = "a"
        self.state.completed = False
        self.state.visible = False
        self.state.text_style = "none"
        self.state.text_color = "black"

        # TODO uifile loading custom module not compatible in DCC
        ui_file = os.path.join(__file__, "..", "item.ui")
        loadUi(ui_file, self)
        # self.setupUi(self)

        self.ItemText.bind(self)
        self.ItemText.setText(lambda: self.state.text)
        self.ItemText.setStyleSheet(
            lambda: "color:%s;text-decoration:%s"
            % (self.state.text_color, self.state.text_style)
        )
        self.ItemDelete.setVisible(lambda: self.state.visible)
        self.ItemCheck.setChecked(lambda: self.state.completed)

        self.state["completed"].connect(self.completedChanged)
        self.state["completed"].connect(gstate.update_count)

        self.ItemDelete.clicked.connect(lambda: gstate.todo_data.pop(self.__index__))

    def __item__(self, index, data, layout):
        self.__index__ = index

    def completedChanged(self):
        completed = self.state.completed
        self.state.text_style = "line-through" if completed else "none"
        self.state.text_color = "gray" if completed else "black"
        if gstate.todo_data[self.__index__]["completed"] != completed:
            gstate.todo_data[self.__index__]["completed"] = completed

    def setCompleted(self, completed):
        self.state.completed = completed

    def setText(self, text):
        self.state.text = text

    def enterEvent(self, event):
        self.state.visible = True

    def leaveEvent(self, event):
        self.state.visible = False
Ejemplo n.º 4
0
class WidgetTest(QtWidgets.QWidget):
    state = Binder()
    state.text = "aasdsd"
    state.num = 1
    state.val = 2.0
    state.color = "black"
    state.spin_color = "black"

    def __init__(self):
        super(WidgetTest, self).__init__()
        self.initialize()

    def initialize(self):
        layout = QtWidgets.QVBoxLayout()
        self.setLayout(layout)

        self.edit = QtWidgets.QLineEdit()
        self.label = QtWidgets.QLabel()
        self.button = QtWidgets.QPushButton("change Text")
        layout.addWidget(self.edit)
        layout.addWidget(self.label)
        layout.addWidget(self.button)

        self.button.clicked.connect(lambda: self.state.text >> Set("asd"))
        self.edit.setText(lambda: self.state.text)
        self.label.setText(lambda: "message is %s" % self.state.text)

        event_hook.add_hook(self.edit, QtCore.QEvent.FocusIn,
                            lambda: self.state.color >> Set("red"))
        event_hook.add_hook(self.edit, QtCore.QEvent.FocusOut,
                            lambda: self.state.color >> Set("black"))
        self.label.setStyleSheet(lambda: "color:%s" % self.state.color)

        self.spin = QtWidgets.QSpinBox(self)
        self.label = QtWidgets.QLabel()
        layout.addWidget(self.spin)
        layout.addWidget(self.label)
        self.spin.setValue(lambda: self.state.num)
        self.label.setText(lambda: "num is %s" % self.state.num)

        self.spin >> event_hook("HoverEnter",
                                lambda: self.state.spin_color >> Set("pink"))
        self.spin >> event_hook("HoverLeave",
                                lambda: self.state.spin_color >> Set("blue"))
        self.label.setStyleSheet(lambda: "color:%s" % self.state.spin_color)

        self.spin = QtWidgets.QDoubleSpinBox(self)
        self.label = QtWidgets.QLabel()
        layout.addWidget(self.spin)
        layout.addWidget(self.label)
        self.spin.setValue(lambda: self.state.val)
        self.label.setText(lambda: "val is %s" % self.state.val)
Ejemplo n.º 5
0
class ComboTest(QtWidgets.QWidget):

    state = Binder()
    state.text = "asd"
    state.text2 = "asd"
    state.num = 123
    state.enable = True
    # state.data_list = Model([state.text2, state.enable])
    state.data_list = Model([state["text2"], state["enable"]])

    def __init__(self):
        super(ComboTest, self).__init__()
        self.initialize()

        # print(~self.state)

    def initialize(self):
        layout = QtWidgets.QVBoxLayout()
        self.setLayout(layout)

        self.line = QtWidgets.QLineEdit()
        self.btn = QtWidgets.QPushButton("change enable")
        self.label = QtWidgets.QLabel()
        self.cb = QtWidgets.QCheckBox("disable")
        self.label2 = QtWidgets.QLabel()

        self.combo = QtWidgets.QComboBox()
        self.combo.setModel(self.state.data_list)
        # self.combo.addItem(self.state.text)

        layout.addWidget(self.btn)
        layout.addWidget(self.line)
        layout.addWidget(self.label)
        layout.addWidget(self.cb)
        layout.addWidget(self.combo)
        layout.addWidget(self.label2)

        self.line.setText(lambda: self.state.text2)
        self.label.setText(
            lambda: "{text2} {enable}".format(
                text2=self.state.text2, enable=self.state.enable
            )
        )
        self.label2.setText(lambda: str(self.state.data_list))
        self.cb.setChecked(lambda: self.state.enable)

        # self.line.textChanged.connect(self.modify)
        self.btn.clicked.connect(self.clickEvent)

    def clickEvent(self):
        self.state.enable = not self.state.enable
        print(self.state.enable)
Ejemplo n.º 6
0
    def __init__(self):
        super(TodoWidget, self).__init__()
        ui_file = os.path.join(__file__, "..", "todo.ui")
        loadUi(ui_file, self)
        self.state = Binder()
        self.state.clear_text_style = "none"

        self.TodoHeader.setStyleSheet(
            lambda: "#TodoHeader { border-bottom:%spx solid lightgray; }"
            % (gstate.header_border)
        )
        self.TodoInput.setText(lambda: gstate.input)
        self.TodoInput.setStyleSheet(lambda: "font-style:%s" % (gstate.input_font))
        self.TodoInput.textChanged.connect(self.input_change)
        self.TodoInput.returnPressed.connect(self.add_item)
        self.TodoFooter.setVisible(lambda: gstate.footer_visible)
        self.TodoList.setVisible(lambda: gstate.todolist_visible)

        # NOTE add hover effect
        self.effect = QtWidgets.QGraphicsDropShadowEffect()
        self.effect.setBlurRadius(40)
        self.effect.setColor(QtGui.QColor("lightgray"))
        self.TodoContainer.setGraphicsEffect(self.effect)

        self.ItemClear.linkActivated.connect(self.clear_items)
        self.ItemClear.setText(
            lambda: '<html><head/><body><p><a href="clear" style="text-decoration: %s;color:gray">Clear completed</a></p></body></html>'
            % self.state.clear_text_style
        )
        self.ItemClear >> event_hook(
            "Enter", lambda: self.state.clear_text_style >> Set("underline")
        )
        self.ItemClear >> event_hook(
            "Leave", lambda: self.state.clear_text_style >> Set("none")
        )

        self.ItemComplted.linkActivated.connect(self.complete_items)
        self.ItemComplted.setText(
            lambda: '<html><head/><body><a href="complted" style="text-decoration:none;color:%s">﹀</p></body></html>'
            % gstate.completed_color
        )
        gstate["item_count"].connect(self.change_completed_color)

        self.ItemCount.setText(lambda: "%s item left" % gstate.item_count)

        # NOTE filter radiobutton handler
        gstate.selected >> GroupBoxBind(self.StateGroup)

        gstate["selected"].connect(self.update_item)
        gstate["todo_data"].connect(self.update_item)
        self.update_item()
Ejemplo n.º 7
0
class WidgetTest(QtWidgets.QWidget):

    state = Binder()
    with state('dumper') as dumper:
        state.text = "empty"
        state.num = 1
        state.val = 2.0
        state.start = 0
        state.end = 2

    def __init__(self):
        super(WidgetTest, self).__init__()
        self.initialize()

    def initialize(self):
        layout = QtWidgets.QVBoxLayout()
        self.setLayout(layout)

        self.edit = QtWidgets.QLineEdit()
        self.label = QtWidgets.QLabel()
        self.button = QtWidgets.QPushButton("set selection")
        layout.addWidget(self.edit)
        layout.addWidget(self.label)
        layout.addWidget(self.button)

        self.button.clicked.connect(self.change_selection)
        self.edit.setText(lambda: self.state.text)
        self.edit.setSelection(lambda: (self.state.start, self.state.end))
        self.label.setText(lambda: "message is %s" % self.state.text)

        self.spin = QtWidgets.QSpinBox(self)
        self.label = QtWidgets.QLabel()
        layout.addWidget(self.spin)
        layout.addWidget(self.label)
        self.spin.setValue(lambda: self.state.num)
        self.label.setText(lambda: "num is %s" % self.state.num)
        self.spin = QtWidgets.QDoubleSpinBox(self)
        self.label = QtWidgets.QLabel()
        layout.addWidget(self.spin)
        layout.addWidget(self.label)
        self.spin.setValue(lambda: self.state.val)
        self.label.setText(lambda: "val is %s" % self.state.val)

    def change_selection(self):
        self.state.end += 1
        print("end", self.state.end)
Ejemplo n.º 8
0
class InputTest(QtWidgets.QWidget):
    state = Binder()
    state.text = "abc"

    def __init__(self):
        super(InputTest, self).__init__()
        layout = QtWidgets.QVBoxLayout()
        layout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(layout)

        self.line = QtWidgets.QLineEdit()
        self.label = QtWidgets.QLabel()
        layout.addWidget(self.line)
        layout.addWidget(self.label)

        self.line.setText(lambda: self.state.text)
        self.label.setText(lambda: self.state.text)
Ejemplo n.º 9
0
class ComboBoxWidget_2(QtWidgets.QWidget):

    state = Binder()
    state.selected = ""
    state.options = [
        {
            "text": "One",
            "value": "A"
        },
        {
            "text": "Two",
            "value": "B"
        },
        {
            "text": "Three",
            "value": "C"
        },
    ]

    def __init__(self):
        super(ComboBoxWidget_2, self).__init__()
        self.initialize()
        # print(self.state.options[0].text)

    def initialize(self):
        layout = QtWidgets.QVBoxLayout()
        self.setLayout(layout)

        self.combo = QtWidgets.QComboBox()
        self.combo.addItems([data.get("text") for data in self.state.options])

        self.label = QtWidgets.QLabel()
        layout.addWidget(self.combo)
        layout.addWidget(self.label)
        self.label.setText(lambda: "Selected: %s" % self.state.selected)

        self.combo.currentTextChanged.connect(self.update)
        self.update(self.combo.currentText())

    def update(self, text):
        for data in self.state.options:
            if data.get("text") == text:
                self.state.selected = data.get("value")
Ejemplo n.º 10
0
class LineEditWidget(QtWidgets.QWidget):

    state = Binder()
    with state("dumper"):
        state.message = "asd"

    def __init__(self):
        super(LineEditWidget, self).__init__()
        self.initialize()

    def initialize(self):
        layout = QtWidgets.QVBoxLayout()
        self.setLayout(layout)

        self.edit = QtWidgets.QLineEdit()
        self.label = QtWidgets.QLabel()
        layout.addWidget(self.edit)
        layout.addWidget(self.label)

        self.edit.setText(lambda: self.state.message)
        self.label.setText(lambda: "message is %s" % self.state.message)
Ejemplo n.º 11
0
class CheckBoxWidget(QtWidgets.QWidget):

    state = Binder()
    state.checkedNames = []

    def __init__(self):
        super(CheckBoxWidget, self).__init__()
        self.initialize()

    def initialize(self):
        layout = QtWidgets.QVBoxLayout()
        self.setLayout(layout)

        groupBox = QtWidgets.QGroupBox("Exclusive Check Buttons")
        groupBox.setChecked(True)
        self.cb1 = QtWidgets.QCheckBox("Jack")
        self.cb2 = QtWidgets.QCheckBox("John")
        self.cb3 = QtWidgets.QCheckBox("Mike")

        h_layout = QtWidgets.QHBoxLayout()
        h_layout.addWidget(self.cb1)
        h_layout.addWidget(self.cb2)
        h_layout.addWidget(self.cb3)
        groupBox.setLayout(h_layout)

        self.label = QtWidgets.QLabel()
        layout.addWidget(groupBox)
        layout.addWidget(self.label)

        self.label.setText(
            lambda: "CheckedNames: %s" % self.state.checkedNames)
        for cb in groupBox.findChildren(QtWidgets.QCheckBox):
            cb.stateChanged.connect(partial(self.updateCB, cb))

    def updateCB(self, widget, state):
        method = (self.state.checkedNames.append
                  if state else self.state.checkedNames.remove)
        method(widget.text())
Ejemplo n.º 12
0
class WidgetTest(QtWidgets.QWidget):

    state = Binder()
    state.selected = ""
    state.option_A = "A"
    state.option_B = "B"
    state.option_C = "C"
    state.item_list = [
        state.selected, state.option_A, state.option_B, state.option_C
    ]

    def __init__(self):
        super(WidgetTest, self).__init__()
        self.initialize()

    def initialize(self):
        layout = QtWidgets.QVBoxLayout()
        self.setLayout(layout)

        self.combo = QtWidgets.QComboBox()
        # self.combo.addItems(self.state.item_list)
        self.combo.addItems(["A", "B", "C"])

        self.label = QtWidgets.QLabel()
        self.button = QtWidgets.QPushButton("click")
        layout.addWidget(self.combo)
        layout.addWidget(self.label)
        layout.addWidget(self.button)

        self.button.clicked.connect(self.testComputed)
        self.state.selected = self.combo.currentText()
        self.combo.setCurrentText(lambda: self.state.selected)

        self.label.setText(
            lambda: "selected {selected}".format(selected=self.state.selected))

    def testComputed(self):
        self.state.selected = "AAA"
Ejemplo n.º 13
0
class ComboBoxWidget_1(QtWidgets.QWidget):

    state = Binder()
    with state("dumper", "combo_test1"):
        state.selected = ""

    def __init__(self):
        super(ComboBoxWidget_1, self).__init__()
        self.initialize()

    def initialize(self):
        layout = QtWidgets.QVBoxLayout()
        self.setLayout(layout)

        self.combo = QtWidgets.QComboBox()
        self.combo.addItems(["A", "B", "C"])

        self.label = QtWidgets.QLabel()
        layout.addWidget(self.combo)
        layout.addWidget(self.label)

        self.label.setText(lambda: "Selected: %s" % self.state.selected)
        self.combo.setCurrentText(lambda: self.state.selected)
Ejemplo n.º 14
0
class WidgetTest(QtWidgets.QWidget):
    state = Binder()
    state.selected = ""
    state.option_A = 123.0
    state.option_B = "B"
    state.option_C = "C"
    state.item_list = [
        state["selected"],
        state["option_A"],
        state["option_B"],
        state["option_C"],
    ]
    state.item_model = Model(
        [
            [[state["option_A"], state["option_B"]], "1"],
            [state["option_A"], state["option_B"]],
            [None, "asd", None, 123],
            ["asd", "1234"],
        ]
    )
    
    # with Binder() as state:
    #     state.selected = ""
    #     state.option_A = 123.0
    #     state.option_B = "B"
    #     state.option_C = "C"
    #     state.item_list = [
    #         state.selected,
    #         state.option_A,
    #         state.option_B,
    #         state.option_C,
    #     ]
    #     state.item_model = Model(
    #         [
    #             [[state.option_A, state.option_B], "1"],
    #             [state.option_A, state.option_B],
    #             state.option_B,
    #             state.option_C,
    #             [None, "asd", None, 123],
    #             ["asd", "1234"],
    #         ]
    #     )

    def __init__(self):
        super(WidgetTest, self).__init__()
        layout = QtWidgets.QVBoxLayout()
        self.setLayout(layout)

        self.input = InputTest()
        layout.addWidget(self.input)
        self.input.label.setText(lambda: "%s test" % self.state.option_B)

        # print (self.state.toJson())

        self.line = QtWidgets.QLineEdit()
        # print(self.line.STATE)
        layout.addWidget(self.line)
        self.label = QtWidgets.QLabel()
        layout.addWidget(self.label)

        self.line.setText(lambda: self.state.option_B)
        self.label.setText(lambda: self.state.option_B)

        # ALL OF OUR VIEWS
        listView = QtWidgets.QListView()
        layout.addWidget(listView)

        treeView = QtWidgets.QTreeView()
        layout.addWidget(treeView)

        comboBox = QtWidgets.QComboBox()

        # print ("dynamicPropertyNames",comboBox.dynamicPropertyNames())
        layout.addWidget(comboBox)

        tableView = QtWidgets.QTableView()
        layout.addWidget(tableView)

        # red = QtGui.QColor(255, 0, 0)
        # green = QtGui.QColor(0, 255, 0)
        # blue = QtGui.QColor(0, 0, 255)
        # item_list = [red, "green", "blue"]

        # print (self.state.item_list)
        self.state.selected = "selected"
        # print (self.state.item_list)

        # print ("item_model",self.state.item_model)
        model = self.state.item_model

        # model = QtGui.QStandardItemModel()
        # model.appendRow(QtGui.QStandardItem("A"))
        # model.appendRow(QtGui.QStandardItem("B"))
        
        listView.setModel(model)
        comboBox.setModel(model)
        tableView.setModel(model)
        treeView.setModel(model)

        button = QtWidgets.QPushButton("change")
        button.clicked.connect(self.changeOrder)
        layout.addWidget(button)
        button = QtWidgets.QPushButton("change2")
        button.clicked.connect(self.addComboBox)
        layout.addWidget(button)

        self.text = "123"
        self.label = QtWidgets.QLabel("label")
        self.label.setText(lambda: "%s %s" % (self.state.option_B, self.text))
        layout.addWidget(self.label)

    def addComboBox(self):
        self.state.option_B = "123"
        # val = self.state.item_list[2]
        # print(val)

    def changeOrder(self):
        self.text = "asd"
Ejemplo n.º 15
0
signal.signal(signal.SIGINT, signal.SIG_DFL)

DIR = os.path.dirname(__file__)
import sys

MODULE = os.path.join(DIR, "..")
if MODULE not in sys.path:
    sys.path.insert(0, MODULE)

from QBinder import Binder
from QBinder.hook import MethodHook, FuncHook
from Qt import QtWidgets
import os
import sys

state = Binder()
state.msg = "test"


@FuncHook
def print_test(msg):
    print("print_test: %s" % msg)


class Test(object):
    @MethodHook
    def cls_print_test(cls, msg):
        print("cls_print_test: %s" % msg)


def main():
Ejemplo n.º 16
0
class Counter(QtWidgets.QWidget):

    state = Binder()
    state.count = 0
    state.count2 = 6

    def __init__(self):
        super(Counter, self).__init__()
        self.count = 4
        self.count3 = 15
        self.initialize()

        print(self.state.count)

    def initialize(self):
        layout = QtWidgets.QVBoxLayout()
        self.setLayout(layout)

        self.label = QtWidgets.QLabel()

        plus_button = QtWidgets.QPushButton("count ++")
        minus_button = QtWidgets.QPushButton("count --")

        label2 = QtWidgets.QLabel()
        label3 = QtWidgets.QLabel()
        label4 = QtWidgets.QLabel()

        plus_button2 = QtWidgets.QPushButton("count2 ++")
        minus_button2 = QtWidgets.QPushButton("count2 --")
        label5 = QtWidgets.QLabel()

        self.label.setText(lambda: str(self.state.count))
        label2.setText(lambda: "<center>%s %s</center>" %
                       (self.count, self.state.count))
        label3.setText(lambda: "<center>%s</center>" % self.count)
        label4.setText(
            lambda: self.calculate(self.state.count, self.state.count2))
        label5.setText(lambda: str(self.state.count2))

        layout.addWidget(self.label)
        layout.addWidget(plus_button)
        layout.addWidget(minus_button)
        layout.addWidget(label2)
        layout.addWidget(label3)
        layout.addWidget(label4)
        layout.addWidget(plus_button2)
        layout.addWidget(minus_button2)
        layout.addWidget(label5)

        plus_button.clicked.connect(self.add)
        minus_button.clicked.connect(self.subtract)
        plus_button2.clicked.connect(self.add2)
        minus_button2.clicked.connect(self.subtract2)

    #     test_button = QtWidgets.QPushButton("Test")
    #     test_button.clicked.connect(self.test)
    #     layout.addWidget(test_button)

    # def test(self):
    #     self.state.count = "a"

    def add(self):
        self.state.count += 1

    def subtract(self):
        self.state.count -= 1

    def add2(self):
        self.state.count2 += 1

    def subtract2(self):
        self.state.count2 -= 1

    def calculate(self, a, b):
        return str(a * b + self.state.count)

    def mul(self):
        return str(self.state.count2 + self.state.count)
Ejemplo n.º 17
0
sys.path.insert(0, repo) if repo not in sys.path else None

# os.environ["QT_PREFERRED_BINDING"] = "PyQt4;PyQt5;PySide;PySide2"

from QBinder import Binder, QEventHook, FnBinding
from QBinder.handler import Set, ItemConstructor, GroupBoxBind
from QBinder.decorator import inject

import Qt

print("__binding__", Qt.__binding__)
from Qt import QtGui, QtWidgets, QtCore
from Qt.QtCompat import loadUi

event_hook = QEventHook.instance()
gstate = Binder()

with gstate("dumper") as dumper:
    gstate.todo_data = []
    gstate.selected = "All"
    gstate.input = ""

gstate.item_count = 0
gstate.input_font = "italic"
gstate.completed_color = "lightgray"
gstate.footer_visible = False
gstate.todolist_visible = False
gstate.header_border = 0


gstate.update_count = FnBinding()