Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Scientific Software
MDANSE
Commits
59c7b4e8
Commit
59c7b4e8
authored
Jul 02, 2015
by
eric pellegrini
Browse files
Implemented a generic dialog for setting user definitions
Removed the old unused UserDefinitionsPanel
parent
2a25af75
Changes
1
Show whitespace changes
Inline
Side-by-side
MDANSE/App/GUI/ComboWidgets/UserDefinitions
Panel
.py
→
MDANSE/App/GUI/ComboWidgets/UserDefinitions
Dialog
.py
View file @
59c7b4e8
...
...
@@ -30,42 +30,93 @@ Created on Apr 14, 2015
:author: Eric C. Pellegrini
'''
import
abc
import
wx
class
UserDefinitionsPanel
(
wx
.
Panel
):
from
MDANSE
import
LOGGER
from
MDANSE.Externals.pubsub
import
pub
from
MDANSE.Framework.UserDefinitionsStore
import
UD_STORE
class
UserDefinitionsDialog
(
wx
.
Dialog
):
__metaclass__
=
abc
.
ABCMeta
def
__init__
(
self
,
parent
,
*
args
,
**
kwargs
):
def
__init__
(
self
,
parent
,
target
,
section
,
*
args
,
**
kwargs
):
wx
.
Panel
.
__init__
(
self
,
parent
,
wx
.
ID_ANY
,
*
args
,
**
kwargs
)
wx
.
Dialog
.
__init__
(
self
,
parent
,
*
args
,
**
kwargs
)
self
.
_parent
=
parent
sb
=
wx
.
StaticBox
(
self
,
wx
.
ID_ANY
)
self
.
_target
=
target
self
.
_section
=
section
self
.
_ud
=
{}
self
.
_mainSizer
=
wx
.
BoxSizer
(
wx
.
VERTICAL
)
self
.
build_dialog
()
udPanel
=
wx
.
Panel
(
self
,
wx
.
ID_ANY
)
sb
=
wx
.
StaticBox
(
udPanel
,
wx
.
ID_ANY
)
actionsSizer
=
wx
.
StaticBoxSizer
(
sb
,
wx
.
HORIZONTAL
)
self
.
_
cancelButton
=
wx
.
Button
(
s
el
f
,
wx
.
ID_ANY
,
label
=
"Cancel"
)
self
.
_udName
=
wx
.
TextCtrl
(
s
el
f
,
wx
.
ID_ANY
,
style
=
wx
.
TE_PROCESS_ENTER
)
self
.
_
saveButton
=
wx
.
Button
(
s
el
f
,
wx
.
ID_ANY
,
label
=
"Save"
)
cancelButton
=
wx
.
Button
(
udPan
el
,
wx
.
ID_ANY
,
label
=
"Cancel"
)
self
.
_udName
=
wx
.
TextCtrl
(
udPan
el
,
wx
.
ID_ANY
,
style
=
wx
.
TE_PROCESS_ENTER
)
saveButton
=
wx
.
Button
(
udPan
el
,
wx
.
ID_ANY
,
label
=
"Save"
)
actionsSizer
.
Add
(
self
.
_
cancelButton
,
0
,
wx
.
ALL
,
5
)
actionsSizer
.
Add
(
cancelButton
,
0
,
wx
.
ALL
,
5
)
actionsSizer
.
Add
(
self
.
_udName
,
1
,
wx
.
ALL
|
wx
.
EXPAND
,
5
)
actionsSizer
.
Add
(
self
.
_
saveButton
,
0
,
wx
.
ALL
,
5
)
actionsSizer
.
Add
(
saveButton
,
0
,
wx
.
ALL
,
5
)
s
el
f
.
SetSizer
(
actionsSizer
)
udPan
el
.
SetSizer
(
actionsSizer
)
self
.
Layout
()
self
.
_mainSizer
.
Add
(
udPanel
,
0
,
wx
.
EXPAND
|
wx
.
ALL
,
5
)
self
.
Bind
(
wx
.
EVT_BUTTON
,
self
.
on_close
,
self
.
_cancelButton
)
self
.
Bind
(
wx
.
EVT_BUTTON
,
self
.
on_save
,
self
.
_saveButton
)
self
.
SetSizer
(
self
.
_mainSizer
)
def
get_selection_name
(
self
):
self
.
Bind
(
wx
.
EVT_CLOSE
,
self
.
on_close
)
self
.
Bind
(
wx
.
EVT_BUTTON
,
self
.
on_close
,
cancelButton
)
self
.
Bind
(
wx
.
EVT_BUTTON
,
self
.
on_save
,
saveButton
)
return
self
.
_udName
.
GetValue
()
@
abc
.
abstractmethod
def
build_dialog
(
self
):
pass
def
on_close
(
self
,
event
):
@
abc
.
abstractmethod
def
validate
(
self
):
pass
self
.
_parent
.
Parent
.
on_close
()
def
getUserDefinitionName
(
self
):
return
str
(
self
.
_udName
.
GetValue
())
def
on_save
(
self
,
event
):
self
.
_parent
.
Parent
.
on_save
()
\ No newline at end of file
name
=
str
(
self
.
_udName
.
GetValue
().
strip
())
if
not
name
:
LOGGER
(
'Empty user definition name.'
,
'error'
,[
'dialog'
])
return
value
=
self
.
validate
()
if
value
is
None
:
return
if
UD_STORE
.
has_definition
(
self
.
_target
,
self
.
_section
,
name
):
LOGGER
(
'There is already a user-definition that matches %s,%s,%s'
%
(
self
.
_target
,
self
.
_section
,
name
),
'error'
,[
'dialog'
])
self
.
EndModal
(
wx
.
ID_CANCEL
)
return
UD_STORE
.
set_definition
(
self
.
_target
,
self
.
_section
,
name
,
value
)
UD_STORE
.
save
()
pub
.
sendMessage
(
"save_definition"
,
message
=
(
self
.
_target
,
name
))
self
.
EndModal
(
wx
.
ID_OK
)
def
on_close
(
self
,
event
):
self
.
EndModal
(
wx
.
ID_CANCEL
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment