473,378 Members | 1,140 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

wx position of items in list

Hi All,

This would seem to be easy, but I have had no luck in working out how to do
this.

In wx.python a list of text is displayed as a bitmap and given it's
position.

shape.pos = (145, 270)

What I want to do is to increase the y value for every 20 items in the list,
so the text is displayed to a new line. So for items in list numbered 0 -19
y = 270, for items in list numbered 20 - 39 y = 370 etc...

Thanks for any help,

Malcolm
Jul 18 '05 #1
4 1906
M. Clift <no***@here.com> wrote:
Hi All,

This would seem to be easy, but I have had no luck in working out how to do
this.

In wx.python a list of text is displayed as a bitmap and given it's
position.

shape.pos = (145, 270)

What I want to do is to increase the y value for every 20 items in the list,
so the text is displayed to a new line. So for items in list numbered 0 -19
y = 270, for items in list numbered 20 - 39 y = 370 etc...


maybe 270 + (i//20)*100 is what you want?
Alex
Jul 18 '05 #2
Hi Alex,

Thanks for helping me again. I'm using the DragImage demo in wx. Here is
some of the code. I am getting the following error regardless of whether I
use a list or string, 'unsupported operand type(s) for //: 'str' and
'int''. I've also tried inserting \n into the text, but I can't get that to
work either.
# Make a shape from some text
text = ['a', 'b','c','d','z','y','a', 'b','c','d','z','y','a',
'b','c','d','z','y','a', 'b','c','d','z','y']
text4 = " "+"".join(text)
bg_colour = wx.Colour(57, 115, 57) # matches the bg image
font4 = wx.Font(36, wx.MODERN, wx.NORMAL, wx.NORMAL, 0, "Arial")
textExtent = self.GetFullTextExtent(text4, font4)

# create a bitmap the same size as our text
bmp4 = wx.EmptyBitmap(textExtent[0], textExtent[1])

# 'draw' the text onto the bitmap
dc = wx.MemoryDC()
dc.SelectObject(bmp4)
dc.SetBackground(wx.Brush(bg_colour, wx.SOLID))
dc.Clear()
dc.SetTextForeground(wx.BLACK)
dc.SetFont(font4)
dc.DrawText(text4, 0, 0)
dc.SelectObject(wx.NullBitmap)
mask4 = wx.Mask(bmp4, bg_colour)
bmp4.SetMask(mask4)
shape = DragShape(bmp4)
shape.text = "Some dragging text"

for i in text:
shape.pos = (145, 170 + (i//2)*100)
self.shapes.append(shape)

Thanks for your time,

Malcolm

Jul 18 '05 #3
On Sun, 2004-10-24 at 19:13 +0100, M. Clift wrote:
I am getting the following error regardless of whether I
use a list or string, 'unsupported operand type(s) for //: 'str' and
'int''.
That's because you're trying to divide i (a string) by an integer.
for i in text:
shape.pos = (145, 170 + (i//2)*100)
self.shapes.append(shape)


Try this instead:

for i in range(len(text)):
shape.pos = (145, 170 + (i//2)*100)
self.shapes.append(shape)

For future reference, try adding print statements when you get errors
like this so you can verify that you are doing what you think you are.
I'm assuming that you know you can't divide a string by an integer, so
my guess is that for some reason you thought that 'for i in text' would
give you a list of integers. A quick 'print i' after the for statement
would have told you otherwise (as would have the Python tutorial had you
bothered to read it).

Regards,
Cliff

--
Cliff Wells <cl************@comcast.net>

Jul 18 '05 #4
Hi Cliff,

Thankyou for your help. I know that you can't divide a string by an integer
and true to form I didn't check with 'print' to see what was going on.
Yesterday I tried len, but without the range attached...

Looking at demos and examples it is easy (most of the time) to see how
things work. It is another thing to be creative and cook up some code (even
the most basic) when you are trying to run before you can walk. I do need to
just play around with loads of basic stuff, but like a child in a sweet shop
I get carried away. Saying that I do think that it is sometimes easier to
learn by applying all the help I can get to problems for my project. Getting
something to work for some problem of your own is less dry than some
tutorial example and seems to spot-light.the language.

But before I go to look up some more tutorials I would like to ask something
else
regarding this problem. I can see how this works, but what it does is to
move the
whole text to the new position. Basically I was hoping for a simplified word
wrap.
This is the code (slightly altered) from the wx DragImage demo that I'm
using.

# Make a shape from some text
l1 =
['a','b','c','d','a','b','c','d','a','b','c','d','a ','b','c','d',]
text = " "+"".join(l1)
bg_colour = wx.Colour(57, 115, 57) # matches the bg image
font = wx.Font(36, wx.MODERN, wx.NORMAL, wx.NORMAL, 0, "Arial")
textExtent = self.GetFullTextExtent(text, font)

# create a bitmap the same size as our text
bmp = wx.EmptyBitmap(textExtent[0], textExtent[1])

# 'draw' the text onto the bitmap
dc = wx.MemoryDC()
dc.SelectObject(bmp)
dc.SetBackground(wx.Brush(bg_colour, wx.SOLID))
dc.Clear()
dc.SetTextForeground(wx.RED)
dc.SetFont(font)
dc.DrawText(text, 0, 0)
dc.SelectObject(wx.NullBitmap)
mask = wx.Mask(bmp, bg_colour)
bmp.SetMask(mask)
shape = DragShape(bmp)
for i in range(len(text)):
shape.pos = (145, 170 + (i//12)*100)
shape.text = "Some dragging text"
self.shapes.append(shape)

I think that I need to have something further back in the code, before,
the text is drawn. I've tried \ n in the text, but I can't get that to
work.
Any ideas?

Thanks for your time and patience,

Malcolm

Jul 18 '05 #5

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

Similar topics

9
by: Irene | last post by:
I'm developing a Web application where a user selects from a listbox which can have many items. The initial display only shows about 10 items. After a postback, the listbox is automatically...
1
by: Steve Edwards | last post by:
I have a form with a list box, and the items selected from that list box are used to add values to the WHERE clause of a query that is the data source for a report. For each item chosen from the...
0
by: Shravan | last post by:
Hi, I have a combo bound to a dataview, when I am settting the position of the currencymanager it's not set combo.BindingContext.Position = index; it's happening only for one index in the...
6
by: | last post by:
Hi all, I have a long web form on asp.net 2.0. When I go at the bottom and click on submit, a postback occurs and if there are any validation errors (no client-side checking being done), the...
3
by: Mark Vergara | last post by:
Hi to all, I want to know if there is a way of getting the position of the particular record in the dataset aside from CurrencyManger.position let say for example we have a record.. cntID ...
5
by: Joe Fallon | last post by:
I have a list box with 7 text values in it. I have a pair of buttons to Move Up or Move Down the selected item one position. What is the simplest way to code the buttons so the item moves one...
1
by: Sim | last post by:
Hello NG, I try to use drag and drop function between two list views. For this I found following code: ...
6
Robbie
by: Robbie | last post by:
Hi again, I have a listview which gets cleared and has items added again every now and then, and it's very annoying to use because once it's cleared, the scrollbar goes back to the top. I'd like it...
7
by: Lit | last post by:
Hi, How can I capture the vertical scroll bar position for a Listbox. I have a Listbox of 100 items + when I click on it I post back remove the item selected. After returning to the client...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.