Приветствую. У меня есть скрипт для питона который присваивает hid устройству (в моем случае usb кнопка) клавишу от клавиатуры. Так же есть GUI которое я сделал в pyqt4. Как мне теперь собрать это все воедино? Что бы по нажатию Start у меня значение введенное в окошке присваивалось переменной ptt_key если устройство обнаружено писалось Connected а если не обнаружено disconnected? Подскажите. Сам в программировании не очень силен. Спасибо.
Сам скрипт
import time
import pywinusb.hid as hid
from win32api import keybd_event
class App:
hid_vendor_id = 0x07CA
hid_product_id = 0x9850
hid_device_list = None
sound_enabled = True
def __init__(self, ptt_key=0x08):
self._ptt_key = ptt_key
def set_ptt_key(self, value):
self._ptt_key = value
def get_ptt_key(self):
return self._ptt_key
ptt_key = property(get_ptt_key, set_ptt_key)
def start( self ):
self.hid_device_list = hid.HidDeviceFilter( vendor_id = self.hid_vendor_id, product_id = self.hid_product_id )
self.hid_device_list = self.hid_device_list.get_devices( )
print "Looking for Device... \nPress Control+C to Quit"
if self.hid_device_list:
for device in self.hid_device_list:
print "Found One!\n"
device.open( )
device.set_raw_data_handler( self.raw_input_callback )
else:
print "Oh No, no devices were found! \n"
while True:
time.sleep( 1000 ) #HID input/keysend on separate thread.
def raw_input_callback( self, data ):
if data[2] == 1:
keybd_event( self.ptt_key, 0, 0x0000, 0 )
elif data[2] == 0:
keybd_event( self.ptt_key, 0, 0x0002, 0 )
if __name__ == '__main__':
app = App( )
app.start( )
GUI
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'HotKey.ui'
#
# Created: Sat Oct 28 05:12:26 2017
# by: PyQt4 UI code generator 4.9.4
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName(_fromUtf8("Dialog"))
Dialog.resize(268, 70)
self.pbStart = QtGui.QPushButton(Dialog)
self.pbStart.setGeometry(QtCore.QRect(20, 40, 75, 23))
self.pbStart.setObjectName(_fromUtf8("pbStart"))
self.leButtonCode = QtGui.QLineEdit(Dialog)
self.leButtonCode.setGeometry(QtCore.QRect(120, 10, 61, 20))
self.leButtonCode.setReadOnly(True)
self.leButtonCode.setObjectName(_fromUtf8("leButtonCode"))
self.label = QtGui.QLabel(Dialog)
self.label.setGeometry(QtCore.QRect(20, 10, 91, 21))
self.label.setObjectName(_fromUtf8("label"))
self.pbStop = QtGui.QPushButton(Dialog)
self.pbStop.setGeometry(QtCore.QRect(110, 40, 75, 23))
self.pbStop.setObjectName(_fromUtf8("pbStop"))
self.lStatus = QtGui.QLabel(Dialog)
self.lStatus.setGeometry(QtCore.QRect(190, 10, 71, 21))
self.lStatus.setObjectName(_fromUtf8("lStatus"))
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
Dialog.setWindowTitle(QtGui.QApplication.translate("Dialog", "Hot Key", None, QtGui.QApplication.UnicodeUTF8))
self.pbStart.setText(QtGui.QApplication.translate("Dialog", "Start", None, QtGui.QApplication.UnicodeUTF8))
self.label.setText(QtGui.QApplication.translate("Dialog", "Button code", None, QtGui.QApplication.UnicodeUTF8))
self.pbStop.setText(QtGui.QApplication.translate("Dialog", "Stop", None, QtGui.QApplication.UnicodeUTF8))
self.lStatus.setText(QtGui.QApplication.translate("Dialog", "<font color=\"red\">disconnected</font>", None, QtGui.QApplication.UnicodeUTF8))