示例#1
0
class InputDialog(QDialog):
    def __init__(self, parent):
        super(InputDialog, self).__init__(parent)
        self.setWindowFlags(QtCore.Qt.Window)
        self.setModal(True)
        self.screen_resolution = QApplication.desktop().screenGeometry()
        self.screen_width, self.screen_height = self.screen_resolution.width(
        ), self.screen_resolution.height()
        self.parent = parent
        self.key_list = []
        self.click_list = []
        self.current_selection = []
        self.setStyleSheet('font-size:20px')
        self.initUI()

    def initUI(self):
        widget = QWidget()
        vbox = QVBoxLayout()
        leftlist = QListWidget()
        leftlist.setMaximumWidth(100)
        leftlist.insertItem(0, 'key')
        leftlist.insertItem(1, 'click')

        keystack = QWidget()
        clickstack = QWidget()

        syms = [
            '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c',
            'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
            'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C',
            'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
            'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'Up', 'Down',
            'Left', 'Right', 'Alt_L', 'Alt_R', 'BackSpace', 'Cancel',
            'Caps_Lock', 'Control_L', 'Control_R', 'Shift_L', 'Shift_R', 'Tab',
            'space', 'Delete', 'End', 'Super_L', 'Suprer_R', 'Return',
            'Escape', 'Execute', 'F1', 'F2', 'F3', 'F4', 'F5', 'F6', 'F7',
            'F8', 'F9', 'F10', 'F11', 'F12', 'Fi', 'KP_0', 'KP_1', 'KP_2',
            'KP_3', 'KP_4', 'KP_5', 'KP_6', 'KP_7', 'KP_8', 'KP_9', 'KP_Add',
            'KP_Begin', 'KP_Decimal', 'KP_Delete', 'KP_Divide', 'KP_Down',
            'KP_End', 'KP_Enter', 'KP_Home', 'KP_Insert', 'KP_Left',
            'KP_Multiply', 'KP_Next', 'KP_Prior', 'KP_Right', 'KP_Subtract',
            'KP_Up', 'Home', 'Insert', 'Linefeed', 'Next', 'Num_Lock', 'Pause',
            'Print', 'Prior', 'Scroll_Lock', 'exclam', 'quotedbl',
            'numbersign', 'dollar', 'percent', 'ampersand', 'quoteright',
            'parenleft', 'parenright', 'asterisk', 'plus', 'comma', 'minus',
            'period', 'slash', 'colon', 'semicolon', 'less', 'equal',
            'greater', 'question', 'at', 'grave', 'bracketleft',
            'bracketright', 'backslash', 'apostrophe'
        ]

        click_types = ['1', '2', '3']

        self.btnstyle = 'background-color:#dddddd;font-size:24px;'

        self.keyUI(syms, keystack)
        self.clickUI(click_types, clickstack)

        self.Stack = QStackedWidget()
        self.Stack.addWidget(keystack)
        self.Stack.addWidget(clickstack)

        hbox = QHBoxLayout(self)
        hbox.addWidget(leftlist)
        hbox.addWidget(self.Stack)
        h = QHBoxLayout()

        deleteButton = QPushButton(" Delete Last Input")
        clearButton = QPushButton(" Clear All ")
        deleteButton.setMinimumHeight(50)
        clearButton.setMinimumHeight(50)

        deleteButton.clicked.connect(self.delete_last)
        clearButton.clicked.connect(self.clear_all)

        self.buttons = QDialogButtonBox(
            QDialogButtonBox.Ok | QDialogButtonBox.Cancel,
            QtCore.Qt.Horizontal, self)

        self.buttons.accepted.connect(self.accept)
        self.buttons.rejected.connect(self.reject)

        self.buttons.setMinimumSize(QtCore.QSize(50, 50))
        for b in self.buttons.buttons():
            b.setMinimumSize(QtCore.QSize(50, 50))

        h.addWidget(clearButton)
        h.addWidget(deleteButton)
        h.addStretch(1)
        h.addWidget(self.buttons)
        widget.setLayout(hbox)

        selection_box = QHBoxLayout()
        self.selection_widget = QLabel(self.input_display_text())
        self.selection_widget.setMinimumHeight(50)
        self.selection_widget.setObjectName('SelectionWidget')
        self.selection_widget.setStyleSheet('#SelectionWidget { \
			background-color:#cccccc;border: 1px solid #aaaaaa; \
			border-radius:5px;color:blue; \
		}')

        selection_box.addStretch(1)
        selection_box.addWidget(self.selection_widget)
        selection_box.addStretch(1)
        vbox.addLayout(selection_box)
        vbox.addWidget(widget)
        vbox.addLayout(h)
        self.setLayout(vbox)
        leftlist.currentRowChanged.connect(self.display)

        w, h = self.screen_width * .9, self.screen_height * .8
        self.setGeometry((self.screen_width - w) / 2,
                         (self.screen_height - h) / 2, w, h)
        self.setWindowTitle(
            'Select Input(s). You can choose multiple keys/clicks.')

    def close_settings(self):
        self.close()

    def keyUI(self, syms, keystack):
        layout = QGridLayout()
        scroll = QScrollArea()
        scroll.setWidgetResizable(True)
        widget = QWidget()
        vbox = QVBoxLayout()
        widget.setLayout(layout)
        btn_list = []
        positions = [(i, j) for i in range(int(len(syms) / 4) + 1)
                     for j in range(4)]
        for position, name in zip(positions, syms):
            kbtn = QPushButton(name)
            kbtn.setMinimumSize(QtCore.QSize(50, 50))
            kbtn.setStyleSheet(self.btnstyle)
            layout.addWidget(kbtn, *position)
            kbtn.clicked.connect(partial(self.all_keys_list, name, kbtn,
                                         'key'))
        scroll.setWidget(widget)

        qs = QScroller.scroller(scroll.viewport())
        props = qs.scrollerProperties()
        props.setScrollMetric(QScrollerProperties.DecelerationFactor, 0.35)
        props.setScrollMetric(QScrollerProperties.DragStartDistance, .001)
        qs.setScrollerProperties(props)
        qs.grabGesture(scroll.viewport(), QScroller.TouchGesture)

        vbox.addWidget(scroll)
        keystack.setLayout(vbox)

    def clickUI(self, click_types, clickstack):
        layout = QVBoxLayout()
        widget = QWidget()
        hbox = QHBoxLayout()

        for name in click_types:
            cbtn = QPushButton(name)
            cbtn.setMinimumSize(QtCore.QSize(100, 50))
            cbtn.setStyleSheet(self.btnstyle)
            cbtn.clicked.connect(
                partial(self.all_keys_list, name, cbtn, 'click'))
            layout.addWidget(cbtn)

        widget.setLayout(layout)
        hbox.addStretch(1)
        hbox.addWidget(widget)
        hbox.addStretch(1)
        clickstack.setLayout(hbox)

    def display(self, i):
        self.Stack.setCurrentIndex(i)

    def all_keys_list(self, name, btn, input_type):
        label = btn.text()
        if label:
            self.key_list.append(input_type)
            self.key_list.append(label)
            self.selection_widget.setText(self.input_display_text())

    def input_display_text(self):
        if self.key_list:
            t = ' '.join(self.key_list)
        else:
            t = 'Nothing Selected'
        return t

    def delete_last(self):
        if self.key_list:
            del self.key_list[-2:]
            self.selection_widget.setText(self.input_display_text())

    def clear_all(self):
        if self.key_list:
            self.key_list = []
            self.selection_widget.setText(self.input_display_text())

    def all_input_values(self):
        return self.key_list
示例#2
0
class NewButtonDialog(QDialog):
    def __init__(self, parent):
        super(NewButtonDialog, self).__init__(parent)
        # self.setWindowFlags(QtCore.Qt.Window)
        self.setModal(True)
        self.screen_resolution = QApplication.desktop().screenGeometry()
        self.screen_width, self.screen_height = self.screen_resolution.width(
        ), self.screen_resolution.height()
        self.parent = parent
        self.values = [None, 50, 50, 50, 50, None, 'normal', None]
        self.setStyleSheet('font-size:20px')
        self.initUI()

    def initUI(self):
        w = QLabel()
        text = 'Define properties of your new button below.'
        w.setText(text)
        hbox = QHBoxLayout()
        hbox.addStretch(1)

        self.buttons = QDialogButtonBox(
            QDialogButtonBox.Ok | QDialogButtonBox.Cancel,
            QtCore.Qt.Horizontal, self)

        self.buttons.accepted.connect(self.accept)
        self.buttons.rejected.connect(self.reject)

        self.buttons.setMinimumSize(QtCore.QSize(50, 50))
        for b in self.buttons.buttons():
            b.setMinimumHeight(50)

        hbox.addWidget(self.buttons)
        vbox = QVBoxLayout()
        h = QHBoxLayout()
        vbox.addWidget(w)

        l = [
            'Name', 'X Positon', 'Y Position', 'Width', 'Height', 'Color',
            'Behavior', 'Input'
        ]
        behavior_list = ['normal', 'sticky', 'autorepeat', 'combo']

        for i in range(8):
            if i == 0:
                new_vbox = QVBoxLayout()
                new_widget = QWidget()
                lbl = QLabel(l[i])
                b = QLineEdit()
                b.setMinimumHeight(50)
                new_vbox.addWidget(lbl)
                new_vbox.addWidget(b)
                new_widget.setLayout(new_vbox)
                h.addWidget(new_widget)
                b.textChanged.connect(
                    partial(self.write_widget_value, i, b.text))
            if i > 0 and i <= 4:
                new_vbox = QVBoxLayout()
                new_widget = QWidget()
                lbl = QLabel(l[i])
                b = QSpinBox()
                b.setMinimum(0)
                b.setMaximum(100)
                b.setSingleStep(1)
                b.setValue(50)
                b.setMinimumHeight(50)
                new_vbox.addWidget(lbl)
                new_vbox.addWidget(b)
                new_widget.setLayout(new_vbox)
                h.addWidget(new_widget)
                b.valueChanged.connect(
                    partial(self.write_widget_value, i, b.value))
            if i == 5:
                new_vbox = QVBoxLayout()
                new_widget = QWidget()
                lbl = QLabel(l[i])
                b = QPushButton()
                b.setMinimumHeight(50)
                new_vbox.addWidget(lbl)
                new_vbox.addWidget(b)
                new_widget.setLayout(new_vbox)
                h.addWidget(new_widget)
                b.clicked.connect(partial(self.get_color, i, b))
            if i == 6:
                new_vbox = QVBoxLayout()
                new_widget = QWidget()
                lbl = QLabel(l[i])
                b = QComboBox()
                b.setMinimumHeight(50)
                b.addItem(behavior_list[0])
                b.addItem(behavior_list[1])
                b.addItem(behavior_list[2])
                new_vbox.addWidget(lbl)
                new_vbox.addWidget(b)
                new_widget.setLayout(new_vbox)
                h.addWidget(new_widget)
                b.currentIndexChanged.connect(
                    partial(self.write_widget_value, i, b.currentText))
            if i == 7:
                new_vbox = QVBoxLayout()
                new_widget = QWidget()
                lbl = QLabel(l[i])
                b = QPushButton()
                b.setMinimumHeight(50)
                new_vbox.addWidget(lbl)
                new_vbox.addWidget(b)
                new_widget.setLayout(new_vbox)
                h.addWidget(new_widget)
                b.clicked.connect(partial(self.keypicker, i, b))

        vbox.addSpacing(10)
        vbox.addLayout(h)
        vbox.addSpacing(20)
        vbox.addLayout(hbox)
        self.setLayout(vbox)

        w, h = self.screen_width * .9, self.sizeHint().height()
        self.setGeometry((self.screen_width - w) / 2,
                         (self.screen_height - h) / 2, w, h)
        self.setWindowTitle('Create a New Button')

    def close_settings(self):
        self.close()

    def write_widget_value(self, index, value):
        value = value()
        self.values[index] = value

    def get_color(self, index, btn):
        color = QColorDialog.getColor()
        if color.isValid():
            color = color.name()
            stl = "background-color:%s;" % color
            btn.setStyleSheet(stl)
            self.values[index] = color

    def keypicker(self, index, btn):
        picker = InputDialog(self)
        result = picker.exec_()
        if result == 1:
            keys = picker.all_input_values()
        else:
            keys = None
        if keys:
            self.values = self.values[:7]
            self.values = self.values + keys
            btn.setText(' '.join(keys))

    def final_list(self):
        for i in self.values:
            if i == None:
                self.values = []
                break
        return self.values
示例#3
0
class HelpButtonDialog(QDialog):
    def __init__(self, parent):
        super(HelpButtonDialog, self).__init__(parent)
        self.setWindowFlags(QtCore.Qt.Window)
        self.setModal(True)
        self.screen_resolution = QApplication.desktop().screenGeometry()
        self.screen_width, self.screen_height = self.screen_resolution.width(
        ), self.screen_resolution.height()
        self.parent = parent
        self.setStyleSheet('font-size:20px')
        self.initUI()

    def initUI(self):
        w = QLabel()
        text = 'Big wall of text below.'
        w.setText(text)
        hbox = QHBoxLayout()
        hbox.addStretch(1)

        self.buttons = QDialogButtonBox(
            QDialogButtonBox.Ok | QDialogButtonBox.Cancel,
            QtCore.Qt.Horizontal, self)

        self.buttons.accepted.connect(self.accept)
        self.buttons.rejected.connect(self.reject)

        self.buttons.setMinimumSize(QtCore.QSize(50, 50))
        for b in self.buttons.buttons():
            b.setMinimumHeight(50)

        hbox.addWidget(self.buttons)
        vbox = QVBoxLayout()
        h = QHBoxLayout()
        vbox.addWidget(w)

        l = [
            'Name', 'X Positon', 'Y Position', 'Width', 'Height', 'Color',
            'Behavior', 'Input'
        ]
        behavior_list = ['normal', 'sticky', 'autorepeat', 'combo']

        for i in range(8):
            if i == 0:
                new_vbox = QVBoxLayout()
                new_widget = QWidget()
                lbl = QLabel(l[i])
                b = QLineEdit()
                b.setText('Z1')
                b.setMinimumHeight(50)
                new_vbox.addWidget(lbl)
                new_vbox.addWidget(b)
                new_widget.setLayout(new_vbox)
                h.addWidget(new_widget)
            if i > 0 and i <= 4:
                new_vbox = QVBoxLayout()
                new_widget = QWidget()
                lbl = QLabel(l[i])
                b = QSpinBox()
                b.setMinimum(0)
                b.setMaximum(100)
                b.setSingleStep(1)
                b.setValue(50)
                b.setMinimumHeight(50)
                new_vbox.addWidget(lbl)
                new_vbox.addWidget(b)
                new_widget.setLayout(new_vbox)
                h.addWidget(new_widget)
            if i == 5:
                new_vbox = QVBoxLayout()
                new_widget = QWidget()
                lbl = QLabel(l[i])
                b = QPushButton()
                b.setStyleSheet('background-color:green')
                b.setMinimumHeight(50)
                new_vbox.addWidget(lbl)
                new_vbox.addWidget(b)
                new_widget.setLayout(new_vbox)
                h.addWidget(new_widget)
            if i == 6:
                new_vbox = QVBoxLayout()
                new_widget = QWidget()
                lbl = QLabel(l[i])
                b = QComboBox()
                b.setMinimumHeight(50)
                b.addItem(behavior_list[0])
                b.addItem(behavior_list[1])
                b.addItem(behavior_list[2])
                new_vbox.addWidget(lbl)
                new_vbox.addWidget(b)
                new_widget.setLayout(new_vbox)
                h.addWidget(new_widget)
            if i == 7:
                new_vbox = QVBoxLayout()
                new_widget = QWidget()
                lbl = QLabel(l[i])
                b = QPushButton()
                b.setText('key D click 2')
                b.setMinimumHeight(50)
                new_vbox.addWidget(lbl)
                new_vbox.addWidget(b)
                new_widget.setLayout(new_vbox)
                h.addWidget(new_widget)

        scroll = QScrollArea()
        scroll.setWidgetResizable(True)
        widget = QLabel()
        widget.setWordWrap(True)

        t = (
            "<font color='blue'>Some fields in default buttons are disabled. "
            "This has been done on purpose to define a standard set of buttons. "
            "However, there are no such restrictions on creating a new button. "
            "If you want to hide an existing button, set its width and height to zero.</font><br><br>"
            "<b>Name:</b> Identification label for your button. "
            "You cannot change names of existing buttons. "
            "However you can always create a new button with any name.<br><br>"
            "<b>X Position:</b> Defines horizontal position of a button in terms of percentages of 'Overlay Width'. "
            "E.g., a value of 6 will postion a button horizontally at 6% of total overlay width value. "
            "Please note that overlay width may not be your screen width. "
            "You can change overlay width in settings.<br><br>"
            "<b>Y Position:</b> Defines vertical position of a button in terms of percentages of 'Overlay Height'. "
            "E.g., a value of 30 will postion a button vertically at 30% of total overlay height value. "
            "Please note that overlay height may not be your screen height. "
            "You can change overlay height in settings.<br><br>"
            "<b>Width:</b> Defines width of the button. "
            "If 'Override Button Size' is enabled in settings, this value will have no effect on button.<br><br>"
            "<b>Height:</b> Defines height of the button. "
            "If 'Override Button Size' is enabled in settings, this value will have no effect on button.<br><br>"
            "<font color='blue'><u>Tip:</u> To hide a button, set its width and height to zero.</font><br><br>"
            "<b>Color:</b> Sets the color of the button.<br><br>"
            "<b>Behavior:</b> Defines behavior of the button.<br>"
            "<font color='blue'>Some of the options below will only work if your game/emulator supports it.</font><br>"
            "<u>Normal:</u> Standard tap or long press on a button. "
            "Duplicate keys like 'Up, Up, Down, Down' will not work in this mode.<br>"
            "<u>Sticky:</u> Simulates press and hold behavior on a single press (continues unless stopped). "
            "Duplicate keys like 'Up, Up, Down, Down' will not work in this mode.<br>"
            "<u>Autorepeat:</u> Also known as rapid-fire/turbo. After touching once, it goes on and on, unless stopped. "
            "Duplicate keys like 'Up, Up, Down, Down' will not work in this mode.<br>"
            "<u>Combo:</u> Auto-executes keys one by one in a time interval defined in the settings. "
            "Once a combo starts, it cannot be interrupted until its done. "
            "Duplicate keys like 'Up, Up, Down, Down' will work in this mode if the game/emulator supports it.<br><br>"
            "<font color='blue'><u>Tip:</u> Tap on 'Stop All Inputs' to halt all sticky and autorepeating keys/clicks.</font><br><br>"
            "<b>Input:</b> Choose one or multiple keys/clicks to be executed on a button press. "
            "You can even combine keys and clicks together. "
            "There are more than 150 options, so you can now execute all those 'Soul Calibur' combos in one hit.<br><br>"
            "<font color='blue'><u>Tip:</u> If you find that the app is crashing at startup,"
            " delete 'settings.conf' file in main app folder and 'DefaultLayout.conf'"
            " file in profiles folder and then relaunch the app.</font><br><br>"
        )
        widget.setText(t)
        widget.setContentsMargins(10, 10, 10, 10)
        widget.setAlignment(QtCore.Qt.AlignJustify)
        widget.setStyleSheet('background-color:white;')

        scroll.setWidget(widget)
        scroll.setObjectName('scroll1')
        scroll.setStyleSheet('#scroll1 {background-color:white;}')

        qs = QScroller.scroller(scroll.viewport())
        props = qs.scrollerProperties()
        props.setScrollMetric(QScrollerProperties.DecelerationFactor, 0.35)
        props.setScrollMetric(QScrollerProperties.DragStartDistance, .001)
        qs.setScrollerProperties(props)
        qs.grabGesture(scroll.viewport(), QScroller.TouchGesture)

        vbox.addSpacing(10)
        vbox.addLayout(h)
        vbox.addSpacing(20)
        vbox.addWidget(scroll)
        vbox.addLayout(hbox)
        self.setLayout(vbox)

        w, h = self.screen_width * .9, self.sizeHint().height()
        self.setGeometry((self.screen_width - w) / 2,
                         (self.screen_height - h) / 2, w, h)
        self.setWindowTitle('Help')

    def close_settings(self):
        self.close()