| Trees | Indices | Help |
|
|---|
|
|
1 # Copyright (c) 2009-2010, Alexander Cherniuk (ts33kr@gmail.com) 2 # All rights reserved. 3 # 4 # Redistribution and use in source and binary forms, with or without 5 # modification, are permitted provided that the following conditions 6 # are met: 7 # 8 # * Redistributions of source code must retain the above copyright 9 # notice, this list of conditions and the following disclaimer. 10 # 11 # * Redistributions in binary form must reproduce the above copyright 12 # notice, this list of conditions and the following disclaimer in the 13 # documentation and/or other materials provided with the distribution. 14 # 15 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 # HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 27 """ 28 Provides a glue to tie command system framework and the actual code 29 where it would be dropped in. Defines a little bit of scaffolding to 30 support interaction between the two and a few utility methods so you 31 don't need to dig up the code itself to write basic commands. 32 """ 33 34 from types import StringTypes 35 from traceback import print_exc 36 37 from pango import FontDescription 38 from common import gajim 39 40 from ..framework import CommandProcessor 41 from ..errors import CommandError, NoCommandError 42 from ..tools import gconf45 """ 46 A basic scaffolding to provide convenient interaction between the 47 command system and chat controls. It will be merged directly into 48 the controls, by ChatCommandProcessor being among superclasses of 49 the controls. 50 """ 5110353 self.command_succeeded = False 54 parents = super(ChatCommandProcessor, self) 55 flag = parents.process_as_command(text) 56 if flag and self.command_succeeded: 57 self.add_history(text) 58 self.clear_input() 59 return flag6062 try: 63 parents = super(ChatCommandProcessor, self) 64 parents.execute_command(name, arguments) 65 except NoCommandError, error: 66 details = dict(name=error.name, message=error.message) 67 message = "%(name)s: %(message)s\n" % details 68 message += "Try using the //%(name)s or /say /%(name)s " % details 69 message += "construct if you intended to send it as a text." 70 self.echo_error(message) 71 except CommandError, error: 72 self.echo_error("%s: %s" % (error.name, error.message)) 73 except Exception: 74 self.echo_error("Error during command execution!") 75 print_exc() 76 else: 77 self.command_succeeded = True7880 # Command escape stuff ggoes here. If text was prepended by the 81 # command prefix twice, like //not_a_command (if prefix is set 82 # to /) then it will be escaped, that is sent just as a regular 83 # message with one (only one) prefix removed, so message will be 84 # /not_a_command. 85 if body.startswith(self.COMMAND_PREFIX): 86 self.send(body) 87 return True8890 # If command argument contain h or help option - forward it to 91 # the /help command. Dont forget to pass self, as all commands 92 # are unbound. And also don't forget to print output. 93 if 'h' in kwargs or 'help' in kwargs: 94 help = self.get_command('help') 95 self.echo(help(self, name)) 96 return True97105 """ 106 Contains a set of basic tools and shortcuts you can use in your 107 commands to perform some simple operations. These will be merged 108 directly into the controls, by CommandTools being among superclasses 109 of the controls. 110 """ 111193113 self.install_tags()114 129131 buffer = self.conv_textview.tv.get_buffer() 132 iter = buffer.get_end_iter() 133 if iter.ends_line() and not iter.is_start(): 134 buffer.insert_with_tags_by_name(iter, "\n", "eol")135 140142 """ 143 Print given text to the user, as a regular command output. 144 """ 145 self.shift_line() 146 self.append_with_tags(text, tag)147149 """ 150 Print given text to the user, as an error command output. 151 """ 152 self.echo(text, "command_error")153155 """ 156 Send a message to the contact. 157 """ 158 self.send_message(text, process_commands=False)159161 """ 162 Set given text into the input. 163 """ 164 buffer = self.msg_textview.get_buffer() 165 buffer.set_text(text)166 172174 """ 175 Add given text to the input history, so user can scroll through 176 it using ctrl + up/down arrow keys. 177 """ 178 self.save_sent_message(text)179 180 @property 186 187 @property
| Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Thu Aug 12 02:07:35 2010 | http://epydoc.sourceforge.net |