win.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. """"
  2. #============================================================================
  3. # This file is part of Pwman3.
  4. #
  5. # Pwman3 is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License, version 2
  7. # as published by the Free Software Foundation;
  8. #
  9. # Pwman3 is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with Pwman3; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  17. #============================================================================
  18. # Copyright (C) 2012 Oz Nahum <nahumoz@gmail.com>
  19. #============================================================================
  20. # Copyright (C) 2006 Ivan Kelly <ivan@ivankelly.net>
  21. #============================================================================
  22. """
  23. from pwman.ui.cli import PwmanCliNew
  24. from pwman.ui import tools
  25. import time
  26. import msvcrt
  27. import pwman.util.config as config
  28. class PwmanCliWinNew(PwmanCliNew):
  29. def print_node(self, node):
  30. width = str(tools._defaultwidth)
  31. print "Node %d." % (node.get_id())
  32. print ("%"+width+"s %s") % (tools.typeset("Username:", tools.ANSI.Red),
  33. node.get_username())
  34. print ("%"+width+"s %s") % (tools.typeset("Password:", tools.ANSI.Red),
  35. node.get_password())
  36. print ("%"+width+"s %s") % (tools.typeset("Url:", tools.ANSI.Red),
  37. node.get_url())
  38. print ("%"+width+"s %s") % (tools.typeset("Notes:", tools.ANSI.Red),
  39. node.get_notes())
  40. print tools.typeset("Tags: ", tools.ANSI.Red),
  41. for t in node.get_tags():
  42. print " %s \n" % t.get_name(),
  43. def heardEnterWin():
  44. c = msvcrt.kbhit()
  45. if c == 1:
  46. ret = msvcrt.getch()
  47. if ret is not None:
  48. return True
  49. return False
  50. def waituntil_enter(somepredicate, timeout, period=0.25):
  51. mustend = time.time() + timeout
  52. while time.time() < mustend:
  53. cond = somepredicate()
  54. if cond:
  55. break
  56. time.sleep(period)
  57. self.do_cls('')
  58. flushtimeout = int(config.get_value("Global", "cls_timeout"))
  59. if flushtimeout > 0:
  60. print "Press any key to flush screen (autoflash "\
  61. + "in %d sec.)" % flushtimeout
  62. waituntil_enter(heardEnterWin, flushtimeout)