Utiliser FloatCanvas avec wx n'est pas très dur et c'est très stable. Je
l'utilise
pour une appli assez élaborée et j'en suis très content.
Le seul problème, c'est que je n'ai pas vu comment on pouvait exporter
le contenu du Canvas ?
Y a-t-il un genre de 'canvas.postscript(file="your_file_name.ps")' comme
sous Tkinter ?
Côté stabilité les plantes sont dues à une mauvaise utilisation plutôt
qu'à
un pb
de stabilité de la librairie. Sous windows wx ne plante pas et pourtant
je
l'utilise
de manière assez soutenue.
Je n'ai pas dit le contraire... simplement, les erreurs sont gérées plus
élégamment sous Tkinter. Quand un message s'affiche dans une console,
c'est plus facile pour un débutant comme moi de trouver l'erreur que
quand c'est le système qui plante. ;-)
Utiliser FloatCanvas avec wx n'est pas très dur et c'est très stable. Je
l'utilise
pour une appli assez élaborée et j'en suis très content.
Le seul problème, c'est que je n'ai pas vu comment on pouvait exporter
le contenu du Canvas ?
Y a-t-il un genre de 'canvas.postscript(file="your_file_name.ps")' comme
sous Tkinter ?
Côté stabilité les plantes sont dues à une mauvaise utilisation plutôt
qu'à
un pb
de stabilité de la librairie. Sous windows wx ne plante pas et pourtant
je
l'utilise
de manière assez soutenue.
Je n'ai pas dit le contraire... simplement, les erreurs sont gérées plus
élégamment sous Tkinter. Quand un message s'affiche dans une console,
c'est plus facile pour un débutant comme moi de trouver l'erreur que
quand c'est le système qui plante. ;-)
Utiliser FloatCanvas avec wx n'est pas très dur et c'est très stable. Je
l'utilise
pour une appli assez élaborée et j'en suis très content.
Le seul problème, c'est que je n'ai pas vu comment on pouvait exporter
le contenu du Canvas ?
Y a-t-il un genre de 'canvas.postscript(file="your_file_name.ps")' comme
sous Tkinter ?
Côté stabilité les plantes sont dues à une mauvaise utilisation plutôt
qu'à
un pb
de stabilité de la librairie. Sous windows wx ne plante pas et pourtant
je
l'utilise
de manière assez soutenue.
Je n'ai pas dit le contraire... simplement, les erreurs sont gérées plus
élégamment sous Tkinter. Quand un message s'affiche dans une console,
c'est plus facile pour un débutant comme moi de trouver l'erreur que
quand c'est le système qui plante. ;-)
Utiliser FloatCanvas avec wx n'est pas très dur et c'est très stable. Je
l'utilise
pour une appli assez élaborée et j'en suis très content.
Est-ce que vous auriez un exemple d'utilisation pour que je puisse le
modifier et voir comment ça marche ?
Utiliser FloatCanvas avec wx n'est pas très dur et c'est très stable. Je
l'utilise
pour une appli assez élaborée et j'en suis très content.
Est-ce que vous auriez un exemple d'utilisation pour que je puisse le
modifier et voir comment ça marche ?
Utiliser FloatCanvas avec wx n'est pas très dur et c'est très stable. Je
l'utilise
pour une appli assez élaborée et j'en suis très content.
Est-ce que vous auriez un exemple d'utilisation pour que je puisse le
modifier et voir comment ça marche ?
"Nicolas Pourcelot" a écrit dans le message de
news: 41f922c4$0$2075$Utiliser FloatCanvas avec wx n'est pas très dur et c'est très stable. Je
l'utilise
pour une appli assez élaborée et j'en suis très content.
Est-ce que vous auriez un exemple d'utilisation pour que je puisse le
modifier et voir comment ça marche ?
Je n'ai pas d'exemple simple, mais voici un petit exemple repris et modifié
des démos wx.
(attention, je ne l'ai pas testé... j'ai simplement simplifié le code de la
démo).
Par ailleurs, pour créer et placer les objets wx j'utilise un module que
j'ai développé
qui permet d'utiliser la syntaxe Tk.
Exemple : Button(root, text='button 1', command=handler).pack(side='left',
pady)
Ceci car j'ai programmé pas mal de temps en utilisant Tkinter et je trouvais
la syntaxe
wx moins clair...
import Numeric
import RandomArray
import wx
import time, random
from wx.lib.floatcanvas import NavCanvas, FloatCanvas
import wxPython.lib.colourdb
class DrawFrame(wx.Frame):
"""
A frame used for the FloatCanvas Demo
"""
def __init__(self,parent, id,title,position,size):
wx.Frame.__init__(self,parent, id,title,position, size)
# Add the Canvas
self.Canvas = NavCanvas.NavCanvas(self,
-1,
(500,500),
Debug = 0,
BackgroundColor = "DARK SLATE
BLUE")
## getting all the colors and linestyles for random objects
wxPython.lib.colourdb.updateColourDB()
self.colors = wxPython.lib.colourdb.getColourList()
return None
def DrawTest(self,event=None):
wx.GetApp().Yield()
Range = (-10,10)
colors = self.colors
Canvas = self.Canvas
Canvas.ClearAll()
Canvas.SetProjectionFun(None)
## Random tests of everything:
# Rectangles
for i in range(3):
x,y > (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
lw = random.randint(1,5)
cf = random.randint(0,len(colors)-1)
h = random.randint(1,5)
w = random.randint(1,5)
Canvas.AddRectangle(x,y,w,h,LineWidth = lw,FillColor > colors[cf])
# Ellipses
for i in range(3):
x,y > (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
lw = random.randint(1,5)
cf = random.randint(0,len(colors)-1)
h = random.randint(1,5)
w = random.randint(1,5)
Canvas.AddEllipse(x,y,h,w,LineWidth = lw,FillColor > colors[cf])
# Points
for i in range(5):
x,y > (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
D = random.randint(1,50)
cf = random.randint(0,len(colors)-1)
Canvas.AddPoint((x,y), Color = colors[cf], Diameter = D)
# Circles
for i in range(5):
x,y > (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
D = random.randint(1,5)
lw = random.randint(1,5)
cf = random.randint(0,len(colors)-1)
cl = random.randint(0,len(colors)-1)
Canvas.AddCircle(x,y,D,LineWidth = lw,LineColor > colors[cl],FillColor = colors[cf])
Canvas.AddText("Circle # %i"%(i),x,y,Size > 12,BackgroundColor = None,Position = "cc")
# Lines
for i in range(5):
points = []
for j in range(random.randint(2,10)):
point > (random.randint(Range[0],Range[1]),random.randint(Range[0],Range[1]))
points.append(point)
lw = random.randint(1,10)
cf = random.randint(0,len(colors)-1)
cl = random.randint(0,len(colors)-1)
Canvas.AddLine(points, LineWidth = lw, LineColor > colors[cl])
# Polygons
for i in range(3):
points = []
for j in range(random.randint(2,6)):
point > (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
points.append(point)
lw = random.randint(1,6)
cf = random.randint(0,len(colors)-1)
cl = random.randint(0,len(colors)-1)
Canvas.AddPolygon(points,
LineWidth = lw,
LineColor = colors[cl],
FillColor = colors[cf],
FillStyle = 'Solid')
## Pointset
for i in range(4):
points = []
points = RandomArray.uniform(Range[0],Range[1],(100,2))
cf = random.randint(0,len(colors)-1)
D = random.randint(1,4)
Canvas.AddPointSet(points, Color = colors[cf], Diameter = D)
# Text
String = "Unscaled text"
for i in range(3):
ts = random.randint(10,40)
cf = random.randint(0,len(colors)-1)
x,y > (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
Canvas.AddText(String, x, y, Size = ts, Color = colors[cf],
Position = "cc")
# Scaled Text
String = "Scaled text"
for i in range(3):
ts = random.random()*3 + 0.2
cf = random.randint(0,len(colors)-1)
x,y > (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
Canvas.AddScaledText(String, x, y, Size = ts, Color > colors[cf], Position = "cc")
Canvas.ZoomToBB()
if __name__=='__main__':
win = DrawFrame(None, -1, "FloatCanvas Drawing
Window",wx.DefaultPosition,(500,500))
win.Show(True)
win.DrawTest()
"Nicolas Pourcelot" <baudelaire_2c@yahoo.fr> a écrit dans le message de
news: 41f922c4$0$2075$626a14ce@news.free.fr...
Utiliser FloatCanvas avec wx n'est pas très dur et c'est très stable. Je
l'utilise
pour une appli assez élaborée et j'en suis très content.
Est-ce que vous auriez un exemple d'utilisation pour que je puisse le
modifier et voir comment ça marche ?
Je n'ai pas d'exemple simple, mais voici un petit exemple repris et modifié
des démos wx.
(attention, je ne l'ai pas testé... j'ai simplement simplifié le code de la
démo).
Par ailleurs, pour créer et placer les objets wx j'utilise un module que
j'ai développé
qui permet d'utiliser la syntaxe Tk.
Exemple : Button(root, text='button 1', command=handler).pack(side='left',
pady)
Ceci car j'ai programmé pas mal de temps en utilisant Tkinter et je trouvais
la syntaxe
wx moins clair...
import Numeric
import RandomArray
import wx
import time, random
from wx.lib.floatcanvas import NavCanvas, FloatCanvas
import wxPython.lib.colourdb
class DrawFrame(wx.Frame):
"""
A frame used for the FloatCanvas Demo
"""
def __init__(self,parent, id,title,position,size):
wx.Frame.__init__(self,parent, id,title,position, size)
# Add the Canvas
self.Canvas = NavCanvas.NavCanvas(self,
-1,
(500,500),
Debug = 0,
BackgroundColor = "DARK SLATE
BLUE")
## getting all the colors and linestyles for random objects
wxPython.lib.colourdb.updateColourDB()
self.colors = wxPython.lib.colourdb.getColourList()
return None
def DrawTest(self,event=None):
wx.GetApp().Yield()
Range = (-10,10)
colors = self.colors
Canvas = self.Canvas
Canvas.ClearAll()
Canvas.SetProjectionFun(None)
## Random tests of everything:
# Rectangles
for i in range(3):
x,y > (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
lw = random.randint(1,5)
cf = random.randint(0,len(colors)-1)
h = random.randint(1,5)
w = random.randint(1,5)
Canvas.AddRectangle(x,y,w,h,LineWidth = lw,FillColor > colors[cf])
# Ellipses
for i in range(3):
x,y > (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
lw = random.randint(1,5)
cf = random.randint(0,len(colors)-1)
h = random.randint(1,5)
w = random.randint(1,5)
Canvas.AddEllipse(x,y,h,w,LineWidth = lw,FillColor > colors[cf])
# Points
for i in range(5):
x,y > (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
D = random.randint(1,50)
cf = random.randint(0,len(colors)-1)
Canvas.AddPoint((x,y), Color = colors[cf], Diameter = D)
# Circles
for i in range(5):
x,y > (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
D = random.randint(1,5)
lw = random.randint(1,5)
cf = random.randint(0,len(colors)-1)
cl = random.randint(0,len(colors)-1)
Canvas.AddCircle(x,y,D,LineWidth = lw,LineColor > colors[cl],FillColor = colors[cf])
Canvas.AddText("Circle # %i"%(i),x,y,Size > 12,BackgroundColor = None,Position = "cc")
# Lines
for i in range(5):
points = []
for j in range(random.randint(2,10)):
point > (random.randint(Range[0],Range[1]),random.randint(Range[0],Range[1]))
points.append(point)
lw = random.randint(1,10)
cf = random.randint(0,len(colors)-1)
cl = random.randint(0,len(colors)-1)
Canvas.AddLine(points, LineWidth = lw, LineColor > colors[cl])
# Polygons
for i in range(3):
points = []
for j in range(random.randint(2,6)):
point > (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
points.append(point)
lw = random.randint(1,6)
cf = random.randint(0,len(colors)-1)
cl = random.randint(0,len(colors)-1)
Canvas.AddPolygon(points,
LineWidth = lw,
LineColor = colors[cl],
FillColor = colors[cf],
FillStyle = 'Solid')
## Pointset
for i in range(4):
points = []
points = RandomArray.uniform(Range[0],Range[1],(100,2))
cf = random.randint(0,len(colors)-1)
D = random.randint(1,4)
Canvas.AddPointSet(points, Color = colors[cf], Diameter = D)
# Text
String = "Unscaled text"
for i in range(3):
ts = random.randint(10,40)
cf = random.randint(0,len(colors)-1)
x,y > (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
Canvas.AddText(String, x, y, Size = ts, Color = colors[cf],
Position = "cc")
# Scaled Text
String = "Scaled text"
for i in range(3):
ts = random.random()*3 + 0.2
cf = random.randint(0,len(colors)-1)
x,y > (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
Canvas.AddScaledText(String, x, y, Size = ts, Color > colors[cf], Position = "cc")
Canvas.ZoomToBB()
if __name__=='__main__':
win = DrawFrame(None, -1, "FloatCanvas Drawing
Window",wx.DefaultPosition,(500,500))
win.Show(True)
win.DrawTest()
"Nicolas Pourcelot" a écrit dans le message de
news: 41f922c4$0$2075$Utiliser FloatCanvas avec wx n'est pas très dur et c'est très stable. Je
l'utilise
pour une appli assez élaborée et j'en suis très content.
Est-ce que vous auriez un exemple d'utilisation pour que je puisse le
modifier et voir comment ça marche ?
Je n'ai pas d'exemple simple, mais voici un petit exemple repris et modifié
des démos wx.
(attention, je ne l'ai pas testé... j'ai simplement simplifié le code de la
démo).
Par ailleurs, pour créer et placer les objets wx j'utilise un module que
j'ai développé
qui permet d'utiliser la syntaxe Tk.
Exemple : Button(root, text='button 1', command=handler).pack(side='left',
pady)
Ceci car j'ai programmé pas mal de temps en utilisant Tkinter et je trouvais
la syntaxe
wx moins clair...
import Numeric
import RandomArray
import wx
import time, random
from wx.lib.floatcanvas import NavCanvas, FloatCanvas
import wxPython.lib.colourdb
class DrawFrame(wx.Frame):
"""
A frame used for the FloatCanvas Demo
"""
def __init__(self,parent, id,title,position,size):
wx.Frame.__init__(self,parent, id,title,position, size)
# Add the Canvas
self.Canvas = NavCanvas.NavCanvas(self,
-1,
(500,500),
Debug = 0,
BackgroundColor = "DARK SLATE
BLUE")
## getting all the colors and linestyles for random objects
wxPython.lib.colourdb.updateColourDB()
self.colors = wxPython.lib.colourdb.getColourList()
return None
def DrawTest(self,event=None):
wx.GetApp().Yield()
Range = (-10,10)
colors = self.colors
Canvas = self.Canvas
Canvas.ClearAll()
Canvas.SetProjectionFun(None)
## Random tests of everything:
# Rectangles
for i in range(3):
x,y > (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
lw = random.randint(1,5)
cf = random.randint(0,len(colors)-1)
h = random.randint(1,5)
w = random.randint(1,5)
Canvas.AddRectangle(x,y,w,h,LineWidth = lw,FillColor > colors[cf])
# Ellipses
for i in range(3):
x,y > (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
lw = random.randint(1,5)
cf = random.randint(0,len(colors)-1)
h = random.randint(1,5)
w = random.randint(1,5)
Canvas.AddEllipse(x,y,h,w,LineWidth = lw,FillColor > colors[cf])
# Points
for i in range(5):
x,y > (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
D = random.randint(1,50)
cf = random.randint(0,len(colors)-1)
Canvas.AddPoint((x,y), Color = colors[cf], Diameter = D)
# Circles
for i in range(5):
x,y > (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
D = random.randint(1,5)
lw = random.randint(1,5)
cf = random.randint(0,len(colors)-1)
cl = random.randint(0,len(colors)-1)
Canvas.AddCircle(x,y,D,LineWidth = lw,LineColor > colors[cl],FillColor = colors[cf])
Canvas.AddText("Circle # %i"%(i),x,y,Size > 12,BackgroundColor = None,Position = "cc")
# Lines
for i in range(5):
points = []
for j in range(random.randint(2,10)):
point > (random.randint(Range[0],Range[1]),random.randint(Range[0],Range[1]))
points.append(point)
lw = random.randint(1,10)
cf = random.randint(0,len(colors)-1)
cl = random.randint(0,len(colors)-1)
Canvas.AddLine(points, LineWidth = lw, LineColor > colors[cl])
# Polygons
for i in range(3):
points = []
for j in range(random.randint(2,6)):
point > (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
points.append(point)
lw = random.randint(1,6)
cf = random.randint(0,len(colors)-1)
cl = random.randint(0,len(colors)-1)
Canvas.AddPolygon(points,
LineWidth = lw,
LineColor = colors[cl],
FillColor = colors[cf],
FillStyle = 'Solid')
## Pointset
for i in range(4):
points = []
points = RandomArray.uniform(Range[0],Range[1],(100,2))
cf = random.randint(0,len(colors)-1)
D = random.randint(1,4)
Canvas.AddPointSet(points, Color = colors[cf], Diameter = D)
# Text
String = "Unscaled text"
for i in range(3):
ts = random.randint(10,40)
cf = random.randint(0,len(colors)-1)
x,y > (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
Canvas.AddText(String, x, y, Size = ts, Color = colors[cf],
Position = "cc")
# Scaled Text
String = "Scaled text"
for i in range(3):
ts = random.random()*3 + 0.2
cf = random.randint(0,len(colors)-1)
x,y > (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
Canvas.AddScaledText(String, x, y, Size = ts, Color > colors[cf], Position = "cc")
Canvas.ZoomToBB()
if __name__=='__main__':
win = DrawFrame(None, -1, "FloatCanvas Drawing
Window",wx.DefaultPosition,(500,500))
win.Show(True)
win.DrawTest()
Merci pour ces éléments de réponse...
La librairie FloatCanvas ne répond pas tout à fait à mes besoins, mais
je vais essayer de l'adapter, ça sera déjà mieux que de partir de zéro...
(par exemple, implémenter un export en PNG, implémenter des objets dont
la position soit relative à la taille de la fenêtre)
Le seul truc, c'est que je suis un peu perdu avec ces histoires de
buffer et doubles buffers, et puis le code de la librairie n'est presque
pas commenté... enfin, on va essayer.
Merci bien en tout cas,
Nicolas
PS:
comment faire pour connaître la nouvelle taille du Panel (ou du canvas),
après que j'ai agrandi ma fenêtre ?
"Nicolas Pourcelot" a écrit dans le message de
news: 41f922c4$0$2075$Utiliser FloatCanvas avec wx n'est pas très dur et c'est très stable.
Je
l'utilise
pour une appli assez élaborée et j'en suis très content.
Est-ce que vous auriez un exemple d'utilisation pour que je puisse le
modifier et voir comment ça marche ?
Je n'ai pas d'exemple simple, mais voici un petit exemple repris et
modifié
des démos wx.
(attention, je ne l'ai pas testé... j'ai simplement simplifié le code de
la
démo).
Par ailleurs, pour créer et placer les objets wx j'utilise un module que
j'ai développé
qui permet d'utiliser la syntaxe Tk.
Exemple : Button(root, text='button 1',
command=handler).pack(side='left',
pady)
Ceci car j'ai programmé pas mal de temps en utilisant Tkinter et je
trouvais
la syntaxe
wx moins clair...
import Numeric
import RandomArray
import wx
import time, random
from wx.lib.floatcanvas import NavCanvas, FloatCanvas
import wxPython.lib.colourdb
class DrawFrame(wx.Frame):
"""
A frame used for the FloatCanvas Demo
"""
def __init__(self,parent, id,title,position,size):
wx.Frame.__init__(self,parent, id,title,position, size)
# Add the Canvas
self.Canvas = NavCanvas.NavCanvas(self,
-1,
(500,500),
Debug = 0,
BackgroundColor = "DARK
SLATE
BLUE")
## getting all the colors and linestyles for random objects
wxPython.lib.colourdb.updateColourDB()
self.colors = wxPython.lib.colourdb.getColourList()
return None
def DrawTest(self,event=None):
wx.GetApp().Yield()
Range = (-10,10)
colors = self.colors
Canvas = self.Canvas
Canvas.ClearAll()
Canvas.SetProjectionFun(None)
## Random tests of everything:
# Rectangles
for i in range(3):
x,y > > (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
lw = random.randint(1,5)
cf = random.randint(0,len(colors)-1)
h = random.randint(1,5)
w = random.randint(1,5)
Canvas.AddRectangle(x,y,w,h,LineWidth = lw,FillColor > > colors[cf])
# Ellipses
for i in range(3):
x,y > > (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
lw = random.randint(1,5)
cf = random.randint(0,len(colors)-1)
h = random.randint(1,5)
w = random.randint(1,5)
Canvas.AddEllipse(x,y,h,w,LineWidth = lw,FillColor > > colors[cf])
# Points
for i in range(5):
x,y > > (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
D = random.randint(1,50)
cf = random.randint(0,len(colors)-1)
Canvas.AddPoint((x,y), Color = colors[cf], Diameter = D)
# Circles
for i in range(5):
x,y > > (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
D = random.randint(1,5)
lw = random.randint(1,5)
cf = random.randint(0,len(colors)-1)
cl = random.randint(0,len(colors)-1)
Canvas.AddCircle(x,y,D,LineWidth = lw,LineColor > > colors[cl],FillColor = colors[cf])
Canvas.AddText("Circle # %i"%(i),x,y,Size > > 12,BackgroundColor = None,Position = "cc")
# Lines
for i in range(5):
points = []
for j in range(random.randint(2,10)):
point > > (random.randint(Range[0],Range[1]),random.randint(Range[0],Range[1]))
points.append(point)
lw = random.randint(1,10)
cf = random.randint(0,len(colors)-1)
cl = random.randint(0,len(colors)-1)
Canvas.AddLine(points, LineWidth = lw, LineColor > > colors[cl])
# Polygons
for i in range(3):
points = []
for j in range(random.randint(2,6)):
point > > (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
points.append(point)
lw = random.randint(1,6)
cf = random.randint(0,len(colors)-1)
cl = random.randint(0,len(colors)-1)
Canvas.AddPolygon(points,
LineWidth = lw,
LineColor = colors[cl],
FillColor = colors[cf],
FillStyle = 'Solid')
## Pointset
for i in range(4):
points = []
points = RandomArray.uniform(Range[0],Range[1],(100,2))
cf = random.randint(0,len(colors)-1)
D = random.randint(1,4)
Canvas.AddPointSet(points, Color = colors[cf], Diameter
= D)
# Text
String = "Unscaled text"
for i in range(3):
ts = random.randint(10,40)
cf = random.randint(0,len(colors)-1)
x,y > > (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
Canvas.AddText(String, x, y, Size = ts, Color colors[cf],
Position = "cc")
# Scaled Text
String = "Scaled text"
for i in range(3):
ts = random.random()*3 + 0.2
cf = random.randint(0,len(colors)-1)
x,y > > (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
Canvas.AddScaledText(String, x, y, Size = ts, Color > > colors[cf], Position = "cc")
Canvas.ZoomToBB()
if __name__=='__main__':
win = DrawFrame(None, -1, "FloatCanvas Drawing
Window",wx.DefaultPosition,(500,500))
win.Show(True)
win.DrawTest()
Merci pour ces éléments de réponse...
La librairie FloatCanvas ne répond pas tout à fait à mes besoins, mais
je vais essayer de l'adapter, ça sera déjà mieux que de partir de zéro...
(par exemple, implémenter un export en PNG, implémenter des objets dont
la position soit relative à la taille de la fenêtre)
Le seul truc, c'est que je suis un peu perdu avec ces histoires de
buffer et doubles buffers, et puis le code de la librairie n'est presque
pas commenté... enfin, on va essayer.
Merci bien en tout cas,
Nicolas
PS:
comment faire pour connaître la nouvelle taille du Panel (ou du canvas),
après que j'ai agrandi ma fenêtre ?
"Nicolas Pourcelot" <baudelaire_2c@yahoo.fr> a écrit dans le message de
news: 41f922c4$0$2075$626a14ce@news.free.fr...
Utiliser FloatCanvas avec wx n'est pas très dur et c'est très stable.
Je
l'utilise
pour une appli assez élaborée et j'en suis très content.
Est-ce que vous auriez un exemple d'utilisation pour que je puisse le
modifier et voir comment ça marche ?
Je n'ai pas d'exemple simple, mais voici un petit exemple repris et
modifié
des démos wx.
(attention, je ne l'ai pas testé... j'ai simplement simplifié le code de
la
démo).
Par ailleurs, pour créer et placer les objets wx j'utilise un module que
j'ai développé
qui permet d'utiliser la syntaxe Tk.
Exemple : Button(root, text='button 1',
command=handler).pack(side='left',
pady)
Ceci car j'ai programmé pas mal de temps en utilisant Tkinter et je
trouvais
la syntaxe
wx moins clair...
import Numeric
import RandomArray
import wx
import time, random
from wx.lib.floatcanvas import NavCanvas, FloatCanvas
import wxPython.lib.colourdb
class DrawFrame(wx.Frame):
"""
A frame used for the FloatCanvas Demo
"""
def __init__(self,parent, id,title,position,size):
wx.Frame.__init__(self,parent, id,title,position, size)
# Add the Canvas
self.Canvas = NavCanvas.NavCanvas(self,
-1,
(500,500),
Debug = 0,
BackgroundColor = "DARK
SLATE
BLUE")
## getting all the colors and linestyles for random objects
wxPython.lib.colourdb.updateColourDB()
self.colors = wxPython.lib.colourdb.getColourList()
return None
def DrawTest(self,event=None):
wx.GetApp().Yield()
Range = (-10,10)
colors = self.colors
Canvas = self.Canvas
Canvas.ClearAll()
Canvas.SetProjectionFun(None)
## Random tests of everything:
# Rectangles
for i in range(3):
x,y > > (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
lw = random.randint(1,5)
cf = random.randint(0,len(colors)-1)
h = random.randint(1,5)
w = random.randint(1,5)
Canvas.AddRectangle(x,y,w,h,LineWidth = lw,FillColor > > colors[cf])
# Ellipses
for i in range(3):
x,y > > (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
lw = random.randint(1,5)
cf = random.randint(0,len(colors)-1)
h = random.randint(1,5)
w = random.randint(1,5)
Canvas.AddEllipse(x,y,h,w,LineWidth = lw,FillColor > > colors[cf])
# Points
for i in range(5):
x,y > > (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
D = random.randint(1,50)
cf = random.randint(0,len(colors)-1)
Canvas.AddPoint((x,y), Color = colors[cf], Diameter = D)
# Circles
for i in range(5):
x,y > > (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
D = random.randint(1,5)
lw = random.randint(1,5)
cf = random.randint(0,len(colors)-1)
cl = random.randint(0,len(colors)-1)
Canvas.AddCircle(x,y,D,LineWidth = lw,LineColor > > colors[cl],FillColor = colors[cf])
Canvas.AddText("Circle # %i"%(i),x,y,Size > > 12,BackgroundColor = None,Position = "cc")
# Lines
for i in range(5):
points = []
for j in range(random.randint(2,10)):
point > > (random.randint(Range[0],Range[1]),random.randint(Range[0],Range[1]))
points.append(point)
lw = random.randint(1,10)
cf = random.randint(0,len(colors)-1)
cl = random.randint(0,len(colors)-1)
Canvas.AddLine(points, LineWidth = lw, LineColor > > colors[cl])
# Polygons
for i in range(3):
points = []
for j in range(random.randint(2,6)):
point > > (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
points.append(point)
lw = random.randint(1,6)
cf = random.randint(0,len(colors)-1)
cl = random.randint(0,len(colors)-1)
Canvas.AddPolygon(points,
LineWidth = lw,
LineColor = colors[cl],
FillColor = colors[cf],
FillStyle = 'Solid')
## Pointset
for i in range(4):
points = []
points = RandomArray.uniform(Range[0],Range[1],(100,2))
cf = random.randint(0,len(colors)-1)
D = random.randint(1,4)
Canvas.AddPointSet(points, Color = colors[cf], Diameter
= D)
# Text
String = "Unscaled text"
for i in range(3):
ts = random.randint(10,40)
cf = random.randint(0,len(colors)-1)
x,y > > (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
Canvas.AddText(String, x, y, Size = ts, Color colors[cf],
Position = "cc")
# Scaled Text
String = "Scaled text"
for i in range(3):
ts = random.random()*3 + 0.2
cf = random.randint(0,len(colors)-1)
x,y > > (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
Canvas.AddScaledText(String, x, y, Size = ts, Color > > colors[cf], Position = "cc")
Canvas.ZoomToBB()
if __name__=='__main__':
win = DrawFrame(None, -1, "FloatCanvas Drawing
Window",wx.DefaultPosition,(500,500))
win.Show(True)
win.DrawTest()
Merci pour ces éléments de réponse...
La librairie FloatCanvas ne répond pas tout à fait à mes besoins, mais
je vais essayer de l'adapter, ça sera déjà mieux que de partir de zéro...
(par exemple, implémenter un export en PNG, implémenter des objets dont
la position soit relative à la taille de la fenêtre)
Le seul truc, c'est que je suis un peu perdu avec ces histoires de
buffer et doubles buffers, et puis le code de la librairie n'est presque
pas commenté... enfin, on va essayer.
Merci bien en tout cas,
Nicolas
PS:
comment faire pour connaître la nouvelle taille du Panel (ou du canvas),
après que j'ai agrandi ma fenêtre ?
"Nicolas Pourcelot" a écrit dans le message de
news: 41f922c4$0$2075$Utiliser FloatCanvas avec wx n'est pas très dur et c'est très stable.
Je
l'utilise
pour une appli assez élaborée et j'en suis très content.
Est-ce que vous auriez un exemple d'utilisation pour que je puisse le
modifier et voir comment ça marche ?
Je n'ai pas d'exemple simple, mais voici un petit exemple repris et
modifié
des démos wx.
(attention, je ne l'ai pas testé... j'ai simplement simplifié le code de
la
démo).
Par ailleurs, pour créer et placer les objets wx j'utilise un module que
j'ai développé
qui permet d'utiliser la syntaxe Tk.
Exemple : Button(root, text='button 1',
command=handler).pack(side='left',
pady)
Ceci car j'ai programmé pas mal de temps en utilisant Tkinter et je
trouvais
la syntaxe
wx moins clair...
import Numeric
import RandomArray
import wx
import time, random
from wx.lib.floatcanvas import NavCanvas, FloatCanvas
import wxPython.lib.colourdb
class DrawFrame(wx.Frame):
"""
A frame used for the FloatCanvas Demo
"""
def __init__(self,parent, id,title,position,size):
wx.Frame.__init__(self,parent, id,title,position, size)
# Add the Canvas
self.Canvas = NavCanvas.NavCanvas(self,
-1,
(500,500),
Debug = 0,
BackgroundColor = "DARK
SLATE
BLUE")
## getting all the colors and linestyles for random objects
wxPython.lib.colourdb.updateColourDB()
self.colors = wxPython.lib.colourdb.getColourList()
return None
def DrawTest(self,event=None):
wx.GetApp().Yield()
Range = (-10,10)
colors = self.colors
Canvas = self.Canvas
Canvas.ClearAll()
Canvas.SetProjectionFun(None)
## Random tests of everything:
# Rectangles
for i in range(3):
x,y > > (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
lw = random.randint(1,5)
cf = random.randint(0,len(colors)-1)
h = random.randint(1,5)
w = random.randint(1,5)
Canvas.AddRectangle(x,y,w,h,LineWidth = lw,FillColor > > colors[cf])
# Ellipses
for i in range(3):
x,y > > (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
lw = random.randint(1,5)
cf = random.randint(0,len(colors)-1)
h = random.randint(1,5)
w = random.randint(1,5)
Canvas.AddEllipse(x,y,h,w,LineWidth = lw,FillColor > > colors[cf])
# Points
for i in range(5):
x,y > > (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
D = random.randint(1,50)
cf = random.randint(0,len(colors)-1)
Canvas.AddPoint((x,y), Color = colors[cf], Diameter = D)
# Circles
for i in range(5):
x,y > > (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
D = random.randint(1,5)
lw = random.randint(1,5)
cf = random.randint(0,len(colors)-1)
cl = random.randint(0,len(colors)-1)
Canvas.AddCircle(x,y,D,LineWidth = lw,LineColor > > colors[cl],FillColor = colors[cf])
Canvas.AddText("Circle # %i"%(i),x,y,Size > > 12,BackgroundColor = None,Position = "cc")
# Lines
for i in range(5):
points = []
for j in range(random.randint(2,10)):
point > > (random.randint(Range[0],Range[1]),random.randint(Range[0],Range[1]))
points.append(point)
lw = random.randint(1,10)
cf = random.randint(0,len(colors)-1)
cl = random.randint(0,len(colors)-1)
Canvas.AddLine(points, LineWidth = lw, LineColor > > colors[cl])
# Polygons
for i in range(3):
points = []
for j in range(random.randint(2,6)):
point > > (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
points.append(point)
lw = random.randint(1,6)
cf = random.randint(0,len(colors)-1)
cl = random.randint(0,len(colors)-1)
Canvas.AddPolygon(points,
LineWidth = lw,
LineColor = colors[cl],
FillColor = colors[cf],
FillStyle = 'Solid')
## Pointset
for i in range(4):
points = []
points = RandomArray.uniform(Range[0],Range[1],(100,2))
cf = random.randint(0,len(colors)-1)
D = random.randint(1,4)
Canvas.AddPointSet(points, Color = colors[cf], Diameter
= D)
# Text
String = "Unscaled text"
for i in range(3):
ts = random.randint(10,40)
cf = random.randint(0,len(colors)-1)
x,y > > (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
Canvas.AddText(String, x, y, Size = ts, Color colors[cf],
Position = "cc")
# Scaled Text
String = "Scaled text"
for i in range(3):
ts = random.random()*3 + 0.2
cf = random.randint(0,len(colors)-1)
x,y > > (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
Canvas.AddScaledText(String, x, y, Size = ts, Color > > colors[cf], Position = "cc")
Canvas.ZoomToBB()
if __name__=='__main__':
win = DrawFrame(None, -1, "FloatCanvas Drawing
Window",wx.DefaultPosition,(500,500))
win.Show(True)
win.DrawTest()
je voudrais créer une fenêtre où je puisse dessiner des formes
géométriques (cercle, rectangles, lignes, ...), puis exporter le contenu
de la fenêtre (en PNG par exemple, ou en EPS, GIF à la rigueur).
coûteux en temps je resterai à Tkinter. Comme je débute en programmation
objet, je cherche qqch d'assez simple pour ne pas me dégoûter.
je voudrais créer une fenêtre où je puisse dessiner des formes
géométriques (cercle, rectangles, lignes, ...), puis exporter le contenu
de la fenêtre (en PNG par exemple, ou en EPS, GIF à la rigueur).
coûteux en temps je resterai à Tkinter. Comme je débute en programmation
objet, je cherche qqch d'assez simple pour ne pas me dégoûter.
je voudrais créer une fenêtre où je puisse dessiner des formes
géométriques (cercle, rectangles, lignes, ...), puis exporter le contenu
de la fenêtre (en PNG par exemple, ou en EPS, GIF à la rigueur).
coûteux en temps je resterai à Tkinter. Comme je débute en programmation
objet, je cherche qqch d'assez simple pour ne pas me dégoûter.
Je trouve personellement Qt plus simple, plus puissant et mieux documenté
que wx ou tk.
Je trouve personellement Qt plus simple, plus puissant et mieux documenté
que wx ou tk.
Je trouve personellement Qt plus simple, plus puissant et mieux documenté
que wx ou tk.
Je trouve personellement Qt plus simple, plus puissant et mieux documenté
que wx ou tk.
Pourquoi pas Gtk et Glade ?
Je trouve personellement Qt plus simple, plus puissant et mieux documenté
que wx ou tk.
Pourquoi pas Gtk et Glade ?
Je trouve personellement Qt plus simple, plus puissant et mieux documenté
que wx ou tk.
Pourquoi pas Gtk et Glade ?