0

I've been trying for a few days to make a function that copies certain informations about a selected item in a listbox. However, the primary clipboard of MobaXterm seems to be interfering with my clipboard append.

It works the first time I click on the button though.

def copy2clip():
    '''
    Dans MobaXterm, Settings -> Configuration -> X11 -> X11 Settings -> Clipboard -> "disable primary" 
    pour que ça fonctionne sur les serveurs de dev
    Problème : le clipboard primary de mobaxterm prend la priorité sur le clipboard_append de tkinter
    Solution : désactiver le clipboard primary de mobaxterm, ou ????
    '''
    
    centre = 54
    window.clipboard_clear()

    etiquette_produit = ""
    logging.info("Informations copiées dans le presse-papier")
    # logging.debug(window.winfo_width(), window.winfo_height())
    logging.debug(liste_finale)
    logging.debug(liste_apps)
    logging.debug(liste_sources)
    logging.debug(liste_interfaces)
    logging.debug(listbox.get(listbox.curselection()))
    
    liste_finale.reverse()

    string_prd = "Produit " + str(listbox.get(listbox.curselection()))
    etiquette_produit = "\n######################################################\n"
    etiquette_produit += string_prd.center(centre)
    etiquette_produit += "\n######################################################\n"
    etiquette_produit += "\nChemin : "

    for i in liste_finale:
        etiquette_produit += "\n" + str(i).center(centre) + "\n"
        if i != liste_finale[-1]:
            etiquette_produit += "↓".center(centre)
    
    etiquette_produit += "\nSous forme de liste :\n"
    etiquette_produit += "\n" + str(liste_finale).center(centre) + "\n"

    etiquette_produit += "\n######################################################\n"
    
    etiquette_produit += ("\nApplications : ").center(centre)
    etiquette_produit += "\n" + str(liste_apps) + "\n"

    etiquette_produit += "\nSources : ".center(centre)
    etiquette_produit += "\n" + str(liste_sources) + "\n"

    etiquette_produit += "\nInterfaces : ".center(centre)
    etiquette_produit += "\n" + str(liste_interfaces) + "\n"

    etiquette_produit += "\nÉléments introuvables : ".center(centre)
    etiquette_produit += "\n" + str(liste_inexistants) + "\n"
    
    etiquette_produit += "\n######################################################\n"
    
    logging.debug(etiquette_produit)
        
    window.clipboard_append(etiquette_produit, format="STRING")
        
    time.sleep(0.5)
    temp = window.clipboard_get()
    logging.debug(f"temp: {temp}")

This function is bound to a button using

bouton_copier = Button(frame_boutons, text="Copier dans le presse-papiers", command=copy2clip, height=2, state = DISABLED)

The result on the first selected item works fine and I get my "etiquette_produit" in the clipboard when clicking on the button.

However, after clicking on an other item, the only thing I get in my clipboard is the selected item name. I'm almost sure this is because of MobaXterm primary clipboard, but I would like to know if there is a way to disable that without having to disable the primary clipboard in MobaXterm.

I've tried going in MobaXterm Settings -> Configuration -> X11 -> and setting clipboard to disable primary, which works, but it's client side and I don't want every user to have to modify their settings.

Also tried using subprocess for the copy but it doesn't change anything.

If anyone has any idea, I'd gladly appreciate it.

Thanks, Nox

JRiggles
  • 4,847
  • 1
  • 12
  • 27
Noxeal
  • 1

0 Answers0