Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
lemi2seed
Manage
Activity
Members
Labels
Plan
Issues
2
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Software Public
MT
lemi2seed
Commits
f28452bf
Commit
f28452bf
authored
2 years ago
by
Maeva Pourpoint
Browse files
Options
Downloads
Patches
Plain Diff
Module implementing the widgets
parent
ea097c5d
No related branches found
Branches containing commit
No related tags found
1 merge request
!21
Update/Implement GUI functionalities
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lemi2seed/gui_widgets.py
+178
-0
178 additions, 0 deletions
lemi2seed/gui_widgets.py
with
178 additions
and
0 deletions
lemi2seed/gui_widgets.py
0 → 100644
+
178
−
0
View file @
f28452bf
# -*- coding: utf-8 -*-
"""
lemi2seed GUI Framework - Widgets.
Maeva Pourpoint - IRIS/PASSCAL
"""
import
sys
from
pathlib
import
Path
from
PySide2
import
QtCore
,
QtWidgets
from
PySide2.QtUiTools
import
loadUiType
# Handle issues importing resources (allows python to find module resources_rc)
sys
.
path
.
append
(
str
(
Path
(
__file__
).
resolve
().
parent
))
def
load_ui
(
filename
):
"""
Load a ui file relative to its source file.
"""
path
=
Path
(
__file__
).
resolve
().
parent
.
joinpath
(
'
ui_files
'
,
filename
)
return
loadUiType
(
str
(
path
))
class
BaseWidget
():
"""
Implements the basic functionalities of all category widgets: Net, Sta, Run,
Elec, Mag.
"""
def
__init__
(
self
,
parent
=
None
):
super
().
__init__
(
parent
)
self
.
setupUi
(
self
)
self
.
setMapper
()
def
setFlags
(
self
,
fields
):
"""
Flag each missing or invalid metadata field by applying a solid red
border to its input widget.
"""
widget_ids
=
[]
for
field
in
fields
:
field
=
""
.
join
([
'
ui
'
,
*
[
s
.
capitalize
()
for
s
in
field
.
split
(
'
_
'
)]])
if
hasattr
(
self
,
field
):
widget_ids
.
append
(
"
#
"
.
join
([
type
(
getattr
(
self
,
field
)).
__name__
,
field
]))
if
widget_ids
:
widget_ids
=
"
,
"
.
join
(
widget_ids
)
widget_styles
=
f
'
{
widget_ids
}
{{border:2px ridge red;}}
'
else
:
widget_styles
=
""
self
.
setStyleSheet
(
widget_styles
)
def
setMapper
(
self
):
self
.
mapper
=
QtWidgets
.
QDataWidgetMapper
()
self
.
mapper
.
setSubmitPolicy
(
QtWidgets
.
QDataWidgetMapper
.
ManualSubmit
)
self
.
mapper
.
setOrientation
(
QtCore
.
Qt
.
Vertical
)
def
setMapping
(
self
,
parent
):
self
.
mapper
.
setRootIndex
(
parent
)
for
ind
,
childItem
in
enumerate
(
self
.
mapper
.
model
().
getItem
(
parent
).
childItems
):
field
=
childItem
.
data
(
0
)
field
=
""
.
join
([
'
ui
'
,
*
[
s
.
capitalize
()
for
s
in
field
.
split
(
'
_
'
)]])
if
not
hasattr
(
self
,
field
):
continue
self
.
mapper
.
addMapping
(
getattr
(
self
,
field
),
ind
)
def
setModel
(
self
,
model
,
cat
,
set_selection
=
True
):
if
model
.
inputData
.
get
(
cat
):
self
.
model
=
model
.
inputData
[
cat
]
else
:
if
'
Elec
'
in
cat
:
self
.
model
=
model
.
inputData
[
'
Elec
'
][
cat
]
elif
'
Mag
'
in
cat
:
self
.
model
=
model
.
inputData
[
'
Mag
'
][
cat
]
else
:
self
.
model
=
model
.
inputData
[
'
Run
'
][
cat
]
self
.
mapper
.
setModel
(
model
)
self
.
setMapping
(
parent
=
model
.
categoryIndex
[
cat
])
if
set_selection
:
self
.
mapper
.
setCurrentIndex
(
1
)
class
NetWidgets
(
BaseWidget
,
*
load_ui
(
"
networkwidget.ui
"
)):
def
__init__
(
self
,
parent
=
None
):
super
().
__init__
(
parent
)
def
setModel
(
self
,
model
):
super
().
setModel
(
model
,
cat
=
'
Net
'
)
class
StaWidgets
(
BaseWidget
,
*
load_ui
(
"
stationwidget.ui
"
)):
def
__init__
(
self
,
parent
=
None
):
super
().
__init__
(
parent
)
for
combobox
in
[
self
.
uiDeclinationModel
,
self
.
uiOrientationMethod
]:
combobox
.
textActivated
.
connect
(
lambda
text
,
val
=
combobox
:
self
.
other_option
(
text
,
val
))
def
setModel
(
self
,
model
):
super
().
setModel
(
model
,
cat
=
'
Sta
'
)
@staticmethod
def
other_option
(
val
,
combobox
):
if
val
==
'
If other, enter here.
'
:
if
combobox
.
findText
(
val
)
!=
combobox
.
count
()
-
1
:
combobox
.
removeItem
(
combobox
.
count
()
-
1
)
combobox
.
setEditable
(
True
)
combobox
.
currentTextChanged
.
connect
(
combobox
.
setEditText
)
else
:
combobox
.
setEditable
(
False
)
class
RunWidgets
(
BaseWidget
,
*
load_ui
(
"
runwidget.ui
"
)):
def
__init__
(
self
,
parent
=
None
):
super
().
__init__
(
parent
)
def
setModel
(
self
,
model
,
cat
):
super
().
setModel
(
model
,
cat
=
cat
)
def
get_channel_widgets
(
base
):
class
ChannelWidgets
(
*
base
):
def
__init__
(
self
,
parent
=
None
,
type
=
None
):
super
().
__init__
(
parent
)
self
.
inst_widgets
=
InstInfoWidgets
(
type
)
self
.
uiInstSpecs
.
textActivated
.
connect
(
self
.
toggle_inst_window
)
self
.
inst_widgets
.
uiSaveButton
.
clicked
.
connect
(
self
.
show_inst_info
)
def
show_inst_info
(
self
,
checked
):
ind
=
self
.
uiInstSpecs
.
count
()
-
1
text
=
(
"
Manufacturer: {} - Model: {} - Type: {}
"
.
format
(
self
.
inst_widgets
.
uiManufacturer
.
text
(),
self
.
inst_widgets
.
uiModel
.
text
(),
self
.
inst_widgets
.
uiType
.
text
()))
self
.
uiInstSpecs
.
insertItem
(
ind
,
text
)
self
.
uiInstSpecs
.
setCurrentIndex
(
ind
)
self
.
inst_widgets
.
hide
()
def
setModel
(
self
,
model
,
cat
):
super
().
setModel
(
model
,
cat
=
cat
,
set_selection
=
False
)
parent
=
model
.
getItem
(
model
.
categoryIndex
[
cat
])
self
.
mapper
.
addMapping
(
self
.
inst_widgets
.
uiManufacturer
,
parent
.
getChildIndex
(
0
,
'
inst_manufacturer
'
))
self
.
mapper
.
addMapping
(
self
.
inst_widgets
.
uiModel
,
parent
.
getChildIndex
(
0
,
'
inst_model
'
))
self
.
mapper
.
addMapping
(
self
.
inst_widgets
.
uiType
,
parent
.
getChildIndex
(
0
,
'
inst_type
'
))
self
.
mapper
.
setCurrentIndex
(
1
)
def
toggle_inst_window
(
self
,
val
):
if
self
.
inst_widgets
.
isVisible
():
self
.
inst_widgets
.
hide
()
elif
val
==
"
If other, click here.
"
:
self
.
inst_widgets
.
show
()
return
ChannelWidgets
class
InstInfoWidgets
(
*
load_ui
(
"
instrumentwidget.ui
"
)):
def
__init__
(
self
,
type
):
super
().
__init__
()
self
.
setupUi
(
self
)
if
type
==
'
elec
'
:
self
.
setWindowTitle
(
'
Electrode - Specs
'
)
else
:
self
.
setWindowTitle
(
'
Fluxgate - Specs
'
)
class
HelpWidgets
(
*
load_ui
(
"
helpwidget.ui
"
)):
def
__init__
(
self
):
super
().
__init__
()
self
.
setupUi
(
self
)
self
.
setWindowTitle
(
'
Help
'
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment