make renew a self-contained dialog
authorsmbaker <smbaker@fc8clean.lan>
Tue, 6 Sep 2011 10:34:22 +0000 (03:34 -0700)
committersmbaker <smbaker@fc8clean.lan>
Tue, 6 Sep 2011 10:34:22 +0000 (03:34 -0700)
sface/screens/mainscreen.py
sface/sfirenew.py

index e6e4fb4..f169915 100644 (file)
@@ -7,7 +7,7 @@ from PyQt4.QtGui import *
 #from sfa.util.rspecHelper import RSpec
 from sfa.rspecs.rspec_parser import parse_rspec
 from sface.config import config
-from sface.sfirenew import SfiRenewer
+from sface.sfirenew import RenewWindow
 from sface.sfiprocess import SfiProcess
 from sface.screens.sfascreen import SfaScreen
 
@@ -461,19 +461,7 @@ class SliceWidget(QWidget):
 
     def renew(self):
         dlg = RenewWindow(parent=self)
-        if (dlg.exec_() == QDialog.Accepted):
-            self.setStatus("Renewing Slice.")
-
-            self.renewProcess = SfiRenewer(config.getSlice(), dlg.get_new_expiration(), self)
-            self.connect(self.renewProcess, SIGNAL('finished()'), self.renewFinished)
-
-    def renewFinished(self):
-        if self.renewProcess.statusMsg:
-            self.setStatus("Renew " + self.renewProcess.status + ": " + self.renewProcess.statusMsg)
-        else:
-            self.setStatus("Renew " + self.renewProcess.status)
-        self.disconnect(self.renewProcess, SIGNAL('finished()'), self.renewFinished)
-        self.renewProcess = None
+        dlg.exec_()
 
     def refresh(self):
         if not config.getSlice():
@@ -571,44 +559,6 @@ class SliceWidget(QWidget):
     def nodeSelectionChanged(self, hostname):
         self.parent().nodeSelectionChanged(hostname)
 
-class RenewWindow(QDialog):
-    def __init__(self, parent=None):
-        super(RenewWindow, self).__init__(parent)
-        self.setWindowTitle("Renew Slivers")
-
-        self.duration = QComboBox()
-
-        self.expirations = []
-
-        durations = ( (1, "One Week"), (2, "Two Weeks"), (3, "Three Weeks"), (4, "One Month") )
-
-        now = datetime.datetime.utcnow()
-        for (weeks, desc) in durations:
-            exp = now + datetime.timedelta(days = weeks * 7)
-            desc = desc + " " + exp.strftime("%Y-%m-%d %H:%M:%S")
-            self.expirations.append(exp)
-            self.duration.addItem(desc)
-
-        self.duration.setCurrentIndex(0)
-
-        buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
-        buttonBox.button(QDialogButtonBox.Ok).setDefault(True)
-
-        layout = QVBoxLayout()
-        layout.addWidget(self.duration)
-        layout.addWidget(buttonBox)
-        self.setLayout(layout)
-
-        self.connect(buttonBox, SIGNAL("accepted()"), self, SLOT("accept()"))
-        self.connect(buttonBox, SIGNAL("rejected()"), self, SLOT("reject()"))
-
-    def accept(self):
-        QDialog.accept(self)
-
-    def get_new_expiration(self):
-        index = self.duration.currentIndex()
-        return self.expirations[index]
-
 class MainScreen(SfaScreen):
     def __init__(self, parent):
         SfaScreen.__init__(self, parent)
index 863b253..ca80386 100644 (file)
@@ -6,8 +6,10 @@ import sys
 import time
 
 from PyQt4.QtCore import *
+from PyQt4.QtGui import *
 from sface.config import config
 from sface.sfiprocess import SfiProcess
+#from sface.sfithread import SfiThread
 
 class SfiRenewer(QObject):
     def __init__(self, hrn, newExpiration, parent=None):
@@ -63,3 +65,68 @@ class SfiRenewer(QObject):
         self.statusMsg = statusMsg
         self.emit(SIGNAL("finished()"))
 
+class RenewWindow(QDialog):
+    def __init__(self, parent=None):
+        super(RenewWindow, self).__init__(parent)
+        self.setWindowTitle("Renew Slivers")
+
+        self.renewProcess = None
+
+        self.duration = QComboBox()
+
+        self.expirations = []
+
+        durations = ( (1, "One Week"), (2, "Two Weeks"), (3, "Three Weeks"), (4, "One Month") )
+
+        now = datetime.datetime.utcnow()
+        for (weeks, desc) in durations:
+            exp = now + datetime.timedelta(days = weeks * 7)
+            desc = desc + " " + exp.strftime("%Y-%m-%d %H:%M:%S")
+            self.expirations.append(exp)
+            self.duration.addItem(desc)
+
+        self.duration.setCurrentIndex(0)
+
+        self.status = QLabel("")
+
+        self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
+        self.buttonBox.button(QDialogButtonBox.Ok).setDefault(True)
+
+        layout = QVBoxLayout()
+        layout.addWidget(self.duration)
+        layout.addWidget(self.status)
+        layout.addWidget(self.buttonBox)
+        self.setLayout(layout)
+
+        #self.status.hide()
+
+        self.connect(self.buttonBox, SIGNAL("accepted()"), self, SLOT("accept()"))
+        self.connect(self.buttonBox, SIGNAL("rejected()"), self, SLOT("reject()"))
+
+    def accept(self):
+        self.setStatus("Renewing Slice...")
+
+        self.renewProcess = SfiRenewer(config.getSlice(), self.get_new_expiration(), self)
+        self.connect(self.renewProcess, SIGNAL('finished()'), self.renewFinished)
+
+        self.duration.setEnabled(False)
+        self.buttonBox.setEnabled(False)
+
+    def setStatus(self, x):
+        self.status.setText(x)
+
+    def renewFinished(self):
+        if self.renewProcess.statusMsg:
+            self.setStatus("Renew " + self.renewProcess.status + ": " + self.renewProcess.statusMsg)
+        else:
+            self.setStatus("Renew " + self.renewProcess.status)
+        self.disconnect(self.renewProcess, SIGNAL('finished()'), self.renewFinished)
+        self.renewProcess = None
+
+        self.buttonBox.setEnabled(True)
+        self.buttonBox.clear()
+        self.buttonBox.addButton(QDialogButtonBox.Close)
+
+    def get_new_expiration(self):
+        index = self.duration.currentIndex()
+        return self.expirations[index]