1 # Authors: Amaury Medeiros and Paulo Ouriques
2 # Software License: GPL
4 from PyQt4.QtCore import *
5 from PyQt4.QtGui import *
7 from ui.pcsuiutils import *
8 from pcsbackupmanagerui import *
9 from pcsrestorebackupui import *
10 from style.styleTabletSuite import *
13 class PcsProgressWizard(QWizardPage):
15 def __init__(self, deviceInfo, wizard, windowManager, parent = None):
16 QWizardPage.__init__(self, parent)
17 self.windowManager = windowManager
18 self.deviceInfo = deviceInfo
20 self.layout = QVBoxLayout()
21 self.layout.setMargin(0)
22 self.cancelButton = QPushButton("Cancel")
23 self.doneButton = QPushButton("Done")
24 self.completeReportButton = QPushButton("View Complete Report")
25 self.lockMenuButtons = True
28 def _insertLayout(self, name = ""):
29 self.vLayout = QVBoxLayout()
30 self.vLayout.setMargin(0)
31 self.wayLayout = self._wayLayout(name)
32 buttonLayout = self._menuButtons()
33 spc = QSpacerItem(0, 3)
34 self.vLayout.addLayout(buttonLayout, Qt.AlignTop)
35 self.vLayout.addItem(spc)
36 self.vLayout.addLayout(self.wayLayout, Qt.AlignLeft)
37 spc = QSpacerItem(0, 68)
38 self.vLayout.addItem(spc)
39 self.vLayout.addLayout(self._createCenterLayout(), Qt.AlignVCenter)
40 self.vLayout.addItem(spc)
41 self.vLayout.addLayout(self._createInformationsLabel(), Qt.AlignVCenter)
42 self.setLayout(self.vLayout)
44 def _menuButtons(self):
45 infList = [("New Backup", SMALL_ICON_NEW_BACKUP_STYLE_SELECTED),
46 ("Manager Backup", SMALL_ICON_MANAGER_BACKUP_STYLE, self._manageDialog),
47 ("Restore Backup", SMALL_ICON_RESTORE_BACKUP_STYLE, self._restoreDialog)]
48 buttonsLayout = QHBoxLayout()
49 buttonsLayout.setMargin(0)
51 but = QPushButton(infList[i][0])
52 but.setStyleSheet(infList[i][1])
54 buttonsLayout.addWidget(but, Qt.AlignLeft)
55 self.connect(but, SIGNAL("clicked()"), infList[i][2])
57 buttonsLayout.addWidget(but)
60 def _wayLayout(self, name = ""):
61 self.barLayout = QHBoxLayout()
62 self.barLayout.setMargin(0)
63 main = QLabel("<font style='color: #333333'; size=2>Main</font>")
64 arrow1 = self._arrow()
65 arrow2 = self._arrow()
66 arrow3 = self._arrow()
67 arrow4 = self._arrow()
68 spc = QSpacerItem(2, 0)
69 newBackup = QLabel("<font style='color: #333333'; size=2> New Backup</font>")
70 files = QLabel("<font style='color: #333333'; size=2>Files</font>")
71 folder = QLabel("<font style='color: #333333'; size=2>Folder</font>")
73 loading = QLabel("<font style='color: #333333'; size=2>loading</font>")
75 loading = QLabel("<font style='color: #FFFFFF'; size=2>loading</font>")
76 widgetList = [main, self._arrow(), newBackup, self._arrow(), files,
77 self._arrow(), folder, self._arrow(), loading]
78 for widget in widgetList:
79 self.barLayout.addWidget(widget, Qt.AlignLeft)
80 self.barLayout.addItem(spc)
82 newLabel = QLabel("<font style='color: #FFFFFF'; size=2>"+ name +"</font>")
83 self.barLayout.addWidget(self._arrow(), Qt.AlignLeft)
84 self.barLayout.addItem(spc)
85 self.barLayout.addWidget(newLabel, Qt.AlignLeft)
86 self.barLayout.addItem(spc)
88 self.barLayout.addItem(QSpacerItem(300, 0))
91 def _manageDialog(self):
92 if self.lockMenuButtons == False:
93 if(self.deviceInfo and self.deviceInfo.ip != None):
94 backupManager = self.windowManager.getBackupManager()
95 centralize(backupManager)
96 backupManager.setGeometry(self.wizard.geometry())
100 self.lockMenuButtons = True
103 self._showNoDeviceFoundMessage()
105 def _restoreDialog(self):
106 if self.lockMenuButtons == False:
107 if(self.deviceInfo and self.deviceInfo.ip != None):
108 restoreBackup = self.windowManager.getRestoreBackup()
109 centralize(restoreBackup)
110 restoreBackup.setGeometry(self.wizard.geometry())
114 self.lockMenuButtons = True
117 self._showNoDeviceFoundMessage()
119 def _showNoDeviceFoundMessage(self):
120 inf = QMessageBox(self)
121 inf.setWindowTitle("Connect a device.")
122 inf.setText("No devices were found.")
127 label.setPixmap(QPixmap(BLACK_ARROW))
130 def _createInformationsLabel(self):
132 spc = QSpacerItem(10, 0)
133 self.infLabel = QLabel("<font style='color:"\
135 "Do backup from Device to your PC.</font>")
137 iconAlert.setPixmap(QPixmap(ICON_ALERT))
139 hLay.addWidget(iconAlert)
140 hLay.addWidget(self.infLabel, Qt.AlignLeft)
144 def _resetPage(self):
145 self.lockMenuButtons = True
146 self.cancelButton.setVisible(True)
147 self.doneButton.setVisible(False)
148 self.progressBar.setValue(0)
149 self.progressReport.setText("")
150 self.categoryLabel.setText("<font style='color:"\
152 "Backup starting...</font>")
154 def _createCenterLayout(self):
155 gridLayout = QGridLayout()
156 gridLayout.setMargin(27)
158 self.categoryLabel = QLabel("<font style='color:"\
160 "Backup starting...</font>")
163 bgLabel.setPixmap(QPixmap(PROGRESS_BAR_BG))
166 self.progressBar = QProgressBar()
167 self.progressBar.setObjectName("progressBarWizard")
168 self.progressBar.setValue(0)
169 self.progressBar.setTextVisible(False)
171 grid.addWidget(bgLabel, 0, 0, Qt.AlignCenter)
172 grid.addWidget(self.progressBar, 0, 0, Qt.AlignCenter)
174 self.progressReport = QLabel("")
176 self.cancelButton.setStyleSheet(DEFAULT_BUTTON_STYLE)
177 self.cancelButton.setShortcut(Qt.Key_Return)
178 self.doneButton.setVisible(False)
179 self.doneButton.setStyleSheet(DEFAULT_BUTTON_STYLE)
180 # self.completeReportButton.setStyleSheet()
182 gridLayout.setSpacing(3)
183 gridLayout.addWidget(self.categoryLabel, 0, 0, Qt.AlignRight)
184 gridLayout.addLayout(grid, 1, 0)
185 gridLayout.addWidget(self.progressReport, 2, 0, Qt.AlignRight)
186 gridLayout.addWidget(self.cancelButton, 3, 0, Qt.AlignRight)
187 gridLayout.addWidget(self.doneButton, 3, 0, Qt.AlignRight)
191 def progressCanceled(self):
192 self.progressDone(True)
194 def progressDone(self, cancel=False):
195 self.lockMenuButtons = False
196 self.cancelButton.setVisible(False)
197 self.doneButton.setVisible(True)
199 self.categoryLabel.setText("<font style='color:"\
201 "Backup finished.</font>")
203 totalSize = "%.2f" % (self.totalSize/(1024.0**2))
205 self.progressReport.setText("<font style='color:"\
207 + str(self.backedUpNumber) +\
208 " Files - " + totalSize + " MB</font>")
210 self.progressReport.setText("<font style='color:"\
211 "#333333'; size=2> Canceled")
212 self.categoryLabel.setText("")
213 self.progressBar.setValue(100)
216 self.infLabel.setText("<font style='color:"\
218 "Select an action</font>")
220 def updateInfo(self, totalSize, backedUpNumber):
221 self.totalSize = totalSize
222 self.backedUpNumber = backedUpNumber
224 def setProgress(self, progress):
225 self.progressBar.setValue(progress)
227 self.progressReport.setText("<font style='color:"\
229 + str(int(progress))+\
232 def setCategory(self, category):
233 self.categoryLabel.setText("<font style='color:"\
234 "#333333'; size=2> Category name: "\
235 + category +"</font>")