-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainUI.py
192 lines (150 loc) · 7.59 KB
/
MainUI.py
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
from PyQt4 import QtGui, QtCore, QtWebKit
from Menu import Menu
from ClickedQLabel import DoubleClickedQLabel
from DeezerIcon import DeezerIcon
from Search import Search
__author__ = 'postrowski'
# -*-coding: utf-8-*-
class MainUI(QtGui.QMainWindow, DeezerIcon):
def __init__(self, parent=None):
super(MainUI, self).__init__(parent)
self.searchButton = QtGui.QPushButton()
self.playButton = QtGui.QPushButton()
self.showButton = QtGui.QPushButton()
self.hideButton = QtGui.QPushButton()
self.pageButton = QtGui.QPushButton()
self.iconLabel = DoubleClickedQLabel(self)
self.searchLabel = QtGui.QLabel()
self.albumLabel = QtGui.QLabel()
self.artistLabel = QtGui.QLabel()
self.songLabel = QtGui.QLabel()
self.songList = QtGui.QListWidget()
self.artistList = QtGui.QListWidget()
self.albumList = QtGui.QListWidget()
self.searchEdit = QtGui.QLineEdit()
self.timer = QtCore.QTimer()
self.hLine = QtGui.QFrame()
self.classicWebView = QtWebKit.QWebView()
self.coverWebView = QtWebKit.QWebView()
self.setup_ui()
Menu(self)
self.search = Search(self)
# ------------------------------------------------------------
# deezer button timer on hover and on double click
self.timer.timeout.connect(self.hover_button)
self.iconLabel.signalDoubleClick.connect(self.click_button)
# hide and show player (Bottom panel) on button single click
self.hideButton.clicked.connect(self.search.hide_button_clicked)
self.showButton.clicked.connect(self.search.show_button_clicked)
# play album on button single click and press Enter
self.playButton.clicked.connect(self.search.play_album)
self.playButton.pressed.connect(self.search.play_album)
# find artist names on button single click and on item press Enter
self.searchButton.clicked.connect(self.search.run_artist_thread)
self.searchEdit.returnPressed.connect(self.search.run_artist_thread)
# find album titles on item single click and on item press Enter
self.artistList.itemClicked.connect(self.search.run_album_thread)
self.artistList.itemActivated.connect(self.search.run_album_thread)
# find song titles and show album cover on item single click and on item press Enter
self.albumList.itemClicked.connect(self.search.run_song_thread)
self.albumList.itemActivated.connect(self.search.run_song_thread)
self.coverWebView.loadFinished.connect(self.search.cover_loaded)
# go to album page on deezer.com on single click and press Enter
self.pageButton.clicked.connect(self.search.listen_on)
self.pageButton.pressed.connect(self.search.listen_on)
def setup_ui(self):
"""
Setup widgets.
"""
self.central_widget = QtGui.QWidget()
self.setCentralWidget(self.central_widget)
# button
self.searchButton.setText("Search")
self.searchButton.setAutoDefault(True) # button focus
self.playButton.setText("Play album")
self.playButton.setAutoDefault(True) # button focus
self.hideButton.hide()
self.hideButton.setText("hide")
self.hideButton.setAutoDefault(True) # button focus
self.showButton.hide()
self.showButton.setText("show")
self.showButton.setAutoDefault(True) # button focus
self.pageButton.hide()
self.pageButton.setText("listen")
self.pageButton.setToolTip("Listen album on deezer.com")
self.pageButton.setAutoDefault(True) # button focus
# label
self.iconLabel.setToolTip("deezer.com")
pixmap = QtGui.QPixmap("icon.svg")
self.iconLabel.setPixmap(pixmap)
self.iconLabel.setAlignment(QtCore.Qt.AlignRight)
self.searchLabel.setText("Search")
self.artistLabel.setText("Artist")
self.albumLabel.setText("Album")
self.songLabel.setText("Song")
# list
self.artistList.setMinimumHeight(300)
self.artistList.setToolTip("Choose the artist")
self.albumList.setMinimumHeight(300)
self.albumList.setToolTip("Choose the album")
self.songList.setMinimumHeight(300)
self.songList.setToolTip("Choose the song")
# --
self.searchEdit.setMinimumWidth(250)
self.searchEdit.setToolTip("Enter artist name, and press Enter")
self.timer.start(10) # timer initial state
self.hLine.setFrameShape(QtGui.QFrame.HLine)
self.hLine.setFrameShadow(QtGui.QFrame.Sunken)
# web view
self.classicWebView.hide()
self.classicWebView.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed)
self.classicWebView.settings().setAttribute(QtWebKit.QWebSettings.PluginsEnabled, True)
self.classicWebView.settings().setMaximumPagesInCache(0)
self.coverWebView.setFixedSize(300, 300)
self.coverWebView.settings().setMaximumPagesInCache(0)
# window geometry
self.setGeometry(300, 100, 1200, 400)
self.setSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Expanding)
self.setWindowTitle("10heures player")
self.setWindowIcon(QtGui.QIcon("images/icon.svg"))
# grid layout
sub_layout_1 = QtGui.QGridLayout()
sub_layout_1.setSpacing(5)
sub_layout_1.addWidget(self.searchLabel, 1, 1, 1, 1, QtCore.Qt.AlignLeft)
sub_layout_1.addWidget(self.searchEdit, 1, 2, 1, 1, QtCore.Qt.AlignLeft)
sub_layout_1.addWidget(self.searchButton, 1, 3, 1, 1, QtCore.Qt.AlignLeft)
sub_layout_1.addWidget(self.playButton, 1, 4, 1, 1, QtCore.Qt.AlignLeft)
self.sub_layout_2 = QtGui.QGridLayout()
self.sub_layout_2.setSpacing(5)
self.sub_layout_2.addWidget(self.hLine, 1, 1, 1, 4)
self.sub_layout_2.addWidget(self.artistLabel, 2, 1, 1, 1)
self.sub_layout_2.addWidget(self.albumLabel, 2, 2, 1, 1)
self.sub_layout_2.addWidget(self.songLabel, 2, 3, 1, 1)
self.sub_layout_2.addWidget(self.artistList, 3, 1, 1, 1)
self.sub_layout_2.addWidget(self.albumList, 3, 2, 1, 1)
self.sub_layout_2.addWidget(self.songList, 3, 3, 1, 1)
self.sub_layout_2.addWidget(self.coverWebView, 3, 4, 1, 1)
sub_layout_3 = QtGui.QGridLayout()
sub_layout_3.setSpacing(5)
sub_layout_3.addWidget(self.classicWebView, 4, 1, 1, 1)
sub_layout_4 = QtGui.QGridLayout()
sub_layout_4.setSpacing(5)
sub_layout_4.addWidget(self.hideButton, 5, 1, 1, 1, QtCore.Qt.AlignLeft)
sub_layout_4.addWidget(self.showButton, 5, 1, 1, 1, QtCore.Qt.AlignLeft)
sub_layout_4.addWidget(self.pageButton, 5, 2, 1, 1, QtCore.Qt.AlignLeft)
grid = QtGui.QGridLayout()
grid.addWidget(self.iconLabel, 1, 1, 1, 1, QtCore.Qt.AlignRight)
grid.addLayout(sub_layout_1, 1, 1, 1, 1, QtCore.Qt.AlignLeft)
grid.addLayout(self.sub_layout_2, 2, 1, 1, 1)
grid.addLayout(sub_layout_3, 3, 1, 1, 1)
grid.addLayout(sub_layout_4, 4, 1, 1, 1, QtCore.Qt.AlignLeft)
self.central_widget.setLayout(grid)
# tab order
self.setTabOrder(self.searchEdit, self.searchButton)
self.setTabOrder(self.searchButton, self.artistList)
self.setTabOrder(self.artistList, self.albumList)
self.setTabOrder(self.albumList, self.songList)
self.setTabOrder(self.songList, self.showButton)
self.setTabOrder(self.showButton, self.hideButton)
self.setTabOrder(self.hideButton, self.pageButton)
self.setTabOrder(self.pageButton, self.playButton)