def setup_translation_box (self): """ Pack the translation box """ self.translation_box = TranslationBox (self.application, self) self.translation_box.show () self.translate_button = gtk.Button ("_Translate") self.translate_button.set_sensitive (False) self.translate_button.set_use_underline (True) image = gtk.image_new_from_stock (gtk.STOCK_REFRESH, gtk.ICON_SIZE_BUTTON) self.translate_button.set_image (image) self.translate_button.connect ('clicked', self.on_translate_clicked) self.translate_button.show () self.translation_box.pack_start (self.translate_button, False) self.layout.pack_start (self.translation_box, False)
class BaseUITranslation (gtk.VBox, BaseTranslation): """ The basic translation page class """ capability = None DESTINATION_COLOR = gtk.gdk.color_parse ("#fff8ae") def __init__ (self, *args): gtk.VBox.__init__ (self, spacing=12) BaseTranslation.__init__ (self, *args) def setup_layout (self): """ Setup the layout of the container """ self.layout = gtk.VBox (spacing=12) self.layout.show () self.pack_start (self.layout) def setup_label (self): """ Create the tab label for the notebook """ self.label = TranslationLabel (self.application, self) self.label.show () def setup_translation_box (self): """ Pack the translation box """ self.translation_box = TranslationBox (self.application, self) self.translation_box.show () self.translate_button = gtk.Button ("_Translate") self.translate_button.set_sensitive (False) self.translate_button.set_use_underline (True) image = gtk.image_new_from_stock (gtk.STOCK_REFRESH, gtk.ICON_SIZE_BUTTON) self.translate_button.set_image (image) self.translate_button.connect ('clicked', self.on_translate_clicked) self.translate_button.show () self.translation_box.pack_start (self.translate_button, False) self.layout.pack_start (self.translation_box, False) def setup_progress (self): """ Create the progress bar """ self.progress = uiutils.Progress () self.progress.connect ('cancelled', self.on_cancelled) self.pack_start (self.progress, False) def setup_ui (self): """ Virtual method, should be implemented in subclasses to add custom widgets. """ pass def setup_clipboard (self): """ Virtual method, must be implemented. Will handle the clipboard when the translation is begin opened. """ raise NotImplementedError () def get_label (self): """ Returns the tab label for the manager """ return self.label def started (self): """ Internally called to indicate the translation has been started """ self.progress.show () self.progress.start () self.label.start_loading () self.layout.set_sensitive (False) def stopped (self): """ Internally called to indicate the translation has been stopped """ self.progress.hide () self.progress.stop () self.label.stop_loading () self.layout.set_sensitive (True) # Events def on_translate_clicked (self, button): """ Start the real translation when the Translate button is clicked """ request = self.create_request () if request: self.translate (request) def on_cancelled (self, progress): """ Cancellation button has been called. This will request the cancellation of the translation. """ self.cancel () # Overrided methods def setup (self): """ Setup the whole widget """ self.setup_layout () self.setup_translation_box () self.setup_label () self.setup_ui () self.setup_progress () self.setup_clipboard () @utils.syncronized def update_translator (self, translator): """ Update the translator. This will dispatch the event to the translation box and set the translation icon in the tab label. """ self.translation_box.set_translator (translator) if translator: pixbuf = self.application.icon_theme.load_icon (translator.icon, Spinner.PIXELS, 0) self.label.icon.set_idle (pixbuf) def update_from_lang (self, lang): """ Externally called to change the source language """ self.translation_box.set_from_lang (lang) def update_to_lang (self, lang): """ Externally called to change the destination language """ self.translation_box.set_to_lang (lang) def update_from_langs (self, langs): """ Externally called to change the list of source languages """ self.translation_box.update_from_langs (langs) def update_to_langs (self, langs): """ Externally called to change the list of destination languages """ self.translation_box.update_to_langs (langs) @utils.syncronized def update_can_translate (self, can_translate): """ Externally called to notify whether we can start the translation """ self.translate_button.set_sensitive (can_translate) @utils.syncronized def update_status (self, status): """ Externally called whenever the status of the translation changes """ if isinstance (status, StatusStarted): self.started () elif (isinstance (status, StatusComplete) or isinstance (status, StatusCancelled)): self.stopped () self.progress.set_text (status.description) # Virtual methods def create_request (self): """ Virtual method, must be implemented to create the translation request """ raise NotImplementedError ()