forked from capocchi/DEVSimPy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLibPanel.py
More file actions
165 lines (129 loc) · 6.02 KB
/
LibPanel.py
File metadata and controls
165 lines (129 loc) · 6.02 KB
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# -*- coding: utf-8 -*-
## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
# LibPanel.py ---
# --------------------------------
# Copyright (c) 2013
# Laurent CAPOCCHI
# University of Corsica
# --------------------------------
# Version 1.0 last modified: 10/11/2013
## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
#
# GENERAL NOTES AND REMARKS:
#
## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
#
# GLOBAL VARIABLES AND FUNCTIONS
#
## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
import wx
import os
import gettext
_ = gettext.gettext
from LibraryTree import LibraryTree
import Menu
#-----------------------------------------------------------------------
class SearchLib(wx.SearchCtrl):
"""
"""
def __init__(self, *args, **kwargs):
"""
"""
super(SearchLib, self).__init__(*args, **kwargs)
self.treeChildren = []
self.treeCopy = None
self.ShowCancelButton( True)
self.Bind(wx.EVT_SEARCHCTRL_CANCEL_BTN, self.OnCancel)
self.Bind(wx.EVT_TEXT, self.OnSearch)
if wx.VERSION_STRING < '4.0':
self.SetToolTipString(_("Find model in the library depending its name."))
else:
self.SetToolTip(_("Find model in the library depending its name."))
def OnCancel(self, evt):
"""
"""
self.Clear()
def OnSearch(self, evt):
"""
"""
mainW = evt.GetEventObject().GetTopLevelParent()
mainW.OnSearch(evt)
#-----------------------------------------------------------------------
class LibPanel(wx.Panel):
"""
"""
def __init__(self, parent, name):
super(LibPanel, self).__init__(parent, name=name)
libSizer = wx.BoxSizer(wx.VERTICAL)
### create libraries tree
self.tree = LibraryTree(self, wx.NewIdRef(), wx.DefaultPosition, style=wx.TR_DEFAULT_STYLE|wx.TR_HIDE_ROOT|wx.TR_LINES_AT_ROOT|wx.TR_HAS_BUTTONS|wx.SUNKEN_BORDER)
mainW = parent.GetTopLevelParent()
### read ChargedDomainList from .devsimpy
cfg_domain_list = mainW.cfg.Read('ChargedDomainList')
chargedDomainList = eval(cfg_domain_list) if cfg_domain_list else []
self.tree.Populate(chargedDomainList)
self.tree.UnselectAll()
### search tree that is hide when starting devsimpy (see __do_layout)
self.searchTree = LibraryTree(self, wx.NewIdRef(), wx.DefaultPosition, style=wx.TR_DEFAULT_STYLE|wx.TR_HIDE_ROOT|wx.TR_MULTIPLE|wx.TR_LINES_AT_ROOT|wx.TR_HAS_BUTTONS|wx.SUNKEN_BORDER)
### search field creation
self.search = SearchLib(self, size=(200,-1), style = wx.TE_PROCESS_ENTER)
#self.tree.UpdateAll()
self.searchTree.Hide()
tb = self.BuildToolbar()
libSizer.Add(tb, 0, wx.ALL | wx.ALIGN_LEFT | wx.EXPAND)
libSizer.Add(self.tree, 1 ,wx.EXPAND)
libSizer.Add(self.searchTree, 1 ,wx.EXPAND)
libSizer.Add(self.search, 0 ,wx.BOTTOM|wx.EXPAND)
self.SetSizer(libSizer)
self.SetAutoLayout(True)
self.SetBackgroundColour(wx.WHITE)
self.__set_tips()
def BuildToolbar(self):
""" creates one of the tool-bars
The buttons act like radio buttons, setting a mode for the Panel
Only one of them is pressed at a time. The SetMode() method handles this
"""
tb = wx.ToolBar(self, wx.NewIdRef())
#self.ToolBar = tb
tb.SetToolBitmapSize((16,16))# this required for non-standard size buttons on MSW
### for Phoenix version
if wx.VERSION_STRING < '4.0':
tb.AddTool(Menu.ID_NEW_LIB, wx.Bitmap(os.path.join(ICON_PATH_16_16,'db+2.png')), shortHelpString=_('Import'), longHelpString=_('Import new libraries from directory'))
tb.AddTool(Menu.ID_DELETE_LIB, wx.Bitmap(os.path.join(ICON_PATH_16_16,'db-2.png')), shortHelpString=_('Delete'), longHelpString=_('Delete the selected libraries'))
tb.AddTool(Menu.ID_REFRESH_LIB, wx.Bitmap(os.path.join(ICON_PATH_16_16,'db_refresh2.png')), shortHelpString=_('Reload'), longHelpString=_('Force to reload libraries'))
#tb.AddTool(Menu.ID_IMPORT_LIB, wx.Bitmap(os.path.join(ICON_PATH_16_16,'dbimport2.png')), shortHelpString=_('Import library'), longHelpString=_('Call the import manager'))
tb.AddTool(Menu.ID_HELP_LIB, wx.Bitmap(os.path.join(ICON_PATH_16_16, 'dbinfo2.png')), shortHelpString=_('Help'), longHelpString=_('Information about import manager'))
else:
tb.AddTool(Menu.ID_NEW_LIB, "", wx.Bitmap(os.path.join(ICON_PATH_16_16,'db+2.png')), shortHelp=_('Import'))
tb.AddTool(Menu.ID_DELETE_LIB, "", wx.Bitmap(os.path.join(ICON_PATH_16_16,'db-2.png')), shortHelp=_('Delete'))
tb.AddTool(Menu.ID_REFRESH_LIB, "", wx.Bitmap(os.path.join(ICON_PATH_16_16,'db_refresh2.png')), shortHelp=_('Reload'))
tb.AddTool(Menu.ID_HELP_LIB, "", wx.Bitmap(os.path.join(ICON_PATH_16_16, 'dbinfo2.png')), shortHelp=_('Help'))
tb.AddCheckTool(Menu.ID_MCC_LIB, '', wx.Bitmap(os.path.join(ICON_PATH_16_16,'a-z.png')), shortHelp='MacCabe')
tb.ToggleTool(Menu.ID_MCC_LIB, True)
mainW = self.GetTopLevelParent()
### for Phoenix version ()
if wx.VERSION_STRING < '4.0':
wx.EVT_TOOL(self, Menu.ID_NEW_LIB, mainW.OnImport)
wx.EVT_TOOL(self, Menu.ID_DELETE_LIB, self.tree.OnDelete)
#wx.EVT_TOOL(self, Menu.ID_IMPORT_LIB, mainW.OnImport)
wx.EVT_TOOL(self, Menu.ID_REFRESH_LIB, self.tree.OnUpdateAll)
wx.EVT_TOOL(self, Menu.ID_HELP_LIB, self.tree.OnInfo)
else:
self.Bind(wx.EVT_TOOL, mainW.OnImport, id=Menu.ID_NEW_LIB)
self.Bind(wx.EVT_TOOL, self.tree.OnDelete, id=Menu.ID_DELETE_LIB)
#wx.EVT_TOOL(self, Menu.ID_IMPORT_LIB, mainW.OnImport)
self.Bind(wx.EVT_TOOL, self.tree.OnUpdateAll, id=Menu.ID_REFRESH_LIB)
self.Bind(wx.EVT_TOOL, self.tree.OnInfo, id=Menu.ID_HELP_LIB)
self.Bind(wx.EVT_TOOL, self.tree.OnMCCClick, id=Menu.ID_MCC_LIB)
tb.Realize()
return tb
def __set_tips(self):
"""
"""
self.propToolTip =[_("Select model and instantiate it in the diagram (right part) using a drag-and-drop.")]
### for Phoenix version ()
if wx.VERSION_STRING < '4.0':
self.SetToolTipString(self.propToolTip[0])
else:
self.SetToolTip(self.propToolTip[0])