1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
# -*- coding: cp1252 -*-
#/usr/bin/env
import wx
class window(wx.Frame):
#window
def __init__(self, parent, id, titre):
wx.Frame.__init__(self, parent, id, titre)
#taille de la fenetre/width of this window
a = wx.GetDisplaySize()
b = str(a)
b = b.replace('(','')
b = b.replace(')','')
b = b.replace(' ','')
self.windowWidth = int(b.split(',')[0])
self.windowHeight = int(b.split(',')[1])
a = self.windowWidth
self.windowWidth2 = int(a/2.2)
self.SetSize(wx.Size(self.windowWidth2,self.windowHeight))
#panel
self.cnv=wx.Panel(self,-1)
print "panneau créé"
#creation of Client DC
self.dc=wx.ClientDC(self.cnv)
print "clientDC créé"
def OnCloseWindow(self, evt):
self.Destroy()
class windowTool(window):
#windowTool inheriting class window () / héritant de la classe window()
def __init__(self, parent, id, titre):
window.__init__(self, parent, id, titre)
#taille de la fenetre/width of this window
height = self.GetParent().windowHeight
a = self.GetParent().windowWidth2
b = self.GetParent().windowWidth - 1920 #cela m'est utile pour le dualscreen /
width = int(b-a)
self.SetSize(wx.Size(width, height))
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
#panel dans lequel on va mettre les boutons / panel in which we will put the buttons
panel = wx.Panel(self, size=(170, height))
#boutons / buttuns
button_drawLine = wx.Button(panel, -1, "Tracer ligne", (10,10))
button_drawRectangle = wx.Button(panel, -2, "Placer masque", (10,50))
button_highlight = wx.Button(panel, -3, "Surligner", (10,90))
button_close = wx.Button(panel, -4, "Fermer Application", (10,130))
#evenements / Events
self.Bind(wx.EVT_BUTTON, self.EventPosition, button_drawLine)
self.Bind(wx.EVT_BUTTON, self.EventPosition, button_highlight)
self.Bind(wx.EVT_BUTTON, self.EventPosition, button_drawRectangle)
self.Bind(wx.EVT_BUTTON, self.GetParent().OnCloseWindow, button_close)
def OnCloseWindow(self, evt):
self.Destroy()
def EventPosition(self, evt):
self.btn = evt.GetEventObject()
print "event position"
#Focus sur la fenetre transparente et détection des mouvements de la souris
#Focus on the transparent window and detection of mouse movements
self.GetParent().Raise()
self.GetParent().cnv.Bind(wx.EVT_LEFT_DOWN, self.EventMotion)
def EventMotion(self, evt):
print "event motion"
#sauvegarde de la position du clique / #save the position of clicks
self.posx = evt.GetX()
self.posy = evt.GetY()
self.GetParent().Refresh ()
self.GetParent().cnv.Bind(wx.EVT_MOTION, self.Position)
def Position(self, evt):
#if mouse leftbutton is down
if wx.GetMouseState().LeftDown():
print "position"
#Assignation de la position du curseur/ #Detection, arrest and send the cursor position
self.posx2 = evt.GetX()
self.posy2 = evt.GetY()
self.GetParent().Refresh ()
self.GetParent().cnv.Bind(wx.EVT_PAINT, self.Paint)
def Paint(self, evt):
print "Paint"
#creation de la toile / creation of the painting canvas
self.GetParent().dc = wx.PaintDC(self.GetParent().cnv)
if self.btn.GetLabelText()=="Tracer ligne":
self.drawLine(self.dc)
if self.btn.GetLabelText()=="Placer masque":
self.drawMask(self.dc)
if self.btn.GetLabelText()=="Surligner":
self.highlight(self.dc)
def drawLine(self, dc):
print "i drawing line"
self.GetParent().dc.SetPen(wx.Pen('black', 2))
self.GetParent().dc.DrawLine(self.posx2, self.posy2,self.posx,self.posy)
def drawMask(self, dc):
print "i drawing mask"
self.GetParent().dc.SetPen(wx.Pen('red', 2))
self.GetParent().dc.SetBrush(wx.Brush(wx.Color(0, 0, 0), wx.ALPHA_OPAQUE))
self.GetParent().dc.DrawRectangle(self.posx, self.posy, self.posx2 - self.posx, self.posy2- self.posy)
def highlight (self, dc):
print "i drawing highlight"
self.GetParent().dc.SetBrush(wx.Brush(wx.Color(150, 250, 150)))
self.GetParent().dc.DrawRectangle(self.posx, self.posy, self.posx2 - self.posx, self.posy2- self.posy)
class monApp (wx.App):
def OnInit(self):
frm = window(None, -1, 'transparent')
frm.Show(True)
frm.SetTransparent(55) # pour l'instant j'utilise une semi transparence sinon je ne vois pas les dessins.
frmTool = windowTool(frm, -2, 'outils')
frmTool.Show(True)
return True
if __name__ == "__main__":
app = monApp()
app.MainLoop() |
Partager