comparison plugins/xxfontchng.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
comparison
equal deleted inserted replaced
-1:000000000000 0:4385a7d0efd1
1 import os
2 import orpg.pluginhandler
3
4 class Plugin(orpg.pluginhandler.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 orpg.pluginhandler.PluginHandler.__init__(self, plugindb, parent)
11
12
13 # The Following code should be edited to contain the proper information
14 self.name = 'Font Tools'
15 self.author = 'mDuo13'
16 self.help = "You can change your font in chat by typing '/myfont *key*'\n"
17 self.help += "where *key* is this plugin's shorthand for a font, like 'c'\n"
18 self.help += "for Courier. You can type /myfont list for the whole list.\n"
19 self.help += "You can use another font by typing '/myfont custom=*name*', where\n"
20 self.help += "*name* is the EXACT name of the font, case-sensitive and all.\n"
21 self.help += "Font resizing is no longer supported by the plugin as it is in\n"
22 self.help += "the official code now. (Try typing '/fontsize *x*' to change your\n"
23 self.help += "font to size *x*.)"
24 #define any variables here, but always define them as ''. you will set thier values and proper type in plugin_enabled
25 self.fontstring = ''
26 self.fontlist = {}
27
28 def plugin_enabled(self):
29 #This is where you set any variables that need to be initalized when your plugin starts
30 #You can add new /commands like
31 self.plugin_addcommand('/myfont', self.on_myfont, '[list|custom (fontname)|fontname] - This lets you change the font type for your messages, but leaves other peoples alone')
32 #Argument 1 is the command it self
33 #Argument 2 is the function to be called when you issue the command
34 #Argument 3 is the help text for the command
35
36 self.fontstring = self.plugindb.GetString("xxfontchng", "fontstring", "")
37 self.fontlist = {"a" : "<font>",
38 "arial" : "<font>",
39 "c" : "<font face='Courier New, Courier, monospace'>",
40 "courier" : "<font face='Courier New, Courier, monospace'>",
41 "t" : "<font face='Times New Roman, Times, serif'>",
42 "times" : "<font face='Times New Roman, Times, serif'>",
43 "tempus" : "<font face='Tempus Sans ITC'>",
44 "westminster" : "<font face='Westminster' size=+1>",
45 "mistral" : "<font face='Mistral' size=+2>",
46 "lucida sans" : "<font face='Lucida Sans'>",
47 "lucida handwriting" : "<font face='Lucida Handwriting'>",
48 "western" : "<font face='Rockwell'>",
49 "rockwell" : "<font face='Rockwell'>"}
50
51 def plugin_disabled(self):
52 self.plugin_removecmd('/myfont')
53
54 def on_myfont(self, cmdargs):
55 args = cmdargs.split(None,1)
56
57 if len(args) == 0 or args[0] == 'list':
58 the_list = ''
59 for entry in self.fontlist.keys():
60 the_list += '<br />' + self.fontlist[entry] + entry + '</font>'
61 the_list += '<br />custom *anyfont*'
62 self.chat.InfoPost(the_list)
63 elif args[0] == 'custom':
64 self.fontstring = '<font face="' + args[1] + '">'
65 elif self.fontlist.has_key(args[0]):
66 self.fontstring = self.fontlist[args[0]]
67 self.chat.InfoPost("Your font now looks " + self.fontstring + "like this.</font>")
68 self.plugindb.SetString("xxfontchng", "fontstring", self.fontstring)
69 else:
70 self.chat.InfoPost("Invalid font name. Type /myfont list for a list of font names, or use custom preceding the font name")
71
72 def pre_parse(self, text):
73 #This is called just before a message is parsed by openrpg
74 cmdsearch = text.split(None,1)
75 if len(cmdsearch) == 0:
76 return text
77 cmd = cmdsearch[0].lower()
78 start = len(cmd)
79 end = len(text)
80 cmdargs = text[start:end]
81
82 if cmd == "/whisper" or cmd == "/w":
83 text = cmd + ' ' + cmdargs[:cmdargs.find("=")+1] + self.fontstring + cmdargs + '</font>'
84 elif cmd == "/me" or cmd == "/he" or cmd == "/she":
85 text = cmd + ' ' + self.fontstring + cmdargs + '</font>'
86 elif cmd[0] != '/':
87 text = self.fontstring + text + '</font>'
88 return text
89
90 def send_msg(self, text, send):
91 if self.fontstring.find("<font") > -1:
92 text = self.fontstring + text + '</font>'
93 return text, send