IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

GUI Python Discussion :

[Tix]Tree documentation [Python 2.X]


Sujet :

GUI Python

  1. #1
    Membre expérimenté
    Profil pro
    Développeur en systèmes embarqués retraité
    Inscrit en
    Mars 2006
    Messages
    946
    Détails du profil
    Informations personnelles :
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Développeur en systèmes embarqués retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2006
    Messages : 946
    Points : 1 351
    Points
    1 351
    Par défaut [Tix]Tree documentation
    Salut,

    Je suis en train de faire une gestion de vieux disques Atari et je bloque sur la partie graphique. J'ai beaucoup de mal avec la doc de Tix qui n'a rien à voir avec la doc de Tkinter qui est beaucoup plus compréhensible. J'aimerai pouvoir faire une multiselection de fichiers. On en sélectionne un en cliquant dessus, puis les suivants avec un Ctrl-click. Ensuite un click droit sur n'importe lequel des fichiers sélectionnés ouvrirait un menu popup où l'on pourrait sélectionner l'action: Copier vers le presse papier, renommer, effacer etc... Quelqu'un aurait une vague idée? Je pensais procéder avec la méthode "bind", mais clairement la doc me décourage.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
     
    import Tix as tix
     
    class TREE(object):
        def __init__(self, win, tree_data,sep=":"):
            self.win = win
            self.frm = tix.Frame(win)
            self.sep = sep
            tree = tix.Tree(win, browsecmd=self.selectItem, options='separator "%s"'%self.sep)
            tree.hlist.config(bg='white', selectbackground='white', selectforeground='black', selectmode="extended")
            tree.hlist.config(command=self.command)
            for dname, fnames in tree_data:
                disk_id = tree.hlist.add(dname, itemtype=tix.IMAGETEXT, image=tree.tk.call('tix', 'getimage', 'harddisk'), text=dname)
                tree.open(disk_id)
                for fname in fnames:
                    try:
                        tree.hlist.add(dname + self.sep + fname, itemtype=tix.IMAGETEXT, image=tree.tk.call('tix', 'getimage', 'file'), text=fname)
                    except Exception as (errmsg):
                        # Let's see that later
                        pass
            tree.pack()
            tree.autosetmode()
            tree.pack(expand=1, fill=tix.BOTH)
            self.frm.pack()
            self.tree = tree
     
        def selectItem(self, item):
            pass
            print "selectItem", item
     
        def command(self, item):
            print "command", item
     
    if __name__ == '__main__':
     
        tree_data = [('../disks/filedisk/Files01a', ['DOS.SYS', 'BOULDERD.ASH', 'NMPINBAL.L', 'STARFIGH.TER', 'AUTORUN.SYS', 'CAMBODIA']),
            ('../disks/filedisk/Files01b', ['ABRACADA.BRA', 'PREMONTY', 'ALLEYCAT', 'PHARAON']),
            ('../disks/filedisk/FILES02A', ['DOS.SYS', 'FLYING', 'UNKNOWN.COM', 'SPYBACK', 'BLUEMAX.XL', 'AUTORUN.SYS']),
            ('../disks/filedisk/FILES02B', ['FINALLEG.ACY', 'DOS.SYS', 'SHUTTLE', 'SPYHUNTE.R', 'UPNDOWN', 'KONG']),
            ('../disks/filedisk/FILES03A', ['DOS.SYS', 'ZENJI', 'DROPZONE', 'RIVERRAI.D', 'DEFENDER', 'AUTORUN.SYS']),
            ('../disks/filedisk/FILES03A.ATR', ['ZENJI', 'DROPZONE', 'RIVERRAI.D', 'DEFENDER', 'AUTORUN.SYS']),
            ('../disks/filedisk/FILES03B', ['DOS.SYS', 'AUTORUN.SYS', 'GYRUSS', 'FUNWITHA.RTS', 'LOSANGEL.ES']),
            ('../disks/filedisk/FILES04A', ['DOS.SYS', 'NEWQBERT.COM', 'FLIPFLOP.COM', 'RAINBOW.COM', 'JUICE.COM', 'AUTORUN.SYS', 'HERO']),
            ('../disks/filedisk/FILES04B', ['DOS.SYS', 'AZTEC', 'SHOWDOWN', 'SHAMUS2', 'AUTORUN.SYS']),
            ('../disks/filedisk/FILES07A', ['DOS.SYS', 'GHOSTCHA.SER', 'ARCHON.II', 'HARDHATM.AC', 'HIGHRISE'])]
     
        win = tix.Tk()
        tree = TREE(win, tree_data)
        win.geometry("260x400")
        win.mainloop()

  2. #2
    Membre expérimenté
    Profil pro
    Développeur en systèmes embarqués retraité
    Inscrit en
    Mars 2006
    Messages
    946
    Détails du profil
    Informations personnelles :
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Développeur en systèmes embarqués retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2006
    Messages : 946
    Points : 1 351
    Points
    1 351
    Par défaut
    Hello,

    J'ai réussi à résoudre une partie de mon problème, sélectionner plusieurs entrées de l'arbre grâce à un click suivi d'autres Ctrl-clicks... Mais je n'arrive toujours pas à binder sur un click droit, quelqu'un a une idée?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
     
    import Tix as tix
     
    class TREE(tix.Tree):
        SEP = "/"
        def __init__(self, win, tree_data):
            tix.Tree.__init__(self, win, browsecmd=self.selectItem, options='separator "%s"'%TREE.SEP)
            entries = []
            self.hlist.config(bg='white', selectbackground='blue', selectforeground='white', selectmode="extended")
            for dname, fnames in tree_data:
                folders = dname.split(TREE.SEP)
                size = len(folders)
                current_dir = None
                for x in range(size - 1):
                    if current_dir == None:
                        current_dir = folders[0]
                    else:
                        current_dir += TREE.SEP + folders[x]
                    if not current_dir in entries:
                        self.hlist.add(current_dir, itemtype=tix.IMAGETEXT, image=self.tk.call('tix', 'getimage', 'folder'), text=folders[x])
                        entries.append(current_dir)
                current_dir += TREE.SEP + folders[size-1]
                assert dname == self.hlist.add(current_dir, itemtype=tix.IMAGETEXT, image=self.tk.call('tix', 'getimage', 'harddisk'), text=folders[size-1])
                entries.append(current_dir)
                self.close(current_dir)
     
                for fname in fnames:
                    _id = dname + TREE.SEP + fname
                    if not _id in entries:
                        assert _id == self.hlist.add(dname + TREE.SEP + fname, itemtype=tix.IMAGETEXT, image=self.tk.call('tix', 'getimage', 'file'), text=fname)
                        entries.append(_id)
                    else:
                        pass
            self.autosetmode()
            self.__entries = entries
     
        def selectItem(self, *args):
            pass
     
        def getSelectedItems(self, *args):
            print self.hlist.info_selection()
     
    if __name__ == '__main__':
     
        tree_data = [
            ('../disks/filedisk/Files01a', ['DOS.SYS', 'BOULDERD.ASH', 'NMPINBAL.L', 'STARFIGH.TER', 'AUTORUN.SYS', 'CAMBODIA']),
            ('../disks/filedisk/Files01b', ['ABRACADA.BRA', 'PREMONTY', 'ALLEYCAT', 'PHARAON']),
            ('../disks/filedisk/FILES02A', ['DOS.SYS', 'FLYING', 'UNKNOWN.COM', 'SPYBACK', 'BLUEMAX.XL', 'AUTORUN.SYS']),
            ('../disks/filedisk/FILES02B', ['FINALLEG.ACY', 'DOS.SYS', 'SHUTTLE', 'SPYHUNTE.R', 'UPNDOWN', 'KONG']),
            ('../disks/filedisk/FILES03A', ['DOS.SYS', 'ZENJI', 'DROPZONE', 'RIVERRAI.D', 'DEFENDER', 'AUTORUN.SYS']),
            ('../disks/filedisk/FILES03A.ATR', ['ZENJI', 'DROPZONE', 'RIVERRAI.D', 'DEFENDER', 'AUTORUN.SYS']),
            ('../disks/filedisk/FILES03B', ['DOS.SYS', 'AUTORUN.SYS', 'GYRUSS', 'FUNWITHA.RTS', 'LOSANGEL.ES']),
            ('../disks/filedisk/FILES04A', ['DOS.SYS', 'NEWQBERT.COM', 'FLIPFLOP.COM', 'RAINBOW.COM', 'JUICE.COM', 'AUTORUN.SYS', 'HERO']),
            ('../disks/filedisk/FILES04B', ['DOS.SYS', 'AZTEC', 'SHOWDOWN', 'SHAMUS2', 'AUTORUN.SYS']),
            ('../disks/filedisk/FILES07A', ['DOS.SYS', 'GHOSTCHA.SER', 'ARCHON.II', 'HARDHATM.AC', 'HIGHRISE'])]
     
        win = tix.Tk()
        tree = TREE(win, tree_data)
        tree.pack(expand=1, fill=tix.BOTH)
        tix.Button(win, text="CLIPBOARD", command=tree.getSelectedItems).pack()
        win.geometry("260x400")
        win.mainloop()

  3. #3
    Membre expérimenté
    Profil pro
    Développeur en systèmes embarqués retraité
    Inscrit en
    Mars 2006
    Messages
    946
    Détails du profil
    Informations personnelles :
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Développeur en systèmes embarqués retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2006
    Messages : 946
    Points : 1 351
    Points
    1 351
    Par défaut
    Bon, c'est résolu, merci pour votre aide.

    A+

    Pfeuh

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
     
    import Tix as tix
     
    class TREE(tix.Tree):
        SEP = "/"
        def __init__(self, win, tree_data):
            tix.Tree.__init__(self, win, browsecmd=self.selectItem, options='separator "%s"'%TREE.SEP)
            entries = []
            self.hlist.config(bg='white', selectbackground='blue', selectforeground='white', selectmode="extended")
            for dname, fnames in tree_data:
                folders = dname.split(TREE.SEP)
                size = len(folders)
                current_dir = None
                for x in range(size - 1):
                    if current_dir == None:
                        current_dir = folders[0]
                    else:
                        current_dir += TREE.SEP + folders[x]
                    if not current_dir in entries:
                        self.hlist.add(current_dir, itemtype=tix.IMAGETEXT, image=self.tk.call('tix', 'getimage', 'folder'), text=folders[x])
                        entries.append(current_dir)
                current_dir += TREE.SEP + folders[size-1]
                assert dname == self.hlist.add(current_dir, itemtype=tix.IMAGETEXT, image=self.tk.call('tix', 'getimage', 'harddisk'), text=folders[size-1])
                entries.append(current_dir)
                self.close(current_dir)
     
                for fname in fnames:
                    _id = dname + TREE.SEP + fname
                    if not _id in entries:
                        assert _id == self.hlist.add(dname + TREE.SEP + fname, itemtype=tix.IMAGETEXT, image=self.tk.call('tix', 'getimage', 'file'), text=fname)
                        entries.append(_id)
                    else:
                        pass
     
            self.autosetmode()
            self.hlist.bind("<ButtonRelease-3>", self.getSelectedItems)
     
        def selectItem(self, *args):
            pass
     
        def getSelectedItems(self, *args):
            print self.hlist.info_selection()
     
    if __name__ == '__main__':
     
        tree_data = [
            ('../disks/filedisk/Files01a', ['DOS.SYS', 'BOULDERD.ASH', 'NMPINBAL.L', 'STARFIGH.TER', 'AUTORUN.SYS', 'CAMBODIA']),
            ('../disks/filedisk/Files01b', ['ABRACADA.BRA', 'PREMONTY', 'ALLEYCAT', 'PHARAON']),
            ('../disks/filedisk/FILES02A', ['DOS.SYS', 'FLYING', 'UNKNOWN.COM', 'SPYBACK', 'BLUEMAX.XL', 'AUTORUN.SYS']),
            ('../disks/filedisk/FILES02B', ['FINALLEG.ACY', 'DOS.SYS', 'SHUTTLE', 'SPYHUNTE.R', 'UPNDOWN', 'KONG']),
            ('../disks/filedisk/FILES03A', ['DOS.SYS', 'ZENJI', 'DROPZONE', 'RIVERRAI.D', 'DEFENDER', 'AUTORUN.SYS']),
            ('../disks/filedisk/FILES03A.ATR', ['ZENJI', 'DROPZONE', 'RIVERRAI.D', 'DEFENDER', 'AUTORUN.SYS']),
            ('../disks/filedisk/FILES03B', ['DOS.SYS', 'AUTORUN.SYS', 'GYRUSS', 'FUNWITHA.RTS', 'LOSANGEL.ES']),
            ('../disks/filedisk/FILES04A', ['DOS.SYS', 'NEWQBERT.COM', 'FLIPFLOP.COM', 'RAINBOW.COM', 'JUICE.COM', 'AUTORUN.SYS', 'HERO']),
            ('../disks/filedisk/FILES04B', ['DOS.SYS', 'AZTEC', 'SHOWDOWN', 'SHAMUS2', 'AUTORUN.SYS']),
            ('../disks/filedisk/FILES07A', ['DOS.SYS', 'GHOSTCHA.SER', 'ARCHON.II', 'HARDHATM.AC', 'HIGHRISE'])]
     
        win = tix.Tk()
        win.title("TITLE")
        tree = TREE(win, tree_data)
        tree.pack(expand=1, fill=tix.BOTH)
        frm = tix.Frame(win)
        frm.pack()
        win.geometry("260x400")
        win.mainloop()

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 4
    Dernier message: 02/08/2010, 14h49
  2. Documentation gratuite sur l'API Windows, COM, DCOM, OLE, etc.
    Par Community Management dans le forum Windows
    Réponses: 1
    Dernier message: 16/11/2006, 15h28
  3. pb formatage document XML généré par un dom tree
    Par lionel69 dans le forum APIs
    Réponses: 11
    Dernier message: 17/10/2002, 09h53
  4. Bibliothèques et documentation
    Par Anonymous dans le forum OpenGL
    Réponses: 4
    Dernier message: 01/04/2002, 12h24
  5. Recherche de documentation complète en algorithmes
    Par Anonymous dans le forum Algorithmes et structures de données
    Réponses: 1
    Dernier message: 29/03/2002, 12h09

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo