473,513 Members | 2,368 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

getting terminal display size?

I looked around a lot on the internet and couldn't find out how to do
this, how do I get the sizer (in rows and columns) of the view?

Feb 26 '07 #1
6 7405
On 2007-02-26, jeff <je****************@gmail.comwrote:
I looked around a lot on the internet and couldn't find out how to do
this, how do I get the sizer (in rows and columns) of the view?
You use the TIOCGWINSZ ioctl() call on the tty device in question.

import termios, fcntl, struct, sys

s = struct.pack("HHHH", 0, 0, 0, 0)
fd_stdout = sys.stdout.fileno()
x = fcntl.ioctl(fd_stdout, termios.TIOCGWINSZ, s)
print '(rows, cols, x pixels, y pixels) =',
print struct.unpack("HHHH", x)

--
Grant Edwards
gr****@visi.com
Feb 26 '07 #2
On 2007-02-26, Grant Edwards <gr****@visi.comwrote:
On 2007-02-26, jeff <je****************@gmail.comwrote:
>I looked around a lot on the internet and couldn't find out how to do
this, how do I get the sizer (in rows and columns) of the view?

You use the TIOCGWINSZ ioctl() call on the tty device in question.

import termios, fcntl, struct, sys

s = struct.pack("HHHH", 0, 0, 0, 0)
fd_stdout = sys.stdout.fileno()
x = fcntl.ioctl(fd_stdout, termios.TIOCGWINSZ, s)
print '(rows, cols, x pixels, y pixels) =',
print struct.unpack("HHHH", x)
You may also want to handle the WINCH signal so that you know
when the window size has been changed.

--
Feb 26 '07 #3
I don't really understand any of that; can you right me a function
that'll return the size as a tuple?

Feb 27 '07 #4
jeff wrote:
I don't really understand any of that; can you right me a function
that'll return the size as a tuple?
Did you even *try* his code? I ran this:

import termios, fcntl, struct, sys

s = struct.pack("HHHH", 0, 0, 0, 0)
fd_stdout = sys.stdout.fileno()
x = fcntl.ioctl(fd_stdout, termios.TIOCGWINSZ, s)
print '(rows, cols, x pixels, y pixels) =',
print struct.unpack("HHHH", x)

And got this result:

(36, 96, 0, 0)

Looks like a tuple to me. return 'return' instead of 'print' the result.
We don't mind helping, but it's nice to know that the user has made some
attempt to understand what is going on before asking for free work to be
done.

j

--
Joshua Kugler
Lead System Admin -- Senior Programmer
http://www.eeinternet.com
PGP Key: http://pgp.mit.edu/ Â*ID 0xDB26D7CE

--
Posted via a free Usenet account from http://www.teranews.com

Feb 27 '07 #5
On 2007-02-27, jeff <je****************@gmail.comwrote:
I don't really understand any of that; can you right me a function
that'll return the size as a tuple?
What do you think I posted?

--
Grant Edwards grante Yow! I selected E5... but
at I didn't hear "Sam the Sham
visi.com and the Pharoahs"!
Feb 27 '07 #6
On Feb 26, 8:01 pm, Grant Edwards <gra...@visi.comwrote:
On 2007-02-27, jeff <jeffrey.ayleswo...@gmail.comwrote:
I don't really understand any of that; can you right me a function
that'll return the size as a tuple?

What do you think I posted?

--
Grant Edwards grante Yow! I selected E5... but
at I didn't hear "Sam the Sham
visi.com and the Pharoahs"!
nevermind, I figured it outr, it just looked confusing

Feb 27 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
2110
by: middletree | last post by:
How do I request the actual page name that I'm on? This is going to go into an include file, and depending on which page I'm on, I'd like to do different things. I'm looking for "pagename.asp"
0
1424
by: LRW | last post by:
I manage our mySQL database through putty (SSH terminal client). And whenever I do a select * from the table that contains ENCODEd passwords, the funky characters do funky things with the display....
0
1519
by: dynfax | last post by:
When I use Access 97 with Terminal Services, and the terminal window is minimized, the popup form displays - and when i reset the focus to the terminal window the popup form displays. In...
2
5050
by: velle | last post by:
My headache is growing while playing arround with unicode in Python, please help this novice. I have chosen to divide my problem into a few questions. Python 2.3.4 (#1, Feb 2 2005, 12:11:53) ...
20
10808
by: Joel Hedlund | last post by:
Hi all! I use python for writing terminal applications and I have been bothered by how hard it seems to be to determine the terminal size. What is the best way of doing this? At the end I've...
7
2408
by: Captain Dondo | last post by:
I'm working on a terminal emulator for an embedded system. The key requirements are small size, code clarity, maintainability, and portability. We have machines that regularly see a service life...
7
5683
by: =?gb2312?B?yMvR1MLkyNXKx8zs0cSjrM37vKvM7NHEsru8+7z | last post by:
Who could explain the follow issue ? ¦¤ Traceback (most recent call last): File "<stdin>", line 1, in <module> UnicodeEncodeError: 'gbk' codec can't encode character u'\x80' in position 0: il...
2
3549
by: rustyc | last post by:
Well, here's my first post in this forum (other than saying 'HI' over in the hi forum ;-) As I said over there: ... for a little side project at home, I'm writing a ham radio web site in...
2
1588
by: David | last post by:
Hi list. I've never used unicode in a Python script before, but I need to now. I'm not sure where to start. I'm hoping that a kind soul can help me out here. My current (almost non-existant)...
0
7267
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7391
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7553
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7542
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5697
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5100
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4754
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3247
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3235
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.