~lorzeteam/lorze/trunk

« back to all changes in this revision

Viewing changes to Scripts/lrzgdiprev.py

  • Committer: Andreas Ulrich
  • Date: 2012-09-03 20:55:18 UTC
  • Revision ID: ulrich3110@gmail.com-20120903205518-enag9dpdiqpc3oh9
- line command
- paint methods in gdipanel
- select methods in selection
- cursor methods in smartcursor
- rect coordinates (x, y, w, h) for all rect methods
- geometry help object
- new dialog for options: with a listcontrol
- attribute help object
- attribute dialog 1st version
- new options
- mehtods for dialogues to save current sizes

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python
2
 
# -*- coding: utf-8 -*-
3
 
 
4
 
# LORZE erasandcad, a 2D CAD with an intuitive user interface, simple and easy.
5
 
# http://erasand.jimdo.com/python-programme/lorze/
6
 
# (C) 2012, Andreas Ulrich
7
 
 
8
 
# This program is free software: you can redistribute it and/or modify
9
 
# it under the terms of the GNU General Public License as published by
10
 
# the Free Software Foundation, either version 3 of the License, or
11
 
# (at your option) any later version.
12
 
 
13
 
# This program is distributed in the hope that it will be useful,
14
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 
# GNU General Public License for more details.
17
 
 
18
 
# You should have received a copy of the GNU General Public License
19
 
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
 
 
21
 
import wx
22
 
from lrzoptions import LorzeOptions
23
 
 
24
 
class LorzePreview():
25
 
    #Lorze preview for the graphic panel
26
 
 
27
 
    def __init__(self, parent, options):
28
 
        # parent, GraphicPanel(), options
29
 
        self.__parent= parent
30
 
        self.__options= options
31
 
 
32
 
        # pen for wxPaint
33
 
        self.__pen= wx.Pen(self.__options.GetPreviewColor(),
34
 
         options.GetPreviewPenSize(), options.GetPreviewPenStyle())
35
 
 
36
 
        # reset counter
37
 
        self.Clear()
38
 
 
39
 
 
40
 
    def Clear(self):
41
 
        # counter for clicks
42
 
        self.__click= 0
43
 
        # coordinates
44
 
        self.__xa, self.__ya, self.__xb, self.__yb= 0, 0, 0, 0
45
 
 
46
 
 
47
 
    def IncreaseClick(self, mousex, mousey):
48
 
        # click in the GraphicPanel
49
 
        self.__click+= 1
50
 
        if self.__click== 1:
51
 
            self.__xa= float(mousex)
52
 
            self.__ya= float(mousey)
53
 
        elif self.__click== 2:
54
 
            self.__xb= float(mousex)
55
 
            self.__yb= float(mousey)
56
 
 
57
 
 
58
 
    def GetClick(self):
59
 
        return (self.__click)
60
 
 
61
 
 
62
 
    def GetCoords(self):
63
 
        # return coord as a tuple
64
 
        return((self.__xa, self.__ya, self.__xb, self.__yb))
65
 
 
66
 
 
67
 
    def wxPaint(self, dc, userscale, mousex, mousey):
68
 
        # paint preview in wxpython drawing client
69
 
        # userscale: scale factor for zoom
70
 
        # x, y: mouse coordinates
71
 
        # set pen
72
 
        dc.SetPen(self.__pen)
73
 
        dc.SetBrush(wx.Brush('#000000', wx.TRANSPARENT))
74
 
 
75
 
        # read action
76
 
        action= self.__parent.GetAction()
77
 
 
78
 
        # select & paint preview
79
 
        if action== 'elementsel':
80
 
            if self.__click== 1:
81
 
                # 1st point of rect, rect coordinates
82
 
                if self.__xa< mousex:
83
 
                    x= self.__xa* userscale
84
 
                    w= (mousex- self.__xa)* userscale
85
 
                else:
86
 
                    x= mousex* userscale
87
 
                    w= (self.__xa - mousex)* userscale
88
 
 
89
 
                if self.__ya< mousey:
90
 
                    y= self.__ya* userscale
91
 
                    h= (mousey- self.__ya)* userscale
92
 
                else:
93
 
                    y= mousey* userscale
94
 
                    h= (self.__ya - mousey)* userscale
95
 
 
96
 
                dc.DrawRectangle(x, y, w, h)
97
 
 
98
 
 
99
 
class TestFrame(wx.Frame):
100
 
    # object for testing
101
 
    def __init__(self):
102
 
        wx.Frame.__init__(self, None, title= 'Testcode Selection',
103
 
         size= (400, 600))
104
 
        self.__options= LorzeOptions()
105
 
        self.__dps= self.__options.GetDezPlcs()
106
 
        self.__panel= wx.Panel(self)
107
 
        buttonA= wx.Button(self, label= 'Element Selection Preview')
108
 
 
109
 
        vbox= wx.BoxSizer(wx.VERTICAL)
110
 
        self.__panel.Bind(wx.EVT_MOTION, self.OnMouseMove)
111
 
        vbox= wx.BoxSizer(wx.VERTICAL)
112
 
        vbox.Add(buttonA)
113
 
        vbox.Add(self.__panel, 1, wx.EXPAND)
114
 
 
115
 
        self.Bind(wx.EVT_PAINT, self.OnPaint)
116
 
        buttonA.Bind(wx.EVT_BUTTON, self.OnButtonA)
117
 
 
118
 
        self.__prev= LorzePreview(self, self.__options)
119
 
        self.__mousex= 0
120
 
        self.__mousey= 0
121
 
        self.__userscale= 96/ 25.4
122
 
        self.__action=''
123
 
 
124
 
        self.SetSizer(vbox)
125
 
        self.Center()
126
 
        self.Show()
127
 
 
128
 
 
129
 
    def OnButtonA(self, event):
130
 
        self.__action= 'elementsel'
131
 
        self.__prev.Clear()
132
 
        self.__prev.IncreaseClick(0, 0)
133
 
 
134
 
    def OnPaint(self, event):
135
 
        dc = wx.PaintDC(self.__panel)
136
 
        w, h= self.GetSize()
137
 
        self.__originx= w/ 2
138
 
        self.__originy= h/2
139
 
        dc.SetDeviceOrigin(self.__originx, self.__originy)
140
 
        dc.SetAxisOrientation(True, True)
141
 
        pensizefactor= 1
142
 
        showpenstyle= True
143
 
        self.__prev.wxPaint(dc, self.__userscale, self.__mousex, self.__mousey)
144
 
 
145
 
 
146
 
    def GetAction(self):
147
 
        # simulates the method of the GraphicPanel()
148
 
        return(self.__action)
149
 
 
150
 
 
151
 
    def OnMouseMove(self, event):
152
 
        # mouse movement, mouse-position, pixel on the panel
153
 
        xpanel, ypanel= event.GetPosition()
154
 
        dc= wx.ClientDC(self)
155
 
        dc.SetDeviceOrigin(self.__originx, self.__originy)
156
 
        dc.SetAxisOrientation(True, True)
157
 
        self.__mousex= dc.DeviceToLogicalX(xpanel)/ self.__userscale
158
 
        self.__mousey= dc.DeviceToLogicalY(ypanel)/ self.__userscale
159
 
        self.__mousex= round(self.__mousex, self.__dps)
160
 
        self.__mousey= round(self.__mousey, self.__dps)
161
 
        self.Refresh()
162
 
 
163
 
 
164
 
if __name__== '__main__':
165
 
    app= wx.App()
166
 
    frame= TestFrame()
167
 
    app.MainLoop()
168