wxPython, tree Control text cutoff

K

Kiran

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 == 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 == connection:
# find the register
for j in range(1, len(self.connections)):
if self.tree.GetItemText((self.connections[j])[0]) == register:

x = self.tree.AppendItem(self.connections[j][0], "")
self.connections[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 == connection:
# find the register
for j in range(1, len(self.connections)):
if self.tree.GetItemText(self.connections[j][0]) == register:
# find the alarm
for k in range(1, len(self.connections[j])):
if self.connections[j][k][1] == alarm:
self.tree.SetItemImage(self.connections[j][k][0],
self.fileidx, wx.TreeItemIcon_Normal)
self.tree.SetItemText(self.connections[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()
 
J

jean-michel bain-cornu

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[j][0], "")
to
x = self.tree.AppendItem(self.connections[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()
 
K

Kiran

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 said:
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[j][0], "")
to
x = self.tree.AppendItem(self.connections[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()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top