~lorzeteam/lorze/trunk

« back to all changes in this revision

Viewing changes to Scripts/lrzdlgattribut.py

  • Committer: Andreas Ulrich
  • Date: 2012-12-13 20:54:19 UTC
  • Revision ID: ulrich3110@gmail.com-20121213205419-aucgdskqtqmyrj10
new file structure, new object structure, about dialogue, help dialogue, hep pages in english and german, german translation, ponton5h installer, documentation

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  it under  the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
9
 
 
10
 
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
11
 
 
12
 
# You should have received a copy of the GNU General Public License along with this program.  If not, see <http://www.gnu.org/licenses/>.
13
 
 
14
 
import wx, locale
15
 
from lrzvalchck import LorzeValueCheck
16
 
from lrzdlghelper import LorzeDlgHelper
17
 
from lrzdlgoptions import SortedListCtrl
18
 
 
19
 
_= wx.GetTranslation # name for translations texts
20
 
 
21
 
 
22
 
class LorzeDlgAttribut(wx.Dialog):
23
 
    #Lorze Atrtribut Dialog to the GUI of LORZE erasandcad
24
 
 
25
 
    def __init__(self, parent, options):
26
 
        # parent class
27
 
        self.__parent= parent
28
 
 
29
 
        # LorzeOptions() of parent class
30
 
        self.__options= options
31
 
 
32
 
        # get settings for dialog from options
33
 
        dlgborder= self.__options.GetDlgBorder()
34
 
        wdlg, hdlg= self.DialogueSize()
35
 
 
36
 
        # subclass
37
 
        wx.Dialog.__init__(self, self.__parent, wx.ID_ANY, _(u'Attributes'), size= (wdlg, hdlg), style= wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER)
38
 
 
39
 
        # LorzeValueCheck
40
 
        self.__valchck= LorzeValueCheck()
41
 
 
42
 
        # Dialog Helper
43
 
        self.__dlg= LorzeDlgHelper(self)
44
 
 
45
 
        # Dictionairy for borders, cursors, penstyles
46
 
        self.__bordersdict= self.__parent.GetBordersDict()
47
 
        self.__cursorsdict= self.__parent.GetCursorsDict()
48
 
        self.__penstyledict= self.__parent.GetPenStyleDict()
49
 
 
50
 
        # default drawing list, label & combobox
51
 
        self.__drawlist= []
52
 
        self.__drawcombo= wx.ComboBox(self, size= (-1, -1), choices= self.__drawlist, style=wx.CB_READONLY)
53
 
 
54
 
        # info texts
55
 
        self.__colortxt= wx.StaticText(self)
56
 
        self.__layertxt= wx.StaticText(self)
57
 
        self.__styletxt= wx.StaticText(self)
58
 
        self.__widthtxt= wx.StaticText(self)
59
 
 
60
 
        colortitle= wx.StaticText(self, label=_(u'Colour'))
61
 
        layertitle= wx.StaticText(self, label=_(u'Layer'))
62
 
        styletitle= wx.StaticText(self, label=_(u'Line type'))
63
 
        widthtitle= wx.StaticText(self, label=_(u'Line width'))
64
 
 
65
 
        # boxes for infotexts, attribute list, options, default drawing
66
 
        infobox= wx.StaticBox(self, label= _(u'Chosen attributes'))
67
 
        optionbox= wx.StaticBox(self, label= _(u'Filter options'))
68
 
        drawbox= wx.StaticBox(self, label= _(u'Drawings'))
69
 
 
70
 
        # notebook
71
 
        nbook= wx.Notebook(self)
72
 
        widths= self.__options.GetAttrListWidths()
73
 
 
74
 
        # panels
75
 
        self.__color= LorzeAttrPanel(nbook, dlgborder, 'color', (widths[0], widths[1], widths[2], widths[3]))
76
 
        self.__layer= LorzeAttrPanel(nbook, dlgborder, 'layer', (widths[4], widths[5], widths[6], widths[7]))
77
 
        self.__style= LorzeAttrPanel(nbook, dlgborder, 'style', (widths[8], widths[9], widths[10], widths[11]))
78
 
        self.__width= LorzeAttrPanel(nbook, dlgborder, 'width', (widths[12], widths[13], widths[14], widths[15]))
79
 
 
80
 
        nbook.AddPage(self.__color, _(u'Color'))
81
 
        nbook.AddPage(self.__layer, _(u'Layer'))
82
 
        nbook.AddPage(self.__style, _(u'Line style'))
83
 
        nbook.AddPage(self.__width, _(u'Line width'))
84
 
 
85
 
        # option: from actual drawing, from all drawings, from defaults, from selection
86
 
        self.__optdrawings= wx.RadioButton(self, label= _(u'Drawings'), style=wx.RB_GROUP)
87
 
        self.__optselected= wx.RadioButton(self, label= _(u'Selected'))
88
 
        self.__optdefault= wx.RadioButton(self, label= _(u'Defaults'))
89
 
        self.__optdictionairy= wx.RadioButton(self, label= _(u'Dictionairy'))
90
 
 
91
 
        # dialog control buttons
92
 
        buttonok= wx.Button(self, label= _(u'OK'))
93
 
        buttoncancel= wx.Button(self, label= _(u'Cancel'))
94
 
 
95
 
        buttonok.Bind(wx.EVT_BUTTON, self.OnOk)
96
 
        buttoncancel.Bind(wx.EVT_BUTTON, self.OnCancel)
97
 
        self.Bind(wx.EVT_CLOSE, self.OnDialogueClose)
98
 
 
99
 
        # layout
100
 
        vbox= wx.BoxSizer(wx.VERTICAL)
101
 
 
102
 
        # drawing
103
 
        drawsizer= wx.StaticBoxSizer(drawbox, wx.VERTICAL)
104
 
        drawsizer.Add(self.__drawcombo, 0, wx.ALL, dlgborder)
105
 
        vbox.Add(drawsizer, 0, wx.EXPAND|wx.ALL, dlgborder)
106
 
 
107
 
        # infotexts
108
 
        infosizer= wx.StaticBoxSizer(infobox, wx.VERTICAL)
109
 
        infogrid= wx.GridSizer(2, 4, 0, dlgborder)
110
 
        infogrid.AddMany([(colortitle, 0, wx.EXPAND), (layertitle, 0, wx.EXPAND), (styletitle, 0, wx.EXPAND), (widthtitle, 0, wx.EXPAND), (self.__colortxt, 0, wx.EXPAND), (self.__layertxt, 0, wx.EXPAND), (self.__styletxt, 0, wx.EXPAND), (self.__widthtxt, 0, wx.EXPAND)])
111
 
        infosizer.Add(infogrid, 0, wx.EXPAND)
112
 
        vbox.Add(infosizer, 0, wx.EXPAND|wx.ALL, dlgborder)
113
 
 
114
 
        vbox.Add(nbook, 2, wx.EXPAND|wx.ALL, dlgborder)
115
 
 
116
 
        # filter options
117
 
        optionsizer= wx.StaticBoxSizer(optionbox, wx.VERTICAL)
118
 
        optiongrid= wx.GridSizer(1, 4, dlgborder, dlgborder)
119
 
        optiongrid.AddMany([(self.__optdrawings, 0, wx.EXPAND), (self.__optselected, 0, wx.EXPAND), (self.__optdefault, 0, wx.EXPAND), (self.__optdictionairy, 0, wx.EXPAND)])
120
 
        optionsizer.Add(optiongrid, 0, wx.EXPAND)
121
 
        vbox.Add(optionsizer, 0, wx.EXPAND|wx.ALL, dlgborder)
122
 
 
123
 
        # dialog buttons
124
 
        hbox2= wx.BoxSizer(wx.HORIZONTAL)
125
 
        hbox2.Add(buttonok, 0, wx.ALL, dlgborder)
126
 
        hbox2.Add(buttoncancel, 0, wx.ALL, dlgborder)
127
 
        vbox.Add(hbox2, 0, wx.EXPAND|wx.ALL, dlgborder)
128
 
 
129
 
        self.SetSizer(vbox)
130
 
        self.Centre()
131
 
 
132
 
 
133
 
    def OnDialogueClose(self, event):
134
 
        # last commando before close the dialogue
135
 
        dlgw, dlgh= self.GetSize()
136
 
        self.__options.SetDlgAttrSize(dlgw, dlgh)
137
 
 
138
 
        w0, w1, w2, w3= self.__color.GetWidths()
139
 
        w4, w5, w6, w7= self.__layer.GetWidths()
140
 
        w8, w9, w10, w11= self.__style.GetWidths()
141
 
        w12, w13, w14, w15= self.__width.GetWidths()
142
 
        self.__options.SetAttrListWidths(w0, w1, w2, w3, w4, w5, w6, w7, w8, w9, w10, w11, w12, w13, w14, w15)
143
 
 
144
 
        event.Skip()
145
 
 
146
 
 
147
 
    def OnActDraw(self, event):
148
 
        # attributes from actual drawing
149
 
        pass
150
 
 
151
 
 
152
 
    def OnAllDraw(self, event):
153
 
        # attributes from all drawings
154
 
        pass
155
 
 
156
 
 
157
 
    def OnSelected(self, event):
158
 
        # attributes from selected elements
159
 
        pass
160
 
 
161
 
 
162
 
    def OnDefault(self, event):
163
 
        # attributes from defaults
164
 
        pass
165
 
 
166
 
 
167
 
    def OnOk(self, event):
168
 
        # ok clicked, get all attributes
169
 
        pass
170
 
 
171
 
 
172
 
    def OnCancel(self, event):
173
 
        # cancel clicked, leave without changes
174
 
        pass
175
 
 
176
 
 
177
 
    def DialogueSize(self):
178
 
        wdlg, hdlg= self.__options.GetDlgAttrSize()
179
 
 
180
 
        # get size from parent
181
 
        wparent, hparent= self.__parent.GetSize()
182
 
 
183
 
        # dialog size control
184
 
        if hdlg> hparent:
185
 
            # correct height to parent size
186
 
            hdlg= hparent
187
 
 
188
 
        if wdlg> wparent:
189
 
            # correct width to parent size
190
 
            wdlg= wparent
191
 
 
192
 
        return(wdlg, hdlg)
193
 
 
194
 
 
195
 
class LorzeAttrPanel(wx.Panel):
196
 
    # Lorze attribut panel for the attribut dialog
197
 
 
198
 
    def __init__(self, parent, dlgborder, title, widths):
199
 
        # dlgborder is the space between the widgets / title can be 'color', 'layer', 'style' or 'width' / widths is a tuple (w0, w1, w2, w3)= column with for the list control / parent class
200
 
        self.__parent= parent
201
 
        self.__title= title
202
 
 
203
 
        # subclass
204
 
        wx.Panel.__init__(self, self.__parent)
205
 
 
206
 
        titledict= {'color':_(u'Colour'), 'layer':_(u'Layer'), 'style':_(u'Line style'), 'width':_(u'Line width')}
207
 
 
208
 
        # sorted list conntrol
209
 
        self.__list= SortedListCtrl(self)
210
 
        self.__list.InsertColumn(0, titledict[self.__title]+ _(u' name'), width= widths[0])
211
 
        self.__list.InsertColumn(1, _(u'Description'), width= widths[1])
212
 
        self.__list.InsertColumn(2, titledict[self.__title]+ _(u' value'), width= widths[2])
213
 
        self.__list.InsertColumn(3, _(u' Used by'), width= widths[3])
214
 
 
215
 
        # preview panel
216
 
        self.__prev= wx.Panel(self)
217
 
 
218
 
        # buttons
219
 
        new= wx.Button(self, label= _(u'New entry'))
220
 
 
221
 
        # bindings
222
 
        self.__list.Bind(wx.EVT_LISTBOX_DCLICK, self.OnNew)
223
 
        new.Bind(wx.EVT_BUTTON, self.OnNew)
224
 
 
225
 
        # layout
226
 
        vbox= wx.BoxSizer(wx.VERTICAL)
227
 
        hbox= wx.BoxSizer(wx.HORIZONTAL)
228
 
 
229
 
        hbox.Add(self.__prev, 1, wx.EXPAND|wx.ALL, dlgborder)
230
 
        hbox.Add(new, 0, wx.EXPAND|wx.ALL, dlgborder)
231
 
 
232
 
        #~ grid=wx.GridSizer(1, 3, dlgborder, dlgborder)
233
 
        #~ grid.AddMany([(), (edit, 0, wx.EXPAND), (delete, 0, wx.EXPAND)])
234
 
 
235
 
        vbox.Add(self.__list, 2, wx.EXPAND|wx.ALL, dlgborder)
236
 
        vbox.Add(hbox, 0, wx.EXPAND|wx.ALL, dlgborder)
237
 
        #~ vbox.Add(grid, 0, wx.EXPAND|wx.ALL, dlgborder)
238
 
 
239
 
        self.SetSizer(vbox)
240
 
 
241
 
 
242
 
    def OnNew(self, event):
243
 
        # get a new entry
244
 
        pass
245
 
 
246
 
 
247
 
    def GetWidths(self):
248
 
        return(self.__list.GetColumnWidth(0), self.__list.GetColumnWidth(1), self.__list.GetColumnWidth(2), self.__list.GetColumnWidth(3))
249
 
 
250
 
 
251
 
    def GetSortedListDict(self):
252
 
        # Returns a dictionairy for SortedListCtrl
253
 
        sortedlistdict= {}
254
 
        #~ index= 0
255
 
        #~ for i in self.__orderlist:
256
 
            #~ sortedlistdict[index]= (self.__labeldict[i], self.__valuedict[i])
257
 
            #~ index+= 1
258
 
        return(sortedlistdict)
259
 
 
260
 
 
261
 
        #~ elif seloption== 'drawdefcolour':
262
 
            #~ # get color as html string from color selection dialogue
263
 
            #~ colour= self.__dlg.ColorDialog(self.__valuedict['drawdefcolour'])
264
 
            #~ if colour!= '':
265
 
                #~ # clicked ok, get colour html string
266
 
                #~ self.__valuedict['drawdefcolour']= colour
267
 
#~
268
 
        #~ elif seloption== 'drawdeflayer':
269
 
            #~ # get text from text entry dialogue
270
 
            #~ text= self.__dlg.TextDialog(self.__labeldict['drawdeflayer'], _(u'Please give the name of the default layer'), self.__valuedict['drawdeflayer'])
271
 
            #~ if text!= '':
272
 
                #~ # clicked ok, get string
273
 
                #~ self.__valuedict['drawdeflayer']= text
274
 
#~
275
 
        #~ elif seloption== 'drawdefstyle':
276
 
            #~ # read penstyle and user definition, style1= wx.PenStyle, style2= user definied list
277
 
            #~ stylelist= self.__valuedict['drawdefstyle'].split('/')
278
 
            #~ if len(stylelist)== 2:
279
 
                #~ style1= stylelist[0].lstrip().rstrip()
280
 
                #~ style2= self.__valchck.StringToList(stylelist[1], ',', False)
281
 
            #~ else:
282
 
                #~ style1= stylelist[0].lstrip().rstrip()
283
 
                #~ style2= []
284
 
#~
285
 
            #~ # get string from list selection dialogue
286
 
            #~ text= self.__dlg.ListSelection(self.__labeldict['drawdefstyle'], self.__penstyledict.keys(), style1)
287
 
            #~ if text!= '':
288
 
                #~ # clicked ok
289
 
                #~ if text== 'wx.USER_DASH':
290
 
                    #~ # user definied line types, get list for style, set style2 as default
291
 
                    #~ styletext= self.__dlg.TextDialog(_(u'User definied line type'), _(u'Please give the values for the style defnition, for example 5, 1, 5)'), self.__valchck.ListToString(style2))
292
 
                    #~ if styletext!= '':
293
 
                        #~ # clicked ok, get list of integers
294
 
                        #~ stylelist= self.__valchck.StringToList(styletext, ',', False)
295
 
                        #~ text2= ' / '+ self.__valchck.ListToString(stylelist)
296
 
                    #~ else:
297
 
                        #~ text2= ' / 10, 5'
298
 
                #~ else:
299
 
                    #~ text2= ''
300
 
#~
301
 
                #~ self.__valuedict['drawdefstyle']= text+ text2
302
 
#~
303
 
        #~ elif seloption== 'drawdefsize':
304
 
            #~ # get text from text entry dialogue
305
 
            #~ text= self.__dlg.TextDialog(self.__labeldict['drawdefsize'], _(u'Please give the default pen strength'), self.__valuedict['drawdefsize'])
306
 
            #~ if text!= '':
307
 
                #~ # clicked ok, get float
308
 
                #~ self.__valuedict['drawdefsize']= self.__valchck.Float(text, str(self.__options.GetSmartCursMarkPenSize()), 0)
309
 
 
310
 
 
311
 
class TestFrame(wx.Frame):
312
 
    # object for testing
313
 
    def __init__(self):
314
 
        self.__options= LorzeOptions()
315
 
        wx.Frame.__init__(self, None, title= u'Testcode LorzeDlgAttribut', size= (600, 600))
316
 
 
317
 
        buttontest= wx.Button(self, label= u'Test')
318
 
        buttonexit= wx.Button(self, label= u'Exit')
319
 
 
320
 
        vbox= wx.BoxSizer(wx.VERTICAL)
321
 
        vbox.Add(buttontest)
322
 
        vbox.Add(buttonexit)
323
 
        self.SetSizer(vbox)
324
 
 
325
 
        buttontest.Bind(wx.EVT_BUTTON, self.OnTest)
326
 
        buttonexit.Bind(wx.EVT_BUTTON, self.OnExit)
327
 
 
328
 
        self.Center()
329
 
        self.Show()
330
 
 
331
 
 
332
 
    def OnTest(self, event):
333
 
        dlg= LorzeDlgAttribut(self, self.__options)
334
 
        dlg.ShowModal()
335
 
        dlg.Destroy()
336
 
 
337
 
 
338
 
    def OnExit(self, event):
339
 
        self.Close()
340
 
 
341
 
 
342
 
    def GetBordersDict(self):
343
 
        return({'wx.SIMPLE_BORDER': wx.SIMPLE_BORDER, 'wx.RAISED_BORDER': wx.RAISED_BORDER, 'wx.SUNKEN_BORDER': wx.SUNKEN_BORDER, 'wx.NO_BORDER': wx.NO_BORDER})
344
 
 
345
 
 
346
 
    def GetCursorsDict(self):
347
 
        return({'wx.CURSOR_ARROW': wx.CURSOR_ARROW, 'wx.CURSOR_RIGHT_ARROW': wx.CURSOR_RIGHT_ARROW, 'wx.CURSOR_BLANK': wx.CURSOR_BLANK, 'wx.CURSOR_BULLSEYE': wx.CURSOR_BULLSEYE, 'wx.CURSOR_CHAR': wx.CURSOR_CHAR, 'wx.CURSOR_CROSS': wx.CURSOR_CROSS, 'wx.CURSOR_HAND': wx.CURSOR_HAND, 'wx.CURSOR_IBEAM': wx.CURSOR_IBEAM, 'wx.CURSOR_LEFT_BUTTON': wx.CURSOR_LEFT_BUTTON, 'wx.CURSOR_MAGNIFIER': wx.CURSOR_MAGNIFIER, 'wx.CURSOR_MIDDLE_BUTTON': wx.CURSOR_MIDDLE_BUTTON, 'wx.CURSOR_NO_ENTRY': wx.CURSOR_NO_ENTRY, 'wx.CURSOR_PAINT_BRUSH': wx.CURSOR_PAINT_BRUSH, 'wx.CURSOR_PENCIL': wx.CURSOR_PENCIL, 'wx.CURSOR_POINT_LEFT': wx.CURSOR_POINT_LEFT, 'wx.CURSOR_POINT_RIGHT': wx.CURSOR_POINT_RIGHT, 'wx.CURSOR_QUESTION_ARROW': wx.CURSOR_QUESTION_ARROW, 'wx.CURSOR_RIGHT_BUTTON': wx.CURSOR_RIGHT_BUTTON, 'wx.CURSOR_SIZENESW': wx.CURSOR_SIZENESW, 'wx.CURSOR_SIZENS': wx.CURSOR_SIZENS, 'wx.CURSOR_SIZENWSE': wx.CURSOR_SIZENWSE, 'wx.CURSOR_SIZEWE': wx.CURSOR_SIZEWE, 'wx.CURSOR_SIZING': wx.CURSOR_SIZING, 'wx.CURSOR_SPRAYCAN': wx.CURSOR_SPRAYCAN, 'wx.CURSOR_WAIT': wx.CURSOR_WAIT, 'wx.CURSOR_WATCH': wx.CURSOR_WATCH, 'wx.CURSOR_ARROWWAIT': wx.CURSOR_ARROWWAIT, 'wx.CURSOR_DEFAULT': wx.CURSOR_DEFAULT})
348
 
 
349
 
 
350
 
    def GetPenStyleDict(self):
351
 
        return({'wx.SOLID':wx.SOLID, 'wx.DOT':wx.DOT, 'wx.LONG_DASH':wx.LONG_DASH, 'wx.SHORT_DASH':wx.SHORT_DASH, 'wx.DOT_DASH':wx.DOT_DASH, 'wx.USER_DASH':wx.USER_DASH})
352
 
 
353
 
 
354
 
if __name__== '__main__':
355
 
    from lrzoptions import LorzeOptions
356
 
 
357
 
    app= wx.App()
358
 
 
359
 
    # internationalization
360
 
    wxloc= wx.Locale()
361
 
    wxloc.AddCatalogLookupPathPrefix('./in18')
362
 
    # get system language ('xx_XX', 'CHARSET')
363
 
    wxlang= locale.getdefaultlocale()
364
 
    wxlang= wxlang[0][:2]
365
 
    # select translations
366
 
    if wxlang== 'de':
367
 
        wxloc.AddCatalog('LORZE_de')
368
 
 
369
 
    frame= TestFrame()
370
 
    app.MainLoop()
371