예제 #1
0
 def OnTestButton(dummyEvent):
     args = GetResult()[:-2]  # we don't need timeout and stopMacro
     # parameter
     hwnds = eg.WindowMatcher(*args)()
     dialog = TestDialog(panel.dialog, hwnds)
     dialog.ShowModal()
     dialog.Destroy()
예제 #2
0
    def Compile(self,
                program=None,
                winName=None,
                winClass=None,
                childName=None,
                childClass=None,
                matchNum=1,
                includeInvisible=False,
                timeout=0,
                stopMacro=STOP_IF_NOT_FOUND):
        if stopMacro is None:
            return UseForegroundWindowOnly

        matcher = eg.WindowMatcher(
            program,
            winName,
            winClass,
            childName,
            childClass,
            matchNum,
            includeInvisible,
            timeout,
        )

        def Do():
            hwnds = matcher()
            if ((stopMacro == STOP_IF_NOT_FOUND and not hwnds)
                    or (stopMacro == STOP_IF_FOUND and hwnds)):
                eg.programCounter = None
            eg.lastFoundWindows[:] = hwnds
            return hwnds

        return Do
예제 #3
0
    def Configure(
        self,
        program="",
        winName=None,
        winClass=None,
        childName=None,
        childClass=None,
        matchNum=1,
        includeInvisible=False,
        timeout=0,
        stop=STOP_IF_NOT_FOUND
    ):
        panel = eg.ConfigPanel(resizable=True)
        text = self.text
        searchOnlyFrontmost = False
        if stop is None:
            program = ""
            matchNum = 1
            includeInvisible = False
            timeout = 0
            stop = 0
            searchOnlyFrontmost = True
        self.dialog = panel.dialog
        self.lastHwnd = None
        self.lastPid = None
        self.hideOnDrag = True

        # the "only search for the frontmost" checkbox
        cbOnlyFrontmost = wx.CheckBox(panel, -1, text.onlyFrontmost)

        def OnSearchOnlyFrontmostCheckbox(event):
            flag = not cbOnlyFrontmost.IsChecked()
            cbIncludeInvisible.Enable(flag)
            if not flag:
                stopMacroCtrl_1.SetValue(False)
                stopMacroCtrl_2.SetValue(False)
            stopMacroCtrl_1.Enable(flag)
            stopMacroCtrl_2.Enable(flag)
            waitCtrl.Enable(flag)
            for checkBox, textCtrl in self.options[:-1]:
                checkBox.Enable(flag)
                textCtrl.Enable(flag and checkBox.GetValue())
            self.options[-1][0].Enable(flag)
            self.options[-1][1].Enable(flag)
            event.Skip()
        cbOnlyFrontmost.Bind(wx.EVT_CHECKBOX, OnSearchOnlyFrontmostCheckbox)

        # the IncludeInvisible checkbox
        cbIncludeInvisible = wx.CheckBox(panel, -1, text.invisible_box)

        def OnIncludeInvisibleCheckbox(event):
            hwnd = self.lastHwnd
            self.tree.includeInvisible = cbIncludeInvisible.IsChecked()
            self.tree.Refresh()
            self.tree.SelectHwnd(hwnd)
            event.Skip()
        cbIncludeInvisible.Bind(wx.EVT_CHECKBOX, OnIncludeInvisibleCheckbox)

        # the stop-macro choice
        id_1 = wx.NewId()
        stopMacroCtrl_1 = wx.CheckBox(panel, id_1, text.stopMacro[0])
        id_2 = wx.NewId()
        stopMacroCtrl_2 = wx.CheckBox(panel, id_2, text.stopMacro[1])

        if stop == STOP_IF_NOT_FOUND:
            stopMacroCtrl_1.SetValue(True)
            stopMacroCtrl_2.Enable(False)
        elif stop == STOP_IF_FOUND:
            stopMacroCtrl_2.SetValue(True)
            stopMacroCtrl_1.Enable(False)

        def OnStopMacroCtrl(event):
           # if cbOnlyFrontmost.IsChecked():
            id = event.GetId()
            flag = event.IsChecked()
            if id == id_1:
                stopMacroCtrl_2.Enable(not flag)
                if flag:
                    stopMacroCtrl_2.SetValue(False)
            else:
                stopMacroCtrl_1.Enable(not flag)
                if flag:
                    stopMacroCtrl_1.SetValue(False)
            event.Skip()
        stopMacroCtrl_1.Bind(wx.EVT_CHECKBOX, OnStopMacroCtrl)
        stopMacroCtrl_2.Bind(wx.EVT_CHECKBOX, OnStopMacroCtrl)

        finderTool = eg.WindowDragFinder(
            panel,
            self.OnFinderToolLeftClick,
            self.OnFinderTool
        )
        self.finderTool = finderTool

        # the HideOnDrag checkbox
        cbHideOnDrag = wx.CheckBox(panel, -1, text.hide_box)
        cbHideOnDrag.SetValue(Config.hideOnDrag)

        def OnHideOnDragCheckbox(dummyEvent):
            Config.hideOnDrag = cbHideOnDrag.IsChecked()
        cbHideOnDrag.Bind(wx.EVT_CHECKBOX, OnHideOnDragCheckbox)

        # the tree to display processes and windows
        self.tree = eg.WindowTree(panel, includeInvisible=includeInvisible)
        cbIncludeInvisible.SetValue(includeInvisible)

        # the refresh button
        refreshButton = wx.Button(panel, -1, text.refresh_btn)

        def OnButton(dummyEvent):
            hwnd = self.lastHwnd
            self.tree.Refresh()
            self.tree.SelectHwnd(hwnd)
        refreshButton.Bind(wx.EVT_BUTTON, OnButton)

        # construction of the layout with sizers
        dragSizer = wx.StaticBoxSizer(
            wx.StaticBox(panel, -1, "Drag Finder"),
            wx.VERTICAL
        )
        dragSizer.Add(finderTool, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.BOTTOM, 4)
        dragSizer.Add(cbHideOnDrag)

        leftTopSizer = wx.BoxSizer(wx.VERTICAL)
        leftTopSizer.Add(cbOnlyFrontmost, 0, wx.BOTTOM, 5)
        leftTopSizer.Add(cbIncludeInvisible, 0, wx.BOTTOM, 5)
        leftTopSizer.Add(stopMacroCtrl_1, 0, wx.BOTTOM, 5)
        leftTopSizer.Add(stopMacroCtrl_2, 0, wx.BOTTOM, 5)

        topSizer = wx.BoxSizer(wx.HORIZONTAL)
        topSizer.Add(leftTopSizer, 1, wx.EXPAND)
        topSizer.Add(dragSizer)

        sizer1 = wx.GridBagSizer(vgap=4, hgap=4)
        sizer1.SetEmptyCellSize((0, 0))
        sizer1.Add(self.tree, (0, 0), (1, 5), wx.EXPAND)
        sizer1.Add(refreshButton, (1, 4), (2, 1), wx.ALIGN_TOP | wx.ALIGN_RIGHT)

        self.options = options = []

        def Wrapper(textCtrl, checkBox):
            def OnCheckBox(event):
                textCtrl.Enable(checkBox.GetValue())
                event.Skip()
            return OnCheckBox

        def MakeLine(line, checkBoxText, value):
            checkBox = wx.CheckBox(panel, -1, checkBoxText)
            sizer1.Add(checkBox, (line, 0), (1, 1), wx.ALIGN_CENTER_VERTICAL)
            textCtrl = wx.TextCtrl(panel, -1, size=(20, -1))
            if value is not None:
                checkBox.SetValue(True)
                textCtrl.SetValue(value)
            else:
                textCtrl.Enable(False)
            sizer1.Add(textCtrl, (line, 1), (1, 3), wx.EXPAND)
            checkBox.Bind(wx.EVT_CHECKBOX, Wrapper(textCtrl, checkBox))
            options.append((checkBox, textCtrl))
            line += 1

        MakeLine(1, text.options[0], program)
        MakeLine(2, text.options[1], winName)
        MakeLine(3, text.options[2], winClass)
        MakeLine(4, text.options[3], childName)
        MakeLine(5, text.options[4], childClass)
        line = 6
        numMatchCB = wx.CheckBox(panel, -1, text.matchNum1)
        numMatchCB.SetValue(bool(matchNum))
        sizer1.Add(numMatchCB, (line, 0), (1, 1), wx.ALIGN_CENTER_VERTICAL)
        numMatchCtrl = eg.SpinIntCtrl(panel, -1, matchNum or 1, 1)
        sizer1.Add(numMatchCtrl, (line, 1), (1, 1), wx.EXPAND)
        sizer1.Add(
            wx.StaticText(panel, -1, text.matchNum2),
            (line, 2),
            (1, 3),
            wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT
        )
        numMatchCB.Bind(wx.EVT_CHECKBOX, Wrapper(numMatchCtrl, numMatchCB))
        options.append((numMatchCB, numMatchCtrl))
        line += 1

        # the wait parameter
        waitCtrl = eg.SpinNumCtrl(panel)
        waitCtrl.SetValue(timeout)

        sizer1.Add(
            panel.StaticText(text.wait1),
            (line, 0),
            (1, 1),
            wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT
        )
        sizer1.Add(
            waitCtrl,
            (line, 1),
            (1, 1),
            wx.ALIGN_CENTER_VERTICAL | wx.EXPAND
        )
        sizer1.Add(
            panel.StaticText(text.wait2),
            (line, 2),
            (1, 3),
            wx.ALIGN_CENTER_VERTICAL
        )
        line += 1
        sizer1.Add((1, 1), (line, 0))
        sizer1.AddGrowableCol(2, 100)
        sizer1.AddGrowableRow(0, 100)
        #sizer1.SetItemMinSize(options[0][1], 300, -1)

        # group the main lines together
        panel.sizer.AddMany([
            (topSizer, 0, wx.EXPAND),
            ((5, 5), ),
            (sizer1, 1, wx.EXPAND),
        ])

        # re-assign the test button
        def OnTestButton(dummyEvent):
            args = GetResult()[:-2]  # we don't need timeout and stopMacro
            hwnds = eg.WindowMatcher(*args)()
            dialog = TestDialog(panel.dialog, hwnds)
            dialog.ShowModal()
            dialog.Destroy()
        panel.dialog.buttonRow.testButton.Bind(wx.EVT_BUTTON, OnTestButton)

        @eg.LogIt
        def GetResult():
            resultList = []
            for checkBox, textCtrl in options:
                if not checkBox.IsChecked():
                    resultList.append(None)
                else:
                    resultList.append(textCtrl.GetValue())
            resultList.append(self.tree.includeInvisible)
            resultList.append(waitCtrl.GetValue())
            if stopMacroCtrl_1.IsChecked():
                resultList.append(STOP_IF_NOT_FOUND)
            elif stopMacroCtrl_2.IsChecked():
                resultList.append(STOP_IF_FOUND)
            else:
                resultList.append(STOP_NEVER)
            return resultList

        hwnds = eg.WindowMatcher(
            program,
            winName,
            winClass,
            childName,
            childClass,
            matchNum,
            includeInvisible,
        )()
        if matchNum is not None and len(hwnds):
            self.lastHwnd = hwnds[0]
            self.tree.SelectHwnd(self.lastHwnd)
        if searchOnlyFrontmost:
            cbOnlyFrontmost.SetValue(True)
            OnSearchOnlyFrontmostCheckbox(wx.CommandEvent())
        while True:
            self.tree.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnSelectionChanged)
            affirmed = panel.Affirmed()
            self.tree.Unbind(wx.EVT_TREE_SEL_CHANGED)
            if not affirmed:
                break
            if cbOnlyFrontmost.IsChecked():
                panel.SetResult(
                    None, None, None, None, None, None, None, None, None
                )
            else:
                panel.SetResult(*GetResult())
예제 #4
0
    ("MyPictures", "MyPictures", None, 73),
    ("MyVideos", "MyVideos", None, 74),
    ("Print", "Print", None, 78),
    ("MyRadio", "MyRadio", None, 80),
    ("Teletext", "Teletext", None, 90),
    ("Red", "Red", None, 91),
    ("Green", "Green", None, 92),
    ("Yellow", "Yellow", None, 93),
    ("Blue", "Blue", None, 94),
    ("PowerTV", "PowerTV", None, 101),
    ("Messenger", "Messenger", None, 105),
]

from eg.WinApi import SendMessageTimeout

gWindowMatcher = eg.WindowMatcher("MediaPortal.exe")


class ActionPrototype(eg.ActionBase):
    def __call__(self):
        try:
            hwnd = gWindowMatcher()[0]
            return SendMessageTimeout(hwnd, 32768, 24, self.value)
        except:
            raise self.Exceptions.ProgramNotRunning


class MediaPortal(eg.PluginBase):
    def __init__(self):
        self.AddActionsFromList(ACTIONS, ActionPrototype)
예제 #5
0
    ("ChangeAudioMode", "Change Audio Mode", None, "{CTRL+SHIFT+C}"),
    ("VizUp", "Viz Up", None, "{PAGEUP}"),
    ("VizDown", "Viz Down", None, "{PAGEDOWN}"),
    ("NumPad0", "NumPad 0", None, "{0}"),
    ("NumPad1", "NumPad 1", None, "{1}"),
    ("NumPad2", "NumPad 2", None, "{2}"),
    ("NumPad3", "NumPad 3", None, "{3}"),
    ("NumPad4", "NumPad 4", None, "{4}"),
    ("NumPad5", "NumPad 5", None, "{5}"),
    ("NumPad6", "NumPad 6", None, "{6}"),
    ("NumPad7", "NumPad 7", None, "{7}"),
    ("NumPad8", "NumPad 8", None, "{8}"),
    ("NumPad9", "NumPad 9", None, "{9}"),
]

gWindowMatcher = eg.WindowMatcher('PowerCinema{*}.exe', '{*}PowerCinema{*}')


class ActionPrototype(eg.ActionBase):
    def __call__(self):
        hwnds = gWindowMatcher()
        if hwnds:
            eg.SendKeys(hwnds[0], self.value)
        else:
            raise self.Exceptions.ProgramNotRunning


class PowerCinema(eg.PluginBase):
    def __init__(self):
        self.AddActionsFromList(ACTIONS, ActionPrototype)
예제 #6
0
    ("NextAudioStream", "Next audio stream", "Switches among available audio streams.", "h"),
    ("NextSubtitle", "Next subtitle", "Switches among available subtitles during playback.", "u"),
    ("NextAngel", "Next angel", "Switches among available angles if any.", "a"),
    ("SayItAgain", "Say-It-Again", "Repeats the last dialog.", "w"),
    ("SeeItAll", "See-It-All", "Activates See-It-All function, refer to Blu-ray Disc Configuration.", "{LCtrl+S}"),
    ("CaptureFrame", "Capture frame", "Captures video content as bitmap image files. (Not supported during HD DVD and Blu-ray Disc playback.)", "c"),
    ("NavigationUp", "Navigation Up", "Navigates through disc menus.", "{Up}"),
    ("NavigationDown", "Navigation Down", "Navigates through disc menus.", "{Down}"),
    ("NavigationLeft", "Navigation Left", "Navigates through disc menus.", "{Left}"),
    ("NavigationRight", "Navigation Right", "Navigates through disc menus.", "{Right}"),
    ("NavigationEnter", "Navigation Enter", "Navigates through disc menus. (Has actually the same function as the Play action.)", "{Return}"),
    ("Close", "Close", "Close PowerDVD.", "{Ctrl+x}"),
]


gWindowMatcher = eg.WindowMatcher('PowerDVD{*}.exe', 'CyberLink PowerDVD{*}')


class ActionPrototype(eg.ActionBase):
    
    def __call__(self):
        hwnds = gWindowMatcher()
        if hwnds:
            eg.SendKeys(hwnds[0], self.value)
        else:
            raise self.Exceptions.ProgramNotRunning
        
        
        
class PowerDvd(eg.PluginBase):
    
예제 #7
0
# with EventGhost. If not, see <http://www.gnu.org/licenses/>.

import eg

eg.RegisterPlugin(
    name="CyberLink PowerDVD",
    description="Adds actions to control CyberLink PowerDVD.",
    kind="program",
    author="Bitmonster, GruberMarkus",
    guid="{4DBDFFA7-9E47-4782-B843-B196C74DE3EF}",
    version="2.0",
    createMacrosOnAdd=True,
)

gWindowMatcherMainWindow = eg.WindowMatcher('PowerDVD{*}.exe', 'PowerDVD',
                                            None, None, None, 1, "false", 0,
                                            None)
gWindowMatcherPlayerWindow = eg.WindowMatcher('PowerDVD{*}.exe', 'PowerDVD',
                                              '{*}', '{*}', '{*}', 1, "true",
                                              0, None)


class SendAction(eg.ActionBase):
    def __call__(self):
        # Get the window handle (HWND) of the PowerDVD main window and the HWND of the PowerDVD player window.
        #     When PowerDVD is running, the main window is not hidden and always has an HWND.
        #     The player window is hidden and only exists when playback has begun.
        # Combine the two lists, the main window being the first entry.
        # If the list is empty, raise an error.
        # Else, send the key stroke to the last element in the list
        # (i.e., to the player window when playback has begun, else to the main window).