Difference between revisions of "Mah!Cade:Plugins"

From Wah!ki
Jump to navigation Jump to search
Line 11: Line 11:
 
* Message
 
* Message
  
==== Example ====
+
=== Launcher ===
 +
Launcher plugins are tied to Mah!Cade by the lauched file extension. During the game launch process Mah!Cade looks for a plugin named '''launcher_<ext>.py''' (ext is loaded at runtime during launch). if a plugin is found Mah!Cade tries to executes the '''read_scexec()''' function; from this function Mah!Cade expects a returned set of values as per the table below.
 +
 
 +
{{Main page box|Mah!Cade Plugin Return Values
 +
|Mah!Cade:Plugins}}
 +
<div style="margin: -.3em -1em -1em -1em;">
 +
{| width="100%" bgcolor="#fff" border="0" cellpadding="2px" cellspacing="2px" style="margin:auto;"
 +
|- align="center" bgcolor="#e7eef6"
 +
! width="5%" | '''Pos'''
 +
| width="20%" | '''Name'''
 +
! width="55%" | '''Description'''
 +
! width="20%" | '''Value Type'''
 +
|- valign="top" align="left" style="background: #F5FAFF;"
 +
|1
 +
|Message
 +
|A Return Message for log file
 +
|String
 +
|-
 +
|2
 +
|Executable
 +
|The commandline for the emulator (emulator_executable)
 +
|String
 +
|-
 +
|3
 +
|Arguments
 +
|The arguments for the emulator
 +
|String
 +
|-
 +
|4
 +
|Working Directory
 +
|No Longer used; chdir executed from base path of emulator_executable
 +
|Obsolete
 +
|-
 +
|5
 +
|Check Executable
 +
|Verify existance of executable before launch (default)
 +
|Booleen
 +
|-
 +
|6
 +
|Launch with Shell
 +
|Pass Shell=True to popen
 +
|Booleen
 +
|}
 +
</div>
 +
{{box-footer-empty}}
 +
 
 +
==== Example Template ====
 +
<pre>
 +
"""Plugin for Mah!Cade"""
 +
def read_scexec(String):
 +
    return  String, String, String, String, Booleen, Booleen
 +
</pre>
 +
 
 +
The example above illustrates the bare minimum requirement for a launcher plugin in Mah!Cade
 +
 
 +
==== Functional Example ====
 +
<pre>
 +
#!/usr/bin/env python
 +
# -*- coding: UTF-8 -*-
 +
#
 +
###
 +
# Application: sc_desktop
 +
# File:        sc_desktop.py
 +
# Description: .desktop shortcut plugin
 +
# Copyright (c) 2005-2012  Wayne Moulden <http://www.mameau.com>
 +
###
 +
#
 +
# This program 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.
 +
#
 +
# This program 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 Library General Public License for more details.
 +
#
 +
# You should have received a copy of the GNU General Public License
 +
# along with this program; if not, write to the Free Software
 +
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 +
#
 +
# EXAMPLE FILE
 +
#============================================================
 +
# [Desktop Entry]
 +
# Version=1.0
 +
# Type=Application
 +
# Terminal=false
 +
# Icon[en_AU]=/usr/local/share/wahcade/pixmaps/wahcade.png
 +
# Name[en_AU]=Wah!Cade
 +
# Exec=/usr/bin/wahcade
 +
# Name=Wah!Cade
 +
# Icon=/usr/local/share/wahcade/pixmaps/wahcade-logo.png
 +
 
 +
import sys
 +
 
 +
"""Plugin for Mah!Cade"""
 +
def read_scexec(scfile):
 +
    """ read shortcut and return executable path """
 +
    if sys.platform != 'win32':
 +
        f = open(scfile)
 +
        for line in f:
 +
            if line[:5] == "Exec=":
 +
                cmd = line[5:]
 +
                return  "Executing " + cmd, cmd, "", "", False, True
 +
        return "Ran into problems finding executable in .desktop shortcut"
 +
    else:
 +
        return "Only available for non-windows platforms! returning"
 +
</pre>
 +
 
 +
==== Standalone Example ====
 +
Here is the full standalone script.
 +
 
 
<pre>
 
<pre>
 
#!/usr/bin/env python
 
#!/usr/bin/env python
Line 72: Line 183:
 
             if line[:5] == "Exec=":
 
             if line[:5] == "Exec=":
 
                 cmd = line[5:]
 
                 cmd = line[5:]
                 return cmd, "", "", "Executing " + cmd
+
                 return "Executing " + cmd, cmd, "", "", False, True
        return "","","","Ran into problems finding executable in .desktop shortcut"
+
        return "Ran into problems finding executable in .desktop shortcut"
 
     else:
 
     else:
         return "","","","Only available for non-windows platforms! returning"  
+
         return "Only available for non-windows platforms! returning"  
 
      
 
      
 
def run_scexec(cmd, args, work_dir, message=""):
 
def run_scexec(cmd, args, work_dir, message=""):
Line 86: Line 197:
 
     p = subprocess.Popen(cmd, shell=True)
 
     p = subprocess.Popen(cmd, shell=True)
 
     p.wait
 
     p.wait
 
 
</pre>
 
</pre>
  
The example above is a completely self contained launcher in its own right (written as such intentionally) to execute from a path stored in a *.desktop file under linux. It was built around the current Mah!Cade plugin implementation; you can see the function '''read_scexec()''' exists in the example above which Mah!Cade calls by default. The only requirement for your plugin to work is that the '''read_scexec()''' function is present and returns values as required for Mah!Cade to use.
+
The example above is a completely self contained launcher in its own right (written as such intentionally) to execute from a path stored in a *.desktop file under linux. It was built around the current Mah!Cade plugin implementation; you can see the function '''read_scexec()''' exists in the example above.

Revision as of 01:01, 26 December 2011

Plugins

The plugins system for Mah!Cade was initially created to add support for reading shortcut files under windows and linux; executing them directly instead of through a 3rd party launcher. They were built into plugins to allow for ease of changes in the future.

Plugin Types

Launcher

Launcher plugins are tied to Mah!Cade by a file extension. During the game launch process Mah!Cade looks for a plugin named launcher_<ext>.py (ext is loaded from rom_extension in the emulator ini file) if found it then executes the read_scexec() function. Mah!Cade expects the function to return a minmum of 4 values, of which it uses 3

  • Path to executable
  • Arguments from the command line
  • Working Directory (Not used by Mah!Cade)
  • Message

Launcher

Launcher plugins are tied to Mah!Cade by the lauched file extension. During the game launch process Mah!Cade looks for a plugin named launcher_<ext>.py (ext is loaded at runtime during launch). if a plugin is found Mah!Cade tries to executes the read_scexec() function; from this function Mah!Cade expects a returned set of values as per the table below.

edit  

Mah!Cade Plugin Return Values

Pos Name Description Value Type
1 Message A Return Message for log file String
2 Executable The commandline for the emulator (emulator_executable) String
3 Arguments The arguments for the emulator String
4 Working Directory No Longer used; chdir executed from base path of emulator_executable Obsolete
5 Check Executable Verify existance of executable before launch (default) Booleen
6 Launch with Shell Pass Shell=True to popen Booleen

Example Template

"""Plugin for Mah!Cade"""
def read_scexec(String):
    return  String, String, String, String, Booleen, Booleen

The example above illustrates the bare minimum requirement for a launcher plugin in Mah!Cade

Functional Example

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
#
###
# Application: sc_desktop
# File:        sc_desktop.py
# Description: .desktop shortcut plugin
# Copyright (c) 2005-2012   Wayne Moulden <http://www.mameau.com>
###
#
# This program 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.
#
# This program 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 Library General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# EXAMPLE FILE
#============================================================
# [Desktop Entry]
# Version=1.0
# Type=Application
# Terminal=false
# Icon[en_AU]=/usr/local/share/wahcade/pixmaps/wahcade.png
# Name[en_AU]=Wah!Cade
# Exec=/usr/bin/wahcade
# Name=Wah!Cade
# Icon=/usr/local/share/wahcade/pixmaps/wahcade-logo.png

import sys

"""Plugin for Mah!Cade"""
def read_scexec(scfile):
    """ read shortcut and return executable path """
    if sys.platform != 'win32':
        f = open(scfile)
        for line in f:
            if line[:5] == "Exec=":
                cmd = line[5:]
                return  "Executing " + cmd, cmd, "", "", False, True
        return "Ran into problems finding executable in .desktop shortcut"
    else:
        return "Only available for non-windows platforms! returning" 

Standalone Example

Here is the full standalone script.

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
#
###
# Application: sc_desktop
# File:        sc_desktop.py
# Description: .desktop shortcut plugin
# Copyright (c) 2005-2012   Wayne Moulden <http://www.mameau.com>
###
#
# This program 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.
#
# This program 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 Library General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# EXAMPLE FILE
#============================================================
# [Desktop Entry]
# Version=1.0
# Type=Application
# Terminal=false
# Icon[en_AU]=/usr/local/share/wahcade/pixmaps/wahcade.png
# Name[en_AU]=Wah!Cade
# Exec=/usr/bin/wahcade
# Name=Wah!Cade
# Icon=/usr/local/share/wahcade/pixmaps/wahcade-logo.png

import os, sys, subprocess
from subprocess import Popen

"""Plugin for Mah!Cade"""
def __init__(scfile=""):
    if (len(sys.argv) > 1):
        scfile = sys.argv[1]
    if (len(scfile) > 1):
        result = read_scexec(scfile) 
        if (len(result[0]) > 1): 
            run_scexec(result[0],result[1])
        else:
            return result[3]          
    else:
        return "No shortcut file passed"        

def read_scexec(scfile):
    """ read shortcut and return executable path """
    if sys.platform != 'win32':
        f = open(scfile)
        for line in f:
            if line[:5] == "Exec=":
                cmd = line[5:]
                return  "Executing " + cmd, cmd, "", "", False, True
        return "Ran into problems finding executable in .desktop shortcut"
    else:
        return "Only available for non-windows platforms! returning" 
    
def run_scexec(cmd, args, work_dir, message=""):
    if work_dir:
        os.chdir(os.path.join(os.path.abspath(sys.path[0]), work_dir))
    else:
        os.chdir(os.path.split(cmd)[0])
    if args:
        cmd = cmd + " " + args
    p = subprocess.Popen(cmd, shell=True)
    p.wait

The example above is a completely self contained launcher in its own right (written as such intentionally) to execute from a path stored in a *.desktop file under linux. It was built around the current Mah!Cade plugin implementation; you can see the function read_scexec() exists in the example above.