def _compute_cell_height(self, widget, width): srclang = self.view.controller.main_controller.lang_controller.source_lang.code tgtlang = self.view.controller.main_controller.lang_controller.target_lang.code self.target_layout = self._get_pango_layout( widget, self.matchdata['target'], width - (2*self.BOX_MARGIN), rendering.get_target_font_description() ) self.target_layout.get_context().set_language(rendering.get_language(tgtlang)) if self.matchdata.get('quality', 0) == 0 and \ self.matchdata['source'] == self.matchdata['query_str']: # We do less for MT results self.source_layout = None height = self.target_layout.get_pixel_size()[1] return height + self.ROW_PADDING else: self.source_layout = self._get_pango_layout( widget, self.matchdata['source'], width - (2*self.BOX_MARGIN), rendering.get_source_font_description(), self.matchdata['query_str'] ) self.source_layout.get_context().set_language(rendering.get_language(srclang)) height = self.source_layout.get_pixel_size()[1] + self.target_layout.get_pixel_size()[1] return height + self.LINE_SEPARATION + self.ROW_PADDING
def reset(self): unitview = self.unit_controller.view source_text = u'' for src in unitview.sources: selection = src.buffer.get_selection_bounds() if selection: source_text = src.get_text(*selection) break from virtaal.views import rendering self.ent_source.modify_font(rendering.get_source_font_description()) self.ent_source.set_text(source_text.strip()) srclang = self.lang_controller.source_lang.code self.ent_source.get_pango_context().set_language(rendering.get_language(srclang)) target_text = u'' for tgt in unitview.targets: selection = tgt.buffer.get_selection_bounds() if selection: target_text = tgt.get_text(*selection) break self.ent_target.modify_font(rendering.get_target_font_description()) self.ent_target.set_text(target_text.strip()) tgtlang = self.lang_controller.target_lang.code self.ent_target.get_pango_context().set_language(rendering.get_language(tgtlang)) self.txt_comment.get_buffer().set_text('') self.eb_add_term_errors.hide() self.btn_add_term.props.sensitive = True self.lbl_srclang.set_text_with_mnemonic(_(u'_Source term — %(langname)s') % {'langname': self.lang_controller.source_lang.name}) self.lbl_tgtlang.set_text_with_mnemonic(_(u'_Target term — %(langname)s') % {'langname': self.lang_controller.target_lang.name}) self.lst_termfiles.clear() extendfile = self.term_model.config.get('extendfile', None) select_index = -1 i = 0 for f in self.term_model.config['files']: if f == extendfile: select_index = i self.lst_termfiles.append([f]) i += 1 if select_index >= 0: self.cmb_termfile.set_active(select_index)
def compute_cell_height(self, widget, width): lang_controller = self.view.controller.main_controller.lang_controller srclang = lang_controller.source_lang.code tgtlang = lang_controller.target_lang.code self.source_layout = self._get_pango_layout(widget, self.unit.source, width / 2, rendering.get_source_font_description()) self.source_layout.get_context().set_language(rendering.get_language(srclang)) self.target_layout = self._get_pango_layout(widget, self.unit.target, width / 2, rendering.get_target_font_description()) self.target_layout.get_context().set_language(rendering.get_language(tgtlang)) # This makes no sense, but has the desired effect to align things correctly for # both LTR and RTL languages: if widget.get_direction() == gtk.TEXT_DIR_RTL: self.source_layout.set_alignment(pango.ALIGN_RIGHT) self.target_layout.set_alignment(pango.ALIGN_RIGHT) self.target_layout.set_auto_dir(False) _layout_width, source_height = self.source_layout.get_pixel_size() _layout_width, target_height = self.target_layout.get_pixel_size() return max(source_height, target_height) + self.ROW_PADDING
def compute_cell_height(self, widget, width): lang_controller = self.view.controller.main_controller.lang_controller srclang = lang_controller.source_lang.code tgtlang = lang_controller.target_lang.code self.source_layout = self._get_pango_layout( widget, self.unit.source, width / 2, rendering.get_source_font_description()) self.source_layout.get_context().set_language( rendering.get_language(srclang)) self.target_layout = self._get_pango_layout( widget, self.unit.target, width / 2, rendering.get_target_font_description()) self.target_layout.get_context().set_language( rendering.get_language(tgtlang)) # This makes no sense, but has the desired effect to align things correctly for # both LTR and RTL languages: if widget.get_direction() == gtk.TEXT_DIR_RTL: self.source_layout.set_alignment(pango.ALIGN_RIGHT) self.target_layout.set_alignment(pango.ALIGN_RIGHT) self.target_layout.set_auto_dir(False) _layout_width, source_height = self.source_layout.get_pixel_size() _layout_width, target_height = self.target_layout.get_pixel_size() return max(source_height, target_height) + self.ROW_PADDING