Python,混合使用PyQt5和abc.ABCMeta [英] Python, mixing PyQt5 and abc.ABCMeta

查看:189
本文介绍了Python,混合使用PyQt5和abc.ABCMeta的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用abc.ABCMeta和QObject作为父类来创建AbstractClass,并且似乎无法使其正常工作.

I am trying to create an AbstractClass using both abc.ABCMeta and QObject as parents and cannot seems to make it work.

这是基类的初始化.我有Pyqt5和python 2.7

Here is the Base class init. I have Pyqt5 and python 2.7

pyqtWrapperType = type(QObject)

class ParamsHandler(abc.ABCMeta, pyqtWrapperType):
    def __init__(self, device_model, read_only=False):
        super(ParamsHandler, self).__init__()
        self.cmd_to_get_data = None
        self.device_model = device_model

class ConfigParamsHandler(ParamsHandler):
    def __init__(self, device_model):
        super(ConfigParamsHandler, self).__init__(device_model)
        self.cmd_to_get_data = Commands.CONFIG_PARAMS

我得到一个TypeError(' new ()恰好接受4个参数(给定2个)',)我也有Pycharm建议我使用cls代替self

I get a TypeError('new() takes exactly 4 arguments (2 given)',) I also have Pycharm suggesting that I use cls instead of self

如果我提供4个参数,它将要求一个字符串作为第一个参数.

If I supply 4 arguments, it asks for a string as the first argument.

推荐答案

我改用这种方法解决了它:

I solved it using this approach instead:

class ParamsHandler_Meta(type(QObject), type(abc.ABCMeta)):
    pass
class ParamsHandlerClass(QObject):
    pass
class ParamsHandler(ParamsHandlerClass):
    __metaclass__ = ParamsHandler_Meta
    def __init__(self, device_model, cmd_to_get_data, read_only=False):
        super(ParamsHandler, self).__init__()
        self.cmd_to_get_data = cmd_to_get_data

这篇关于Python,混合使用PyQt5和abc.ABCMeta的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆