473,322 Members | 1,421 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,322 software developers and data experts.

wxPython, tree Control text cutoff

Hello all,
I am using a tree to display stuff, and it is constantly updated, but
what I have noticed is in the lowest level, there is clearly noticable
cutoff of the text I place there. The cutoff is existent even if I do
not update the text inside the tree constantly. It seems that the text
is halfway below where it should line up. I tried placing an image to
see if that would correct it, but it does not. The image is perfectly
lined up, but the text is still misaligned.

Any known issues of this and how to fix it? By the way, it happens in
both Linux and Windows.

thanks a lot for your help!

here is the code that I am using, I realize that it is a bit
convoluted, but the parts where I am setting the text should be
evident.

import wx
import wx.gizmos as gizmos

class AlarmsWindow(wx.MDIChildFrame):
def __init__(self, parent, title, size, pos):
wx.MDIChildFrame.__init__(self, parent, -1, title, size = size, pos =
pos)

self.tree = gizmos.TreeListCtrl(self, -1, style = wx.TR_DEFAULT_STYLE
| wx.TR_FULL_ROW_HIGHLIGHT)

# images of the tree
isz = (16,16)
il = wx.ImageList(isz[0], isz[1])
self.fldridx = il.Add(wx.ArtProvider_GetBitmap(wx.ART_FOLDER,
wx.ART_OTHER, isz))
self.fldropenidx = il.Add(wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN,
wx.ART_OTHER, isz))
self.fileidx =
il.Add(wx.ArtProvider_GetBitmap(wx.ART_NORMAL_FILE , wx.ART_OTHER, isz))
self.selidx = il.Add(wx.ArtProvider_GetBitmap(wx.ART_CROSS_MARK,
wx.ART_OTHER, isz))

self.tree.SetImageList(il)
self.il = il

# create some columns
self.tree.AddColumn("Connection")
self.tree.AddColumn("Alarm")
self.tree.AddColumn("Value")
self.tree.SetMainColumn(0)

self.root = self.tree.AddRoot("Connections")
self.tree.SetItemImage(self.root, self.fldridx, which =
wx.TreeItemIcon_Normal)
self.tree.SetItemImage(self.root, self.fldropenidx, which =
wx.TreeItemIcon_Expanded)

self.connectionsName = []
self.connections = []
self.registers = []

self.tree.Expand(self.root)

self.tree.GetMainWindow().Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
self.Show()
# testing

self.AddConnection("Dummy")
self.AddRegister("Dummy", "R5")
self.AddAlarm("Dummy", "R5", "LOA", "10")
self.UpdateAlarm("Dummy", "R5", "LOA", "14")
self.AddAlarm("Dummy", "R5", "LOS", "1354")
self.AddRegister("Dummy", "R6")
self.AddAlarm("Dummy", "R6", "LOA", "15")
self.AddConnection("DUMMY @#2")
self.AddRegister("DUMMY @#2", "R0")
self.AddAlarm("DUMMY @#2", "R0", "LSKJDF", "S:LKJDF")
# tree control
def OnRightUp(self, evt):
pos = evt.GetPosition()
item, flags, col = self.tree.HitTest(pos)
if item:
print('Flags: %s, Col:%s, Text: %s' %
(flags, col, self.tree.GetItemText(item,
col)))

# tree control
def OnSize(self, evt):
self.tree.SetSize(self.GetSize())

# adds a section to the logger
def AddConnection(self, name):
self.connectionsName.append(name)
self.connections.append([])
child = self.tree.AppendItem(self.root, name)
self.connections[(len(self.connectionsName)-1)].append(child)
self.tree.SetItemText(child, name)
self.tree.SetItemImage(child, self.fldridx, which =
wx.TreeItemIcon_Normal)
self.tree.SetItemImage(child, self.fldropenidx, which =
wx.TreeItemIcon_Expanded)

# adds a register
def AddRegister(self, connection, name):
# find the connection
index = -1
for i in range(len(self.connectionsName)):
if self.connectionsName[i] == connection:
index = i
break
if index != -1:
self.connections[index].append([self.tree.AppendItem(self.connections[index][0],
name)])

# adds a message to a specific section
def AddAlarm(self, connection, register, alarm, value):
# find the connection
for i in range(len(self.connectionsName)):
if self.connectionsName[i] == connection:
# find the register
for j in range(1, len(self.connections[i])):
if self.tree.GetItemText((self.connections[i][j])[0]) == register:

x = self.tree.AppendItem(self.connections[i][j][0], "")
self.connections[i][j].append([x, alarm])
self.tree.SetItemImage(x, self.fileidx, wx.TreeItemIcon_Normal)
self.tree.SetItemText(x, alarm, 1)
self.tree.SetItemText(x, value, 2)
# updates the alarm's window
def UpdateAlarm(self, connection, register, alarm, value):
# find the connection
for i in range(len(self.connectionsName)):
if self.connectionsName[i] == connection:
# find the register
for j in range(1, len(self.connections[i])):
if self.tree.GetItemText(self.connections[i][j][0]) == register:
# find the alarm
for k in range(1, len(self.connections[i][j])):
if self.connections[i][j][k][1] == alarm:
self.tree.SetItemImage(self.connections[i][j][k][0],
self.fileidx, wx.TreeItemIcon_Normal)
self.tree.SetItemText(self.connections[i][j][k][0], value, 2)
return

class MDIFrame(wx.MDIParentFrame):
def __init__(self):
wx.MDIParentFrame.__init__(self, None, -1, "MDI Parent", size =
(600, 400))
child = AlarmsWindow(self, "Alarm", (400, 300), (0, 0))
if __name__=='__main__':
app = wx.PySimpleApp()
frame = MDIFrame()
frame.Show()
app.MainLoop()

Jun 14 '06 #1
2 3443
Kiran a écrit :
Hello all,
I am using a tree to display stuff, and it is constantly updated, but
what I have noticed is in the lowest level, there is clearly noticable
cutoff of the text I place there. The cutoff is existent even if I do
not update the text inside the tree constantly. It seems that the text
is halfway below where it should line up. I tried placing an image to
see if that would correct it, but it does not. The image is perfectly
lined up, but the text is still misaligned.

Any known issues of this and how to fix it? By the way, it happens in
both Linux and Windows.

Hi Kiran,
It works fine if you change :
x = self.tree.AppendItem(self.connections[i][j][0], "")
to
x = self.tree.AppendItem(self.connections[i][j][0], " ")
I let you imagine the explanation...
Regards,
jm

Just a hint : it'd be helpfull to solve such a bug if you make your
program more simple. To find out the solution, I reduced your program to
what's following, and the light came :

import wx
import wx.gizmos as gizmos

class AlarmsWindow(wx.MDIChildFrame):
def __init__(self, parent, title, size, pos):
wx.MDIChildFrame.__init__(self, parent, -1, title, size = size,
pos =pos)
self.tree = gizmos.TreeListCtrl(self, -1, style =
wx.TR_DEFAULT_STYLE| wx.TR_FULL_ROW_HIGHLIGHT)
# create some columns
self.tree.AddColumn("Connection")
self.tree.AddColumn("Alarm")
self.tree.AddColumn("Value")
self.tree.SetMainColumn(0)

self.root = self.tree.AddRoot("Connections")
self.tree.Expand(self.root)
self.tree.GetMainWindow().Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
self.Show()

child = self.tree.AppendItem(self.root, 'name')
self.tree.SetItemText(child, 'name')
child2= self.tree.AppendItem(child,'name2')
## x = self.tree.AppendItem(child2, "")
x = self.tree.AppendItem(child2, "XXX")
self.tree.SetItemText(x, 'alarm', 1)
self.tree.SetItemText(x, 'value', 2)

def OnRightUp(self, evt):
pass

class MDIFrame(wx.MDIParentFrame):
def __init__(self):
wx.MDIParentFrame.__init__(self, None, -1, "MDI Parent", size
=(600, 400))
child = AlarmsWindow(self, "Alarm", (400, 300), (0, 0))
if __name__=='__main__':
app = wx.PySimpleApp()
frame = MDIFrame()
frame.Show()
app.MainLoop()
Jun 14 '06 #2
Ah, dang. Nice find!

thanks a lot for your help. Also, your note is completely called for.
I realize that my code was very complicated, and I just pasted what I
had instead of simplifying it down. Next time, I will do so.

thanks again!
Kiran

jean-michel bain-cornu wrote:
Kiran a écrit :
Hello all,
I am using a tree to display stuff, and it is constantly updated, but
what I have noticed is in the lowest level, there is clearly noticable
cutoff of the text I place there. The cutoff is existent even if I do
not update the text inside the tree constantly. It seems that the text
is halfway below where it should line up. I tried placing an image to
see if that would correct it, but it does not. The image is perfectly
lined up, but the text is still misaligned.

Any known issues of this and how to fix it? By the way, it happens in
both Linux and Windows.

Hi Kiran,
It works fine if you change :
x = self.tree.AppendItem(self.connections[i][j][0], "")
to
x = self.tree.AppendItem(self.connections[i][j][0], " ")
I let you imagine the explanation...
Regards,
jm

Just a hint : it'd be helpfull to solve such a bug if you make your
program more simple. To find out the solution, I reduced your program to
what's following, and the light came :

import wx
import wx.gizmos as gizmos

class AlarmsWindow(wx.MDIChildFrame):
def __init__(self, parent, title, size, pos):
wx.MDIChildFrame.__init__(self, parent, -1, title, size = size,
pos =pos)
self.tree = gizmos.TreeListCtrl(self, -1, style =
wx.TR_DEFAULT_STYLE| wx.TR_FULL_ROW_HIGHLIGHT)
# create some columns
self.tree.AddColumn("Connection")
self.tree.AddColumn("Alarm")
self.tree.AddColumn("Value")
self.tree.SetMainColumn(0)

self.root = self.tree.AddRoot("Connections")
self.tree.Expand(self.root)
self.tree.GetMainWindow().Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
self.Show()

child = self.tree.AppendItem(self.root, 'name')
self.tree.SetItemText(child, 'name')
child2= self.tree.AppendItem(child,'name2')
## x = self.tree.AppendItem(child2, "")
x = self.tree.AppendItem(child2, "XXX")
self.tree.SetItemText(x, 'alarm', 1)
self.tree.SetItemText(x, 'value', 2)

def OnRightUp(self, evt):
pass

class MDIFrame(wx.MDIParentFrame):
def __init__(self):
wx.MDIParentFrame.__init__(self, None, -1, "MDI Parent", size
=(600, 400))
child = AlarmsWindow(self, "Alarm", (400, 300), (0, 0))
if __name__=='__main__':
app = wx.PySimpleApp()
frame = MDIFrame()
frame.Show()
app.MainLoop()


Jun 14 '06 #3

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

Similar topics

0
by: Brendan | last post by:
Hello, I am looking for any pointers on creating a Tree control which can render html snippets as labels. On each leaf of the tree I want to show text, but with more formatting than is...
15
by: Grant Edwards | last post by:
Can anybody recommend a good book on wxPython? Are there any books on wxPython? I've been trying to learn wxPython and/or wax for a few weeks, and I'm just not getting it. wxWindows seems...
1
by: dberlin | last post by:
Hi, I'm building a modest GUI editor for myself using wxPython, and I need some help. I want to create a nice 'Control Property Editing Window', just like VisualBasic, Delphi, Visual C++, etc....
0
by: Mark Johnson | last post by:
The last reply got sort of cutoff. So here again: So for anyone interested, here's the simple regexp patterns for the substitutions required. The textbox control is being 'zoomed' in a popup...
12
by: vivainio | last post by:
I rarely do GUIs, and reminded myself today why that is the case (simply, it's not fun). I implemented a simple TreeCtrl, and had to implement my own 'children' method, of all things! Here it...
9
by: raylopez99 | last post by:
What's the best way of implementing a multi-node tree in C++? What I'm trying to do is traverse a tree of possible chess moves given an intial position (at the root of the tree). Since every...
2
by: OpenPavilion | last post by:
Hello, did anyone succeed in combining wxpython and a 3d engine (pyogre, crystalblend, panda3d, soya etc.) ? I would like to create an application, which uses wxpython tree, menu and grid...
2
by: Rick Muller | last post by:
I'm a computational chemist who frequently dabbles in Python. A collaborator sent me a huge XML file that at one point was evidently modified by a now defunct java application. A sample of this...
16
by: Andrea Gavana | last post by:
Hi Diez & All, Do you mind explaining "why" you find it *buttugly*? I am asking just out of curiosity, obviously. I am so biased towards wxPython that I won't make any comment on this thread...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.