def do_paste_unformatted(self, *args): '''无格式粘贴 ''' #-print 'do_paste_unformatted:' text = Gtk.Clipboard().wait_for_text() or Gtk.Clipboard(selection="PRIMARY").wait_for_text() if text: self.do_insert_text(text) return return
def paste_gtk(): clipboardContents = Gtk.Clipboard().wait_for_text() # for python 2, returns None if the clipboard is blank. if clipboardContents is None: return '' else: return clipboardContents
def __init__(self, main_app): """Create the source view window and init its properties""" self.main = main_app self.model = main_app.model self.clipboard = Gtk.Clipboard() control_viewport = self.main.builder.get_object('control_view') manager = GtkSource.LanguageManager() lang_python = manager.get_language('python') self.buffer = GtkSource.Buffer(language=lang_python) self.buffer.props.highlight_syntax = True self.control_view = GtkSource.View(buffer=self.buffer) self.buffer.place_cursor(self.buffer.get_start_iter()) self.control_view.connect('button-press-event', self.on_control_view_clicked) self.buffer.connect('changed', self.on_buffer_changed) self.buffer.connect('notify::can-undo', lambda o, p: self.main.update_undo_redo_menuitem()) self.buffer.connect('notify::can-redo', lambda o, p: self.main.update_undo_redo_menuitem()) self.tag_error = self.buffer.create_tag("error", background="red") debug_textview = self.main.builder.get_object('trace_textview') self.debug_buffer = LogBuffer(sys.stdout) sys.stdout = self.debug_buffer debug_textview.set_buffer(self.debug_buffer) self.control_view.show() #hide trace window by default #self.main.builder.get_object('hboxdebug').hide() control_viewport.add(self.control_view)
def _paste_cb(self, arg=None): """ Paste a number from the clipboard to the active slide. """ clipBoard = Gtk.Clipboard() text = clipBoard.wait_for_text() if text is not None: self.sr.enter_value(self.sr.last, text) return
def __init__(self, _parent): SugarEditToolbar.__init__(self) self._parent = _parent self.undo.connect('clicked', self.__undo_cb) self.redo.connect('clicked', self.__redo_cb) self.copy.connect('clicked', self.__copy_cb) self.paste.connect('clicked', self.__paste_cb) menu_item = MenuItem(_('Cut')) menu_item.connect('activate', self.__cut_cb) menu_item.show() self.copy.get_palette().menu.append(menu_item) self.insert(Gtk.SeparatorToolItem(), -1) self.erase_button = ToolButton('edit-delete') self.erase_button.set_tooltip(_('Erase selected thought(s)')) self.erase_button.connect('clicked', self.__delete_cb) self.insert(self.erase_button, -1) self.show_all() self.clipboard = Gtk.Clipboard() self.copy.set_sensitive(False) self.paste.set_sensitive(False) self.erase_button.set_sensitive(False)
def _write_scores_to_clipboard(self, button=None): ''' SimpleGraph will plot the cululative results ''' _logger.debug(self.all_scores) scores = '' for i, s in enumerate(self.all_scores): scores += '%s: %s\n' % (str(i + 1), s) Gtk.Clipboard().set_text(scores)
def __init__(self, db): self.last_window_title = "" self.db = db self.ui = Gtk.Builder() self.ui.add_from_file(scriptdir+'query.glade') self.ui.connect_signals({ "do_quit": self.app_close, "on_quit1_activate" : self.app_close, "on_run_query_activate" : self.app_func("run_query"), "on_run_query_output_to_text1_activate" : self.app_func("run_query_to_text"), "on_undo_activate" : self.app_func("undo"), "on_redo_activate" : self.app_func("redo"), "on_new1_activate" : self.new_page, "on_open1_activate" : self.file_open_dialog, "on_save1_activate" : self.app_func("file_save"), "on_save_as1_activate" : self.app_func("file_saveas"), "on_cut1_activate" : self.cut, "on_copy1_activate" : self.copy, "on_paste1_activate" : self.paste }) self.window = self.ui.get_object("window1") self.window.set_icon_from_file(icondir+"db.png") self.notebook = self.ui.get_object("notebook1") self.messages = self.ui.get_object("messages") self.apps = [] self.conn = self.db.connect() self.new_page() self.message("Connected") self.clip = Gtk.Clipboard() self.table_browser = TableBrowser( self.ui.get_object("treeview_tables"), self.ui.get_object("table_browser_filter"), self) self.update_window_title()
def main(): import time from xpra.platform import program_context with program_context("OSX Clipboard Change Test"): log.enable_debug() #init UI watcher with gobject (required by pasteboard monitoring code) get_UI_watcher(GLib.timeout_add, GLib.source_remove) log.info("testing pasteboard") from gi.repository import Gtk pasteboard = NSPasteboard.generalPasteboard() def nosend(*args): log("nosend%s", args) proxy = OSXClipboardProxy("CLIPBOARD", pasteboard, nosend, nosend) log.info("current change count=%s", proxy.change_count) clipboard = Gtk.Clipboard(selection="CLIPBOARD") log.info("changing clipboard %s contents", clipboard) clipboard.set_text("HELLO WORLD %s" % time.time()) proxy.update_change_count() log.info("new change count=%s", proxy.change_count) log.info("any update to your clipboard should get logged (^C to exit)") cc = proxy.change_count while True: v = proxy.change_count if v!=cc: log.info("success! the clipboard change has been detected, new change count=%s", v) else: log.info(".") time.sleep(1) if v==cc: log.info("no clipboard change detected")
def on_btnCopyResponse_clicked(self, widget): txtResponseBuf = self.txtResponse.get_buffer() raw = txtResponseBuf.get_text(txtResponseBuf.get_start_iter(), txtResponseBuf.get_end_iter(), False) clippy = Gtk.Clipboard().get(Gdk.SELECTION_CLIPBOARD) clippy.set_text(raw, len(raw)) clippy.store()
def selection_changed_cb (self, area, start, end, text): clip = Gtk.Clipboard() if text: clip.set_text(text) else: clip.clear ()
def on_toolButtonCopy_clicked(self, widget): try: clipBoard = gtk.Clipboard() if (self.__selectedPixbuf == None): raise ValueError clipBoard.set_image(self.__selectedPixbuf) except ValueError: return
def onStateChange(self, webProgress, request, stateFlags, status): if (stateFlags & interfaces.nsIWebProgressListener.STATE_IS_REQUEST and stateFlags & interfaces.nsIWebProgressListener.STATE_STOP): clipboard = Gtk.Clipboard() clipboard.set_with_data([('text/uri-list', 0, 0)], _clipboard_get_func_cb, _clipboard_clear_func_cb, self._temp_file)
def button_mousepress(self, obj, event): # sys.stderr.write("event.type=0x%x event.button=0x%x\n" % (event.type,event.button)) if event.type == EventType_BUTTON_PRESS and event.button == 3: clipstring = self.determine_command()[5] clipboard = gtk.Clipboard(gdk.display_get_default(), "PRIMARY") clipboard.set_text(clipstring, -1) clipboard.store() clipboard = gtk.Clipboard(gdk.display_get_default(), "CLIPBOARD") clipboard.set_text(clipstring, -1) clipboard.store() return True # eat event else: return False pass
def copy_vol_path(self, ignore=None): vol = self.current_vol() if not vol: return clipboard = Gtk.Clipboard() target_path = vol.get_target_path() if target_path: clipboard.set_text(target_path)
def _copy_cb(self, arg=None): """ Copy a number to the clipboard from the active slide. """ clipBoard = Gtk.Clipboard() if self.sr.last is not None and \ self.sr.last.labels is not None and \ self.sr.last.labels[0] is not None: clipBoard.set_text(self.sr.last.labels[0]) return
def on_mnu_paste_enc_activate(self, widget, data=None): clippy = Gtk.Clipboard().get(Gdk.SELECTION_CLIPBOARD) doc = clippy.wait_for_text() if doc != None: docenc = urllib.quote(doc) txtRequestBuf = self.txtRequest.get_buffer() txtRequestBuf.insert_at_cursor(docenc)
def _tb_copy_selection(self): tb = self.stdout_textview.get_buffer() bounds = tb.get_selection_bounds() if bounds: text = tb.get_text(bounds[0], bounds[1], True) clipboard = Gtk.Clipboard() clipboard.set_text(text) clipboard.store()
def __copy_activate_cb(self, menu_item): clipboard = Gtk.Clipboard() targets = Gtk.target_list_add_uri_targets() targets = Gtk.target_list_add_text_targets(targets) targets.append(('text/x-moz-url', 0, 0)) clipboard.set_with_data(targets, self.__clipboard_get_func_cb, self.__clipboard_clear_func_cb)
def set_clipboard_uris(*uris): '''Convenience function to put a file on the clipboard''' myclipboard = Gtk.Clipboard() targets = [('text/uri-list', 0, 0)] def my_get_data(clipboard, selectiondata, id, file): selectiondata.set_uris(uris) def my_clear_data(*a): pass myclipboard.set_with_data(targets, my_get_data, my_clear_data, file)
def copy_link(self, beans=None): if not beans: return if hasattr(beans[0], 'path'): cb = Gtk.Clipboard().set_text(beans[0].path) cb.store() if FC().notifier: notification = Notify.Notification.new("In clipboard", beans[0].path, "") notification.set_urgency(Notify.Urgency.LOW) notification.set_timeout(FC().notify_time) notification.show()
def process_button_down(self, event, coords): if not self._parent.move_mode and self.textview is None: self._create_textview() self.make_tags() if self.textview is not None: self.textview.grab_focus() if ResizableThought.process_button_down(self, event, coords): return True # With textview, we are always editing # if not self.editing: # return False modifiers = Gtk.accelerator_get_default_mod_mask() if event.button == 1: if event.type == Gdk.EventType.BUTTON_PRESS: x = int((coords[0] - self.min_x) * Pango.SCALE) y = int((coords[1] - self.min_y) * Pango.SCALE) loc = self.layout.xy_to_index(x, y) self.index = loc[0] if loc[0] >= len(self.text) - 1 or self.text[loc[0] + 1] == '\n': self.index += loc[1] self.bindex = self.bindex_from_index(self.index) if not (event.state & modifiers) & Gdk.ModifierType.SHIFT_MASK: self.end_index = self.index elif event.type == Gdk.EventType._2BUTTON_PRESS: self.index = len(self.text) self.end_index = 0 # and mark all self.double_click = True elif event.button == 2: x = int((coords[0] - self.min_x) * Pango.SCALE) y = int((coords[1] - self.min_y) * Pango.SCALE) loc = self.layout.xy_to_index(x, y) self.index = loc[0] if loc[0] >= len(self.text) - 1 or self.text[loc[0] + 1] == '\n': self.index += loc[1] self.bindex = self.bindex_from_index(self.index) self.end_index = self.index if os.name != 'nt': clip = Gtk.Clipboard(selection="PRIMARY") self.paste_text(clip) del self.current_attrs self.current_attrs = [] self.recalc_edges() self.emit("update_view") self.selection_changed()
def set_clipboard_image(file): '''Convenience function to put image data on the clipboard''' myclipboard = Gtk.Clipboard() targets = [('image/png', 0, 0)] def my_get_data(clipboard, selectiondata, id, file): pixbuf = GdkPixbuf.Pixbuf.new_from_file(file.path) selectiondata.set_pixbuf(pixbuf) def my_clear_data(*a): pass myclipboard.set_with_data(targets, my_get_data, my_clear_data, file)
def __copy_to_clipboard_cb(self, menu_item): file_path = model.get_file(self._metadata['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 clipboard = Gtk.Clipboard() clipboard.set_with_data([('text/uri-list', 0, 0)], self.__clipboard_get_func_cb, self.__clipboard_clear_func_cb)
def enter_clicked(self, widget): parameter = self.parameter_entry.get_text() secret = self.secret_entry.get_text() if len(parameter) < 1: self.parameter_entry.grab_focus() elif len(secret) < 1: self.secret_entry.grab_focus() else: generated_password = generate_password(parameter, secret, self.selected_length) Gtk.Clipboard().get(Gdk.SELECTION_CLIPBOARD).set_text( generated_password, -1) self.parameter_entry.set_text('') self.secret_entry.set_text('')
def button_mousepress(self, obj, event): # sys.stderr.write("event.type=0x%x event.button=0x%x\n" % (event.type,event.button)) if event.type == gdk.BUTTON_PRESS and event.button == 3: clipstring = "" if self.state == self.STATE_IDLE or self.state == self.STATE_DONE: clipstring = "cd '%s' ; " % ( unicode(self.paramdb["dest"].dcvalue) ) + self.environstr + self.environstr + self.determine_command( ) pass elif self.state == self.STATE_RUNNING: clipstring = str(self.subprocess_pobj.pid) pass clipboard = gtk.Clipboard(gdk.display_get_default(), "PRIMARY") clipboard.set_text(clipstring, -1) clipboard.store() clipboard = gtk.Clipboard(gdk.display_get_default(), "CLIPBOARD") clipboard.set_text(clipstring, -1) clipboard.store() return True # eat event return False
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() if not x_clipboard.set_with_data( targets, self._clipboard_data_get_cb, self._clipboard_clear_cb, targets): logging.error('GtkClipboard.set_with_data failed!') else: self.owns_clipboard = True
def _do_paste_cb(self, button): ''' Callback for paste button. ''' self.tw.copying_blocks = False self.tw.saving_blocks = False self.tw.deleting_blocks = False self.win.get_window().set_cursor(Gdk.Cursor(Gdk.CursorType.LEFT_PTR)) clipboard = Gtk.Clipboard() text = clipboard.wait_for_text() if text is not None: if self.tw.selected_blk is not None and \ self.tw.selected_blk.name == 'string' and \ text[0:2] != '[[': # Don't paste block data into a string self.tw.paste_text_in_block_label(text) self.tw.selected_blk.resize() else: self.tw.process_data(data_from_string(text), self.tw.paste_offset) self.tw.paste_offset += PASTE_OFFSET
def Popupmenu_Activate(self, menuitem, listview, menuindex): if listview.get_selection() == None: return model = listview.get_selection().get_selected()[0] selection = listview.get_selection().get_selected()[1] clipboard = Gtk.Clipboard().get_for_display(Gdk.Display().get_default(), Gdk.SELECTION_CLIPBOARD) if menuindex == 0: # Copy Data clipboard.set_text(model.get_value(selection, 1), -1) elif menuindex == 1: # Copy Annotation clipboard.set_text(model.get_value(selection, 2), -1) elif menuindex == 2: # Copy Field Name clipboard.set_text(model.get_value(selection, 0), -1)
def _do_paste_cb(self, button): ''' Callback for paste button. ''' self.tw.copying_blocks = False self.tw.saving_blocks = False self.tw.deleting_blocks = False self.win.get_window().set_cursor(Gdk.Cursor.new(Gdk.CursorType.LEFT_PTR)) clipBoard = Gtk.Clipboard() text = clipBoard.wait_for_text() if text is not None: if self.tw.selected_blk is not None and \ self.tw.selected_blk.name == 'string': self.tw.text_buffer.set_text( self.tw.text_buffer.get_text() + text) self.tw.text_entry.set_buffer(self.tw.text_buffer) self.tw.selected_blk.resize() elif text[0:2] == '[[': self.tw.process_data(data_from_string(text), self.tw.paste_offset) self.tw.paste_offset += 20
def process_button_down(self, event, mode, transformed): modifiers = Gtk.accelerator_get_default_mod_mask() if event.button == 1: if event.type == Gtk.gdk.BUTTON_PRESS and not self.editing: self.emit("select_thought", event.state & modifiers) elif event.type == Gtk.gdk.BUTTON_PRESS and self.editing: x = int((transformed[0] - self.ul[0]) * Pango.SCALE) y = int((transformed[1] - self.ul[1]) * Pango.SCALE) loc = self.layout.xy_to_index(x, y) self.index = loc[0] if loc[0] >= len(self.text) - 1 or self.text[loc[0] + 1] == '\n': self.index += loc[1] self.bindex = self.bindex_from_index(self.index) if not (event.state & modifiers) & Gtk.gdk.SHIFT_MASK: self.end_index = self.index elif mode == BaseThought.MODE_EDITING and event.type == Gtk.gdk._2BUTTON_PRESS: if self.editing: self.move_index_horizontal(False) # go to the end self.index = 0 # and mark all else: self.emit("begin_editing") elif event.button == 2 and self.editing: x = int((transformed[0] - self.ul[0]) * Pango.SCALE) y = int((transformed[1] - self.ul[1]) * Pango.SCALE) loc = self.layout.xy_to_index(x, y) self.index = loc[0] if loc[0] >= len(self.text) - 1 or self.text[loc[0] + 1] == '\n': self.index += loc[1] self.bindex = self.bindex_from_index(self.index) self.end_index = self.index if os.name != 'nt': clip = Gtk.Clipboard(selection="PRIMARY") self.paste_text(clip) elif event.button == 3: self.emit("popup_requested", event, 1) del self.current_attrs self.current_attrs = [] self.recalc_edges() self.emit("update_view")