Browse Source

- remove all windows related stuff to own UI class

this should make maintaining of the code a bit more
easy
oz123 11 years ago
parent
commit
40faca5345
4 changed files with 87 additions and 39 deletions
  1. 11 36
      pwman/ui/cli.py
  2. 4 3
      pwman/ui/mac.py
  3. 70 0
      pwman/ui/win.py
  4. 2 0
      scripts/pwman3

+ 11 - 36
pwman/ui/cli.py

@@ -119,7 +119,7 @@ class PwmanCli(cmd.Cmd):
             return password
         # no args given
         password = tools.getpassword("Password (Blank to generate): ",
-                               tools._defaultwidth, False)
+                                     tools._defaultwidth, False)
         if len(password) == 0:
             length = tools.getinput("Password length (default 7): ", "7")
             length = int(length)
@@ -192,15 +192,6 @@ class PwmanCli(cmd.Cmd):
                     return True
                 return False
 
-        def heardEnterWin():
-            import msvcrt
-            c = msvcrt.kbhit()
-            if c == 1:
-                ret = msvcrt.getch()
-                if ret is not None:
-                    return True
-            return False
-
         def waituntil_enter(somepredicate, timeout, period=0.25):
             mustend = time.time() + timeout
             while time.time() < mustend:
@@ -212,12 +203,9 @@ class PwmanCli(cmd.Cmd):
 
         flushtimeout = int(config.get_value("Global", "cls_timeout"))
         if flushtimeout > 0:
-            if sys.platform != 'win32':
-                print "Type Enter to flush screen (autoflash in 5 sec.)"
-                waituntil_enter(heardEnter, flushtimeout)
-            else:
-                print "Press any key to flush screen (autoflash in 5 sec.)"
-                waituntil_enter(heardEnterWin, flushtimeout)
+            print "Type Enter to flush screen (autoflash in "\
+                  + "%d sec.)" % flushtimeout
+            waituntil_enter(heardEnter, flushtimeout)
 
     def do_tags(self, arg):
         tags = self._db.listtags()
@@ -417,7 +405,7 @@ class PwmanCli(cmd.Cmd):
             nodes = self._db.getnodes(ids)
             for n in nodes:
                 b = tools.getyesno("Are you sure you want to delete '%s@%s'?"
-                             % (n.get_username(), n.get_url()), False)
+                                   % (n.get_username(), n.get_url()), False)
                 if b is True:
                     self._db.removenodes([n])
                     print "%s@%s deleted" % (n.get_username(), n.get_url())
@@ -465,7 +453,7 @@ class PwmanCli(cmd.Cmd):
 
                 fmt = "%%5d. %%-%ds %%-%ds" % (name_len, tagstring_len)
                 print tools.typeset(fmt % (n.get_id(), name, tagstring),
-                              tools.ANSI.Yellow, False)
+                                    tools.ANSI.Yellow, False)
                 i += 1
                 if i > rows-2:
                     i = 0
@@ -544,7 +532,7 @@ class PwmanCli(cmd.Cmd):
                 node = self._db.getnodes(ids)
                 tools.text_to_clipboards(node[0].get_password())
                 print "copied password for {}@{} clipboard".format(
-                       node[0].get_username(), node[0].get_url())
+                    node[0].get_username(), node[0].get_url())
 
                 print "erasing in 10 sec..."
                 time.sleep(10)
@@ -577,6 +565,7 @@ class PwmanCli(cmd.Cmd):
     ##
     ## Help functions
     ##
+
     def usage(self, string):
         print "Usage: %s" % (string)
 
@@ -799,15 +788,6 @@ class PwmanCliNew(PwmanCli):
                     return True
                 return False
 
-        def heardEnterWin():
-            import msvcrt
-            c = msvcrt.kbhit()
-            if c == 1:
-                ret = msvcrt.getch()
-                if ret is not None:
-                    return True
-            return False
-
         def waituntil_enter(somepredicate, timeout, period=0.25):
             mustend = time.time() + timeout
             while time.time() < mustend:
@@ -819,12 +799,9 @@ class PwmanCliNew(PwmanCli):
 
         flushtimeout = int(config.get_value("Global", "cls_timeout"))
         if flushtimeout > 0:
-            if sys.platform != 'win32':
-                print "Type Enter to flush screen (autoflash in 5 sec.)"
-                waituntil_enter(heardEnter, flushtimeout)
-            else:
-                print "Press any key to flush screen (autoflash in 5 sec.)"
-                waituntil_enter(heardEnterWin, flushtimeout)
+            print "Type Enter to flush screen (autoflash in "\
+                  + "%d sec.)" % flushtimeout
+            waituntil_enter(heardEnter, flushtimeout)
 
     def do_tags(self, arg):
         tags = self._db.listtags()
@@ -992,5 +969,3 @@ class PwmanCliNew(PwmanCli):
                 zerome(node[0]._password)
             except Exception, e:
                 self.error(e)
-
-

+ 4 - 3
pwman/ui/mac.py

@@ -26,6 +26,8 @@ from pwman.ui import tools
 import time
 
 # pylint: disable=R0904
+
+
 class PwmanCliMac(PwmanCli):
     """
     inherit from PwmanCli, override the right functions...
@@ -39,7 +41,7 @@ class PwmanCliMac(PwmanCli):
             node[0].get_password()
             tools.text_to_mcclipboard(node[0].get_password())
             print "copied password for {}@{} clipboard".format(
-                       node[0].get_username(), node[0].get_url())
+                node[0].get_username(), node[0].get_url())
             time.sleep(10)
             tools.text_to_clipboards("")
         except Exception, e:
@@ -79,7 +81,7 @@ class PwmanCliMac(PwmanCli):
 
     def help_copy(self):
         self.usage("copy <ID>")
-        print "Copy password to Cocoa clipboard using pbcopy)"
+        print "Copy password to Cocoa clipboard using pbcopy"
 
     def help_cp(self):
         self.help_copy()
@@ -87,4 +89,3 @@ class PwmanCliMac(PwmanCli):
 
 class PwmanCliMacNew(PwmanCliMac):
     pass
-

+ 70 - 0
pwman/ui/win.py

@@ -0,0 +1,70 @@
+""""
+#============================================================================
+# This file is part of Pwman3.
+#
+# Pwman3 is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License, version 2
+# as published by the Free Software Foundation;
+#
+# Pwman3 is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Pwman3; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+#============================================================================
+# Copyright (C) 2012 Oz Nahum <nahumoz@gmail.com>
+#============================================================================
+# Copyright (C) 2006 Ivan Kelly <ivan@ivankelly.net>
+#============================================================================
+"""
+
+
+from pwman.ui.cli import PwmanCliNew
+from pwman.ui import tools
+import time
+import msvcrt
+import pwman.util.config as config
+
+
+class PwmanCliWinNew(PwmanCliNew):
+
+    def print_node(self, node):
+        width = str(tools._defaultwidth)
+        print "Node %d." % (node.get_id())
+        print ("%"+width+"s %s") % (tools.typeset("Username:", tools.ANSI.Red),
+                                    node.get_username())
+        print ("%"+width+"s %s") % (tools.typeset("Password:", tools.ANSI.Red),
+                                    node.get_password())
+        print ("%"+width+"s %s") % (tools.typeset("Url:", tools.ANSI.Red),
+                                    node.get_url())
+        print ("%"+width+"s %s") % (tools.typeset("Notes:", tools.ANSI.Red),
+                                    node.get_notes())
+        print tools.typeset("Tags: ", tools.ANSI.Red),
+        for t in node.get_tags():
+            print " %s \n" % t.get_name(),
+
+        def heardEnterWin():
+            c = msvcrt.kbhit()
+            if c == 1:
+                ret = msvcrt.getch()
+                if ret is not None:
+                    return True
+            return False
+
+        def waituntil_enter(somepredicate, timeout, period=0.25):
+            mustend = time.time() + timeout
+            while time.time() < mustend:
+                cond = somepredicate()
+                if cond:
+                    break
+                time.sleep(period)
+            self.do_cls('')
+
+        flushtimeout = int(config.get_value("Global", "cls_timeout"))
+        if flushtimeout > 0:
+            print "Press any key to flush screen (autoflash "\
+                + "in %d sec.)" % flushtimeout
+            waituntil_enter(heardEnterWin, flushtimeout)

+ 2 - 0
scripts/pwman3

@@ -57,6 +57,8 @@ if 'darwin' in sys.platform:
     from pwman.ui.mac import PwmanCliMac as PwmanCli
     from pwman.ui.mac import PwmanCliMacNew as PwmanCliNew
     OSX = True
+elif 'win' in sys.platform:
+    from pwman.ui.win import PwmanCliWinNew as PwmanCliNew
 else:
     from pwman.ui.cli import PwmanCli
     from pwman.ui.cli import PwmanCliNew