+ self._action = self.ACTION_CANCEL
+
+
+class SmsEntryDialog(object):
+
+ MAX_CHAR = 160
+
+ def __init__(self, widgetTree, gcBackend):
+ self._gcBackend = gcBackend
+ self._widgetTree = widgetTree
+ self._dialog = self._widgetTree.get_widget("smsDialog")
+
+ self._smsButton = self._widgetTree.get_widget("sendSmsButton")
+ self._smsButton.connect("clicked", self._on_send)
+
+ self._cancelButton = self._widgetTree.get_widget("cancelSmsButton")
+ self._cancelButton.connect("clicked", self._on_cancel)
+
+ self._letterCountLabel = self._widgetTree.get_widget("smsLetterCount")
+ self._message = self._widgetTree.get_widget("smsMessage")
+ self._smsEntry = self._widgetTree.get_widget("smsEntry")
+ self._smsEntry.get_buffer().connect("changed", self._on_entry_changed)
+
+ def run(self, number, message = ""):
+ if message:
+ self._message.set_markup(message)
+ self._message.show()
+ else:
+ self._message.set_markup("")
+ self._message.hide()
+ self._smsEntry.get_buffer().set_text("")
+ self._update_letter_count()
+
+ userResponse = self._dialog.run()
+ if userResponse == gtk.RESPONSE_OK:
+ entryBuffer = self._smsEntry.get_buffer()
+ enteredMessage = entryBuffer.get_text(entryBuffer.get_start_iter(), entryBuffer.get_end_iter())
+ enteredMessage = enteredMessage[0:self.MAX_CHAR]
+ else:
+ enteredMessage = ""
+
+ self._dialog.hide()
+ return enteredMessage
+
+ def _update_letter_count(self, *args):
+ entryLength = self._smsEntry.get_buffer().get_char_count()
+ self._letterCountLabel.set_text(str(self.MAX_CHAR - entryLength))
+
+ def _on_entry_changed(self, *args):
+ self._update_letter_count()
+
+ def _on_send(self, *args):
+ self._dialog.response(gtk.RESPONSE_OK)
+
+ def _on_cancel(self, *args):
+ self._dialog.response(gtk.RESPONSE_CANCEL)