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.MDIChildFram e.__init__(self , parent, -1, title, size = size, pos =
pos)
self.tree = gizmos.TreeList Ctrl(self, -1, style = wx.TR_DEFAULT_S TYLE
| wx.TR_FULL_ROW_ HIGHLIGHT)
# images of the tree
isz = (16,16)
il = wx.ImageList(is z[0], isz[1])
self.fldridx = il.Add(wx.ArtPr ovider_GetBitma p(wx.ART_FOLDER ,
wx.ART_OTHER, isz))
self.fldropenid x = il.Add(wx.ArtPr ovider_GetBitma p(wx.ART_FILE_O PEN,
wx.ART_OTHER, isz))
self.fileidx =
il.Add(wx.ArtPr ovider_GetBitma p(wx.ART_NORMAL _FILE, wx.ART_OTHER, isz))
self.selidx = il.Add(wx.ArtPr ovider_GetBitma p(wx.ART_CROSS_ MARK,
wx.ART_OTHER, isz))
self.tree.SetIm ageList(il)
self.il = il
# create some columns
self.tree.AddCo lumn("Connectio n")
self.tree.AddCo lumn("Alarm")
self.tree.AddCo lumn("Value")
self.tree.SetMa inColumn(0)
self.root = self.tree.AddRo ot("Connections ")
self.tree.SetIt emImage(self.ro ot, self.fldridx, which =
wx.TreeItemIcon _Normal)
self.tree.SetIt emImage(self.ro ot, self.fldropenid x, which =
wx.TreeItemIcon _Expanded)
self.connection sName = []
self.connection s = []
self.registers = []
self.tree.Expan d(self.root)
self.tree.GetMa inWindow().Bind (wx.EVT_RIGHT_U P, self.OnRightUp)
self.Show()
# testing
self.AddConnect ion("Dummy")
self.AddRegiste r("Dummy", "R5")
self.AddAlarm(" Dummy", "R5", "LOA", "10")
self.UpdateAlar m("Dummy", "R5", "LOA", "14")
self.AddAlarm(" Dummy", "R5", "LOS", "1354")
self.AddRegiste r("Dummy", "R6")
self.AddAlarm(" Dummy", "R6", "LOA", "15")
self.AddConnect ion("DUMMY @#2")
self.AddRegiste r("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.HitTe st(pos)
if item:
print('Flags: %s, Col:%s, Text: %s' %
(flags, col, self.tree.GetIt emText(item,
col)))
# tree control
def OnSize(self, evt):
self.tree.SetSi ze(self.GetSize ())
# adds a section to the logger
def AddConnection(s elf, name):
self.connection sName.append(na me)
self.connection s.append([])
child = self.tree.Appen dItem(self.root , name)
self.connection s[(len(self.conne ctionsName)-1)].append(child)
self.tree.SetIt emText(child, name)
self.tree.SetIt emImage(child, self.fldridx, which =
wx.TreeItemIcon _Normal)
self.tree.SetIt emImage(child, self.fldropenid x, which =
wx.TreeItemIcon _Expanded)
# adds a register
def AddRegister(sel f, connection, name):
# find the connection
index = -1
for i in range(len(self. connectionsName )):
if self.connection sName[i] == connection:
index = i
break
if index != -1:
self.connection s[index].append([self.tree.Appen dItem(self.conn ections[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.connection sName[i] == connection:
# find the register
for j in range(1, len(self.connec tions[i])):
if self.tree.GetIt emText((self.co nnections[i][j])[0]) == register:
x = self.tree.Appen dItem(self.conn ections[i][j][0], "")
self.connection s[i][j].append([x, alarm])
self.tree.SetIt emImage(x, self.fileidx, wx.TreeItemIcon _Normal)
self.tree.SetIt emText(x, alarm, 1)
self.tree.SetIt emText(x, value, 2)
# updates the alarm's window
def UpdateAlarm(sel f, connection, register, alarm, value):
# find the connection
for i in range(len(self. connectionsName )):
if self.connection sName[i] == connection:
# find the register
for j in range(1, len(self.connec tions[i])):
if self.tree.GetIt emText(self.con nections[i][j][0]) == register:
# find the alarm
for k in range(1, len(self.connec tions[i][j])):
if self.connection s[i][j][k][1] == alarm:
self.tree.SetIt emImage(self.co nnections[i][j][k][0],
self.fileidx, wx.TreeItemIcon _Normal)
self.tree.SetIt emText(self.con nections[i][j][k][0], value, 2)
return
class MDIFrame(wx.MDI ParentFrame):
def __init__(self):
wx.MDIParentFra me.__init__(sel f, None, -1, "MDI Parent", size =
(600, 400))
child = AlarmsWindow(se lf, "Alarm", (400, 300), (0, 0))
if __name__=='__ma in__':
app = wx.PySimpleApp( )
frame = MDIFrame()
frame.Show()
app.MainLoop()
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.MDIChildFram e.__init__(self , parent, -1, title, size = size, pos =
pos)
self.tree = gizmos.TreeList Ctrl(self, -1, style = wx.TR_DEFAULT_S TYLE
| wx.TR_FULL_ROW_ HIGHLIGHT)
# images of the tree
isz = (16,16)
il = wx.ImageList(is z[0], isz[1])
self.fldridx = il.Add(wx.ArtPr ovider_GetBitma p(wx.ART_FOLDER ,
wx.ART_OTHER, isz))
self.fldropenid x = il.Add(wx.ArtPr ovider_GetBitma p(wx.ART_FILE_O PEN,
wx.ART_OTHER, isz))
self.fileidx =
il.Add(wx.ArtPr ovider_GetBitma p(wx.ART_NORMAL _FILE, wx.ART_OTHER, isz))
self.selidx = il.Add(wx.ArtPr ovider_GetBitma p(wx.ART_CROSS_ MARK,
wx.ART_OTHER, isz))
self.tree.SetIm ageList(il)
self.il = il
# create some columns
self.tree.AddCo lumn("Connectio n")
self.tree.AddCo lumn("Alarm")
self.tree.AddCo lumn("Value")
self.tree.SetMa inColumn(0)
self.root = self.tree.AddRo ot("Connections ")
self.tree.SetIt emImage(self.ro ot, self.fldridx, which =
wx.TreeItemIcon _Normal)
self.tree.SetIt emImage(self.ro ot, self.fldropenid x, which =
wx.TreeItemIcon _Expanded)
self.connection sName = []
self.connection s = []
self.registers = []
self.tree.Expan d(self.root)
self.tree.GetMa inWindow().Bind (wx.EVT_RIGHT_U P, self.OnRightUp)
self.Show()
# testing
self.AddConnect ion("Dummy")
self.AddRegiste r("Dummy", "R5")
self.AddAlarm(" Dummy", "R5", "LOA", "10")
self.UpdateAlar m("Dummy", "R5", "LOA", "14")
self.AddAlarm(" Dummy", "R5", "LOS", "1354")
self.AddRegiste r("Dummy", "R6")
self.AddAlarm(" Dummy", "R6", "LOA", "15")
self.AddConnect ion("DUMMY @#2")
self.AddRegiste r("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.HitTe st(pos)
if item:
print('Flags: %s, Col:%s, Text: %s' %
(flags, col, self.tree.GetIt emText(item,
col)))
# tree control
def OnSize(self, evt):
self.tree.SetSi ze(self.GetSize ())
# adds a section to the logger
def AddConnection(s elf, name):
self.connection sName.append(na me)
self.connection s.append([])
child = self.tree.Appen dItem(self.root , name)
self.connection s[(len(self.conne ctionsName)-1)].append(child)
self.tree.SetIt emText(child, name)
self.tree.SetIt emImage(child, self.fldridx, which =
wx.TreeItemIcon _Normal)
self.tree.SetIt emImage(child, self.fldropenid x, which =
wx.TreeItemIcon _Expanded)
# adds a register
def AddRegister(sel f, connection, name):
# find the connection
index = -1
for i in range(len(self. connectionsName )):
if self.connection sName[i] == connection:
index = i
break
if index != -1:
self.connection s[index].append([self.tree.Appen dItem(self.conn ections[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.connection sName[i] == connection:
# find the register
for j in range(1, len(self.connec tions[i])):
if self.tree.GetIt emText((self.co nnections[i][j])[0]) == register:
x = self.tree.Appen dItem(self.conn ections[i][j][0], "")
self.connection s[i][j].append([x, alarm])
self.tree.SetIt emImage(x, self.fileidx, wx.TreeItemIcon _Normal)
self.tree.SetIt emText(x, alarm, 1)
self.tree.SetIt emText(x, value, 2)
# updates the alarm's window
def UpdateAlarm(sel f, connection, register, alarm, value):
# find the connection
for i in range(len(self. connectionsName )):
if self.connection sName[i] == connection:
# find the register
for j in range(1, len(self.connec tions[i])):
if self.tree.GetIt emText(self.con nections[i][j][0]) == register:
# find the alarm
for k in range(1, len(self.connec tions[i][j])):
if self.connection s[i][j][k][1] == alarm:
self.tree.SetIt emImage(self.co nnections[i][j][k][0],
self.fileidx, wx.TreeItemIcon _Normal)
self.tree.SetIt emText(self.con nections[i][j][k][0], value, 2)
return
class MDIFrame(wx.MDI ParentFrame):
def __init__(self):
wx.MDIParentFra me.__init__(sel f, None, -1, "MDI Parent", size =
(600, 400))
child = AlarmsWindow(se lf, "Alarm", (400, 300), (0, 0))
if __name__=='__ma in__':
app = wx.PySimpleApp( )
frame = MDIFrame()
frame.Show()
app.MainLoop()
Comment