[weboob] [PATCH 1/2] [win32] replace WConio dependency with a simplified ctypes call to win32 lib

Laurent Dufrechou laurent.dufrechou at gmail.com
Fri Apr 1 01:24:50 CEST 2011


Signed-off-by: Laurent Dufrechou <laurent.dufrechou at gmail.com>
---
 weboob/tools/application/formatters/iformatter.py  |    4 +-
 .../tools/application/formatters/win32_helper.py   |   64 ++++++++++++++++++++
 2 files changed, 66 insertions(+), 2 deletions(-)
 create mode 100644 weboob/tools/application/formatters/win32_helper.py

diff --git a/weboob/tools/application/formatters/iformatter.py b/weboob/tools/application/formatters/iformatter.py
index 13b59c4..ec5b750 100644
--- a/weboob/tools/application/formatters/iformatter.py
+++ b/weboob/tools/application/formatters/iformatter.py
@@ -22,7 +22,7 @@ import os
 import sys
 import subprocess
 if sys.platform == 'win32':
-    import WConio
+    import win32_helper
     
 try:
     import tty, termios
@@ -88,7 +88,7 @@ class IFormatter(object):
 
         if os.isatty(sys.stdout.fileno()) and os.isatty(sys.stdin.fileno()):
             if sys.platform == 'win32':
-                self.termrows = WConio.gettextinfo()[8]
+                self.termrows = win32_helper.get_screen_buffer_info().dwSize.Y
             else:
                 self.termrows = int( subprocess.Popen('stty size', shell=True, stdout=subprocess.PIPE).communicate()[0].split()[0])
 
diff --git a/weboob/tools/application/formatters/win32_helper.py b/weboob/tools/application/formatters/win32_helper.py
new file mode 100644
index 0000000..aeb99e7
--- /dev/null
+++ b/weboob/tools/application/formatters/win32_helper.py
@@ -0,0 +1,64 @@
+# -*- coding: utf-8 -*-
+# Copyright(C) 2010-2011  Laurent Dufréchou
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, version 3 of the License.
+#
+# This program 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 this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+"""
+Some specific fonctions used for win32 port
+
+Some structure definitions come from
+http://www.burgaud.com/bring-colors-to-the-windows-console-with-python/
+"""
+
+from ctypes import windll, Structure, c_short, c_ushort, byref
+
+SHORT = c_short
+WORD = c_ushort
+
+class COORD(Structure):
+  """struct in wincon.h."""
+  _fields_ = [
+    ("X", SHORT),
+    ("Y", SHORT)]
+
+class SMALL_RECT(Structure):
+  """struct in wincon.h."""
+  _fields_ = [
+    ("Left", SHORT),
+    ("Top", SHORT),
+    ("Right", SHORT),
+    ("Bottom", SHORT)]
+
+class CONSOLE_SCREEN_BUFFER_INFO(Structure):
+  """struct in wincon.h."""
+  _fields_ = [
+    ("dwSize", COORD),
+    ("dwCursorPosition", COORD),
+    ("wAttributes", WORD),
+    ("srWindow", SMALL_RECT),
+    ("dwMaximumWindowSize", COORD)]
+
+# winbase.h
+STD_INPUT_HANDLE = -10
+STD_OUTPUT_HANDLE = -11
+STD_ERROR_HANDLE = -12
+
+stdout_handle = windll.kernel32.GetStdHandle(STD_OUTPUT_HANDLE)
+GetConsoleScreenBufferInfo = windll.kernel32.GetConsoleScreenBufferInfo
+
+def get_screen_buffer_info():
+  """Returns the attributes of the console screen buffer."""
+  csbi = CONSOLE_SCREEN_BUFFER_INFO()
+  GetConsoleScreenBufferInfo(stdout_handle, byref(csbi))
+  return csbi
\ No newline at end of file
-- 
1.7.4.msysgit.0

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-win32-replace-WConio-dependency-with-a-simplified-ct.patch
Type: application/octet-stream
Size: 3746 bytes
Desc: not available
URL: <http://lists.symlink.me/pipermail/weboob/attachments/20110401/7396818e/attachment.obj>


More information about the weboob mailing list