Add animation to menu

master
En Yi 2018-07-10 14:48:42 +08:00
parent 5914f1f246
commit b16308bfe4
2 changed files with 17 additions and 7 deletions

View File

@ -43,10 +43,10 @@ class BoxBoard(QGraphicsWidget):
self.length = 0 self.length = 0
# Set up the length to be animated # Set up the length to be animated
self.anim = QPropertyAnimation(self, b'length') self.anim = QPropertyAnimation(self, b'length')
self.anim.setDuration(4000) # Animation speed self.anim.setDuration(800) # Animation speed
self.anim.setStartValue(0) self.anim.setStartValue(0)
for t in range(1, 10): for t in range(1, 10):
self.anim.setKeyValueAt(t / 10, t / 10) self.anim.setKeyValueAt(t / 10, self.half_circumference * t/10)
self.anim.setEndValue(self.half_circumference) self.anim.setEndValue(self.half_circumference)
self.freeze = False self.freeze = False
@ -99,14 +99,14 @@ class GameBoard(BoxBoard):
self.gamegrid = sdk_grap.SudokuGrid(self.width, self.height, parent=self) self.gamegrid = sdk_grap.SudokuGrid(self.width, self.height, parent=self)
self.numring = sdk_grap.NumberRing(parent=self) self.numring = sdk_grap.NumberRing(parent=self)
self.show_children(False) self.show_grid(False)
self.gamegrid.buttonClicked.connect(self.show_number_ring) self.gamegrid.buttonClicked.connect(self.show_number_ring)
self.numring.connect_button_signals(self.select_ring_number) self.numring.connect_button_signals(self.select_ring_number)
self.gamegrid.setFocus(Qt.MouseFocusReason) self.gamegrid.setFocus(Qt.MouseFocusReason)
self.anim.finished.connect(lambda: self.show_children(True)) self.anim.finished.connect(lambda: self.show_grid(True))
self.toggle_anim(True) self.toggle_anim(True)
def show_number_ring(self, x=0, y=0): def show_number_ring(self, x=0, y=0):
@ -147,10 +147,19 @@ class MenuBoard(BoxBoard):
self.layout.addItem(self.timer_display) self.layout.addItem(self.timer_display)
self.layout.setItemSpacing(0, 50) self.layout.setItemSpacing(0, 50)
self.layout.setItemSpacing(1, 0) self.layout.setItemSpacing(1, 0)
self.layout.setContentsMargins(20,15,20,15)
self.setLayout(self.layout) self.setLayout(self.layout)
self.show_children(False)
self.anim.finished.connect(lambda: self.show_children(True))
self.toggle_anim(True)
def show_difficulty(self, state): def show_difficulty(self, state):
print(state) print(state)
self.diff_display.selected = state self.diff_display.selected = state
self.diff_display.update() self.diff_display.update()
def show_children(self, state):
for chd in self.children():
chd.setVisible(state)

View File

@ -11,8 +11,8 @@ from . import buttons
class TimerDisplayer(QGraphicsWidget): class TimerDisplayer(QGraphicsWidget):
def __init__(self, parent=None): def __init__(self, parent=None):
super().__init__(parent) super().__init__()
self.setParent(parent)
self.width = 100 self.width = 100
self.height = 50 self.height = 50
@ -42,7 +42,8 @@ class DifficultyDisplayer(QGraphicsWidget):
notFocus = pyqtSignal() notFocus = pyqtSignal()
def __init__(self, parent=None): def __init__(self, parent=None):
super().__init__(parent) super().__init__()
self.setParent(parent)
self.width = 100 self.width = 100
self.height = 50 self.height = 50