Exemplo n.º 1
0
    def __copy_to_clipboard_cb(self, menu_item):
        clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
        uid_list = self._get_uid_list_cb()
        if len(uid_list) == 1:
            uid = uid_list[0]
            file_path = model.get_file(uid)
            if not file_path or not os.path.exists(file_path):
                logging.warn('Entries without a file cannot be copied.')
                self.emit('volume-error',
                          _('Entries without a file cannot be copied.'),
                          _('Warning'))
                return

            # XXX SL#4307 - until set_with_data bindings are fixed upstream
            if hasattr(clipboard, 'set_with_data'):
                clipboard.set_with_data(
                    [Gtk.TargetEntry.new('text/uri-list', 0, 0)],
                    self.__clipboard_get_func_cb,
                    self.__clipboard_clear_func_cb,
                    None)
            else:
                SugarExt.clipboard_set_with_data(
                    clipboard,
                    [Gtk.TargetEntry.new('text/uri-list', 0, 0)],
                    self.__clipboard_get_func_cb,
                    self.__clipboard_clear_func_cb,
                    None)
Exemplo n.º 2
0
    def __copy_to_clipboard_cb(self, menu_item):
        clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
        uid_list = self._get_uid_list_cb()
        if len(uid_list) == 1:
            uid = uid_list[0]
            file_path = model.get_file(uid)
            if not file_path or not os.path.exists(file_path):
                logging.warn('Entries without a file cannot be copied.')
                self.emit('volume-error',
                          _('Entries without a file cannot be copied.'),
                          _('Warning'))
                return

            # XXX SL#4307 - until set_with_data bindings are fixed upstream
            if hasattr(clipboard, 'set_with_data'):
                clipboard.set_with_data(
                    [Gtk.TargetEntry.new('text/uri-list', 0, 0)],
                    self.__clipboard_get_func_cb,
                    self.__clipboard_clear_func_cb,
                    None)
            else:
                SugarExt.clipboard_set_with_data(
                    clipboard,
                    [Gtk.TargetEntry.new('text/uri-list', 0, 0)],
                    self.__clipboard_get_func_cb,
                    self.__clipboard_clear_func_cb,
                    None)
Exemplo n.º 3
0
    def _put_in_clipboard(self):
        logging.debug('ClipboardIcon._put_in_clipboard')

        if self._cb_object.get_percent() < 100:
            raise ValueError('Object is not complete, cannot be put into the'
                             ' clipboard.')

        targets = self._get_targets()
        if targets:
            x_clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)

            # XXX SL#4307 - until set_with_data bindings are fixed upstream
            if hasattr(x_clipboard, 'set_with_data'):
                stored = x_clipboard.set_with_data(
                    targets,
                    self._clipboard_data_get_cb,
                    self._clipboard_clear_cb,
                    targets)
            else:
                stored = SugarExt.clipboard_set_with_data(
                    x_clipboard,
                    targets,
                    self._clipboard_data_get_cb,
                    self._clipboard_clear_cb,
                    targets)

            if not stored:
                logging.error('GtkClipboard.set_with_data failed!')
            else:
                self.owns_clipboard = True
Exemplo n.º 4
0
    def _put_in_clipboard(self):
        logging.debug('ClipboardIcon._put_in_clipboard')

        if self._cb_object.get_percent() < 100:
            raise ValueError('Object is not complete, cannot be put into the'
                             ' clipboard.')

        targets = self._get_targets()
        if targets:
            x_clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)

            # XXX SL#4307 - until set_with_data bindings are fixed upstream
            if hasattr(x_clipboard, 'set_with_data'):
                stored = x_clipboard.set_with_data(targets,
                                                   self._clipboard_data_get_cb,
                                                   self._clipboard_clear_cb,
                                                   targets)
            else:
                stored = SugarExt.clipboard_set_with_data(
                    x_clipboard, targets, self._clipboard_data_get_cb,
                    self._clipboard_clear_cb, targets)

            if not stored:
                logging.error('GtkClipboard.set_with_data failed!')
            else:
                self.owns_clipboard = True
Exemplo n.º 5
0
 def table_row_to_clipboard(self, table_dict):
     """Put the Selected Table Row to the Clipboard"""
     html_text = self.dad.html_handler.table_export_to_html(table_dict)
     clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
     stored = SugarExt.clipboard_set_with_data(
         clipboard,
         self._targets_names_to_gtk_targets(
             [TARGET_CTD_TABLE, TARGETS_HTML[0]]), self.get_func,
         self.clear_func, (None, None, html_text, table_dict))
     if not stored: print("! clipboard_set_with_data")
Exemplo n.º 6
0
 def selection_to_clipboard(self, text_buffer, sourceview, iter_sel_start,
                            iter_sel_end, num_chars, from_codebox):
     """Write the Selected Content to the Clipboard"""
     clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
     pixbuf_target = None
     if not from_codebox and self.dad.syntax_highlighting == cons.RICH_TEXT_ID and num_chars == 1:
         anchor = iter_sel_start.get_child_anchor()
         if anchor:
             anchor_dir = dir(anchor)
             if "pixbuf" in anchor_dir:
                 pixbuf_target = anchor.pixbuf
             elif "liststore" in anchor_dir:
                 table_dict = self.dad.state_machine.table_to_dict(anchor)
                 html_text = self.dad.html_handler.table_export_to_html(
                     table_dict)
                 txt_handler = exports.Export2Txt(self.dad)
                 text_offsets_range = [
                     iter_sel_start.get_offset(),
                     iter_sel_end.get_offset()
                 ]
                 plain_text = txt_handler.node_export_to_txt(
                     text_buffer,
                     "",
                     sel_range=text_offsets_range,
                     check_link_target=True)
                 stored = SugarExt.clipboard_set_with_data(
                     clipboard,
                     self._targets_names_to_gtk_targets([
                         TARGET_CTD_TABLE, TARGETS_HTML[0],
                         TARGET_CTD_PLAIN_TEXT
                     ]), self.get_func, self.clear_func,
                     (plain_text, None, html_text, table_dict))
                 if not stored: print("! clipboard_set_with_data")
                 return
             elif "sourcebuffer" in anchor_dir:
                 codebox_dict = self.dad.state_machine.codebox_to_dict(
                     anchor, for_print=0)
                 codebox_dict_html = self.dad.state_machine.codebox_to_dict(
                     anchor, for_print=2)
                 html_text = self.dad.html_handler.codebox_export_to_html(
                     codebox_dict_html)
                 txt_handler = exports.Export2Txt(self.dad)
                 text_offsets_range = [
                     iter_sel_start.get_offset(),
                     iter_sel_end.get_offset()
                 ]
                 plain_text = txt_handler.node_export_to_txt(
                     text_buffer,
                     "",
                     sel_range=text_offsets_range,
                     check_link_target=True)
                 stored = SugarExt.clipboard_set_with_data(
                     clipboard,
                     self._targets_names_to_gtk_targets([
                         TARGET_CTD_CODEBOX, TARGETS_HTML[0],
                         TARGET_CTD_PLAIN_TEXT
                     ]), self.get_func, self.clear_func,
                     (plain_text, None, html_text, codebox_dict))
                 if not stored: print("! clipboard_set_with_data")
                 return
     if not os.path.isdir(cons.TMP_FOLDER): os.mkdir(cons.TMP_FOLDER)
     html_text = self.dad.html_handler.selection_export_to_html(
         text_buffer, iter_sel_start, iter_sel_end,
         self.dad.syntax_highlighting
         if not from_codebox else cons.PLAIN_TEXT_ID)
     if not from_codebox and self.dad.syntax_highlighting == cons.RICH_TEXT_ID:
         txt_handler = exports.Export2Txt(self.dad)
         text_offsets_range = [
             iter_sel_start.get_offset(),
             iter_sel_end.get_offset()
         ]
         plain_text = txt_handler.node_export_to_txt(
             text_buffer,
             "",
             sel_range=text_offsets_range,
             check_link_target=True)
         rich_text = self.rich_text_get_from_text_buffer_selection(
             text_buffer, iter_sel_start, iter_sel_end)
         if not self.force_plain_text:
             targets_vector = [
                 TARGET_CTD_PLAIN_TEXT, TARGET_CTD_RICH_TEXT,
                 TARGETS_HTML[0], TARGETS_HTML[1]
             ]
             if pixbuf_target:
                 targets_vector.append(TARGETS_IMAGES[0])
         else:
             targets_vector = [TARGET_CTD_PLAIN_TEXT]
         stored = SugarExt.clipboard_set_with_data(
             clipboard, self._targets_names_to_gtk_targets(targets_vector),
             self.get_func, self.clear_func,
             (plain_text, rich_text, html_text, pixbuf_target))
         if not stored: print("! clipboard_set_with_data")
     else:
         plain_text = text_buffer.get_text(iter_sel_start, iter_sel_end,
                                           False)
         if not self.force_plain_text:
             targets_vector = [
                 TARGET_CTD_PLAIN_TEXT, TARGETS_HTML[0], TARGETS_HTML[1]
             ]
         else:
             targets_vector = [TARGET_CTD_PLAIN_TEXT]
         stored = SugarExt.clipboard_set_with_data(
             clipboard, self._targets_names_to_gtk_targets(targets_vector),
             self.get_func, self.clear_func,
             (plain_text, None, html_text, pixbuf_target))
         if not stored: print("! clipboard_set_with_data")