Variable title question

If you have a question or need help, this is the place to be.
Post Reply
dan Edens
Experienced User
Posts: 110
Joined: Mon Sep 24, 2018 7:57 pm

Variable title question

Post by dan Edens » Tue Jun 25, 2019 12:37 pm

Is it possible to get the OSD to display the values?
askeg.png
Thanks,
Dan.

User avatar
kgschlosser
Site Admin
Posts: 5508
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Variable title question

Post by kgschlosser » Tue Jun 25, 2019 3:43 pm

you would need to edit the plugin. locate the action AddButton

something like this should work

Code: Select all

class AddButton(eg.ActionBase):
    name = "Add Button"

    def __call__(self, kwargs):
        for key, value in list(kwargs.items())[:]:
            if isinstance(key, (str, unicode)) and '{' in key and '}' in key:
                try:
                    new_key = eg.ParseString(key)
                    del kwargs[key]
                    key = new_key
                except:
                    pass
            
            if isinstance(value, (str, unicode)):
                try:
                    value = eg.ParseString(value)
                except:
                    pass
            kwargs[key] = value

        self.plugin.data.append((ButtonType, kwargs))
If you like the work I have been doing then feel free to Image

dan Edens
Experienced User
Posts: 110
Joined: Mon Sep 24, 2018 7:57 pm

Re: Variable title question

Post by dan Edens » Wed Jun 26, 2019 7:56 pm

This worked perfectly, and I'm not exaggerating, has changed my life. lol.
Windows clip-history is cool and whatever, but I can now paste in a cycle or the same one rapidly, endless possibility. Not having to guess what I'm holding in each slot makes it actually useful finally.
Very Cool.

Can i commit this to the repo?
Saw you ask someone to on another thread thought I'd give it a go.

Kinda really need to learn proper git and thought this would be good chance to get my feet in the water.
It's your work tho so I added your tag on the commit.
I committed to my branch titled "[DesktopRemote] Variable parsing", but I'd need access to push it for review, correct?

The develop branch seems reeeeeal stale, so not sure if Master is the right target, but I believe I've followed the EG guides for my commit and branch title correctly so far.


Am really interested in doing more helping out as i learn, been studying hard!
Thanks again man, Having the various code you've sent me in the past to reference has been a huge jumpstart.

https://github.com/DanEdens

2019-06-26 14_46_28-Window.png

User avatar
kgschlosser
Site Admin
Posts: 5508
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Variable title question

Post by kgschlosser » Thu Jun 27, 2019 5:35 am

ok so this is what you want to do..

Fork the EventGhost master branch (if you have not done this already).
Then on your EventGhost repository (https://github.com/DanEdens/EventGhost) you will want to create a new branch. This is something you are going to do using the command line on your computer or via an application like PyCharm or gitkracken. if you do not want to use any of those options then you can just edit the file using the webpage and make the modifications. at that point when you save the changes it is going to ask you if you want to add the changes to the master branch or if you want to make a new one. tell it to make a new one. If using one of the above options after creating the new branch you want to use that branch. then edit the files and do a commit. when the commit takes place the new branch will be made with the code changes.

after you have made the branch and have the changes in it you will want to open a PR (Pull Request) when you start the pull request it is going to ask you what repository and what branch. it should default to EventGhost/EventGhost and the Master branch. this is what you want. Then go ahead and create the PR

when you commit a code change or create a PR you will need to key in a title. we like to have some kind of an identification to what was modified. if it is the core then the filename is good. if it is a plugin, give the plugin name... like the example below.

"[DesktopRemote plugin] Adds eg.ParseString to the AddButton action"

There needs to be more done in order to provide a PR for it. You need to provide a checkbox in the config dialog for the action that will allow the user to enable or disable parsing. You need to add the passed parameter to the end of the call and configure methods and have it defaulted to false. then add a check of that in the call method to parse the string.

I will provide a code example in a few minutes,
If you like the work I have been doing then feel free to Image

User avatar
kgschlosser
Site Admin
Posts: 5508
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Variable title question

Post by kgschlosser » Thu Jun 27, 2019 5:53 am

ok so you need to modify the Text class

Code: Select all



class Text:
    class CreateNew:
        pass

    class AddButton:
        label = "Label:"
        event = "Event:"
        parse = "Contains Python expression:"


and here is the action with the config dialog changes

Code: Select all

class AddButton(eg.ActionBase):
    name = "Add Button"

    def __call__(self, kwargs):

        label_parse = kwargs.pop("label_parse", False)
        event_parse = kwargs.pop("event_parse", False)

        if label_parse:
            try:
                kwargs['label'] = eg.ParseString(kwargs['label'])
            except:
                pass

        if event_parse:
            try:
                kwargs['event'] = eg.ParseString(kwargs['event'])
            except:
                pass

        self.plugin.data.append((ButtonType, kwargs))

    def GetLabel(self, kwargs):
        return self.name + ": " + kwargs.get("label", "")


    def Configure(self, kwargs={}):

        def MakeOption(name, checkBox, ctrl):
            value = kwargs.get(name, None)

            def OnCheckBox(event):
                ctrl.Enable(checkBox.GetValue())
                event.Skip()
            checkBox.Bind(wx.EVT_CHECKBOX, OnCheckBox)
            if value is None:
                checkBox.SetValue(False)
                ctrl.SetValue(self.plugin.defaults[name])
                ctrl.Enable(False)
            else:
                checkBox.SetValue(True)
                ctrl.SetValue(value)
            panel.AddLine(checkBox, ctrl)
            def SetResult():
                if checkBox.GetValue():
                    kwargs[name] = ctrl.GetValue()
            return SetResult

        panel = eg.ConfigPanel()
        panel.SetSizerProperty(vgap=2)
        text = self.text

        labelCtrl = panel.TextCtrl(kwargs.get("label", ""))
        labelParseCtrl = panel.CheckBox(label=text.parse)
        labelParseCtrl.SetValue(kwargs.get("label_parse", False))

        panel.AddLine(text.label, labelCtrl, labelParseCtrl)

        eventCtrl = panel.TextCtrl(kwargs.get("event", ""))
        eventParseCtrl = panel.CheckBox(label=text.parse)
        eventParseCtrl.SetValue(kwargs.get("event_parse", False))

        panel.AddLine(text.event, eventCtrl, eventParseCtrl)

        invisibleCtrl = panel.CheckBox(
            kwargs.get("invisible", False),
            "Invisible"
        )
        panel.AddLine(invisibleCtrl)

        imageButton = ImageButton(panel, label="Choose Image")
        imageBox = wx.StaticBitmap(
            panel,
            size=(40, 40),
            pos=(280, 70),
            style=wx.SUNKEN_BORDER
        )
        imageButton.view = imageBox

        imageOption = MakeOption(
            "image",
            panel.CheckBox(label="Use image as label:"),
            imageButton
        )

        foregroundColour = MakeOption(
            "foregroundColour",
            panel.CheckBox(label="Override foreground colour:"),
            panel.ColourSelectButton(),
        )

        backgroundColour = MakeOption(
            "backgroundColour",
            panel.CheckBox(label="Override background colour:"),
            panel.ColourSelectButton(),
        )

        fontInfo = MakeOption(
            "fontInfo",
            panel.CheckBox(label="Override button font:"),
            panel.FontSelectButton(),
        )

        width = MakeOption(
            "width",
            panel.CheckBox(label="Override width:"),
            panel.SpinIntCtrl()
        )

        height = MakeOption(
            "height",
            panel.CheckBox(label="Override height:"),
            panel.SpinIntCtrl()
        )

        while panel.Affirmed():
            image = kwargs.get("image", None)
            kwargs = dict(
                label=labelCtrl.GetValue(),
                label_parse=labelParseCtrl.GetValue(),
                event=eventCtrl.GetValue(),
                event_parse=eventParseCtrl.GetValue()
            )

            fontInfo()
            foregroundColour()
            backgroundColour()
            width()
            height()
            imageOption()
            if invisibleCtrl.GetValue():
                kwargs["invisible"] = True
            panel.SetResult(kwargs)

There are use cases when the user may not want the text to get parsed. we have to allow the user to turn on and off that feature. for each control that the text gets parsed on. This is a great example to show because it has 2 text controls that a user can enter information into.
If you like the work I have been doing then feel free to Image

dan Edens
Experienced User
Posts: 110
Joined: Mon Sep 24, 2018 7:57 pm

Re: Variable title question

Post by dan Edens » Fri Jun 28, 2019 5:52 pm

Once again I'm blown away with the response man thank you.

I was actually thinking about needing that option before you mentioned it. I'll get right on this! >:D

I had another idea alongside the disable/enable.
Do you think there would be any value in adding another option to limit number of characters in the shown text?
Just to use my use case as an example.
[:7]
If i had a long string in my clip1 value that's being shown, only show the first 7 characters.

I'm going to set this up as you've laid it out.
Than attempt this extra setting myself, than once i get it working (I think it's simple enough i shouldn't have any issues) we can look at it than if it's any value to anyone else.

dan Edens
Experienced User
Posts: 110
Joined: Mon Sep 24, 2018 7:57 pm

Re: Variable title question

Post by dan Edens » Fri Jun 28, 2019 6:06 pm

Ha nevermind.

AGAIN you have answered questions I wasn't even at yet.

Donating.

dan Edens
Experienced User
Posts: 110
Joined: Mon Sep 24, 2018 7:57 pm

Re: Variable title question

Post by dan Edens » Fri Jun 28, 2019 8:49 pm

So I got it to sort of work.
After running the action, It replaces the {eg.globals.clip1} with it's value and removes the check from the box.

Pycharm gave me:

Code: Select all

def Configure(self, kwargs={}):
on the {}
Inspection info: This inspection detects when a mutable value as list or dictionary is detected in a default value for an argument.
Default argument values are evaluated only once at function definition time, which means that modifying the default value of the argument will affect all subsequent calls of the function.

Value of clip1 = 1 for these screenshots
2019-06-28 14_20_48-Clipboard vs Editor.png
2019-06-28 14_21_13-Clipboard vs Editor.png
2019-06-28 14_21_19-EventGhost WIP-2019.04.14-12.39.31 - general ai 0.2.9.png
2019-06-28 14_21_19-EventGhost WIP-2019.04.14-12.39.31 - general ai 0.2.9.png (6.66 KiB) Viewed 2208 times
2019-06-28 14_21_26-Clipboard vs Editor.png
2019-06-28 14_21_26-Clipboard vs Editor.png (7.68 KiB) Viewed 2208 times
Sounds like the problem it's having. I chopped that bit out below so it's easier to see and while giving it context

Here's where it's at:

Code: Select all

class AddButton(eg.ActionBase):
    name = "Add Button"

    def __call__(self, kwargs):

        label_parse = kwargs.pop("label_parse", False)
        event_parse = kwargs.pop("event_parse", False)

        if label_parse:
            try:
                kwargs['label'] = eg.ParseString(kwargs['label'])
            except:
                pass

        if event_parse:
            try:
                kwargs['event'] = eg.ParseString(kwargs['event'])
            except:
                pass

        self.plugin.data.append((ButtonType, kwargs))

    def GetLabel(self, kwargs):
        return self.name + ": " + kwargs.get("label", "")
Config

Code: Select all

    def Configure(self, kwargs={}):

        def MakeOption(name, checkBox, ctrl):
            value = kwargs.get(name, None)
            def OnCheckBox(event):
                ctrl.Enable(checkBox.GetValue())
                event.Skip()
            checkBox.Bind(wx.EVT_CHECKBOX, OnCheckBox)
            if value is None:
                checkBox.SetValue(False)
                ctrl.SetValue(self.plugin.defaults[name])
                ctrl.Enable(False)
            else:
                checkBox.SetValue(True)
                ctrl.SetValue(value)
            panel.AddLine(checkBox, ctrl)
            def SetResult():
                if checkBox.GetValue():
                    kwargs[name] = ctrl.GetValue()
            return SetResult
The rest

Code: Select all

        panel = eg.ConfigPanel()
        panel.SetSizerProperty(vgap=2)
        text = self.text

        labelCtrl = panel.TextCtrl(kwargs.get("label", ""))
        labelParseCtrl = panel.CheckBox(label=text.parse)
        labelParseCtrl.SetValue(kwargs.get("label_parse", False))

        panel.AddLine(text.label, labelCtrl, labelParseCtrl)

        eventCtrl = panel.TextCtrl(kwargs.get("event", ""))
        eventParseCtrl = panel.CheckBox(label=text.parse)
        eventParseCtrl.SetValue(kwargs.get("event_parse", False))

        panel.AddLine(text.event, eventCtrl, eventParseCtrl)

        invisibleCtrl = panel.CheckBox(
            kwargs.get("invisible", False),
            "Invisible"
        )
        panel.AddLine(invisibleCtrl)

        imageButton = ImageButton(panel, label="Choose Image")
        imageBox = wx.StaticBitmap(
            panel,
            size=(40, 40),
            pos=(280, 70),
            style=wx.SUNKEN_BORDER
        )
        imageButton.view = imageBox

        imageOption = MakeOption(
            "image",
            panel.CheckBox(label="Use image as label:"),
            imageButton
        )

        foregroundColour = MakeOption(
            "foregroundColour",
            panel.CheckBox(label="Override foreground colour:"),
            panel.ColourSelectButton()
        )

        backgroundColour = MakeOption(
            "backgroundColour",
            panel.CheckBox(label="Override background colour:"),
            panel.ColourSelectButton()
        )

        fontInfo = MakeOption(
            "fontInfo",
            panel.CheckBox(label="Override button font:"),
            panel.FontSelectButton()
        )

        width = MakeOption(
            "width",
            panel.CheckBox(label="Override width:"),
            panel.SpinIntCtrl()
        )

        height = MakeOption(
            "height",
            panel.CheckBox(label="Override height:"),
            panel.SpinIntCtrl()
        )

        while panel.Affirmed():
            image = kwargs.get("image", None)
            kwargs = dict(
                label=labelCtrl.GetValue(),
                label_parse=labelParseCtrl.GetValue(),
                event=eventCtrl.GetValue(),
                event_parse=eventParseCtrl.GetValue()
            )
            fontInfo()
            foregroundColour()
            backgroundColour()
            width()
            height()
            imageOption()
            if invisibleCtrl.GetValue():
                kwargs["invisible"] = True
            panel.SetResult(kwargs)


class StartNewLine(eg.ActionBase):

Little note, removed 3 "," from your example that seem to prevent building.

Code: Select all

366            panel.ColourSelectButton()
372            panel.ColourSelectButton()
378            panel.FontSelectButton()

dan Edens
Experienced User
Posts: 110
Joined: Mon Sep 24, 2018 7:57 pm

Re: Variable title question

Post by dan Edens » Tue Jul 02, 2019 2:15 pm

I've come to realize I'm an idiot. lol

Web server is the MUCH BETTER answer to the things I'm trying to accomplish here.
I was having issues installing the plugin for months, but I figured it out finally.

While I am curious to learn where in the process the effort fails, I don't think it's a good use of your time to dwell on it.

I've moved on to turning my extended clipboard into a plugin of it's own based on the global var monitor.
Already learned alot following the template line by line.

Post Reply