def message(self, multi=False): text = self.init_change() msg = MESSAGE_REGEX.match(text) if msg is not None: space = 2 + len(msg.group(1)) text = ('%s %s ' % (MSG_SIGN, self.main.message_user)) \ + (text[space + 1:] if not multi else self.next_text) self.next_text = UNSET_TEXT else: text = ('%s %s ' % (MSG_SIGN, self.main.message_user)) + text self.end_change(text)
def on_changed(self, *args): text = self.get_text().lstrip() # Message mode --------------------------------------------------------- if self.gui.mode == MODE_MESSAGES: # Cancel message mode if len(text) == 0 and not self.is_changing: self.main.unset('message') # Remove spaces only if text.strip() == UNSET_TEXT: self.set_text(UNSET_TEXT) text = UNSET_TEXT # check for 'd user' msg = MESSAGE_REGEX.match(text) self.message_len = 0 # Remove whitespace between 'd' and username if len(text) > 2 and text[2].strip(' \n\t\r\v') == UNSET_TEXT: gobject.idle_add(self.clear_text, MSG_SIGN + ' ' + text[1:].lstrip(), 2) elif msg is not None: self.message_len = len('%s %s ' % (MSG_SIGN, msg.group(1))) if self.main.message_user_id == UNSET_ID_NUM: self.main.message_user = msg.group(1) elif msg.group(1) != self.main.message_user: self.main.message_text = UNSET_TEXT self.main.message_user = msg.group(1) self.main.message_user_id = UNSET_ID_NUM # Remove space between username and text check = text[self.message_len:] length = len(check) - len(check.lstrip()) if length > 0: gobject.idle_add(self.clear_text, text[0:self.message_len] \ + text[self.message_len + length:], (self.message_len + length) - 1) elif self.main.message_user_id == UNSET_ID_NUM: self.main.message_user = UNSET_USERNAME # check for '@user' and switch to tweeting at_user = REPLY_REGEX.match(text) if at_user is not None: if self.gui.load_state(): self.switch(self.get_text(), MODE_TWEETS) else: self.tweet_to_send = self.get_text() # Tweet Mode ----------------------------------------------------------- elif self.gui.mode == MODE_TWEETS: self.message_len = 0 # Cancel reply mode at_offset = 1 if text.strip()[0:1] == '.' else 0 if len(text.strip()) > at_offset \ and not text.strip()[at_offset] in AT_SIGNS \ and not self.is_changing: self.main.unset('reply') # Remove spaces only if text.strip() == UNSET_TEXT: self.set_text(UNSET_TEXT) text = UNSET_TEXT # Cancel all modes if len(text) == 0 and not self.is_changing: self.main.unset('reply', 'retweet', 'edit') # check for @ Reply at_user = REPLY_REGEX.match(text) if at_user is not None: at_len = len('%s%s ' % (lang.tweet_at, at_user.group(1))) at_len += at_offset if self.main.reply_id == UNSET_ID_NUM: self.main.reply_user = at_user.group(1) elif at_user.group(1) != self.main.reply_user: self.main.reply_text = UNSET_TEXT self.main.reply_user = at_user.group(1) self.main.reply_id = UNSET_ID_NUM # Remove space between username and text check = text[at_len:] length = len(check) - len(check.lstrip()) if length > 0: gobject.idle_add(self.clear_text, text[0:at_len] + text[at_len + length:], (at_len + length) - 1) elif self.main.reply_id == UNSET_ID_NUM: self.main.reply_user = UNSET_USERNAME # check for 'd user' and switch to messaging msg = MESSAGE_REGEX.match(text) if msg is not None: if self.gui.load_state(): self.switch(self.get_text(), MODE_MESSAGES) else: self.message_to_send = self.get_text() # Strip left space = self.get_text()[0:1] if space.strip() != space: ctext = self.get_text().lstrip() gobject.idle_add(self.clear_text, ctext) # Auto completion self.check_auto_complete() # Resize if not self.switch_profile: self.resize() self.check_typing(text)