Help with a plug-in???

Do you have questions about writing plugins or scripts in Python? Meet the coders here.
Post Reply
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Help with a plug-in???

Post by krambriw » Mon Feb 25, 2008 3:22 pm

Hello, I'm writing on a plug-in and I would like to ask if someone can give me advice of the following:

In the plug in I have a class DeviceCT for definition of counter objects. The user can set the counter number (1 or 2) and a counter limit for each (from 1 and up).

The class definition looks like this

Code: Select all

class DeviceCT(object):
    def Configure(self, ct = 1, ctl = 5):
        nbr_list = []
        for i in range(255):
            nbr_list.append(str(i))
        panel = eg.ConfigPanel(self)
        ctr_ctrl = panel.Choice(ct, choices=['', '1', '2'])
        panel.AddLine("Counter", ctr_ctrl)
        ctr_limit = panel.Choice(ctl, choices=nbr_list)
        panel.AddLine("Counter limit", ctr_limit)
        while panel.Affirmed():
            panel.SetResult(ctr_ctrl.GetValue(), ctr_limit.GetValue())


My problem is how I can read the configured values from anywhere in the plug-in code (like from code inside another class or in my case a thread). How can I read the actual values from ctr_ctrl and ctr_limit above? Do I have to make them eg.globals or is there a more clever way?

Thanks in advance, Walter

User avatar
Bitmonster
Site Admin
Posts: 2239
Joined: Mon Feb 06, 2006 10:28 pm

Re: Help with a plug-in???

Post by Bitmonster » Wed Feb 27, 2008 11:46 pm

Is DeviceCT an action or a plugin?

If it is an action, you can't do it directly. The action needs to be executed first and then it could assign something to self.plugin.myVar for example in the __call__ method.
Just configuring an action to change a parameter the plugin should use isn't enough, because you could have an unlimited number of instances of the action class in the tree and there would be no way to determine which one gives the right value now.
Please post software-related questions in the forum - PMs will only be answered, if really private, thanks!

krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: Help with a plug-in???

Post by krambriw » Thu Feb 28, 2008 4:49 pm

@Bitmonster,

First, most welcome back!!!!

krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: Help with a plug-in???

Post by krambriw » Thu Feb 28, 2008 4:54 pm

Dear Bitmonster,
Yes, I use this class to create actions. I have solved it like the code below. Now as soon as an action is created, I can access the settings of it. Maybe not the most professional....

Best regards, Walter

Code: Select all

class DeviceCT(object):
#Counters on the board, 2 in total
    def Configure(self, ct = 1, ctl = 5, cdb = 10):
        panel = eg.ConfigPanel(self)
        counter_ctrl = panel.Choice(ct, choices=['', '1', '2'])
        panel.AddLine("Counter", counter_ctrl)
        counter_limit = panel.Choice(ctl, choices=eg.globals.nbr_list)
        panel.AddLine("Counter limit", counter_limit)
        ctr_debounce = panel.Choice(cdb, choices=['0', '2', '10', '1000'])
        panel.AddLine("Counter debounce (ms)", ctr_debounce)
        while panel.Affirmed():
            panel.SetResult(counter_ctrl.GetValue(), counter_limit.GetValue(), ctr_debounce.GetValue())
            #Configure the debounce
            dbv = ctr_debounce.GetValue()
            param_1 = counter_ctrl.GetValue()
            param_2 = 0
            if dbv == 0:
                param_2 = 0
            elif dbv == 1:
                param_2 = 2
            elif dbv == 2:
                param_2 = 10
            elif dbv == 3:
                param_2 = 1000
            self.plugin.dll.SetCounterDebounceTime(param_1, param_2)
            #Save counter thresholds
            if param_1 == 1:
                eg.globals.counter_1_threshold = counter_limit.GetValue()
            elif param_1 == 2:
                eg.globals.counter_2_threshold = counter_limit.GetValue()


class Counter(DeviceCT, eg.ActionClass):
    name = "Counter"
    description = "Holds a counter in K8055"
    iconFile = "counter"

    def __call__(self, ct, ctl, cdb):
        ret = self.plugin.dll.ReadCounter(ct)
        print ret
        
        

krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: Help with a plug-in???

Post by krambriw » Thu Feb 28, 2008 5:32 pm

Is it possible to make a already defined action to "run" its own configuration at startup of the plugin it belongs to?

What I mean is that I would like the following to happen:
- plug-in starts
- each defined action for the plug-in shall then (hidden) self execute its configuration (just like if you open the "configure" and click ok)

Otherwise, if not possible, I think I need to use a file I/O solution to make my settings persistent

Post Reply