Last active
May 8, 2021 02:59
-
-
Save Guitlle/3fb29179a61516200cf390d2cba47afe to your computer and use it in GitHub Desktop.
Copiar cada item de una lista de textos al portapapeles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Para utilizar se puede correr este comando, luego se pega la lista de textos y | |
# luego se presiona ctrl+d para terminar de ingresar la lista y correr el programa | |
# El programa abre una ventana con un botón. Cada vez que se presiona ese botón | |
# se copia en el portapapeles o clipboard el próximo texto de la lista | |
# | |
# cat | python3 copylista.py | |
# >linea1 | |
# >linea2 | |
# >CTRL+D | |
import gi | |
import os | |
import sys | |
gi.require_version("Gtk", "3.0") | |
from gi.repository import Gtk | |
copies = [] | |
for line in sys.stdin: | |
copies.append(line.strip()) | |
print("La lista: ",copies) | |
class MyWindow(Gtk.Window): | |
def __init__(self): | |
Gtk.Window.__init__(self, title="Copypaste cola") | |
self.button = Gtk.Button(label="Próximo") | |
self.button.connect("clicked", self.on_button_clicked) | |
self.add(self.button) | |
self.i = 0 | |
def on_button_clicked(self, widget): | |
print("clicked") | |
if self.i >= len(copies)-1: | |
print("quit") | |
Gtk.main_quit() | |
nextcopy = copies[self.i] | |
print("copy", nextcopy) | |
os.system("echo \"" + nextcopy + "\" | xclip -selection c") | |
self.i+=1 | |
win = MyWindow() | |
win.connect("destroy", Gtk.main_quit) | |
win.show_all() | |
Gtk.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment