hi to everybody,
preamble:
I'm not a skilled programmer (at least not for the pc world), I'm learning python and wx from few months.
I'm learning all the stuff starting from OOP and to do it I'm trying to do a program to visualize Unitechnik files (it seems to me there are no free viewer for it) and I aim to do it OS.
Not at least sorry for my bad english.
What I'm looking over here is to ask if does exist such a way to draw geometric entity in the video and to store them as object, and as object if it is possible to change their properties programatically.
Another question is if is possible to keep some reference in a tree view as to identify clearly what have generated it.
Trying to be more clear. I parse a file who describe some geometric entity, they are hierarchically structured, I like to show the structure in a tree and to show such entity in another part of the windows, letting the user to highlight the entity selecting or passing over the tree structure. I'd like also to understand how to keep the shape of those entity on windows resizing, I saw ogl but it seems not to return objects (as wx.DX I done in the example) and it seems to be more pretentious on package installed.
As is now the progrom (the full one not the only example) work correctly and in the same manner in the three platofrm I tested [Windows (XP and Vista), Linux (Debian and Ubuntu) and MACOS (Leopard)] and I like it to be multiplatform (One of the most reason why I'm trying to learn python and wxpython)
To be more clear I've attached a simplified example of what I'm trying to do but a lot of things are missing.
Hope to have explained in an enought clear way what I?m looking to do, Hope somebody have time and like to answer on this thread.
TIA
------------------------------------------------------------------------
#!/usr/bin/env python
# -*- coding: utf-8 -*-
""" Sample code for drawing object """
head =[{'main': 'value main1', 'item1' :'value item1_1', 'item2' : 'value item2_1',
'item3': {'sub3_1': 'value sub3_1', 'sub3_2': [
{'num_points': '5', 'x0':'0', 'y0':'0', 'x1':'100', 'y1':'0', 'x2':'100',
'y2':'100', 'x3':'0', 'y3':'100', 'x4':'0', 'y4':'0', 'geo_name':'rect1'},
{'num_points': '5', 'x0':'10', 'y0':'10', 'x1':'90', 'y1':'10', 'x2':'90',
'y2':'90', 'x3':'10', 'y3':'90', 'x4':'10', 'y4':'10', 'geo_name':'rect2'}],
'sub3_3' : 'value sub3_3'}},
{'main': 'value main2', 'item1' :'value item1_2', 'item2' : 'value item2_2',
'item3': {'sub3_1': 'value sub3_2', 'sub3_2': [
{'num_points': '5', 'x0':'110', 'y0':'0', 'x1':'210', 'y1':'0', 'x2':'210',
'y2':'100', 'x3':'110', 'y3':'100', 'x4':'110', 'y4':'0', 'geo_name':'rect3'},
{'num_points': '5', 'x0':'120', 'y0':'10', 'x1':'200', 'y1':'10', 'x2':'200',
'y2':'90', 'x3':'120', 'y3':'90', 'x4':'120', 'y4':'10', 'geo_name':'rect4'}],
'sub3_3' : 'value sub3_3'}}]
import wx
import os
import sys
class Application(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, "tree graphics example", size =(700, 350))
finestre = self.finestreVerticali() # creo le finestre
self.root = self.tree.AddRoot('example')
indice = 0
keys = ('item1', 'item2', 'item3')
while indice < len(head):
self.header = head[indice]['main']
self.item3key = self.addItem(self.tree, self.root, self.header)
for values in keys:
if values != 'item3': # all but item3
self.addItem(self.tree, self.item3key, (values + ": " + head[indice][values]))
else:
self.item3date = self.addItem(self.tree, self.item3key, 'item3') # explore list of dictionary on item3
index = 0
self.sub3_2key=
for sub in head[indice][values]:
item3 = 0
if sub != 'sub3_2': # all but sub3_2
self.sub3_2key.append(self.addItem(self.tree, self.item3date, (sub + ": " + head[indice][values][sub])))
else: # sub3_2
self.sub3_2key.append(self.addItem(self.tree, self.item3date, sub))
sub3_2 = 0
self.sub3_2=
while sub3_2 < len(head[indice][values]['sub3_2']):
self.sub3_2.append(self.addItem(self.tree, self.sub3_2key[index], 'sub3_2' + '_' + head[indice][values][sub][sub3_2]['geo_name']))
n_lines = int(head[indice][values][sub][sub3_2]['num_points'])
sub3_2 +=1
index += 1
indice = indice + 1
self.tree.Expand(self.item3key)
self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnSelChanged, self.tree)
self.dx.Bind(wx.EVT_PAINT, self.onPaint) self.tree.Expand(self.root)
def onPaint(self, event):
self.maxWidth = 1000
self.maxHeight = 1000
self.SetVirtualSize((self.maxWidth, self.maxHeight))
self.buffer = wx.EmptyBitmap(self.maxWidth, self.maxHeight)
dc = wx.BufferedDC(None, self.buffer)
dc.BeginDrawing()
dc.SetPen(wx.Pen('WHITE'))
dc.SetBrush(wx.LIGHT_GREY_BRUSH)
self.size = self.dx.GetSize()
self.xsize = self.size[0]
self.ysize = self.size[1]
self.xscale = self.yscale = 1
if ((self.xsize*1.0) / (self.ysize*1.0)) > 2:
self.xscale = self.xsize / 300.0
self.yscale = self.xscale
else:
self.xscale = self.ysize / 150.0
self.yscale = self.xscale
index = 0
while index < len(head):
sub3_2 = 0
while sub3_2 < len(head[index]['item3']['sub3_2']):
n_lines = int(head[index]['item3']['sub3_2'][sub3_2]['num_points'])
p_sub3_2 = 1
while p_sub3_2 < n_lines:
x0 = 30.0 + self.xscale * int(head[index]['item3']['sub3_2'][sub3_2]['x' + str(p_sub3_2-1)])
y0 = 15.0 + self.xscale * int(head[index]['item3']['sub3_2'][sub3_2]['y' + str(p_sub3_2-1)])
x1 = 30.0 + self.xscale * int(head[index]['item3']['sub3_2'][sub3_2]['x' + str(p_sub3_2)])
y1 = 15.0 + self.xscale * int(head[index]['item3']['sub3_2'][sub3_2]['y' + str(p_sub3_2)])
dc.DrawLine(x0,y0,x1,y1)
p_sub3_2 += 1
sub3_2 +=1
index += 1
dc.EndDrawing()
dc = wx.BufferedPaintDC(self.dx, self.buffer, wx.BUFFER_VIRTUAL_AREA)
def OnSelChanged(self, evt):
self.sp.statusbar.SetStatusText('Item Selected: ' + self.GetItemText(evt.GetItem()))
#print "OnSelChanged: ", self.GetItemText(evt.GetItem())
def GetItemText(self, item):
if item:
return self.tree.GetItemText(item)
else:
return ""
def onResize(self, event):
self.coords = self.dx.GetSize()
self.sp.statusbar.SetStatusText((str(self.coords[0]) + ', ' + str(self.coords[1])),1)
self.onPaint(event)
#print self.dx.GetSize()
def addItem(self, tree, item, itemLabel):
return tree.AppendItem(item, itemLabel)
def finestreVerticali(self):
self.sp = wx.SplitterWindow(self, style=wx.EXPAND|wx.SP_LIVE_UPDATE)
self.sp.statusbar = self.CreateStatusBar()
self.sp.statusbar.SetFieldsCount(2)
self.sp.statusbar.SetStatusWidths([-3, -1])
self.sx = wx.Panel(self.sp, style = wx.SUNKEN_BORDER)
self.dx = wx.Panel(self.sp, style = wx.SUNKEN_BORDER)
self.dx.Bind(wx.EVT_SIZE, self.onResize)
self.tree = wx.TreeCtrl(self.sx)
self.box = wx.BoxSizer(wx.VERTICAL)
self.box.Add(self.tree, 2, wx.EXPAND)
self.sx.SetSizer(self.box)
self.sp.Initialize(self.sx)
self.sp.Initialize(self.dx)
self.sp.SetMinimumPaneSize(10)
self.sp.SplitVertically(self.sx, self.dx, 200)
if __name__ == '__main__':
app = wx.App()
frame = Application()
frame.Show()
app.MainLoop()