Initial commit (Vesion 0.1)
[tablet-suite] / src / backup / pcsprogressdialog.py
1 # Authors: Amaury Medeiros, Nicholas Alexander and Paulo Ouriques
2 # Software License: GPL
3
4 from PyQt4.QtCore import *
5 from PyQt4.QtGui import *
6
7 from style.styleTabletSuite import *
8 from ui.pcsuiutils import *
9
10 class PcsProgressDialog(QDialog):
11        
12     def __init__(self, parent = None):
13         QDialog.__init__(self, parent, Qt.FramelessWindowHint)
14         self.cancelButton = QPushButton("Cancel")
15         self.doneButton = QPushButton("Done")
16         self.connect(self.doneButton, SIGNAL("clicked()"), self.close)
17         self.actionLabel = QLabel("Action...")
18         self.categoryLabel = QLabel("")  
19         self.progressReport = QLabel("") 
20         self.setLayout(self._insertLayout())
21         
22         
23     def setAction(self, action):
24         self.action = action
25         if action == "copy":
26             message = "Copying..."
27             
28         elif action == "restore":
29             message = "Restoring..."
30         
31         self.categoryLabel.setText("<font style='color:"\
32                                        "#333333'; size=2>"\
33                                        +str(action).capitalize()+
34                                        " in progress...</font>")
35         
36         self.actionLabel.setText('''<font style=color:
37                                 black; size=3>
38                                 '''+ message +'''</font>''')
39     
40     def _insertLayout(self):
41         vLay = QVBoxLayout()
42         vLay.addWidget(self.actionLabel)
43         vLay.addLayout(self._createCenterLayout())
44         return vLay
45     
46     def _createCenterLayout(self):
47         
48         bgLabel = QLabel()
49         bgLabel.setPixmap(QPixmap(PROGRESS_BAR_DIALOG_BG))
50         grid = QGridLayout()
51         
52         self.progressBar = QProgressBar()
53         self.progressBar.setObjectName("progressBarDialog")
54         self.progressBar.setValue(0)
55         self.progressBar.setTextVisible(False)
56         
57         grid.addWidget(bgLabel, 0, 0, Qt.AlignCenter)
58         grid.addWidget(self.progressBar, 0, 0, Qt.AlignCenter)
59
60         self.cancelButton.setStyleSheet(DEFAULT_BUTTON_STYLE)
61         self.cancelButton.setShortcut(Qt.Key_Return)
62         self.doneButton.setVisible(False)
63         self.doneButton.setStyleSheet(DEFAULT_BUTTON_STYLE)
64         
65         gridLayout = QGridLayout()
66         gridLayout.setSpacing(3)
67         gridLayout.addWidget(self.categoryLabel, 0, 0, Qt.AlignRight)
68         gridLayout.addLayout(grid, 1, 0)
69         gridLayout.addWidget(self.progressReport, 2, 0, Qt.AlignRight)
70         gridLayout.addWidget(self.cancelButton, 3, 0, Qt.AlignRight)
71         gridLayout.addWidget(self.doneButton, 3, 0, Qt.AlignRight)
72         
73         return gridLayout
74     
75     def progressCanceled(self):
76         self.progressDone(True)
77     
78     def progressDone(self, cancel=False):
79         self.cancelButton.setVisible(False)
80         self.doneButton.setVisible(True)
81         
82         self.categoryLabel.setText("<font style='color:"\
83                                    "#333333'; size=2>"+\
84                                     str(self.action).capitalize()
85                                     +" finished.</font>")
86         if not cancel:
87             totalSize =  "%.2f" % (self.totalSize/(1024.0**2))
88         
89             self.progressReport.setText("<font style='color:"\
90                                         "#333333'; size=2>"\
91                                         + str(self.numberOfFiles) +\
92                                         " Files - " + totalSize + " MB</font>")
93         else:
94             self.progressReport.setText("<font style='color:"\
95                                         "#333333'; size=2> Canceled")
96             self.categoryLabel.setText("")
97             self.progressBar.setValue(100)
98             
99     def updateInfo(self, totalSize, numberOfFiles):
100         self.totalSize = totalSize
101         self.numberOfFiles = numberOfFiles
102     
103     def setProgress(self, progress):
104         self.progressBar.setValue(float(progress))
105         
106         self.progressReport.setText("<font style='color:"\
107                                     "#333333'; size=2>"\
108                                     + progress +\
109                                     "% Complete</font>")  
110         
111     def setCategory(self, catogory):
112         self.categoryLabel.setText("<font style='color:"\
113                                    "#333333'; size=2> Category name: "\
114                                    + catogory +"</font>")
115     
116     
117