Import parts of a EventGhost plugin in a external script

Do you have questions about writing plugins or scripts in Python? Meet the coders here.
Post Reply
jonib
Plugin Developer
Posts: 1280
Joined: Thu Mar 26, 2009 9:33 pm
Location: Sweden

Import parts of a EventGhost plugin in a external script

Post by jonib » Fri May 27, 2011 1:37 am

Hi, I'm working on a utility to make it easier to sync my XBMC2 plugin to the actions in XBMC.

So I'm trying to import the current actions that are in the XBMC2 plugin in a separate Python script (outside of EventGhost)

This code is a simple test(run from the same directory as the XBMC2 plugin):

Code: Select all

from __init__ import WINDOWS

print WINDOWS
And this is the part I'm trying to import:

Code: Select all

WINDOWS = (
(eg.ActionGroup, "Windows", "Windows", None, (
    ("MyMovies", "Show Movies Screen", "Show Movies screen.", "ActivateWindow(MyVideoLibrary,movietitles,return)"),
    ("MyTVShows", "Show TV Shows Screen", "Show TV Shows screen.", "ActivateWindow(MyVideoLibrary,tvshowtitles,return)"),
    ("ShutdownMenu", "Show Shutdown Menu", "Show the shutdown Menu.", "ActivateWindow(ShutdownMenu)"),
    ("Home", "Home", "Home", "Activatewindow(Home)"),
    ("Programs", "Programs", "Programs", "Activatewindow(Programs)"),
    ("Pictures", "Pictures", "Pictures", "Activatewindow(Pictures)"),
    ("Files", "Files", "Files", "Activatewindow(Files)"),
    ("Settings", "Settings", "Settings", "Activatewindow(Settings)"),
    ("Music", "Music", "Music", "Activatewindow(Music)"),
    ("Musicfiles", "Musicfiles", "Musicfiles", "Activatewindow(Musicfiles)"),
    ("Musiclibrary", "Musiclibrary", "Musiclibrary", "Activatewindow(Musiclibrary)"),
    ("Musicplaylist", "Musicplaylist", "Musicplaylist", "Activatewindow(Musicplaylist)"),
    ("Musicplaylisteditor", "Musicplaylisteditor", "Musicplaylisteditor", "Activatewindow(Musicplaylisteditor)"),
    ("Musicinformation", "Musicinformation", "Musicinformation", "Activatewindow(Musicinformation)"),
    ("Video", "Video", "Video", "Activatewindow(Video)"),
    ("Videofiles", "Videofiles", "Videofiles", "Activatewindow(Videofiles)"),
    ("Videolibrary", "Videolibrary", "Videolibrary", "Activatewindow(Videolibrary)"),
    ("Videoplaylist", "Videoplaylist", "Videoplaylist", "Activatewindow(Videoplaylist)"),
    ("Systeminfo", "Systeminfo", "Systeminfo", "Activatewindow(Systeminfo)"),
    ("Guicalibration", "Guicalibration", "Guicalibration", "Activatewindow(Guicalibration)"),
    ("Screencalibration", "Screencalibration", "Screencalibration", "Activatewindow(Screencalibration)"),
    ("Picturessettings", "Picturessettings", "Picturessettings", "Activatewindow(Picturessettings)"),
    ("Programssettings", "Programssettings", "Programssettings", "Activatewindow(Programssettings)"),
    ("Weathersettings", "Weathersettings", "Weathersettings", "Activatewindow(Weathersettings)"),
    ("Musicsettings", "Musicsettings", "Musicsettings", "Activatewindow(Musicsettings)"),
    ("Systemsettings", "Systemsettings", "Systemsettings", "Activatewindow(Systemsettings)"),
    ("Videossettings", "Videossettings", "Videossettings", "Activatewindow(Videossettings)"),
    ("Networksettings", "Networksettings", "Networksettings", "Activatewindow(Networksettings)"),
    ("Appearancesettings", "Appearancesettings", "Appearancesettings", "Activatewindow(Appearancesettings)"),
    ("Scripts", "Scripts", "Scripts", "Activatewindow(Scripts)"),
    ("Gamesaves", "Gamesaves", "Gamesaves", "Activatewindow(Gamesaves)"),
    ("Profiles", "Profiles", "Profiles", "Activatewindow(Profiles)"),
    ("Virtualkeyboard", "Virtualkeyboard", "Virtualkeyboard", "Activatewindow(Virtualkeyboard)"),
    ("Volumebar", "Volumebar", "Volumebar", "Activatewindow(Volumebar)"),
    ("Favourites", "Favourites", "Favourites", "Activatewindow(Favourites)"),
    ("Musicosd", "Musicosd", "Musicosd", "Activatewindow(Musicosd)"),
    ("Visualisationsettings", "Visualisationsettings", "Visualisationsettings", "Activatewindow(Visualisationsettings)"),
    ("Visualisationpresetlist", "Visualisationpresetlist", "Visualisationpresetlist", "Activatewindow(Visualisationpresetlist)"),
    ("Osdvideosettings", "Osdvideosettings", "Osdvideosettings", "Activatewindow(Osdvideosettings)"),
    ("Osdaudiosettings", "Osdaudiosettings", "Osdaudiosettings", "Activatewindow(Osdaudiosettings)"),
    ("Videobookmarks", "Videobookmarks", "Videobookmarks", "Activatewindow(Videobookmarks)"),
    ("Profilesettings", "Profilesettings", "Profilesettings", "Activatewindow(Profilesettings)"),
    ("Locksettings", "Locksettings", "Locksettings", "Activatewindow(Locksettings)"),
    ("Contentsettings", "Contentsettings", "Contentsettings", "Activatewindow(Contentsettings)"),
    ("Networksetup", "Networksetup", "Networksetup", "Activatewindow(Networksetup)"),
    ("Smartplaylisteditor", "Smartplaylisteditor", "Smartplaylisteditor", "Activatewindow(Smartplaylisteditor)"),
    ("Smartplaylistrule", "Smartplaylistrule", "Smartplaylistrule", "Activatewindow(Smartplaylistrule)"),
    ("Movieinformation", "Movieinformation", "Movieinformation", "Activatewindow(Movieinformation)"),
    ("Scriptsdebuginfo", "Scriptsdebuginfo", "Scriptsdebuginfo", "Activatewindow(Scriptsdebuginfo)"),
    ("Fullscreenvideo", "Fullscreenvideo", "Fullscreenvideo", "Activatewindow(Fullscreenvideo)"),
    ("Visualisation", "Visualisation", "Visualisation", "Activatewindow(Visualisation)"),
    ("Slideshow", "Slideshow", "Slideshow", "Activatewindow(Slideshow)"),
    ("Filestackingdialog", "Filestackingdialog", "Filestackingdialog", "Activatewindow(Filestackingdialog)"),
    ("Weather", "Weather", "Weather", "Activatewindow(Weather)"),
    ("Screensaver", "Screensaver", "Screensaver", "Activatewindow(Screensaver)"),
    ("Videoosd", "Videoosd", "Videoosd", "Activatewindow(Videoosd)"),
    ("Videomenu", "Videomenu", "Videomenu", "Activatewindow(Videomenu)"),
    ("Filebrowser", "Filebrowser", "Filebrowser", "Activatewindow(Filebrowser)"),
    ("Startup", "Startup", "Startup", "Activatewindow(Startup)"),
    ("Startwindow", "Startwindow", "Startwindow", "Activatewindow(Startwindow)"),
    ("Loginscreen", "Loginscreen", "Loginscreen", "Activatewindow(Loginscreen)"),
    ("Musicoverlay", "Musicoverlay", "Musicoverlay", "Activatewindow(Musicoverlay)"),
    ("Videooverlay", "Videooverlay", "Videooverlay", "Activatewindow(Videooverlay)"),
    ("Pictureinfo", "Pictureinfo", "Pictureinfo", "Activatewindow(Pictureinfo)"),
    ("Pluginsettings", "Pluginsettings", "Pluginsettings", "Activatewindow(Pluginsettings)"),
    ("Fullscreeninfo", "Fullscreeninfo", "Fullscreeninfo", "Activatewindow(Fullscreeninfo)"),
    ("PlayerControls", "Player Controls", "Player Controls", "ActivateWindow(PlayerControls)"),
)),
)
So the problem is that I'm getting the error: NameError: name 'eg' is not defined, anyone know how I can define the eg.ActionGroup without changing the __init__.py I'm importing from?
I won't use the eg.ActionGroup variable, I just need Python to not complain about it.

As EventGhost seems to be able to use the code as is, so I'm looking into how it works but haven't found how yet, so I'm asking here.

jonib
XBMC2 plugin to control XBMC. If you want to flatter me Image

User avatar
topix
Experienced User
Posts: 417
Joined: Sat May 05, 2007 3:43 pm
Location: Germany
Contact:

Re: Import parts of a EventGhost plugin in a external script

Post by topix » Fri May 27, 2011 2:22 pm

How about writing a dummy class?

Code: Select all

class DummyEG():
    def ActionGroup(self):
        pass

eg = DummyEG()

from __init__ import WINDOWS

jonib
Plugin Developer
Posts: 1280
Joined: Thu Mar 26, 2009 9:33 pm
Location: Sweden

Re: Import parts of a EventGhost plugin in a external script

Post by jonib » Fri May 27, 2011 2:29 pm

topix wrote:How about writing a dummy class?
Yes, I tried that but couldn't get it to work. Did you try your code?

jonib
XBMC2 plugin to control XBMC. If you want to flatter me Image

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

Re: Import parts of a EventGhost plugin in a external script

Post by Pako » Fri May 27, 2011 2:40 pm

Certainly there are many ways to solve it.
However, unfortunately I'm not a real programmer (such as Bitmonster).
Therefore, my solution is probably not very elegant.
But the important thing is that it works:

Code: Select all

import sys
egPlugins = r"D:\Programs\E\EventGhost\plugins"
sys.path.append(egPlugins)

def DummyFunction(*args, **kwargs):
    pass

class DummyClass:
    __init__ = DummyFunction

import __builtin__
__builtin__.eg = DummyClass()

eg.RegisterPlugin = DummyFunction
eg.ActionGroup    = "DummyClass"
eg.ActionClass    = DummyClass
eg.ActionBase     = DummyClass
eg.PluginClass    = DummyClass

from XBMCRepeat import WINDOWS
print WINDOWS
You only need to change the path "egPlugins".

Pako

jonib
Plugin Developer
Posts: 1280
Joined: Thu Mar 26, 2009 9:33 pm
Location: Sweden

Re: Import parts of a EventGhost plugin in a external script

Post by jonib » Fri May 27, 2011 2:58 pm

Pako wrote:Certainly there are many ways to solve it.
I didn't find any :oops:
However, unfortunately I'm not a real programmer (such as Bitmonster).
Therefore, my solution is probably not very elegant.
But the important thing is that it works:
Elegant or not but it's beautiful. :D Thanks works great.

Edit: Looking at the code looks like I was close at finding a solution as I found the __builtin__.variable, but didn't know that I didn't need the __builtin__ part to access the variable. :oops:

jonib
XBMC2 plugin to control XBMC. If you want to flatter me Image

Post Reply