def no_window(screen, window): return (not screen.supports_net_wm_hint( Gdk.atom_intern('_NET_ACTIVE_WINDOW', True)) or not screen.supports_net_wm_hint( Gdk.atom_intern('_NET_WM_WINDOW_TYPE', True)) or window.get_type_hint().value_name == 'GDK_WINDOW_TYPE_HINT_DESKTOP')
def _get_active_window(self, screen): """ Get the current active window. """ window = screen.get_active_window() if not screen.supports_net_wm_hint(Gdk.atom_intern('_NET_ACTIVE_WINDOW', True)): return None if not screen.supports_net_wm_hint(Gdk.atom_intern('_NET_WM_WINDOW_TYPE', True)): return None if window.get_type_hint().value_name == 'GDK_WINDOW_TYPE_HINT_DESKTOP': return None return window
def _get_active_window(self, screen): """ Get the current active window. """ window = screen.get_active_window() if not screen.supports_net_wm_hint( Gdk.atom_intern('_NET_ACTIVE_WINDOW', True)): return None if not screen.supports_net_wm_hint( Gdk.atom_intern('_NET_WM_WINDOW_TYPE', True)): return None if window.get_type_hint().value_name == 'GDK_WINDOW_TYPE_HINT_DESKTOP': return None return window
def drag_data_get_event(self, widget, context, selection_data, info, time, data): logging.debug('############### Editable_Textbox.drag_data_get_event') if not self.ignore_snap_self and self.snapto != SNAP_NONE: a = self.article if self.snapto == SNAP_SENTENCE: atom = Gdk.atom_intern("sentence", only_if_exists=False) if self.snapto == SNAP_PARAGRAPH: atom = Gdk.atom_intern("paragraph", only_if_exists=False) if self.snapto == SNAP_SECTION: atom = Gdk.atom_intern("section", only_if_exists=False) string = cPickle.dumps(a.getSelection()) selection_data.set(atom, 8, string) self.stop_emission("drag-data-get")
def __init__(self, plugin, window): self._window = window self._plugin = plugin self.tab = None self.pane = None atom = Gdk.atom_intern('CLIPBOARD', True) self.clipboard = Gtk.Clipboard.get(atom) self.plugin_dir = os.path.split(__file__)[0] self.config_store = os.path.join(self.plugin_dir, "defaults.pkl") self.config_fields = { 'nodejs': None, 'braces_on_own_line': None, 'replace_contents': None } self._settings = { 'replace_contents': 2, # 0=clipboard, 1=replace, 2=ask what to do 'nodejs': 'node', 'indent_size': '1', 'indent_char': '\t', 'braces_on_own_line': 'false', 'preserve_newlines': 'true', 'keep_array_indentation': 'true', 'space_after_anon_function': 'true', 'decompress': 'true', } self._insert_menu() self._read_config_file()
def paste_button_clicked(self, button, entry): # get the default clipboard atom = Gdk.atom_intern('CLIPBOARD', True) clipboard = entry.get_clipboard(atom) # set the clipboard's text clipboard.request_text(self.paste_received, entry)
def copy_image(self, item, data): # get the default clipboard atom = Gdk.atom_intern('CLIPBOARD', True) clipboard = Gtk.Clipboard.get(atom) pixbuf = self.get_image_pixbuf(data) clipboard.set_image(pixbuf)
def run(self): log ("PastebinThread started!") cmdline = ["pastebinit"] options = {} options['-b'] = "http://" + self.settings.get_string("pastebin") options['-a'] = self.settings.get_string("author") options['-u'] = self.settings.get_string("username") options['-p'] = self.settings.get_string("password") if not options['-a'] or options['-a'].strip() == '': options['-a'] = os.getenv("USERNAME") for opt in options: if options[opt] != None and options[opt].strip() != '': cmdline.append(opt) cmdline.append(options[opt]) cmdline.append(self.filename) summary = '' message = '' icon = None helper = Gtk.Button() try: pasteurl = check_output(cmdline).strip() except CalledProcessError as error: # error.cmd and error.returncode, pasteurl has strerr summary = error.message icon = helper.render_icon(Gtk.STOCK_DIALOG_ERROR, Gtk.IconSize.DIALOG, None) except: # if not pasteurl or not re.match("^http://.*$", pasteurl): summary = _("Unable to read or parse the result page.") message = _("It could be a server timeout or a change server side. Try later.") icon = helper.render_icon(Gtk.STOCK_DIALOG_ERROR, Gtk.IconSize.DIALOG, None) else: summary = 'File pasted to: ' #URLmarkup = '<a href="%(pasteurl)s">%(pasteurl)s</a>' #message = URLmarkup % {'pasteurl':pasteurl} message = pasteurl icon = helper.render_icon(Gtk.STOCK_PASTE, Gtk.IconSize.DIALOG, None) atom = Gdk.atom_intern('CLIPBOARD', True) cb = Gtk.Clipboard.get(atom) cb.clear() cb.set_text(pasteurl, -1) # Open a browser window if self.settings['openbrowser']: webbrowser.open(pasteurl) # Show a bubble if self.settings['shownotification']: if Notify != None: n = Notify.Notification.new(summary, message, None) n.set_image_from_pixbuf(icon) n.show() else: print "libnotify is not installed"
def _copy_result_2_clipboard(self): atom = Gdk.atom_intern('CLIPBOARD', True) clipboard = self.get_clipboard(atom) buf = self.txt_source.get_buffer() text = buf.get_text(buf.get_start_iter(), buf.get_end_iter(), False) clipboard.set_text(text, len(text))
class Context: targets = [Gdk.atom_intern(drag_type.name(), False)] action = 1 def list_targets(self): return Context.targets def get_actions(self): return Context.action
def _init_data(self): # 取得剪贴板 return atom = Gdk.atom_intern('CLIPBOARD', True) clipboard = self.get_clipboard(atom) clipboard.request_text(self.on_get_text_from_clipboard)
def __init__(self): self.snippet = None self._temp_export = None self.key_press_id = 0 self.dnd_target_list = Gtk.TargetList.new([]) self.dnd_target_list.add(Gdk.atom_intern("text/uri-list", True), 0, self.TARGET_URI)
def send_message(self,socket,dest_xid,message): event = Gdk.Event(Gdk.CLIENT_EVENT) event.window = socket.get_window() # needs sending Gdk window event.message_type = Gdk.atom_intern('Gladevcp') # change to any text you like event.data_format = 8 # 8 bit (char) data (options: long,short) event.data = message # must be exactly 20 char bytes (options: 5 long or 10 short) event.send_event = True # signals this was sent explicedly event.send_client_message(dest_xid) # uses destination XID window number
def copy_url_cb(self, source): data = '' for row in self.selected_images: data += '\n' + self.liststore[row][7].replace('<tt>', '').replace('</tt>', '') clipboard = gtk.Clipboard.get(gdk.atom_intern('CLIPBOARD', True)) clipboard.set_text(data.strip(), -1)
def drag_data_get_event(self, widget, context, selection_data, info, time, data): logging.debug('######## Readonly_Textbox.drag_data_get_event') logging.debug('############################## %s', self.MANUEL) a = self.article if self.selectionmode == SELECT_SENTENCE: atom = Gdk.atom_intern("sentence", only_if_exists=False) if self.selectionmode == SELECT_PARAGRAPH: atom = Gdk.atom_intern("paragraph", only_if_exists=False) if self.selectionmode == SELECT_SECTION: atom = Gdk.atom_intern("section", only_if_exists=False) string = cPickle.dumps(a.getSelection()) selection_data.set(atom, 8, string) self.stop_emission("drag-data-get") self.set_editable(False) self.MANUEL += 1
def paste_image(self, item, data): # get the default clipboard atom = Gdk.atom_intern('CLIPBOARD', True) clipboard = Gtk.Clipboard.get(atom) pixbuf = clipboard.wait_for_image() if pixbuf != None: data.set_from_pixbuf(pixbuf)
def copy_button_clicked(self, button, entry): # get the default clipboard atom = Gdk.atom_intern('CLIPBOARD', True) clipboard = entry.get_clipboard(atom) # set the clipboard's text # FIXME: don't require passing length argument clipboard.set_text(entry.get_text(), -1)
def test_structure(self): a = Gdk.atom_intern('CLIPBOARD', True) self.assertTrue(isinstance(a, Gdk.Atom)) self.assertTrue(isinstance(Gtk.Clipboard.get(a), Gtk.Clipboard)) self.assertRaises(TypeError, Gtk.Clipboard.get, None) self.assertRaises(TypeError, Gtk.Clipboard.get, 0) self.assertRaises(TypeError, Gtk.Clipboard.get, Gdk.Atom) self.assertRaises(TypeError, Gdk.Atom, "baz")
def selection_set_songs(selection_data, songs): """Stores filenames of the passed songs in a Gtk.SelectionData""" filenames = [] for filename in (song["~filename"] for song in songs): filenames.append(fsn2bytes(filename, "utf-8")) type_ = Gdk.atom_intern("text/x-quodlibet-songs", True) selection_data.set(type_, 8, b"\x00".join(filenames))
def ide_edit_copy(self, widget): ve_editor = self.multiEditors.get_current_ide_editor() if ve_editor is None: return atom = Gdk.atom_intern('CLIPBOARD', True) clipboard = ve_editor.cmdList.get_clipboard(atom) ve_editor.cmdList.get_buffer().copy_clipboard(clipboard)
def ide_edit_paste(self, widget): ve_editor = self.multiEditors.get_current_ide_editor() if ve_editor is None: return atom = Gdk.atom_intern('CLIPBOARD', True) clipboard = ve_editor.editor.get_clipboard(atom) ve_editor.editor.get_buffer().paste_clipboard(clipboard, None, True)
def copy_image(f): assert os.path.exists(f), "File does not exist: %s" % f image = Pixbuf.new_from_file(f) atom = Gdk.atom_intern('CLIPBOARD', True) clipboard = Gtk.Clipboard.get(atom) clipboard.set_image(image) clipboard.store() sys.exit(1)
def on_copy_activate(self, widget): clipboard = Gtk.Clipboard.get(Gdk.atom_intern('CLIPBOARD', True)) buf = self.textview_description.get_buffer() if buf.get_has_selection(): buf.copy_clipboard(clipboard) else: (start, end) = buf.get_bounds() text = buf.get_text(start, end, True) clipboard.set_text(text, -1)
def clipb(self, clipboard, EventOwnerChange): if SKIP_FILES: target_atoms = clipboard.get(Gdk.atom_intern("CLIPBOARD", True)).wait_for_targets()[1] targets = [item.name() for item in target_atoms ] if ("text/uri-list" not in targets) or ("x-special/gnome-copied-files" not in targets): clipboard.request_text(self.callback1, None) clipboard.request_image(self.callback2, None) else: clipboard.request_text(self.callback1, None) clipboard.request_image(self.callback2, None)
def copy_url(self, action, shell): # rhythmbox api break up (0.13.2 - 0.13.3) try: selected_source = shell.get_property("selected-source") except: selected_source = shell.get_property("selected-page") download_url = self.entry_view.get_selected_entries()[0].get_playback_uri(); atom = Gdk.atom_intern('CLIPBOARD', True) clipboard = Gtk.Clipboard.get(atom) clipboard.set_text(download_url, -1) clipboard.store()
def drag_data_get_event(self, widget, context, selection_data, info, timestamp, data): logger.debug('############# Journal_Journal_Gallery_View.drag_data_get_event') atom = Gdk.atom_intern("section", only_if_exists=False) imagedata = Picture_Data(self.source_article_id, self.image_list[self.current_index][0]) captiondata = Sentence_Data(0, self.source_article_id, 0, 0, 0, self.image_list[self.current_index][1]) paragraph1data = Paragraph_Data(0, self.source_article_id, 0, 0, [imagedata]) paragraph2data = Paragraph_Data(0, self.source_article_id, 0, 0, [captiondata]) sectionsdata = [Section_Data(0, self.source_article_id, 0, [paragraph1data, paragraph2data])] string = cPickle.dumps(sectionsdata) selection_data.set(atom, 8, string)
def print_possible_clipboard_types(): ''' Print possible clipboard types Stolen from https://stackoverflow.com/questions/3571179/how-does-x11-clipboard-handle-multiple-data-formats See also https://freedesktop.org/wiki/Specifications/ClipboardsWiki/ ''' print(*Gtk.Clipboard.get(Gdk.atom_intern("CLIPBOARD", True)).wait_for_targets()[1], sep="\n")
def on_copy_button_clicked(widget, text): atom = Gdk.atom_intern('CLIPBOARD', True) clipboard = Gtk.Clipboard.get_for_display(Gdk.Display.get_default(), atom) clipboard.set_text(text, -1) notify = Notify.Notification() notify.update(summary=_('Error message has been copied'), body=_('Now click "Report" to enter the bug ' 'report website. Make sure to attach the ' 'error message in "Further information".'), icon='ubuntu-tweak') notify.show()
def selection_set_songs(selection_data, songs): """Stores filenames of the passed songs in a Gtk.SelectionData""" filenames = [] for filename in (song["~filename"] for song in songs): if isinstance(filename, unicode): # win32 filename = filename.encode("utf-8") filenames.append(filename) type_ = Gdk.atom_intern("text/x-quodlibet-songs", True) selection_data.set(type_, 8, "\x00".join(filenames))
def copy_url(self, action, shell): # rhythmbox api break up (0.13.2 - 0.13.3) try: selected_source = shell.get_property("selected-source") except: selected_source = shell.get_property("selected-page") download_url = self.entry_view.get_selected_entries( )[0].get_playback_uri() atom = Gdk.atom_intern('CLIPBOARD', True) clipboard = Gtk.Clipboard.get(atom) clipboard.set_text(download_url, -1) clipboard.store()
def copy_image_data(image_file_path): from gi.repository import Gdk from gi.repository.GdkPixbuf import Pixbuf assert os.path.exists(image_file_path), "File does not exist: %s" % image_file_path image = Pixbuf.new_from_file(image_file_path) atom = Gdk.atom_intern("CLIPBOARD", True) clipboard = Gtk.Clipboard.get(atom) clipboard.set_image(image) clipboard.store() raise SystemExit()
def __init__(self, container, drag_type, target_flags=0, app_id=None): """Create a new DdType: drag_type: string holding the name of the type. target_flags: int value that will be passed to drop target. app_id: integer target id passed to drop target. """ self.drag_type = drag_type self.atom_drag_type = Gdk.atom_intern(drag_type, False) self.target_flags = target_flags self.app_id = app_id or self._calculate_id() container.insert(self)
def copy_image_data(image_file_path): from gi.repository import Gdk from gi.repository.GdkPixbuf import Pixbuf assert os.path.exists( image_file_path), "File does not exist: %s" % image_file_path image = Pixbuf.new_from_file(image_file_path) atom = Gdk.atom_intern("CLIPBOARD", True) clipboard = Gtk.Clipboard.get(atom) clipboard.set_image(image) clipboard.store() raise SystemExit()
def _cbViewerChainIn(self): """ Hook into clipboard. """ if self.gtkDefClipboard is not None: return if loadedGtkMajor < 3: self.gtkDefClipboard = gtk.clipboard_get() else: self.gtkDefClipboard = Gtk.Clipboard.get(Gdk.atom_intern('CLIPBOARD', True)) self.gtkConnHandle = self.gtkDefClipboard.connect("owner-change", lambda clp, evt: self.handleClipboardChange())
def _cbViewerChainIn(self): """ Hook into clipboard. """ if self.gtkDefClipboard is not None: return if wx.version() < "2.9": self.gtkDefClipboard = gtk.clipboard_get() else: self.gtkDefClipboard = Gtk.Clipboard.get( Gdk.atom_intern('CLIPBOARD', True)) self.gtkConnHandle = self.gtkDefClipboard.connect( "owner-change", lambda clp, evt: self.handleClipboardChange())
def drag_data_get_cb(self, widget, context, selection, target_type, time): """Gets the current color when a drop happens somewhere""" if "application/x-color" not in map(str, context.list_targets()): return False color = self.get_managed_color() data = gui.uicolor.to_drag_data(color) selection.set(Gdk.atom_intern("application/x-color", False), 16, data) logger.debug( "drag-data-get: sending type=%r", selection.get_data_type(), ) logger.debug("drag-data-get: sending fmt=%r", selection.get_format()) logger.debug("drag-data-get: sending data=%r len=%r", selection.get_data(), len(selection.get_data())) return True
def copy2clipboard(w, treeview, liststore): import platform path, col = treeview.get_cursor() if path: address = liststore.get_value( liststore.get_iter(path), 0) if platform.system() == 'Windows': from Tkinter import Tk r = Tk() r.withdraw() r.clipboard_clear() r.clipboard_append( address ) r.destroy() else: atom = Gdk.atom_intern('CLIPBOARD', True) c = Gtk.Clipboard.get(atom) c.set_text( address, len(address) )
def numera(self, widget): number = '' base = self.entry.get_text() base = base.replace('.', ',') if base.find(',') != -1: entero = base.split(',') if len(entero[1]) > 0: number = lee_numero(entero[0]) + ' con ' while(len(entero[1]) > 0 and entero[1][0] == '0'): ''' la cadena de decimales es la que había quitando el primer cero ya que ya fue anadido a la cadena number ''' entero[1] = (entero[1])[1:len(entero[1])] number = number + 'cero ' if len(entero[1]) > 0: if self.checkbox.get_active(): number = number + lee_numerof(entero[1]).lower() else: number = number + lee_numero(entero[1]).lower() else: if self.checkbox.get_active(): number = lee_numerof(entero[0]) else: number = lee_numero(entero[0]) else: if self.checkbox.get_active(): number = lee_numerof(self.entry.get_text()) else: number = lee_numero(self.entry.get_text()) number = fi2u(number) # atom = Gdk.atom_intern('CLIPBOARD', True) clipboard = self.textview.get_clipboard(atom) clipboard.set_text(number, -1) # ttbuffer = Gtk.TextBuffer() ttbuffer.set_text(number) self.textview.set_buffer(ttbuffer) self.textview.set_editable(False) self.textview.set_wrap_mode(Gtk.WrapMode.WORD) if number == '': self.entry.set_text('')
def zero_windows_allowed(self): return 0 def query_clipboard(self): return _gtk_clipboard.wait_is_text_available() def get_clipboard(self): return _gtk_clipboard.wait_for_text() def set_clipboard(self, data): _gtk_clipboard.set_text(data, len(data)) #------------------------------------------------------------------------------ CLIPBOARD = Gdk.atom_intern("CLIPBOARD", False) _gtk_clipboard = Gtk.Clipboard.get(CLIPBOARD) #------------------------------------------------------------------------------ def _call_with_excepthook(proc, breakout = None): # This function arranges for exceptions to be propagated # across calls to the Gtk event loop functions. exc_info = [] def excepthook(*args): exc_info[:] = args if breakout: breakout() old_excepthook = sys.excepthook try:
def _init_x_clipboard(self): """Initialize the desktop-wide, persistent clipboard.""" atom = Gdk.atom_intern("CLIPBOARD", True) self.x_clipboard = Gtk.Clipboard.get(atom) self.x_clipboard.set_can_store(None)
def test_atom_repr_str(self): atom = Gdk.atom_intern("", True) assert re.match(r"<Gdk.Atom\(\d+\)>", repr(atom)) assert re.match(r"Gdk.Atom<\d+>", str(atom))
def _on_copy_activate(self, *args): text_buffer = self.view.get_buffer() clipboard = Gtk.Clipboard.get(Gdk.atom_intern("CLIPBOARD", False)) text_buffer.copy_clipboard(clipboard)
def __init__(self): self.window = Gtk.Window() self.window.set_title('Clipboard demo') self.window.connect('destroy', lambda w: Gtk.main_quit()) vbox = Gtk.VBox(homogeneous=False, spacing=0) vbox.set_border_width(8) self.window.add(vbox) label = Gtk.Label(label='"Copy" will copy the text\nin the entry to the clipboard') vbox.pack_start(label, False, False, 0) hbox = Gtk.HBox(homogeneous=False, spacing=4) hbox.set_border_width(8) vbox.pack_start(hbox, False, False, 0) # create first entry entry = Gtk.Entry() hbox.pack_start(entry, True, True, 0) #FIXME: have the button constuctor take a stock_id # create button button = Gtk.Button.new_from_stock(Gtk.STOCK_COPY) hbox.pack_start(button, False, False, 0) button.connect('clicked', self.copy_button_clicked, entry) label = Gtk.Label(label='"Paste" will paste the text from the clipboard to the entry') vbox.pack_start(label, False, False, 0) hbox = Gtk.HBox(homogeneous=False, spacing=4) hbox.set_border_width(8) vbox.pack_start(hbox, False, False, 0) # create secondary entry entry = Gtk.Entry() hbox.pack_start(entry, True, True, 0) #FIXME: have the button constuctor take a stock_id # create button button = Gtk.Button.new_from_stock(Gtk.STOCK_PASTE) hbox.pack_start(button, False, False, 0) button.connect('clicked', self.paste_button_clicked, entry) label = Gtk.Label(label='Images can be transferred via the clipboard, too') vbox.pack_start(label, False, False, 0) hbox = Gtk.HBox(homogeneous=False, spacing=4) hbox.set_border_width(8) vbox.pack_start(hbox, False, False, 0) # create the first image image = Gtk.Image(stock=Gtk.STOCK_DIALOG_WARNING, icon_size=Gtk.IconSize.BUTTON) ebox = Gtk.EventBox() ebox.add(image) hbox.add(ebox) # make ebox a drag source ebox.drag_source_set(Gdk.ModifierType.BUTTON1_MASK, None, Gdk.DragAction.COPY) ebox.drag_source_add_image_targets() ebox.connect('drag-begin', self.drag_begin, image) ebox.connect('drag-data-get', self.drag_data_get, image) # accept drops on ebox ebox.drag_dest_set(Gtk.DestDefaults.ALL, None, Gdk.DragAction.COPY) ebox.drag_dest_add_image_targets() ebox.connect('drag-data-received', self.drag_data_received, image) # context menu on ebox ebox.connect('button-press-event', self.button_press, image) # create the second image image = Gtk.Image(stock=Gtk.STOCK_STOP, icon_size=Gtk.IconSize.BUTTON) ebox = Gtk.EventBox() ebox.add(image) hbox.add(ebox) # make ebox a drag source ebox.drag_source_set(Gdk.ModifierType.BUTTON1_MASK, None, Gdk.DragAction.COPY) ebox.drag_source_add_image_targets() ebox.connect('drag-begin', self.drag_begin, image) ebox.connect('drag-data-get', self.drag_data_get, image) # accept drops on ebox ebox.drag_dest_set(Gtk.DestDefaults.ALL, None, Gdk.DragAction.COPY) ebox.drag_dest_add_image_targets() ebox.connect('drag-data-received', self.drag_data_received, image) # context menu on ebox ebox.connect('button-press-event', self.button_press, image) # tell the clipboard manager to make data persistent #FIXME: Allow sending strings a Atoms and convert in PyGI atom = Gdk.atom_intern('CLIPBOARD', True) clipboard = Gtk.Clipboard.get(atom) clipboard.set_can_store(None) self.window.show_all()