2
# -*- coding: utf-8 -*-
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
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.
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.
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/>.
15
from lrzvalchck import LorzeValueCheck
16
from lrzdlghelper import LorzeDlgHelper
17
from lrzdlgoptions import SortedListCtrl
19
_= wx.GetTranslation # name for translations texts
22
class LorzeDlgAttribut(wx.Dialog):
23
#Lorze Atrtribut Dialog to the GUI of LORZE erasandcad
25
def __init__(self, parent, options):
29
# LorzeOptions() of parent class
30
self.__options= options
32
# get settings for dialog from options
33
dlgborder= self.__options.GetDlgBorder()
34
wdlg, hdlg= self.DialogueSize()
37
wx.Dialog.__init__(self, self.__parent, wx.ID_ANY, _(u'Attributes'), size= (wdlg, hdlg), style= wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER)
40
self.__valchck= LorzeValueCheck()
43
self.__dlg= LorzeDlgHelper(self)
45
# Dictionairy for borders, cursors, penstyles
46
self.__bordersdict= self.__parent.GetBordersDict()
47
self.__cursorsdict= self.__parent.GetCursorsDict()
48
self.__penstyledict= self.__parent.GetPenStyleDict()
50
# default drawing list, label & combobox
52
self.__drawcombo= wx.ComboBox(self, size= (-1, -1), choices= self.__drawlist, style=wx.CB_READONLY)
55
self.__colortxt= wx.StaticText(self)
56
self.__layertxt= wx.StaticText(self)
57
self.__styletxt= wx.StaticText(self)
58
self.__widthtxt= wx.StaticText(self)
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'))
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'))
71
nbook= wx.Notebook(self)
72
widths= self.__options.GetAttrListWidths()
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]))
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'))
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'))
91
# dialog control buttons
92
buttonok= wx.Button(self, label= _(u'OK'))
93
buttoncancel= wx.Button(self, label= _(u'Cancel'))
95
buttonok.Bind(wx.EVT_BUTTON, self.OnOk)
96
buttoncancel.Bind(wx.EVT_BUTTON, self.OnCancel)
97
self.Bind(wx.EVT_CLOSE, self.OnDialogueClose)
100
vbox= wx.BoxSizer(wx.VERTICAL)
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)
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)
114
vbox.Add(nbook, 2, wx.EXPAND|wx.ALL, dlgborder)
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)
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)
133
def OnDialogueClose(self, event):
134
# last commando before close the dialogue
135
dlgw, dlgh= self.GetSize()
136
self.__options.SetDlgAttrSize(dlgw, dlgh)
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)
147
def OnActDraw(self, event):
148
# attributes from actual drawing
152
def OnAllDraw(self, event):
153
# attributes from all drawings
157
def OnSelected(self, event):
158
# attributes from selected elements
162
def OnDefault(self, event):
163
# attributes from defaults
167
def OnOk(self, event):
168
# ok clicked, get all attributes
172
def OnCancel(self, event):
173
# cancel clicked, leave without changes
177
def DialogueSize(self):
178
wdlg, hdlg= self.__options.GetDlgAttrSize()
180
# get size from parent
181
wparent, hparent= self.__parent.GetSize()
183
# dialog size control
185
# correct height to parent size
189
# correct width to parent size
195
class LorzeAttrPanel(wx.Panel):
196
# Lorze attribut panel for the attribut dialog
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
204
wx.Panel.__init__(self, self.__parent)
206
titledict= {'color':_(u'Colour'), 'layer':_(u'Layer'), 'style':_(u'Line style'), 'width':_(u'Line width')}
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])
216
self.__prev= wx.Panel(self)
219
new= wx.Button(self, label= _(u'New entry'))
222
self.__list.Bind(wx.EVT_LISTBOX_DCLICK, self.OnNew)
223
new.Bind(wx.EVT_BUTTON, self.OnNew)
226
vbox= wx.BoxSizer(wx.VERTICAL)
227
hbox= wx.BoxSizer(wx.HORIZONTAL)
229
hbox.Add(self.__prev, 1, wx.EXPAND|wx.ALL, dlgborder)
230
hbox.Add(new, 0, wx.EXPAND|wx.ALL, dlgborder)
232
#~ grid=wx.GridSizer(1, 3, dlgborder, dlgborder)
233
#~ grid.AddMany([(), (edit, 0, wx.EXPAND), (delete, 0, wx.EXPAND)])
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)
242
def OnNew(self, event):
248
return(self.__list.GetColumnWidth(0), self.__list.GetColumnWidth(1), self.__list.GetColumnWidth(2), self.__list.GetColumnWidth(3))
251
def GetSortedListDict(self):
252
# Returns a dictionairy for SortedListCtrl
255
#~ for i in self.__orderlist:
256
#~ sortedlistdict[index]= (self.__labeldict[i], self.__valuedict[i])
258
return(sortedlistdict)
261
#~ elif seloption== 'drawdefcolour':
262
#~ # get color as html string from color selection dialogue
263
#~ colour= self.__dlg.ColorDialog(self.__valuedict['drawdefcolour'])
265
#~ # clicked ok, get colour html string
266
#~ self.__valuedict['drawdefcolour']= colour
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'])
272
#~ # clicked ok, get string
273
#~ self.__valuedict['drawdeflayer']= text
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)
282
#~ style1= stylelist[0].lstrip().rstrip()
285
#~ # get string from list selection dialogue
286
#~ text= self.__dlg.ListSelection(self.__labeldict['drawdefstyle'], self.__penstyledict.keys(), style1)
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)
301
#~ self.__valuedict['drawdefstyle']= text+ text2
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'])
307
#~ # clicked ok, get float
308
#~ self.__valuedict['drawdefsize']= self.__valchck.Float(text, str(self.__options.GetSmartCursMarkPenSize()), 0)
311
class TestFrame(wx.Frame):
314
self.__options= LorzeOptions()
315
wx.Frame.__init__(self, None, title= u'Testcode LorzeDlgAttribut', size= (600, 600))
317
buttontest= wx.Button(self, label= u'Test')
318
buttonexit= wx.Button(self, label= u'Exit')
320
vbox= wx.BoxSizer(wx.VERTICAL)
325
buttontest.Bind(wx.EVT_BUTTON, self.OnTest)
326
buttonexit.Bind(wx.EVT_BUTTON, self.OnExit)
332
def OnTest(self, event):
333
dlg= LorzeDlgAttribut(self, self.__options)
338
def OnExit(self, event):
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})
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})
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})
354
if __name__== '__main__':
355
from lrzoptions import LorzeOptions
359
# internationalization
361
wxloc.AddCatalogLookupPathPrefix('./in18')
362
# get system language ('xx_XX', 'CHARSET')
363
wxlang= locale.getdefaultlocale()
364
wxlang= wxlang[0][:2]
365
# select translations
367
wxloc.AddCatalog('LORZE_de')