It is currently October 14th, 2019, 6:51 am

python plugin help

Share and get help with Plugins and Addons
sundansx
Posts: 4
Joined: February 8th, 2014, 10:31 pm

python plugin help

sundansx » May 12th, 2019, 7:45 am

I am making a nvidia gpu display using python. I have the python 3.6 plugin loaded and am using it with python 3.6 on the system. I am also using the py3nvml plugin with python. I all works great until I put like 16 classes (one for each measure, like clockrate, gpu load, encoder load, etc.) then the plugin brings rainmeter down. I also tried to make it with 16 different python files...same crash. I had all of this working under the 3.3 python plugin, but need to move to a newer python version. I have tried 3.4, 3.5, and now 3.6 and all crash rainmeter.
So...I decide to work around this by making one class for rainmeter and have it dynamically call a specific member method/function:

Code: Select all

    def Update(self):
        self.func = os.getenv('NVFUNC')
        self.writelog("self.func ="+self.func+"\n")
        result = getattr(self, self.func)()
        return result
    def UpdateUtil(self):
        handle = nvmlDeviceGetHandleByIndex(0)
        try:
            util = nvmlDeviceGetUtilizationRates(handle)
            gpu_util = util.gpu
        except NVMLError as err:
            error = handleError(err)
            gpu_util = 0.0
        return float(gpu_util)
    def UpdateLoad(self):
        handle = nvmlDeviceGetHandleByIndex(0)
        try:
            util = nvmlDeviceGetUtilizationRates(handle)
            gpu_util = util.gpu
        except NVMLError as err:
            error = handleError(err)
            gpu_util = 0.0
        return float(gpu_util)
right now I am trying to have rainmeter pass the method name via a env variable, but can't figure out how to get raimeter to do that. I can read env vars with rainmeter, but not set them. What I would really like is a way to pass data from rainmeter into the update() function like "def Reload(self, rm, maxValue):" does. That way I can access a rainmeter variable directly via the "rm" class.
So....anyone have any ideas how to get this done?
sundansx
Posts: 4
Joined: February 8th, 2014, 10:31 pm

Re: python plugin help

sundansx » May 18th, 2019, 4:32 am

I figured out a way to do this. I stored a ref to the rm object in my class and I reference it later. This seems to work well, but not with the newer versions of the python plugin. It is working pretty solid (with occasional rainmeter crash on reload) with python 3.3 and the 3.3 plugin from jblume. newer versions of that plugin/python make it crash right away on loading. Thought I would post here in case someone else finds this useful.

Code: Select all

class Measure:
    debug = False
    strValue = "test"
    floatVal = 0.0
    rmObj = 0
    def __init__(self):
        nvmlInit()
        self.writelog("lib inited\n")
    def Reload(self, rm, maxValue):
        self.writelog("Reload called\n")
        self.rmObj = rm
    def Update(self):
        self.func = self.rmObj.RmReadString('nvFunc', 'UpdateTemp', False)
        self.writelog("self.func ="+self.func+"\n")
        result = getattr(self, self.func)()
        return result
    def GpuLoad(self):
        handle = nvmlDeviceGetHandleByIndex(0)
        try:
            util = nvmlDeviceGetUtilizationRates(handle)
            gpu_util = util.gpu
        except NVMLError as err:
            error = handleError(err)
            gpu_util = 0.0
        return float(gpu_util)
...
measure snip:

Code: Select all

[MeasureNVMLGPU1Usage]
Measure=Plugin
Plugin=Python
PythonHome=E:\Programming\Python33
ScriptPath=defaultCombined.py
ClassName=Measure
UpdateDivider=1
nvFunc=GpuLoad
MinValue=0
MaxValue=100

[MeterNVMLGPU1Usage]
Meter=String
MeasureName=MeasureNVMLGPU1Usage
X=[MeasureLeftTextVal]
Y=[MeasureTopGraphVal]
Text="%1%"
NumOfDecimals=0
MeterStyle=NVMLStyleVal2
mskemalfasya
Posts: 1
Joined: Today, 1:52 am

Re: python plugin help

mskemalfasya » Today, 1:59 am

great job :welcome: , I really wanted to make a akin using python, and there was no tutorial anywhere, and I found https://github.com/adalisan/rainmeter-python but I didn't know how to use it :confused: , and after trying it instead I got a crash on rainmeter :-( . Can you give a sample script? And what do I need to install? thank you, and i got Plugin: Unable to load "Python.dll" (error 126) (Local IP\LocalIP.ini - [MeasurePy]) error :(