473,804 Members | 2,136 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

range and wx co - ords

Hi All,

Using wx, I'm trying to draw all items in a range of 50 in a text at
certain co -ordinates (a simply textwrap) . A while back Alex Martelli
was kind enough to give me the following to work with ;

for i in range(len(text) ):
dc.DrawText(tex t, 100, 100 + ( i // 50 *200)

I have slightly changed this to control the spacing between the
letters by adding this;

dc.DrawText(tex t[i], 100 + ( i * 12 ), 100 + (i//50)*200)

This starts the new line at the right y co-ordinate, but the x remains
at the position where the last line finished. Would anyone know how to
start the line from the starting x co - ords?
I have had an idea to do it another way, but need some help with this
also.

for i in range(len(text) , 50)):
spacer = 200
dc.DrawText(tex t[i], 100 + ( i * 12 ), 100 + spacer )

This of course just draws the items at the every 50 mark, as you might
gather, what I want to say is that for every 50 items draw them at
these co - ordinates then go on to the next 50.

Thanks for any help,

Malcolm
Jul 18 '05 #1
8 1545
Hi All,

I have now got something approaching what I need. Could someone please
show me how to define the 'line', so rather than just the first 50
items being printed over and over it goes through the text
incrementally?
line = text1[:50]
for i in range(1000):
dc.DrawText(lin e, 100, 100 + (i//2)*100)
Thanks,

Malcolm
Jul 18 '05 #2
On 9 Nov 2004 17:07:12 -0800, mj******@virgin .net (Malcolm Clift) wrote:
Hi All,

I have now got something approaching what I need. Could someone please
show me how to define the 'line', so rather than just the first 50
items being printed over and over it goes through the text
incrementall y?
line = text1[:50]
for i in range(1000):
dc.DrawText(lin e, 100, 100 + (i//2)*100)

I don't think you want to do 1000 DrawText calls to display 50 characters ;-)

I can't tell what you really want to do, but if you just want to spread characters
evenly to make an array of characters with 50 per row of some width and a box of
some height, I would just walk through the characters and bump coordinates as I went.

If you are tyring to spread _words_ into the space, you might want to keep the characters
in words more together than what overall average spacing will give. I.e., insert extra
space between words, but none or some mild effect between characters. This also depends
on what font you are using, which gets into font metrics. Also how persnickety you are
about precise inclusion within the box area of characters on the right. An '!' is going
to be narrower than an 'M'. Also, do you want to ignore word boundaries and likely break
words between lines?

If you just want to walk through 20 lines of 50 characters taken successively from text1,
you can write something like (untested!!)

cpl = 50 # chars per line
totlines = 20
top = 100; left = 100 # top left pixel position
width = 500; height = 400 # box pixel(?) dimensions
cleantext = ' '.join(text1.sp lit()) # change all whitespace to single spaces??
for linestart in xrange(0, cpl*totlines, cpl):
line = cleantext[linestart:lines tart+cpl]
for ix, c in enumerate(line) :
# compute position
iy = linestart//cpl # might want to add 1 if top is not baseline pos
x = int(left + width*ix/float(cpl))
y = int(top + height*iy/float(totlines) )
dc.DrawText(c, x, y)

But this is not normal word flowing to fit _words_ in a box justified to both sides,
if that's what you really want. If you want that, you should probably output words
whose characters are not separated as much, and put extra space between words, and
not break words at line ends. Also, if your text has real newlines ('\n') or tabs
etc. in it, you may want to change them to spaces (but not necessarily a single space
for each separation as I did in cleantext above).

HTH and that the bug is not too bad (untested, there's bound to be one ;-)

Regards,
Bengt Richter
Jul 18 '05 #3
Hi Bengt,

Really, a big thankyou for that. It's a lot of work and I appreciate
it. It would seem to be perfect, at very least for what I want to do
right now. I take your point about 'true' word wrap and I may
experiment with that in the future. At least with such a full
explanation I have something to work with if I do.

All the best and thanks once again,

Malcolm
Jul 18 '05 #4
Hi Bengt,

I thought that I would be able to work out how to do this, but as I'm
new to python it's harder than I thought...

Could you tell me how I would get the text to flow on to a new page?

Thanks,

Malcolm
Jul 18 '05 #5
On 14 Nov 2004 04:45:25 -0800, mj******@virgin .net (Malcolm Clift) wrote:
Hi Bengt,

I thought that I would be able to work out how to do this, but as I'm
new to python it's harder than I thought...

Could you tell me how I would get the text to flow on to a new page?

Maybe, but I'd have to know what you meant by that. E.g., are you showing
multiple pages at once? Waiting for a page-turn click? Do you need to turn
back to previous pages? Once you can spell out _exactly_ what you want to
happen in English, you will probably be able to do it in Python. (And when
you get more fluent in Python, you will likely prefer to spell such things
in Python first ;-)

Regards,
Bengt Richter
Jul 18 '05 #6
Hi Bengt,

Sorry, I can see how vague my question is...

I am showing multiple pages at once.I suppose that the simplist way to
do it would be to have the position 'left' increase after so many
lines or so many characters. The problem with that is that although
I imagine it is very simple to do so I cannot work out how to say
for every say something like for every 500 characters (or every 5 or
so lines), left = 100 + say 1000.

As I said, at the moment I'm displaying multiple draggable pages (A4
bmps) and I have just started to realise how slow that will be.
Something akin to wading through mud : ) So although it looks nice I
think that I might have to go for a single page display. If that's the
case could you give me some idea as to how I might define 'a new
page', with the option of going forward and backward through the
pages.You've done a lot for me already, so if that's more involved
than I think I would be greatful if you told me where I might start
looking for ways to do this.

Thanks,

Malcolm
Jul 18 '05 #7
On 15 Nov 2004 08:43:01 -0800, mj******@virgin .net (Malcolm Clift) wrote:
Hi Bengt,

Sorry, I can see how vague my question is...

I am showing multiple pages at once.I suppose that the simplist way to
do it would be to have the position 'left' increase after so many
lines or so many characters. The problem with that is that although
I imagine it is very simple to do so I cannot work out how to say
for every say something like for every 500 characters (or every 5 or
so lines), left = 100 + say 1000.
This isn't homework, is it? ;-)
As I said, at the moment I'm displaying multiple draggable pages (A4
bmps) and I have just started to realise how slow that will be. It is probable that you can improve the speed of dragging bitmaps if
you can do the relevant re-drawing a cached bitmap in a new position
instead of re-creating a bitmap in a new place -- if that's what's
slowing you down.
Something akin to wading through mud : ) So although it looks nice I
think that I might have to go for a single page display. If that's the
case could you give me some idea as to how I might define 'a new
page', with the option of going forward and backward through the
pages.You've done a lot for me already, so if that's more involved
than I think I would be greatful if you told me where I might start
looking for ways to do this.

I would suggest you take an OO aproach, and define a document class
that represents a sequence of pages, which in turn are defined by
a page class. Then you can flesh it out by defining methods for
setting dimensions and positions etc, and for initializing, updating,
and deleting display representations of the pages. Does your page text
come from files? Why don't you post what you have working so far?
I'm sure you will also get comments from people who are more familiar
with wx, which I haven't used. If you post something, I will learn something ;-)

If you don't know about classes and methods and objects and all that,
I suggest reading up on it and trying it out. It is a powerful way
of modeling your problem world, and decomposing it into chunks that
make sense.

Regards,
Bengt Richter
Jul 18 '05 #8
Hi Bengt,
This isn't homework, is it? ;-)
If it was I wouldn't feel so dumb for not knowing half of this stuff.
No, I'm just a late starter with an idea for a program.

Thankyou for your suggestion of taking the OO approach. I think that
you are right and I need to go away and work this out. It was just
that I was trying to find a simple / basic way just to get the thing
up and running before refining it.

The text will eventually come from a generated file, but at the moment
I haven't hooked up the part that does the generating with the
display. At the moment I'm just throwing a little bit of text in just
above the display part of the code.
Why don't you post what you have working so far?...I will learn

something ;-)

Bengt, I really doubt there is anything I can teach you about python /
wx. It is kind of you to suggest otherwise : ) At the present time I
have basically cobbled together the dragImage demo. The 'page' is just
an A4 bmp. That code came from looking at how the cards are displayed
in the demo. To this I have just added some static text ( the stuff
you've helped me to word wrap). So I end up with a so called draggable
'page' with text. To add more pages I pin the bmps on to an empty bmp
so that they drag as one whole. As I said in the other post, one page
is ok, but adding more slows things down a lot. As this is just a mess
around with the DragImage demo I presume that the bmps are buffered,
but as I write, I think that I may have to look into this, as perhaps
pinning 'pages' onto a wx.EmptyBitmap affect things somehow. That or
that with just a few extra pages the bmp becomes massive.

If you or anyone else is interested I will of course post it.

All the best,

Malcolm
Jul 18 '05 #9

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

Similar topics

7
3368
by: Xah Lee | last post by:
Today we'll be writing a function called Range. The Perl documentation is as follows. Perl & Python & Java Solutions will be posted in 48 hours. This is Perl-Python a-day. See http://xahlee.org/web/perl-python/python.html Xah xah@xahlee.org
1
4807
by: Thomas | last post by:
Hi dudes, I have a range object for text (not the one in the IE, the one for Mozilla). Now I have a function to reduce/move the range in the text to the LEFT, e.g.: range.setStart(range.startContainer, startPos-1); range.setEnd(range.endContainer, endPos-1); range ist the range object created via window.getSelection.getRangeAt(0). Now I have the problem to extend or simply move the range to the
4
8468
by: IMS.Rushikesh | last post by:
Hi All, I am trying to execute below code but it gives me an COMException ///// Code Start //// public string GetName(Excel.Range range) { try { if (range.Name != null)
5
282
by: Chris | last post by:
Hey all. Anyone who is familiar with Python programming knows that you can have code like this: list = This code puts all the items processed by the for loop in a list plus 1. Is there a way to do this in C++? Something like: int list = { x + 1 for (int x = 0; x < 5; x++); } Or something?
29
2883
by: Steve R. Hastings | last post by:
When you compile the expression for i in range(1000): pass does Python make an iterator for range(), and then generate the values on the fly? Or does Python actually allocate the list and then step through it? I was under the impression that recent releases of Python optimize this
3
2853
by: toton | last post by:
Hi, I want ro iterate over a few container class within a range specified, instead of begin & end. How to construct a range class, which takes start & end, and iteration is available within that range only. Itaration may be const, bidiractional, forward or backward. Say I have a vector or other container class, like vector<intvec; and want to return a range class like range(vec.begin()+5,
85
4329
by: Russ | last post by:
Every Python programmer gets this message occasionally: IndexError: list index out of range The message tells you where the error occurred, but it doesn't tell you what the range and the offending index are. Why does it force you to determine that information for yourself when it could save you a step and just tell you? This seems like a "no-brainer" to me. Am I missing something?
1
1770
by: helraizer1 | last post by:
Hi all, I have a dynamic image that picks out data from a dynamically created .line file. showimage.php(5) <?php include("linesfile.php5"); $linesDataFile = new DataFile("data.line");
0
1203
by: iain654 | last post by:
I have finally worked out how to automatically send a range of cells in the body of an email using Outlook but it is very clumsy and I have to build up the email using the limit of line continuations. Is there any quicker and easier way of sending this email as it is always a set range of cells that I want to sent. At the moment my code looks like this: Sub Email_DPV() Dim oFolder As Outlook.MAPIFolder Dim oItem As Outlook.MailItem Dim...
0
9711
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9593
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10595
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10343
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10335
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9169
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7633
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5668
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.