J'essaie désespérément de créer un menu qui s'adapte qui effectue une animation
Au clic sur le premier niveau (exemple A) il lance l'animation closeMenu et openMenu avec un nouveau Menu
Au clic sur le deuxième niveau (exemple A.a) il lance l'animation (pas encore crée mais l'esprit est là ^^) open mainFrame

Nom : test.jpg
Affichages : 771
Taille : 13,5 Ko

Ce que je n'arrive pas à faire :
- créer une animation tel que chaque boutons se cachent (ou apparaissent) de manière décalés
- changer le menu (passer de A à A.a et revenir à A si je clic sur back)

de l'aide serait bienvenu ^^

merci d'avance !

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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
 
# -*- coding: utf-8 -*-
 
from PyQt4 import QtCore, QtGui
from functools import partial
import sys
 
try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    def _fromUtf8(s):
        return s
 
try:
    _encoding = QtGui.QApplication.UnicodeUTF8
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig)
 
def MainMenu(text):
    if text == 'A':
        menu = ['back', 'A.a', 'A.b', 'A.c']
    elif text == 'B':
        menu = ['back', 'B.a', 'B.b']
    elif text == 'C':
        menu = ['back', 'C.a', 'C.b', 'C.c', 'C.d']
    else:
        menu = ['A', 'B', 'C']
    return menu
 
class Ui_Form(object):
    def setupUi(self, Form):
        Form.setObjectName(_fromUtf8("form"))
        Form.resize(760, 552)
        Form.setAutoFillBackground(False)
 
        self.menuFrame = QtGui.QFrame(Form)
        self.menuFrame.setGeometry(QtCore.QRect(0, 0, 161, 2000))
        self.menuFrame.setFrameShape(QtGui.QFrame.StyledPanel)
        self.menuFrame.setFrameShadow(QtGui.QFrame.Raised)
        self.menuFrame.setObjectName(_fromUtf8("menuFrame"))
 
        self.mainFrame = QtGui.QFrame(Form)
        self.mainFrame.setGeometry(QtCore.QRect(180, 20, 1700, 2000))
        self.mainFrame.setFrameShape(QtGui.QFrame.StyledPanel)
        self.mainFrame.setFrameShadow(QtGui.QFrame.Raised)
        self.mainFrame.setObjectName(_fromUtf8("mainFrame"))
 
        self = InitMenu(self.menuFrame, MainMenu(''))
 
        self.retranslateUi(Form)
        QtCore.QMetaObject.connectSlotsByName(Form)
 
    def retranslateUi(self, Form):
        pass
 
class InitMenu(object):
    height = 20
    pos = 50
    marg = 2
    xWidth = 143
 
    def __init__(self, frame, menuList):
        self.menuList = menuList
        if not not self.menuList:
            self.btn = []
            newPos = self.pos
            for i in range(len(menuList)):
                self.btn.append( ButtonMenu(newPos, self.height, menuList[i], self.xWidth, frame) )
                newPos = newPos + self.height + self.marg
        self.openMenu(frame)
 
    def openMenu(self, frame):
        newPos = self.pos
        for i in range(len(self.btn)):
			self.btn[i].showButton(newPos, self.height, self.xWidth)
			newPos = newPos + self.height + self.marg
 
    def closeMenu(self, frame):
        newPos = self.pos
        for i in range(len(self.btn)):
			self.btn[i].closeButton(newPos, self.height, self.xWidth)
			newPos = newPos + self.height + self.marg
 
    def retranslateUi(self, Form):
        pass
 
class ButtonMenu(QtGui.QPushButton):
 
    def __init__(self, pos, height, text, xWidth, obj):
        super(ButtonMenu, self).__init__(text, obj)
 
        self.string = text
        self.setGeometry(QtCore.QRect(5 - xWidth, pos, xWidth, height))
        self.setObjectName(_fromUtf8(text))
        self.clicked.connect(partial( DoStuff, text ))
 
    def showButton(self, pos, height, xWidth):
        self.animate = QtCore.QPropertyAnimation(self, "geometry")
        self.animate.setDuration(400)
        self.animate.setStartValue(QtCore.QRect( - xWidth, pos, xWidth, height))
        self.animate.setEndValue(QtCore.QRect(5, pos, xWidth, height))
        self.animate.start()
 
    def closeButton(self, pos, height, xWidth):
        self.animate = QtCore.QPropertyAnimation(self, "geometry")
        self.animate.setDuration(400)
        self.animate.setStartValue(QtCore.QRect(5, pos, xWidth, height))
        self.animate.setEndValue(QtCore.QRect( - xWidth, pos, xWidth, height))
        self.animate.start()
 
def DoStuff(printStr):
    print(printStr)
 
class Gui(QtGui.QDialog, Ui_Form):
 
    def __init__(self, parent = None):
        super(Gui, self).__init__(parent)
        self.setupUi(self)
 
    def main(self):
        self.show()
 
if __name__ == '__main__':
 
    app = QtGui.QApplication(sys.argv)
    useGui = Gui()
    useGui.main()
    sys.exit(app.exec_())