2 # -*- coding: utf-8 -*-
3 # generated by wxGlade 0.6.3 on Wed Mar 16 11:01:01 2011
5 matplotlib
.use('WXAgg')
6 from matplotlib
.backends
.backend_wxagg
import FigureCanvasWxAgg
as FigureCanvas
7 from matplotlib
.backends
.backend_wx
import NavigationToolbar2Wx
10 from wx
.lib
import sheet
16 import os
# New! Manon need
18 import wx
.lib
.newevent
23 wxLogEvent
, EVT_WX_LOG_EVENT
= wx
.lib
.newevent
.NewEvent()
25 logger
= logging
.getLogger()
29 #method that sort dikt by keys
32 for i
in range(length
):
35 lyst
[dikt
[x
].labelKey
]=x
38 def isSelectable(obj
):
39 #Return true if obj is selectable
40 if type(obj
) != type(None) and type(obj
) != connection
.Connection
:
46 #return true if obj is drang and dropable
47 if type(obj
) != type(None) and type(obj
) != connection
.Connection
:
52 def isConnectable(obj
):
53 #return true if obj can be connected
54 if type(obj
) == connection
.Connection
:
60 class MySummaryPanelState(wx
.grid
.Grid
,notif
.Notifiable
):
61 ''' Panel that contain the grid with all state'''
62 def __init__(self
,frame
, parent
,id):
63 wx
.grid
.Grid
.__init
__(self
,parent
)
64 notif
.Notifiable
.__init
__(self
)
66 self
.project
= self
.frame
.app
.project
67 self
.project
.addNotif(self
)
68 self
.Bind(wx
.grid
.EVT_GRID_CELL_CHANGE
,self
.OnChange
)
69 self
.Bind(wx
.grid
.EVT_GRID_CELL_LEFT_DCLICK
,self
.OnDoubleClick
)
70 self
.lyst
= ['name','temperature','pressure','quality','enthalpy','entropy','exergy','specific volume','I1','O1']
71 self
.CreateGrid(1,len(self
.lyst
))
72 self
.SetRowLabelSize(0) #permet de ne pas afficher la premiere colonne
75 self
.SetColLabelValue(i
,x
)
77 for x
in range(len(self
.lyst
)):
78 self
.SetColSize(x
, 110)
81 def OnChange(self
,evt
):
82 row
,col
= evt
.GetRow(),evt
.GetCol()
84 elem
= self
.project
.elemList
[self
.GetRowLabelValue(row
)]
85 elem
.properties
[self
.GetColLabelValue(col
)].impose((self
.GetCellValue(row
,col
)))
87 def OnDoubleClick(self
,evt
):
88 #Allow to travel between element
89 row
,col
= evt
.GetRow(),evt
.GetCol()
91 elem
= self
.GetCellValue(row
,col
)
93 for x
in self
.project
.elemList
:
95 if self
.project
.currentElem
!= None:
96 self
.project
.currentElem
.deselect()
97 self
.project
.currentElem
= self
.project
.elemList
[x
]
98 self
.project
.elemList
[x
].select()
100 elem
= self
.GetRowLabelValue(row
)
102 for x
in self
.project
.elemList
:
104 if self
.project
.currentElem
!= None:
105 self
.project
.currentElem
.deselect()
106 self
.project
.currentElem
= self
.project
.elemList
[x
]
107 self
.project
.elemList
[x
].select()
111 #Delete previous Grid
112 numRows
= self
.GetNumberRows()
114 for z
in range(0,numRows
):
116 #Create new grid with updated value
117 #sortedList ne fonctionne pas car les elem n'ont pas de key
119 for x
in self
.project
.elemList
:
120 if self
.project
.elemList
[x
].genericName() == 'state':
122 self
.SetRowLabelValue(i
,x
)
125 if z
!= 'I1' and z
!= 'O1':
126 value
= self
.project
.elemList
[x
].properties
[z
].value
127 if value
!= None and z
!= 'name' and z
!= 'quality' and z
!= 'specific volume':
128 stringvalue
= str('%0.2f'%value
) #set two digits after decimal
129 elif value
!= None and z
== 'specific volume':
130 stringvalue
= str('%0.4f'%value
)
132 stringvalue
= str(value
)
135 if math
.isnan(float(value
)) :
136 stringvalue
= str(prop
.qualityKind(self
.project
.elemList
[x
].properties
[z
]))
138 stringvalue
= str('%0.5f'%value
)
140 stringvalue
= str(value
)
142 stringvalue
= str(None)
143 self
.SetCellTextColour(i
,j
,self
.project
.elemList
[x
].properties
[z
].colour())
144 self
.SetCellValue(i
,j
,stringvalue
)
146 link
= self
.project
.elemList
[x
].connection
[z
].link
148 self
.SetCellValue(i
,j
,str(self
.project
.nameList
[link
.elem
]))
150 self
.SetCellValue(i
,j
,'Not connected')
156 class MyAnalysisPanel(wx
.Panel
):
157 '''Panel that contains piechart'''
158 def __init__(self
,frame
, parent
, id):
159 wx
.Panel
.__init
__(self
,parent
,id)
161 self
.project
= self
.frame
.app
.project
162 #self.SetBackgroundColour('WHITE')
163 self
.figure
= matplotlib
.figure
.Figure()
164 self
.subplot
= self
.figure
.add_subplot(111)
167 self
.canvas
= FigureCanvas(self
, -1, self
.figure
)
168 self
.sizer
= wx
.BoxSizer(wx
.VERTICAL
)
169 self
.sizer
.Add(self
.canvas
, 1, wx
.LEFT | wx
.TOP | wx
.GROW
)
170 self
.SetSizer(self
.sizer
)
175 def add_toolbar(self
):
176 self
.toolbar
= NavigationToolbar2Wx(self
.canvas
)
177 self
.toolbar
.Realize()
178 # On Windows platform, default window size is incorrect, so set
179 # toolbar width to figure width.
180 tw
, th
= self
.toolbar
.GetSizeTuple()
181 fw
, fh
= self
.canvas
.GetSizeTuple()
182 # By adding toolbar in sizer, we are able to put it at the bottom
183 # of the frame - so appearance is closer to GTK version.
184 # As noted above, doesn't work for Mac.
185 self
.toolbar
.SetSize(wx
.Size(fw
, th
))
186 self
.sizer
.Add(self
.toolbar
, 0, wx
.LEFT | wx
.EXPAND
)
187 # update the axes menu on the toolbar
188 self
.toolbar
.update()
190 def OnPaint(self
, event
):
193 def OnPageChange(self
):
199 for x
in self
.project
.elemList
:
200 for y
in self
.project
.elemList
[x
].properties
:
201 if y
== 'power' and x
[:6] != 'boiler':
203 if self
.project
.elemList
[x
].properties
[y
].value
!= None:
205 t
.append(abs(self
.project
.elemList
[x
].properties
[y
].value
))
207 elif y
== 'power lost':
209 if self
.project
.elemList
[x
].properties
[y
].value
!= None:
211 t
.append(abs(self
.project
.elemList
[x
].properties
[y
].value
))
212 label
.append(x
+' lost')
215 logger
.info('All the powers have not been computed')
216 self
.subplot
.pie([0])
218 logger
.info('All the powers have been computed')
219 self
.subplot
.pie(t
,labels
= label
)
222 self
.figure
.suptitle('Energy Balance',fontsize
= 12)
228 class MyCyclePanel(wx
.Panel
,notif
.Notifiable
):
229 ''' Panel that contain cycle'''
230 def __init__(self
,frame
,parent
,id):
231 wx
.Panel
.__init
__(self
,parent
,id)
232 notif
.Notifiable
.__init
__(self
)
234 self
.project
= self
.frame
.app
.project
235 self
.project
.addNotif(self
)
236 self
.Bind(wx
.EVT_LEFT_DOWN
,self
.OnLeftDown
)
237 self
.Bind(wx
.EVT_MOTION
,self
.OnMouseMove
)
238 self
.Bind(wx
.EVT_LEFT_UP
,self
.OnLeftUp
)
239 self
.Bind(wx
.EVT_RIGHT_UP
,self
.OnRightUp
)
240 self
.Bind(wx
.EVT_KEY_DOWN
,self
.OnKeyDown
)
241 self
.Bind(wx
.EVT_KEY_UP
,self
.OnKeyUp
)
242 self
.Bind(wx
.EVT_PAINT
,self
.OnPaint
)
243 self
.checkCycle
= {'draganddrop':None,'onArrow':False,'onArrowFirstConn':None,'dpos':(0,0)}
244 self
.checkCycleKey
= {'control' : False}
247 def OnLeftDown(self
,event
):
248 posEvent
= event
.GetPosition().Get()
249 obj
= self
.project
.isZoneClick(posEvent
)
252 dx
= posEvent
[0]-obj
.pos
[0]
253 dy
= posEvent
[1]-obj
.pos
[1]
254 self
.checkCycle
['dpos'] = (dx
,dy
)
256 self
.checkCycle
['draganddrop'] = obj
258 def OnMouseMove(self
,event
):
259 if self
.checkCycle
['draganddrop'] != None:
260 posEvent
= event
.GetPosition().Get()
261 self
.checkCycle
['draganddrop'].pos
= (posEvent
[0]-self
.checkCycle
['dpos'][0],posEvent
[1]-self
.checkCycle
['dpos'][1])
264 def OnRightUp(self
,event
):
265 #Deconnect connection if click with right mouseon it
266 posEvent
= event
.GetPosition().Get()
267 obj
= self
.project
.isZoneClick(posEvent
)
268 if isConnectable(obj
):
271 elem_b
= obj
.link
.elem
272 elem_a
.connect(obj
,None)
274 elif isSelectable(obj
):
275 self
.project
.removeElem(self
.project
.nameList
[obj
])
277 def OnLeftUp(self
,event
):
278 posEvent
= event
.GetPosition().Get()
279 obj
= self
.project
.isZoneClick(posEvent
)
280 self
.checkCycle
['dpos'] = None
281 if self
.checkCycle
['draganddrop'] != None:
282 self
.checkCycle
['draganddrop'] = None
283 #si on veut pas de selection apres un dandd, il faut mettre elif dans la creation de composants, mais alors les selection se font en doubleckick O_o
286 elif self
.frame
.window_4
.checkBibli
['composant'] != None:
287 self
.project
.createElem(self
.frame
.window_4
.checkBibli
['composant'],posEvent
)
288 self
.frame
.window_4
.checkBibli
['composant'] = None
289 #SELECTION - DISPLAY PROPRIETES
290 elif isSelectable(obj
) and self
.checkCycle
['onArrow'] == False :
291 if self
.project
.currentElem
== obj
:
293 elif self
.project
.currentElem
!= None and self
.checkCycleKey
['control'] == False:
294 self
.project
.currentElem
.deselect()
295 self
.project
.currentElem
= obj
297 """doit se faire ici et pas dans elem.select(), car en cas de selection multiple ou l'on utilise elem.select() aussi, il ne faut pas changer l'elem current
298 autre remarque : le elem.select() doit se faire apres que le currentelem soit changer, car c'est select() qui contient de doNotify"""
299 elif self
.project
.currentElem
!= None and self
.checkCycleKey
['control'] == True :
301 elif self
.project
.currentElem
== None :
302 self
.project
.currentElem
= self
.project
.isZoneClick(posEvent
)
303 self
.project
.isZoneClick(posEvent
).select()
304 #DESELECTION DE TOUT LES ELEMENTS
306 for z
in self
.project
.elemList
:
307 self
.project
.elemList
[z
].deselect()
309 elif isConnectable(obj
) and self
.checkCycle
['onArrow'] == True :
310 if self
.checkCycle
['onArrowFirstConn'] == None:
311 self
.checkCycle
['onArrowFirstConn'] = obj
312 elif self
.checkCycle
['onArrowFirstConn'] != None:
313 conn1
= self
.checkCycle
['onArrowFirstConn']
315 if type(conn1
) == type(conn2
) :
316 self
.checkCycle
['onArrowFirstConn'].elem
.connect(conn1
,conn2
)
318 logger
.info('Please select a connection not an element')
319 self
.checkCycle
['onArrowFirstConn'] = None
323 def OnKeyDown(self
,event
):
324 key
= event
.GetKeyCode()
325 if key
== wx
.WXK_DELETE
:
326 self
.project
.removeSelectedElem()
328 elif key
== wx
.WXK_CONTROL
:
329 self
.checkCycleKey
['control'] = True
331 def OnKeyUp(self
,event
):
332 key
= event
.GetKeyCode()
333 if key
== wx
.WXK_CONTROL
:
334 self
.checkCycleKey
['control'] = False
336 def OnPaint(self
,event
):
337 #Dessine a partir de elemList les elements et de arrowList les fleches
338 newpaintdc
= wx
.PaintDC(self
)
340 for z
in self
.project
.elemList
:
341 for y
in self
.project
.elemList
[z
].connection
:
343 #Draw Connection's Element
344 newpaintdc
.DrawBitmap(self
.project
.elemList
[z
].connection
[y
].bmp
,self
.project
.elemList
[z
].connection
[y
].dpos
[0]+self
.project
.elemList
[z
].pos
[0],self
.project
.elemList
[z
].connection
[y
].dpos
[1]+self
.project
.elemList
[z
].pos
[1])
345 pen
= wx
.Pen('BLACK',width
= 6,style
= wx
.SOLID
) #Set color and width of connection's line
347 #Set color and width of connection's line
348 #pen = wx.Pen('BLACK',width = 6,style = wx.SOLID) # merge manon sait pas si c le bon >.<
350 newpaintdc
.SetPen(pen
)
351 if self
.project
.elemList
[z
].connection
[y
].link
!= None :
352 elem
= self
.project
.elemList
[z
]
353 if elem
.genericName
!= 'state':
354 x1
= elem
.connection
[y
].dpos
[0]+elem
.pos
[0]
355 y1
= elem
.connection
[y
].dpos
[1]+elem
.pos
[1]
356 elif elem
.genericName
== 'state' :
357 x1
= (elem
.pos
[0]+elem
.zone
[1][0]/2)
358 y1
= (elem
.pos
[0]+elem
.zone
[1][1]/2)
359 x2
= elem
.connection
[y
].link
.dpos
[0]+elem
.connection
[y
].link
.elem
.pos
[0]
360 y2
= elem
.connection
[y
].link
.dpos
[1]+elem
.connection
[y
].link
.elem
.pos
[1]
361 newpaintdc
.DrawLinePoint((x1
,y1
),(x2
,y2
))
363 newpaintdc
.DrawBitmap(self
.project
.elemList
[z
].bmp
,self
.project
.elemList
[z
].pos
[0],self
.project
.elemList
[z
].pos
[1], True)
364 for y
in self
.project
.elemList
[z
].connection
:
365 #Draw Connection's Element
366 newpaintdc
.DrawBitmap(self
.project
.elemList
[z
].connection
[y
].bmp
,self
.project
.elemList
[z
].connection
[y
].dpos
[0]+self
.project
.elemList
[z
].pos
[0],self
.project
.elemList
[z
].connection
[y
].dpos
[1]+self
.project
.elemList
[z
].pos
[1])
374 class MyBibliPanel(wx
.ScrolledWindow
):
375 """ Panel which contains the cycle component library """
376 def __init__(self
,frame
, parent
,id):
377 wx
.ScrolledWindow
.__init
__(self
, parent
= parent
, id = -1)
378 numberOfelement
= len(frame
.app
.id2type
)
380 self
.SetScrollbars(0,height
,0,numberOfelement
)
382 self
.checkBibli
= {'composant':None}
385 for elem
in self
.frame
.app
.id2type
:
386 templist
.append((elem
,self
.frame
.app
.id2type
[elem
]))
391 button
= wx
.Button(self
,id=-1,label
=z
[0],pos
=(x
,y
),size
=(140,height
),name
=z
[0])
392 self
.Bind(wx
.EVT_BUTTON
, self
.OnElem
,button
)
396 def OnElem(self
,event
):
397 bmpButton
= event
.GetEventObject()
398 elemName
= bmpButton
.GetName()
399 for elem
in self
.frame
.app
.id2type
:
401 self
.checkBibli
['composant'] = self
.frame
.app
.id2type
[elem
]
405 class MyPropertyGrid(wx
.Panel
, notif
.Notifiable
):
406 ''' Panel that contains a grid with properties of selected element '''
407 def __init__(self
,frame
,parent
,id):
408 wx
.Panel
.__init
__(self
,parent
,id)
409 notif
.Notifiable
.__init
__(self
)
411 self
.project
= self
.frame
.app
.project
412 self
.project
.addNotif(self
)
413 self
.propertygridsizer
= wx
.BoxSizer(wx
.VERTICAL
)
414 self
.SetSizer(self
.propertygridsizer
)
417 self
.propertygridsizer
.Clear()
418 self
.mypropertygrid
= wx
.propgrid
.PropertyGridManager(self
,style
=wx
.propgrid
.PG_SPLITTER_AUTO_CENTER|wx
.propgrid
.PG_TOOLBAR
)
419 self
.mypropertygrid
.Bind(wx
.propgrid
.EVT_PG_SELECTED
,self
.OnSelected
)
420 self
.mypropertygrid
.Bind(wx
.propgrid
.EVT_PG_DOUBLE_CLICK
,self
.OnDoubleClick
)
421 self
.mypropertygrid
.Bind(wx
.propgrid
.EVT_PG_CHANGED
,self
.OnValueChange
)
423 if self
.project
.currentElem
!= None :
424 self
.mypropertygrid
.Append(wx
.propgrid
.PropertyCategory(self
.project
.nameList
[self
.project
.currentElem
]))
425 #DISLPAY PROPERTIES EXCEPT REFERENCE
426 sortedPropList
= sortBykey(self
.project
.currentElem
.properties
)
427 for x
in sortedPropList
:
428 if x
[:9] != 'reference' :
429 a
= self
.mypropertygrid
.Append(self
.project
.currentElem
.properties
[x
].display
)
430 a
.SetTextColour(self
.project
.currentElem
.properties
[x
].colour())
433 self
.mypropertygrid
.Append(wx
.propgrid
.PropertyCategory('Connections'))
434 for x
in self
.project
.currentElem
.connection
:
435 if self
.project
.currentElem
.connection
[x
].link
!= None:
436 self
.mypropertygrid
.Append(wx
.propgrid
.StringProperty(x
,value
=str(self
.project
.nameList
[self
.project
.currentElem
.connection
[x
].link
.elem
])))
438 self
.mypropertygrid
.Append(wx
.propgrid
.StringProperty(x
,value
=''))
440 self
.mypropertygrid
.Append(wx
.propgrid
.PropertyCategory('Reference'))
441 for x
in sortedPropList
:
442 if x
[0:9] == 'reference':
443 a
= self
.mypropertygrid
.Append(self
.project
.currentElem
.properties
[x
].display
)
444 a
.SetTextColour(self
.project
.currentElem
.properties
[x
].colour())
447 self
.mypropertygrid
.Append(wx
.propgrid
.StringProperty('No current element',value
= 'Please select an element'))
450 self
.propertygridsizer
.Add(self
.mypropertygrid
,1,wx
.EXPAND
)
453 def OnSelected(self
,event
):
454 #event.GetProperty() event.GetPropertyName() event.GetPropertyValue()
455 #print("Selection :",event.GetPropertyName,"\nvalue :",event.GetPropertyValue())
458 def OnDoubleClick(self
,event
):
459 #Allow to travel between element
460 if event
.GetPropertyValue() != None:
461 for x
in self
.project
.elemList
:
462 if str(x
) == event
.GetPropertyValue():
463 self
.project
.currentElem
.deselect()
464 self
.project
.currentElem
= self
.project
.elemList
[x
]
465 self
.project
.elemList
[x
].select()
467 def OnValueChange(self
,event
):
468 #Impose new value given by user
469 propName
= event
.GetProperty().GetLabel()
470 prop
= self
.project
.currentElem
.properties
[propName
]
471 if propName
== 'fluid':
472 num
= event
.GetPropertyValue()
473 fluidname
= self
.project
.app
.fluidListName
[num
]
474 val
= self
.project
.app
.fluidList
[fluidname
]
476 elif propName
== 'reference state':
477 val
= event
.GetPropertyValue()
483 val
= str(event
.GetPropertyValue())
488 class wxLogHandler(logging
.Handler
):
490 A handler class which sends log strings to a wx object
492 def __init__(self
, wxDest
=None):
494 Initialize the handler
495 @param wxDest: the destination object to post the event to
496 @type wxDest: wx.Window
498 logging
.Handler
.__init
__(self
)
500 self
.level
= logging
.DEBUG
504 does nothing for this handler
509 def emit(self
, record
):
515 msg
= self
.format(record
)
516 evt
= wxLogEvent(message
=msg
,levelname
=record
.levelname
)
517 wx
.PostEvent(self
.wxDest
,evt
)
518 except (KeyboardInterrupt, SystemExit):
521 self
.handleError(record
)
524 class MyStatusPanel(wx
.ScrolledWindow
,notif
.Notifiable
):
525 ''' Panel that inform user with log '''
526 def __init__(self
,frame
,parent
,id):
527 notif
.Notifiable
.__init
__(self
)
528 wx
.ScrolledWindow
.__init
__(self
,parent
,id)
529 width
,height
= self
.GetSizeTuple()
530 self
.SetScrollbars(10,10,50,0)
531 self
.Bind(EVT_WX_LOG_EVENT
, self
.onLogEvent
)
532 self
.SetBackgroundColour('BLACK')
533 self
.SetForegroundColour('WHITE')
535 date
= datetime
.date
.today().timetuple()
537 date
= datetime
.datetime
.now().strftime("%d-%m-%y ~ %Hh%M ")
538 self
.startText
= 'Welcome to UCycLe\n'+date
+'\n'
539 self
.disp
= wx
.StaticText(self
,-1,self
.startText
)
543 self
.logger
= logging
.getLogger()
544 self
.logger
.setLevel(logging
.DEBUG
)
545 # create custom handler and set level to debug
546 self
.ch
= wxLogHandler(self
)
547 self
.ch
.setLevel(logging
.DEBUG
)
549 #self.formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
550 #self.formatter = logging.Formatter('%(asctime)s - %(message)s',datefmt='%d-%m-%Y - %H h %M')
551 self
.formatter
= logging
.Formatter('%(message)s')
552 # add formatter to ch
553 self
.ch
.setFormatter(self
.formatter
)
555 self
.logger
.addHandler(self
.ch
)
559 def onLogEvent(self
,event
):
562 Add event.message to text window
565 msg
= event
.message
.strip("\r")+'\n'
566 self
.logtext
.append(msg
)
568 if len(self
.logtext
) >5:
570 disptext
+= self
.logtext
[len(self
.logtext
)-i
]
572 for i
in range(len(self
.logtext
)):
573 disptext
= self
.logtext
[i
]
574 wx
.StaticText
.SetLabel(self
.disp
,str(disptext
))
577 class MyFrame(wx
.Frame
):
578 ''' Principal frame of the interface '''
579 def __init__(self
,app
, *args
, **kwds
):
580 # begin wxGlade: MyFrame.__init__
581 kwds
["style"] = wx
.CAPTION|wx
.CLOSE_BOX|wx
.MINIMIZE_BOX|wx
.MAXIMIZE|wx
.MAXIMIZE_BOX|wx
.SYSTEM_MENU|wx
.RESIZE_BORDER|wx
.FULL_REPAINT_ON_RESIZE|wx
.CLIP_CHILDREN
582 wx
.Frame
.__init
__(self
,parent
= None, *args
, **kwds
)
584 self
.project
= self
.app
.project
586 self
.frame_1_menubar
= wx
.MenuBar()
587 global ID_NEW
; ID_NEW
= wx
.NewId()
588 global ID_OPEN
; ID_OPEN
= wx
.NewId()
589 global ID_SAVEAS
; ID_SAVEAS
= wx
.NewId()
590 global ID_PRINT
; ID_PRINT
= wx
.NewId()
591 global ID_EXIT
; ID_EXIT
= wx
.NewId()
592 global ID_ABOUT
; ID_ABOUT
= wx
.NewId()
593 wxglade_tmp_menu
= wx
.Menu()
594 wxglade_tmp_menu
.Append(ID_NEW
, "&New", "", wx
.ITEM_NORMAL
)
595 wxglade_tmp_menu
.Append(ID_OPEN
, "&Open", "", wx
.ITEM_NORMAL
)
596 wxglade_tmp_menu
.Append(ID_SAVEAS
, "&Save As", "", wx
.ITEM_NORMAL
)
597 wxglade_tmp_menu
.Append(ID_PRINT
, "&Print", "", wx
.ITEM_NORMAL
)
598 wxglade_tmp_menu
.Append(ID_EXIT
, "&Quit", "", wx
.ITEM_NORMAL
)
599 self
.frame_1_menubar
.Append(wxglade_tmp_menu
, "&File")
600 wxglade_tmp_menu
= wx
.Menu()
601 wxglade_tmp_menu
.Append(ID_ABOUT
, "&About", "", wx
.ITEM_NORMAL
)
602 self
.frame_1_menubar
.Append(wxglade_tmp_menu
, "&Help")
603 self
.SetMenuBar(self
.frame_1_menubar
)
607 self
.frame_1_toolbar
= wx
.ToolBar(self
, -1)
608 self
.SetToolBar(self
.frame_1_toolbar
)
609 global ID_CYCLE
; ID_CYCLE
= wx
.NewId()
610 global ID_DATA
; ID_DATA
= wx
.NewId()
611 global ID_ANALYSE
; ID_ANALYSE
= wx
.NewId()
612 global ID_ARROW
; ID_ARROW
= wx
.NewId()
613 self
.frame_1_toolbar
.AddLabelTool(ID_OPEN
, "open", wx
.Bitmap("images/toolbar/open.png", wx
.BITMAP_TYPE_ANY
), wx
.NullBitmap
, wx
.ITEM_NORMAL
, "Open a project", "")
614 self
.frame_1_toolbar
.AddSeparator()
615 self
.frame_1_toolbar
.AddLabelTool(ID_CYCLE
, "cycle", wx
.Bitmap("images/toolbar/cycle.png", wx
.BITMAP_TYPE_ANY
), wx
.NullBitmap
, wx
.ITEM_NORMAL
, "Display cycle", "")
616 self
.frame_1_toolbar
.AddLabelTool(ID_DATA
, "Data", wx
.Bitmap("images/toolbar/data.png", wx
.BITMAP_TYPE_ANY
), wx
.NullBitmap
, wx
.ITEM_NORMAL
, "Display states panel", "")
617 self
.frame_1_toolbar
.AddLabelTool(ID_ANALYSE
, "Analyse", wx
.Bitmap("images/toolbar/piechart.png", wx
.BITMAP_TYPE_ANY
), wx
.NullBitmap
, wx
.ITEM_NORMAL
, "Display energy balance", "")
618 self
.frame_1_toolbar
.AddSeparator()
619 self
.frame_1_toolbar
.AddLabelTool(ID_ARROW
, "Arrow", wx
.Bitmap("images/toolbar/fleche.png", wx
.BITMAP_TYPE_ANY
), wx
.NullBitmap
, wx
.ITEM_CHECK
, "Allow to connect element", "")
621 self
.window_1
= MyStatusPanel(self
, self
, -1)
622 self
.window_2
= MyPropertyGrid(self
, self
, -1)
623 self
.notebook_1
= wx
.Notebook(self
, -1, style
=0)
624 self
.notebook_1_pane_1
= wx
.Panel(self
.notebook_1
, -1)
625 self
.window_3
= MyCyclePanel(self
, self
.notebook_1_pane_1
, -1)
626 self
.window_4
= MyBibliPanel(self
, self
.notebook_1_pane_1
, -1)
627 self
.notebook_1_pane_2
= wx
.Panel(self
.notebook_1
, -1)
628 self
.window_6
= MySummaryPanelState(self
, self
.notebook_1_pane_2
, -1)
629 self
.notebook_1_pane_3
= wx
.Panel(self
.notebook_1
, -1)
630 self
.window_5
= MyAnalysisPanel(self
, self
.notebook_1_pane_3
, -1)
632 self
.__set
_properties
()
635 self
.Bind(wx
.EVT_MENU
, self
.OnNew
, id=ID_NEW
)
636 self
.Bind(wx
.EVT_MENU
, self
.OnOpen
, id=ID_OPEN
)
637 self
.Bind(wx
.EVT_MENU
, self
.OnSaveAs
, id=ID_SAVEAS
)
638 self
.Bind(wx
.EVT_MENU
, self
.OnPrint
, id=ID_PRINT
)
639 self
.Bind(wx
.EVT_MENU
, self
.OnQuit
, id=ID_EXIT
)
640 self
.Bind(wx
.EVT_MENU
, self
.OnAbout
, id=ID_ABOUT
)
641 self
.Bind(wx
.EVT_TOOL
, self
.OnOpen
, id=ID_OPEN
)
642 self
.Bind(wx
.EVT_TOOL
, self
.OnCycle
, id=ID_CYCLE
)
643 self
.Bind(wx
.EVT_TOOL
, self
.OnData
, id=ID_DATA
)
644 self
.Bind(wx
.EVT_TOOL
, self
.OnAnalyse
, id=ID_ANALYSE
)
645 self
.Bind(wx
.EVT_TOOL
, self
.OnArrow
, id=ID_ARROW
)
646 self
.Bind(wx
.EVT_NOTEBOOK_PAGE_CHANGING
, self
.OnPageChanging
, self
.notebook_1
)
649 def __set_properties(self
):
650 # begin wxGlade: MyFrame.__set_properties
651 self
.SetTitle("frame_1")
652 self
.SetSize((800, 600))
653 self
.frame_1_toolbar
.SetToolBitmapSize((20, 20))
654 self
.frame_1_toolbar
.Realize()
655 self
.window_3
.SetFocus()
658 def __do_layout(self
):
659 # begin wxGlade: MyFrame.__do_layout
660 sizer_1
= wx
.BoxSizer(wx
.HORIZONTAL
)
661 sizer_4
= wx
.BoxSizer(wx
.HORIZONTAL
)
662 grid_sizer_1
= wx
.GridSizer(1, 1, 0, 0)
663 sizer_3
= wx
.BoxSizer(wx
.HORIZONTAL
)
664 sizer_2
= wx
.BoxSizer(wx
.VERTICAL
)
665 sizer_2
.Add(self
.window_1
, 1, wx
.EXPAND
, 0)
666 sizer_2
.Add(self
.window_2
, 3, wx
.EXPAND
, 0)
667 sizer_1
.Add(sizer_2
, 1, wx
.EXPAND
, 0)
668 sizer_3
.Add(self
.window_3
, 6, wx
.EXPAND
, 0)
669 sizer_3
.Add(self
.window_4
, 1, wx
.EXPAND
, 0)
670 self
.notebook_1_pane_1
.SetSizer(sizer_3
)
671 grid_sizer_1
.Add(self
.window_6
, 1, wx
.EXPAND
, 0)
672 self
.notebook_1_pane_2
.SetSizer(grid_sizer_1
)
673 sizer_4
.Add(self
.window_5
, 1, wx
.EXPAND
, 0)
674 self
.notebook_1_pane_3
.SetSizer(sizer_4
)
675 self
.notebook_1
.AddPage(self
.notebook_1_pane_1
, "Cycle")
676 self
.notebook_1
.AddPage(self
.notebook_1_pane_2
, "Summary")
677 self
.notebook_1
.AddPage(self
.notebook_1_pane_3
, "Analysis")
678 sizer_1
.Add(self
.notebook_1
, 2, wx
.EXPAND
, 0)
679 self
.SetSizer(sizer_1
)
683 def saveAs(self
): # ajout de Manon
684 dlg
= wx
.FileDialog( self
, "Save project as ...", ' ', "", "*.*", wx
.SAVE | wx
.OVERWRITE_PROMPT
)
685 if dlg
.ShowModal() == wx
.ID_OK
:
686 val
= dlg
.GetMessage()
687 saveName
=dlg
.GetFilename()
688 dirName
=dlg
.GetDirectory()
689 filehandle
= self
.project
.saveProject(saveName
, dirName
)
692 def OnNew(self
, event
): # wxGlade: MyFrame.<event_handler>
693 exitDlg
= wx
.MessageDialog( self
, "The document has been modified.\n Do you want to save it?\n","Confirm", wx
.YES_NO
)
694 gotcha
= exitDlg
.ShowModal()
695 if gotcha
== wx
.ID_YES
:
696 self
.OnSaveAs(wx
.ID_YES
)
697 elif gotcha
== wx
.ID_NO
:
699 self
.project
.newProject()
701 def OnOpen(self
, event
): # wxGlade: MyFrame.<event_handler>
703 dlg
= wx
.FileDialog(self
, "Choose a file", ' ', "", "*.*", wx
.OPEN
)
704 if dlg
.ShowModal() == wx
.ID_OK
:
705 fileName
=dlg
.GetFilename()
706 dirName
=dlg
.GetDirectory()
707 self
.project
.openProject(fileName
, dirName
)
711 def OnSaveAs(self
, event
): # wxGlade: MyFrame.<event_handler>
714 def OnQuit(self
, event
): # wxGlade: MyFrame.<event_handler>
715 exitDlg
= wx
.MessageDialog( self
, "Are you sure you want to quit ?\n","Confirm", wx
.YES_NO
)
716 gotcha
= exitDlg
.ShowModal()
717 if gotcha
== wx
.ID_YES
:
721 def OnCycle(self
, event
): # wxGlade: MyFrame.<event_handler>
722 self
.notebook_1
.ChangeSelection(0)
724 def OnData(self
, event
): # wxGlade: MyFrame.<event_handler>
725 self
.notebook_1
.ChangeSelection(1)
727 def OnAbout(self
, event
): # wxGlade: MyFrame.<event_handler>
728 about_text
= 'Bienvenue sur UCycLE,\n le logiciel de calcul de cycle thermique moteur.'
729 dial
= wx
.MessageDialog(None, about_text
, 'Info', wx
.OK
)
732 def OnAnalyse(self
, event
): # wxGlade: MyFrame.<event_handler>
733 self
.notebook_1
.ChangeSelection(2)
736 def OnArrow(self
, event
): # wxGlade: MyFrame.<event_handler>
737 if self
.window_3
.checkCycle
['onArrow'] == True :
738 self
.window_3
.checkCycle
['onArrow'] = False
739 self
.window_3
.checkCycle
['onArrowFirstElem'] = None
740 elif self
.window_3
.checkCycle
['onArrow'] == False:
741 self
.window_3
.checkCycle
['onArrow'] = True
743 logger
.info('Error in Arrow')
744 def OnTab(self
, event
): # wxGlade: MyFrame.<event_handler>
745 if self
.notebook_1
.GetSelection() == 0 :
746 self
.window_3
.Refresh()
749 def OnPageChanging(self
, event
): # wxGlade: MyFrame.<event_handler>
750 if event
.GetSelection() == 2:
751 self
.window_5
.OnPageChange()
753 def OnPrint(self
, event
): # wxGlade: MyFrame.<event_handler>
754 self
.app
.project
.exportData()
756 # end of class MyFrame
759 '''if __name__ == "__main__":
760 app = wx.PySimpleApp(0)
761 wx.InitAllImageHandlers()
762 frame_1 = MyFrame(None, -1, "")
763 app.SetTopWindow(frame_1)