OVH Cloud OVH Cloud

Quel GUI choisir pour mon application ?

17 réponses
Avatar
Nicolas Pourcelot
Bonjour,
j'explique mon besoin :
je charche à créer un petit logiciel de géométrie.
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).
Pour l'instant, je fais ça avec Tkinter, ça marche bien mais ce n'est
pas très jolie comme librairie sous windows.
J'ai cherché du côté de Wxpython, et là, je vois plein de jolis widgetsn
mais je ne comprends pas comment on fait pour dessiner une simple ligne.
D'après ce que j'ai compris, WxPython ne possède pas encore d'objet
canvas, et il faut installer encore d'autres librairies (Piddle?), etc...
avant que je me lance là dedans, j'aimerais avoir un avis, si c'est trop
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.

7 réponses

1 2
Avatar
Olivier Ravard
"Nicolas Pourcelot" a écrit dans le message de
news: 41f91f44$0$2077$


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 ?


Il y a des exemples dans plot.py, l'outil pour tracer des graphes fourni
avec wx.
Ce n'est pas aussi simple que la commande Tkinter, mais c'est plus puissant.


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. ;-)


Là tu as tout à fait raison...


Avatar
Olivier Ravard
"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()


Avatar
Nicolas Pourcelot
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()






Avatar
Olivier Ravard
"Nicolas Pourcelot" a écrit dans le message de
news: 41fd5548$0$31079$
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.


C'est vrai, c'est moins simple que Tk mais c'est très puissant. Ca mérite
que l'on
s'y arrête.
Pour la doc, c'est vrai, c'est un peu léger.


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 ?



size = win.GetClientSize()

"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()








Avatar
Tibi
Nicolas Pourcelot wrote:

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).


Tu as aussi Qt, qui dispose d'une classe QCanvas sur lequel on peut dessiner
à l'aide de QCanvasLine ou QCanvasSpline par exemple.
Pour exporter vers du postscript il suffit d'ecrire le contenu du canevas
sur une QPrinter

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.

Avatar
atchoum
Je trouve personellement Qt plus simple, plus puissant et mieux documenté
que wx ou tk.


Pourquoi pas Gtk et Glade ?

A+++
Jean-Pierre

Avatar
Tibi
atchoum wrote:

Je trouve personellement Qt plus simple, plus puissant et mieux documenté
que wx ou tk.


Pourquoi pas Gtk et Glade ?


La dernière fois que j'ai regardé gtk+glade étaient loin d'avoir atteind la
maturité de Qt, mais je ne l'ai jamais vraiment utilisé contrairement à Tk
Wx et Qt, c'est pourquoi je n'en parle pas.


1 2