1

As I'm new in python maybe I'm missing the obvious.

I've wrote the updateRates method for the class which counts fps in this RDP program.

When I try to access some attributes from inside the call from the timer method there is this weird Error:

"AttributeError: type object 'RDCToGUI' has no attribute '_cnt_framerate'"

it is really obvious this class inherits this attribute, but in the Timer thread it doesn't seem to be there anymore

So the problem is: I can call the inherited methods of the super (e.g. self.rates) but inside some attributes aren't present in the method

class RDCToGUI(clientProtocol.rdc):
    def __init__(self):
        clientProtocol.rdc.__init__(self)
        self.num = 0
        self.count = 0
        self.framerate_before = 0

    def updateRates(self, framerate_label, datarate_label):
        divisor = 1
        datarate_text = "b/s"

        self.rates(self)
        framerate = self.framerate
        datarate = self.datarate

        if self.logged_in == 1 and self.framerate_before == 0 == framerate:
            self.framebufferUpdateRequest(
                width=800, height=800)
        if datarate > 1000000:
            divisor = 1000000
            rateText = "Mb/s"
        elif datarate > 1000:
            divisor = 1000
            rateText = "Kb/s"

        self.framerate_before = framerate

        framerate_label.setText(f"Framerate: {framerate}")
        datarate_label.setText(
            f"Datarate: {round(datarate / divisor, 2)} {datarate_text}")

        threading.Timer(1, self.updateRates, args=(self,
                                                   framerate_label, datarate_label)).start()
class rdc(Protocol):
    def __init__(self):
        self._packet = ""
        self._expected_len = 0
        self._cnt_framerate = 0
        self._cnt_datarate = 0
        self.framerate = 0
        self.datarate = 0
        self.logged_in = 0

    def rates(self):
        self.setRates(self)
        self.resetCounter(self)

    def setRates(self):
        self.framerate = self._cnt_framerate
        self.datarate = self._cnt_datarate

    def resetCounter(self):
        self._cnt_datarate = 0
        self._cnt_framerate = 0

    def incFramerate(self):
        self._cnt_framerate += 1

    def addDataSize(self, size):
        self._cnt_datarate += size

The classes have more methods and members than what I showed, but wanted to cut it to the most important stuff.

Tried to put the method in different classes and played around with the names of the attributes

class rdc is in another file which is imported as clientProtocol.

ahv2j5dc
  • 11
  • 5

1 Answers1

0

This seems like an inheritance issue. Maybe try replacing

clientProtocol.rdc.__init__(self)

with

super(RDCToGUI, self).__init__()

I'm not an expert on inheritance either and haven't really used it, but there is a ton to read on the super() function and you could maybe start at Understanding Python super() with __init__() methods and just follow it down the rabbit hole :)

Reedinationer
  • 5,661
  • 1
  • 12
  • 33
  • Sadly, this didn't solve the problem. The inheritance seems correct though, because I can call the methods of the super class but some attributes disappear in context to the threading of the timer. – ahv2j5dc Apr 03 '19 at 21:12