Hi!
Thanks for the answers but I have still some question / problems.
-
I need the text to be able copy out from the window (thats why actually
I don’t wanted to draw it). Is this possible with the wxDC? -
I need to cut everything after certain length. Now I draw everything in one line but
this is not very nice for the user, since my drawing is very long. So e.g. 100 chars. text, the corresponding arrows in the next line again 100 char text and so on. Is there any way to cut the “ready full length line” after it’s? -
I want to put a specific label to the arrows over dc.DrawLabel, but it dosen’t work somehow.
There is allways one and the same text written.
Here a quick example (arrow is shown as a rectangle):
import wx
class SketchWindow(wx.Window):
def init(self, parent, ID):
wx.Window.init(self, parent, ID)
self.SetBackgroundColour("White")
self.color = "Black"
self.thickness = 1
self.pen = wx.Pen(self.color, self.thickness, wx.SOLID)
self.lines = []
self.curLine = []
self.pos = (0, 0)
self.InitBuffer()
self.Bind(wx.EVT_SIZE, self.OnSize)
self.Bind(wx.EVT_IDLE, self.OnIdle)
self.Bind(wx.EVT_PAINT, self.OnPaint)
def InitBuffer(self):
size = self.GetClientSize()
self.buffer = wx.EmptyBitmap(size.width, size.height)
if self.buffer.Ok():
dc = wx.BufferedDC(None, self.buffer)
dc.SetBackground(wx.Brush(self.GetBackgroundColour()))
dc.Clear()
dc.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, "Courier New"))
seq = '''tgaattgtaatacgactcactatagggcgaattgggaatgcgctcgcggtctggaggatcgctctccgctaggctcggtaccggttccctttagtgagggttaatttcga'''
dc.DrawText(seq, 10, 10)
text = '-'
tw, th, space, z = dc.GetFullTextExtent(text)
liste = {'GAATTGTAATACGACTCACTATAGGGCGAA':'T7', 'CCCTTTAGTGAGGGTTAATT':'T3'}
seq = seq.upper()
#for i in liste:
for i in liste.iterkeys():
for x in liste.itervalues():
pos = seq.find(i)
length = (len(i) * tw) - space
pos_rec = (pos * tw) + tw
dc.SetBrush(wx.RED_BRUSH)
rect = wx.Rect(pos_rec, 50, length, 20)
dc.DrawRectangle(pos_rec, 50, length, 20)
dc.DrawLabel(x,
rect, wx.ALIGN_CENTER | wx.ALIGN_TOP)
self.reInitBuffer = False
def OnSize(self, event):
self.reInitBuffer = True
def OnIdle(self, event):
if self.reInitBuffer:
self.InitBuffer()
self.Refresh(False)
def OnPaint(self, event):
dc = wx.BufferedPaintDC(self, self.buffer)
class SketchFrame(wx.Frame):
def init(self, parent):
wx.Frame.init(self, parent, -1, “Sketch Frame”,
size=(800,600))
self.sketch = SketchWindow(self, -1)
if name == ‘main’:
app = wx.PySimpleApp()
frame = SketchFrame(None)
frame.Show(True)
app.MainLoop()
Thanks again in advance!
Stefanie