Dear All but most probably wayne and co
Happy new year
Ok so I didn’t do quite what I said i would in my last message, instead I went straight into trying to get a TkHandler to draw into a canvas to see if I could get a handler setup properly from scratch.
The code I have is attached at the bottom. However, it has a couple of problems
1. I seem to be losing expose events under osx (this seems to be a problem with the python version shipped with the ccpnmr distribution I have (2.4.0) Is this a real bug and if so is it fixed in a later update (I see all the expose events with python 2.7.5 from homebrew
2. more importantly this doesn’t seem to draw a line on screen (it does however change the background to red so the handler isn’t completely dead;-)
note I specifically didn’t indulge in doing double buffering so as to reduce the number of unknowns…
regards
gary
test_3.py
from ccpnmr.analysis.core import Util
from Tkinter import Canvas,Tk,mainloop
try:
import memops.c.GlHandler as GlHandler
except:
GlHandler = None
try:
import memops.c.TkHandler as TkHandler
except:
TkHandler = None
if (not GlHandler and not TkHandler):
print 'Error, the WindowFrame module will not work, something is wrong with both the GlHandler and TkHandler C code.'
def getArgServerProject(argServer):
return argServer.parent.project
class Patch(Canvas):
def expose(self,event):
#print 'in expose', event.serial
self.after_idle(self.drawAll)
def drawAll(self):
handler = self.handler
# canvas.doubleBuffer = False
handler.setIsDoubleBuffer(0)
handler.mapRanges(0,0,1,1,0,0,1,1)
handler.makeCurrent()
handler.clearXor()
handler.startFront()
# handler.mapRanges(0,0,1,1,0,0,1,1)
handler.expose(0, 0, self.winfo_width(), self.winfo_height())
self.doCanvas(handler)
handler.flush()
def doCanvas(self, handler):
handler.setBackground((1,0,0))
handler.setColor((1,1,1))
handler.drawLine(0,0,200,200)
pass
def __init__(self,parent):
Canvas.__init__(self,parent)
if TkHandler and not GlHandler:
handlerClass = TkHandler.TkHandler
useGl = False
elif GlHandler and not TkHandler:
handlerClass = GlHandler.GlHandler
useGl = True
elif GlHandler and TkHandler:
graphicsHandler = 'Tk'
if (graphicsHandler == 'OpenGL'):
handlerClass = GlHandler.GlHandler
useGl = True
else:
handlerClass = TkHandler.TkHandler
useGl = False
else:
useGl = False # arbitrary
handlerClass = None
if useGl:
if hasattr(self.topPopup, 'glDirect'):
handlerArgs = (self.topPopup.glDirect,)
else:
handlerArgs = ()
handlerExc = GlHandler.error
# below was for when we had GL_EQUIV
#handlerXorColor = (0.0, 0.0, 0.0)
# below is for GL_XOR
handlerXorColor = (1.0, 1.0, 1.0)
else:
handlerArgs = ()
handlerExc = TkHandler and TkHandler.error
handlerXorColor = (1.0, 1.0, 1.0)
self.handlerClass = handlerClass
self.handlerArgs = handlerArgs
self.handlerExc = handlerExc
self.handlerXorColor = handlerXorColor # for xor mode
print 'graphics setup', self.handlerClass, self.handlerArgs, self.handlerExc, self.handlerXorColor
self.handler = self.handlerClass(self, *self.handlerArgs)
self.bind('<Expose>',self.expose)
def test_3(argServer):
top = argServer.parent
project = getArgServerProject(argServer)
analysisProject = Util.getAnalysisProject(project)
patch = Patch(None)
if (__name__ == '__main__'):
root = Tk()
c = Patch (root)
c.pack()
mainloop()
--
-------------------------------------------------------------------
Dr Gary Thompson [Leeds Biological NMR Facility]
Astbury Centre for Structural Molecular Biology,
University of Leeds,
Leeds, LS2 9JT, West-Yorkshire, UK Tel. +44-113-3433024
email: [log in to unmask]<mailto:[log in to unmask]> Fax +44-113-3431935
-------------------------------------------------------------------
On 10 Dec 2014, at 21:02, Gary Thompson <[log in to unmask]<mailto:[log in to unmask]>> wrote:
On 3 Dec 2014, at 17:33, Wayne Boucher <[log in to unmask]<mailto:[log in to unmask]><mailto:[log in to unmask]>> wrote:
The main requirement is to be a subclass of core/WindowDraw. That's what the printing does, for example, and if you were keen on Qt (or whatever) then that would be the way to go (although obviously all the dialogs are in Tk). But if you mean using Tk then quite probably subclassing WindowPopup (or WindowFrame) would be the way to go. (And we haven't tried this so if you subclassed WindowFrame likely you would hit the odd bug.)
Hi Wayne and All
questions (always questions ;-))
Firstly what is the difference between a windFrame and a widowpopup?
Secondly I am still stuck with the problem with SpectrumWindow the following macros demonstrates it nicely.
from ccpnmr.api.Analysis import SpectrumWindow
from ccpnmr.analysis.core import Util
def getArgServerProject(argServer):
return argServer.parent.project
def test_2(argServer):
top = argServer.parent
project = getArgServerProject(argServer)
analysisProject = Util.getAnalysisProject(project)
spectrumWindow = SpectrumWindow(analysisProject, name ='test22’)
running the script results in the following
[cid:74556BA3-D267-4F72-BB43-F3B08DDFF86A]
I guess the answer is to now go and attempt a direct subclass of windowDraw but unfortunately I appear to be stymied again as the constructor for windowDraw is def __init__(self, parent, windowPane)… so yet again I need a windowPane…. which is a SpectrumWindow
regards
gary
Wayne
On 3 Dec 2014, at 17:16, Gary Thompson wrote:
Hi wayne and all
a low level question is it possible to draw a spectrum in a class/widget that isn't a subclass of windowPopup...
if so can someone guide me ;-)
regards
gary
--
-------------------------------------------------------------------
Dr Gary Thompson [Leeds Biological NMR Facility]
Astbury Centre for Structural Molecular Biology,
University of Leeds,
Leeds, LS2 9JT, West-Yorkshire, UK Tel. +44-113-3433024
email: [log in to unmask]<mailto:[log in to unmask]><mailto:[log in to unmask]> Fax +44-113-3431935
-------------------------------------------------------------------
--
-------------------------------------------------------------------
Dr Gary Thompson [Leeds Biological NMR Facility]
Astbury Centre for Structural Molecular Biology,
University of Leeds,
Leeds, LS2 9JT, West-Yorkshire, UK Tel. +44-113-3433024
email: [log in to unmask]<mailto:[log in to unmask]><mailto:[log in to unmask]> Fax +44-113-3431935
-------------------------------------------------------------------
<CapturFiles.png>
|