comparison orpg/pluginhandler.py @ 0:4385a7d0efd1 grumpy-goblin

Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
author sirebral
date Tue, 14 Jul 2009 16:41:58 -0500
parents
children c54768cffbd4
comparison
equal deleted inserted replaced
-1:000000000000 0:4385a7d0efd1
1 from orpg.orpg_wx import *
2 from orpg.orpgCore import open_rpg
3
4 class PluginHandler:
5 # Initialization subroutine.
6 #
7 # !self : instance of self
8 # !chat : instance of the chat window to write to
9 def __init__(self, plugindb, parent):
10 self.session = open_rpg.get_component("session")
11 self.chat = open_rpg.get_component("chat")
12 self.settings = open_rpg.get_component("settings")
13 self.gametree = open_rpg.get_component("tree")
14 self.startplugs = open_rpg.get_component("startplugs")
15 self.xml = open_rpg.get_component("xml")
16 self.validate = open_rpg.get_component("validate")
17 self.topframe = open_rpg.get_component("frame")
18 self.plugindb = plugindb
19 self.parent = parent
20 self.shortcmdlist = self.chat.chat_cmds.shortcmdlist
21 self.cmdlist = self.chat.chat_cmds.cmdlist
22
23 def plugin_enabled(self):
24 pass
25
26 def plugin_disabled(self):
27 pass
28
29 def menu_start(self):
30 rootMenu = open_rpg.get_component("pluginmenu")
31 try:
32 self.plugin_menu()
33 rootMenu.AppendMenu(wx.ID_ANY, self.name, self.menu)
34 except:
35 self.menu = wx.Menu()
36 empty = wx.MenuItem(self.menu, wx.ID_ANY, 'Empty')
37 self.menu.AppendItem(empty)
38 rootMenu.AppendMenu(wx.ID_ANY, self.name, self.menu)
39
40 def menu_cleanup(self):
41 self.settings.save()
42 rootMenu = open_rpg.get_component("pluginmenu")
43 menus = rootMenu.MenuItems
44 for mi in menus:
45 if mi.GetText() == self.name:
46 rootMenu.RemoveItem(mi)
47 del self.menu
48
49 def plugin_addcommand(self, cmd, function, helptext, show_msg=True):
50 self.chat.chat_cmds.addcommand(cmd, function, helptext)
51 if(show_msg):
52 msg = '<br /><b>New Command added</b><br />'
53 msg += '<b><font color="#000000">%s</font></b> %s' % (cmd, helptext)
54 self.chat.InfoPost(msg)
55
56 def plugin_commandalias(self, shortcmd, longcmd, show_msg=True):
57 self.chat.chat_cmds.addshortcmd(shortcmd, longcmd)
58 if(show_msg):
59 msg = '<br /><b>New Command Alias added:</b><br />'
60 msg += '<b><font color="#0000CC">%s</font></b> is short for <font color="#000000">%s</font>' % (shortcmd, longcmd)
61 self.chat.InfoPost(msg)
62
63 def plugin_removecmd(self, cmd):
64 self.chat.chat_cmds.removecmd(cmd)
65 msg = '<br /><b>Command Removed:</b> %s' % (cmd)
66 self.chat.InfoPost(msg)
67
68 def plugin_add_nodehandler(self, nodehandler, nodeclass):
69 self.gametree.add_nodehandler(nodehandler, nodeclass)
70
71 def plugin_remove_nodehandler(self, nodehandler):
72 self.gametree.remove_nodehandler(nodehandler)
73
74 def plugin_add_msg_handler(self, tag, function):
75 self.session.add_msg_handler(tag, function)
76
77 def plugin_delete_msg_handler(self, tag):
78 self.session.remove_msg_handler(tag)
79
80 def plugin_add_setting(self, setting, value, options, help):
81 self.settings.add_tab('Plugins', self.name, 'grid')
82 self.settings.add_setting(self.name, setting, value, options, help)
83
84 def plugin_send_msg(self, to, plugin_msg):
85 xml_dom = self.xml.parseXml(plugin_msg)
86 xml_dom = xml_dom._get_documentElement()
87 xml_dom.setAttribute('from', str(self.session.id))
88 xml_dom.setAttribute('to', str(to))
89 xml_dom.setAttribute('group_id', str(self.session.group_id))
90 tag_name = xml_dom._get_tagName()
91 if not tag_name in self.session.core_msg_handlers:
92 xml_msg = '<plugin to="' + str(to)
93 xml_msg += '" from="' + str(self.session.id)
94 xml_msg += '" group_id="' + str(self.session.group_id)
95 xml_msg += '" />' + xml_dom.toxml()
96 self.session.outbox.put(xml_msg)
97 else:
98 #Spoofing attempt
99 pass
100 xml_dom.unlink()
101
102 def message(self, text):
103 return text
104
105 def pre_parse(self, text):
106 return text
107
108 def send_msg(self, text, send):
109 return text, send
110
111 def plugin_incoming_msg(self, text, type, name, player):
112 return text, type, name
113
114 def post_msg(self, text, myself):
115 return text
116
117 def refresh_counter(self):
118 pass
119
120 def close_module(self):
121 #This is called when OpenRPG shuts down
122 pass