OSDN Git Service

全GUI化
authorNakajima <fl.kouhei@gmail.com>
Wed, 1 May 2019 10:04:33 +0000 (19:04 +0900)
committerNakajima <fl.kouhei@gmail.com>
Wed, 1 May 2019 10:04:33 +0000 (19:04 +0900)
usr/share/serene-setup-wizard/src/Interfaces.py

index e51fe99..d32ed9d 100755 (executable)
@@ -1,3 +1,5 @@
+import subprocess 
+
 class Interface() :
 
     def yesnoback(self, _strs) :
@@ -52,7 +54,6 @@ class CUI(Interface) :
 
         print("{}: {}".format(_str[0].ljust(25), _str[1]))
 
-
     def choose(self, _num_of_choices) :
        
         str = "\nChoose the item you want to change.({}-{}) > ".format(1, _num_of_choices)
@@ -73,3 +74,72 @@ class CUI(Interface) :
                 print("")
                 return num
 
+class Zenity(CUI) :
+
+    def __init__(self) :
+
+        self.item_list = None
+        
+    def yesnoback(self, _strs) :
+        
+        str = ""
+
+        if len(_strs[0]) >= 2 :
+
+            for tmp in _strs :
+                str = str + "\n" + tmp
+
+        else :
+            str = _strs
+
+        
+        ans = subprocess.call(["zenity", "--question", "--title=Serene Setup Wizard", "--text={}".format(str), "--width=300"], stderr=open("/dev/null", "w"))
+
+        if ans == 0 :
+            return True
+        else :
+            return False
+
+
+    def show(self, _str) :
+        
+        if self.item_list is None :
+
+            self.item_list = list()
+
+        self.item_list.append(_str)
+
+
+    def choose(self, _) :
+
+        str = ["zenity", "--list", "--title=Serene Setup Wizard", "--text", "Choose the item you want to change.", "--height=400", "--width=400", "--column", "No.", "--column", "Item", "--column", "Status", "--print-column=all"]
+        
+
+        for i, item in enumerate(self.item_list) :
+
+            str.append("{}".format(i+1))
+            str.append("{}".format(item[0]))
+            str.append("{}".format(item[1]))
+
+        self.item_list = None
+       
+        while True :
+
+            tmp = open("/tmp/serene-setup-wizard.tmp", "w")
+            ret = subprocess.call(str, stdout=tmp, stderr=open("/dev/null", "w"))
+            tmp.close()
+
+            if ret :
+                print("")
+                return False
+
+            tmp = open("/tmp/serene-setup-wizard.tmp", "r")
+            ans = tmp.readline().split("|")[0]
+            tmp.close()
+
+            if ans != "" :   
+                break
+        
+        print("")
+        return int(ans)
+