Question regarding configuration refresh in plug-ins

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:

Question regarding configuration refresh in plug-ins

Post by krambriw » Mon Dec 29, 2008 8:35 am

Hello,
I have a question related to configuration/settings of data in plug-ins.

In my plug-ins, I have dialogues that allows users to define and alter various data. At run-time, a thread is starting and runs using the configured data.

If I change the data, I have to re-start the thread to make it use the changed data. I would like to make it possible that the data could instead be refreshed without having to re-start the thread.

Is this possible? Any hints would be highly appreciated

Best regards, Walter

Bartman
Plugin Developer
Posts: 881
Joined: Sun Feb 12, 2006 9:03 am

Re: Question regarding configuration refresh in plug-ins

Post by Bartman » Mon Dec 29, 2008 4:23 pm

You do not talk about the plugin configuration dialog right?
If you have a shared variable accessible by the running thread and the plugin you could change the data. You have however notify the thread and make sure you do not run in conflicting states while changing the data.

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

Re: Question regarding configuration refresh in plug-ins

Post by krambriw » Mon Dec 29, 2008 7:02 pm

Dear Bartman,

The variable data is configured in the dialogue that belongs to the action class. The action that is created is running in a thread. Like your timer plug in does. Could you exemplify how I can notify the thread that a variable data has changed?

Best regards, Walter

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

Re: Question regarding configuration refresh in plug-ins

Post by krambriw » Wed Dec 31, 2008 7:55 am

If I explain it in this way;

I have the configuration dialogue for the action on the screen. I make some changes.

When I click on "Apply" the changes are saved as expected

If I instead click on "OK", the changes are saved and the dialogue is closed, also as expected

If I click on "Apply" and then "Test", everything works as I would like to have it

In short, I would like the "Test" to be executed after "OK" button.

Is there a way to catch the "OK" event and then internally trigger the "Test" function????

Best regards, Walter

User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Question regarding configuration refresh in plug-ins

Post by Pako » Wed Dec 31, 2008 11:16 am

I am not sure, whether I understand what you need.
Maybe you will help the attached plugin "Test".
Pako
Attachments
__init__.py
(4.39 KiB) Downloaded 296 times

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

Re: Question regarding configuration refresh in plug-ins

Post by krambriw » Wed Dec 31, 2008 11:31 am

Dear Pako,
Thank You very much, I will study it and see if I can use the logic behind
I wish you a Happy New Year!

Walter

User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Question regarding configuration refresh in plug-ins

Post by Pako » Wed Dec 31, 2008 11:56 am

That's all right.
If you want also something to do for me, try please a functionality of my new plugin "E-mail": http://www.eventghost.org/forum/viewtop ... f=9&t=1168 .
I am surprised that there is no response to it. I would like to know what is not working well.
Pako

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

Re: Question regarding configuration refresh in plug-ins

Post by krambriw » Wed Dec 31, 2008 1:45 pm

Dear Pako, I will for sure try out the email plug-in, I think it is very useful. Actually I used email in one of my old scripts earlier for monitoring purpose (if script execution stopped, an email was sent by another script that monitored the first script).

Anyway, I have tried to understand your sample you gave me and I think its in the right direction, I have modified it to a simpler sample to explain better what I want to do

1. When the user have made changes he clicks on the OK button

This should happen
- configuration changes are saved (like when you click on Apply button)
- configuration dialouge is closed (like with normal OK button)
- execution starts (this works already in your sample with the self.Run )

So there should be some statements needed in this part of the code

Code: Select all

        # re-assign the OK button
        def OnButton(event):
            # 1. Save the settings (like normal apply button)
            # 2. Close the dialog as the normal OK-button does
            self.Run(mValueCtrl.GetValue())
The complete new code is below

Best regards, Walter

Code: Select all

version = "0.0.0"
# This file is part of EventGhost.
# Copyright (C) 2005 Lars-Peter Voss <bitmonster@eventghost.org>
# 
# EventGhost is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# 
# EventGhost is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with EventGhost; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#


eg.RegisterPlugin(
    name = "Test",
    author = "krambriw",
    version = version,
    kind = "program",
    createMacrosOnAdd = False,
    description = "Testing.",
    help = "<i>SOS</i>",
    icon = (
        "iVBORw0KGgoAAAANSUhEUgAAABcAAAAiCAMAAACDQ7KMAAADAFBMVEXRpOgAAAD//wD/"
        "//+AgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
        "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
        "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
        "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
        "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA0sMcANLAAAMgAAAAAAAAA"
        "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
        "AAAAAAAAAADHAACwx7xADwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
        "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
        "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
        "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
        "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADH0qzH0qwAAVwAAAEAAADH0Dj/CYkA"
        "AAAAAAAAAAAAAAMAAADYCo0AAAAAAAAAAAAAAAD///8AAQEAAQAAAAAAAAAAAAAAAAAA"
        "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
        "AAAAAAAAAAAAAAAAAQEAAAAAAADH02zH02wAAJwAAAAAAADH04DH04AAAIgAAAAAABQA"
        "ACtCZRgAAABE9RDH0VDCEnwAAAAAAAgAAGAAAADH07zH07wAAEwAAAAAAADXE2ZbAAAA"
        "AXRSTlMAQObYZgAAAAlwSFlzAAALEgAACxIB0t1+/AAAAIZJREFUeNq1kcsWgCAIRAfj"
        "/785BTEeeXLTrOwCOkzAh0hVaBMhVAa9hmJFaZsCk8PtkRVIMHgI+ojHYkcLMiB8zbLj"
        "dkL4IjgPvov6e97zmvbrx1tjHEjcQsq47y048olR8EyD8i0zDaC0oxhUXvFmn5ySLzC/"
        "4ZjSiTb9ZP/71P+G/+T/Bo2CAlhdZWJTAAAAAElFTkSuQmCC"
    ),
)

#===============================================================================
class Test(eg.PluginClass):
    
    def __init__(self):
        self.AddAction(MyAction)

class MyAction(eg.ActionClass):
    class text:
        txtMyValue = "My value"
        
        
    def Run(self, mValue = 0):
        print mValue       
   
        
    def __call__(self, mValue = 0):
        self.Run(mValue)

                     
    def Configure(self, mValue = 0):
        panel = eg.ConfigPanel(self)
       
        mValueCtrl = panel.SpinIntCtrl(mValue, -120, 120)
        mValueCtrl.SetInitialSize((50,-1))

        panel.AddLine(self.text.txtMyValue,
            mValueCtrl
        )
        
        # re-assign the OK button
        def OnButton(event):
            # 1. Save the settings (like normal apply button)
            # 2. Close the dialog as the normal OK-button does
            self.Run(mValueCtrl.GetValue())
            
        panel.dialog.buttonRow.okButton.Bind(wx.EVT_BUTTON, OnButton)
     
        while panel.Affirmed():
            panel.SetResult(mValueCtrl.GetValue())
        

User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Question regarding configuration refresh in plug-ins

Post by Pako » Wed Dec 31, 2008 7:50 pm

Is this right?

Code: Select all

        # re-assign the OK button
        def OnButton(event):
            # 1. Save the settings (like normal apply button)
            # 2. Close the dialog as the normal OK-button does
            event.Skip()
            self.Run(mValueCtrl.GetValue())
Or this ?

Code: Select all

        # re-assign the OK button
        def OnButton(event):
            # 1. Save the settings (like normal apply button)
            # 2. Close the dialog as the normal OK-button does
            wx.CallAfter(self.Run, mValueCtrl.GetValue())
            event.Skip()
Pako

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

Re: Question regarding configuration refresh in plug-ins

Post by krambriw » Thu Jan 01, 2009 3:43 pm

My Dear Pako,

Both alternatives work very well !!! Exactly the way I think it should.

It would not hurt if this was the standard behaviour in EG. I have seen in many plug-ins that you have to do manual restart or press the "Test" button to make your configuration changes work.

I have implemented the solution in my SunTracker and Scheduler and currently testing them. It seems to work so nice, very convenient. Just make your changes, click OK and it will be affected right away.

Also, I have installed and started to check your email plug in. I think questions & comments shall be posted in the dedicated plug-in topic. Need to try a bit more....

Best regards & and thanks again,
Walter

Bartman
Plugin Developer
Posts: 881
Joined: Sun Feb 12, 2006 9:03 am

Re: Question regarding configuration refresh in plug-ins

Post by Bartman » Thu Jan 01, 2009 8:53 pm

Normally an action should not change anything in the plugin's config as this would be nearly impossible to keep the overview of how the plugin/action reacts if it gets changed anywhere.
If the plugin config is changed via it's config dialog the plugin is restarted automatically.
If you change the action settings the changes will be used the next time the action is called. Otherwise it would be a bug.

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

Re: Question regarding configuration refresh in plug-ins

Post by krambriw » Thu Jan 01, 2009 10:26 pm

You have maybe misunderstood the whole thing, I better explain;

For me there are two important things when I do something; simplicity & user friendliness (I think that's hard to argue against)

In this particular case, the plug-in itself is just a "dumb" container showing running threads

The actual functionality is inside the action, consisting of the thread running a while loop. All user data is configured in the actions

Normally the plug-in is continuously running. If I have to change a setting, there is for sure a reason for it. And I want this to be easy and user friendly

What happened here is just that a very natural and obvious function was added to the OK button. Instead of remembering to do further steps, I got that in one simple shot

I do not see why this is changing anything, its only making things easier. Sooner or later you will anyhow have to restart the thing, otherwise there was no reason to change the configuration

Maybe this brakes some rules but it improves the simplicity & user friendliness

Best regards, Walter

EDIT: I think this problem is only relevant when you have an action "in progress" or "looping". Think about the two following samples; a car is the plug-in and the running engine is the action, a printer is the plug-in and the paper is the action.

Post Reply