comparison orpg/tools/scriptkit.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 # Copyright (C) 2000-2001 The OpenRPG Project
2 #
3 # openrpg-dev@lists.sourceforge.net
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 # --
19 #
20 # File: scriptkit.py
21 # Author: Ted Berg
22 # Maintainer:
23 # Version:
24 # $Id: scriptkit.py,v 1.15 2006/11/04 21:24:22 digitalxero Exp $
25 #
26 # Description: Class that contains convenience methods for various operations. Was created with the purpose
27 # of exposing a simple API to users of an as yet uncreated scripting interface.
28 #
29
30
31 import time
32 from orpg.orpg_windows import *
33 from orpg.orpg_xml import *
34 from orpg.orpg_wx import *
35 import orpg.chat.chat_msg
36
37 class scriptkit:
38 def __init__(self):
39 """Simple constructor. It currently only assigns the openrpg reference to a local variable.
40 <ul>
41 <li>openrpg - a reference to the application openrpg object.
42 </ul>
43 """
44 self.chat = open_rpg.get_component( 'chat' )
45 self.map = open_rpg.get_component( 'map' )
46 self.settings = open_rpg.get_component( 'settings' )
47 self.session = open_rpg.get_component('session')
48 self.xml = open_rpg.get_component('xml')
49
50 def addMiniatureToMap( self, min_label, min_url, unique=0 ):
51 """Adds a new miniature icon to the map. Miniature <em>will</em> be labeled unless autolabel is
52 turned off on the map <em>and</em> the min_label field is blank. Miniature will be numbered unless
53 the 'unique' argument evaluates to True ( i.e. nonzero or a non-empty string ).
54 <ul>
55 <li>min_label - text string to be used as a label for the miniature
56 <li>min_url - the URL for the image to be displayed on the map
57 <li>unique - the mini will be numbered if this evaluates to False.
58 </ul>
59 """
60
61 if min_url[:7] != "http://" :
62 min_url = "http://"+min_url
63
64 if self.map.canvas.auto_label:
65 if min_label == '':
66 start = min_url.rfind('/') + 1
67 min_label = min_url[ start : len( min_url ) - 4 ]
68
69 try:
70 unique = eval( unique )
71 except:
72 pass
73
74 if not unique:
75 min_label = '%s %d' % ( min_label, self.map.canvas.layers['miniatures'].next_serial() )
76 self.map.canvas.add_miniature( min_url, label, unique )
77
78 def become( self, name ):
79 try:
80 self.chat.aliasList.SetStringSelection(name)
81 except:
82 msg = 'Alias: %s Does not exist' % (name)
83 print msg
84
85 def sendToChat( self, text ):
86 """Broadcasts the specified text to the chatbuffer.
87 <ul>
88 <li>text - the text to send.
89 </ul>
90 """
91 if text[0] != "/":
92 self.chat.ParsePost(text, send=1, myself=1)
93 else:
94 self.chat.chat_cmds.docmd(text)
95
96 def sendToChatAs( self, name, text ):
97 """Broadcasts the specified text to the chatbuffer as the specified alias
98 <ul>
99 <li>name - The player's name will be temporarily changed to this value
100 <li>text - The text to broadcast to the chatbuffer
101 </ul>
102 """
103 self.become(name)
104 self.sendToChat( text )
105 self.become("Use Real Name")
106
107 def emoteToChat( self, text):
108 if text[0] != '/':
109 text = '/me ' + text
110 self.sendToChat( text )
111
112 def emoteToChatAs( self, name, text ):
113 text = '/me ' + text
114 self.become(name)
115 self.sendToChat( text )
116 self.become("Use Real Name")
117
118 def whisperToChat( self, who, text):
119 if text[0] != '/':
120 text = '/w %s=%s' % ( who, text )
121 self.sendToChat( text )
122
123 def whisperToChatAs( self, who, name, text ):
124 if text[0] != '/':
125 text = '/w %s=%s' % ( who, text )
126 self.become(name)
127 self.sendToChat( text )
128 self.become("Use Real Name")
129
130 def chatMessage( self, message ):
131 self.chat.Post( self.chat.colorize( self.chat.syscolor, message ) )
132
133 def get_input( self, message, title, default ):
134 dlg = wx.TextEntryDialog( self, message, title, default )
135 if dlg.ShowModal() == rpgutils.wx.ID_OK:
136 return dlg.GetValue()
137 dlg.Destroy()
138 return None
139
140 def show_info( self, title, message ):
141 dlg = wx.MessageDialog( None, message, title, wx.OK | wx.ICON_INFORMATION )
142 dlg.ShowModal()
143 dlg.Destroy()