Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
leversc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OpenSource
leversc
Commits
ea12b7f3
Commit
ea12b7f3
authored
Jan 24, 2022
by
Mark Winter
Browse files
Options
Downloads
Patches
Plain Diff
Transparent-ish property wrappers for leversc setting (autoupdates on changes)
parent
fc8b1760
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Python/_property.py
+65
-2
65 additions, 2 deletions
src/Python/_property.py
src/Python/leversc.py
+1
-1
1 addition, 1 deletion
src/Python/leversc.py
with
66 additions
and
3 deletions
src/Python/_property.py
+
65
−
2
View file @
ea12b7f3
import
requests
import
requests
import
json
import
json
"""
Helper classes for handling leversc settings changes
"""
class
ChangeWrapper
:
"""
A wrapper class for bubbling property change updates to leversc class
"""
def
__init__
(
self
,
parent
,
incollection
):
self
.
_parent
=
parent
self
.
_collection
=
incollection
def
_property_updated
(
self
,
childprop
):
self
.
_parent
.
_property_updated
(
self
)
def
__getitem__
(
self
,
keyidx
):
elem
=
self
.
_collection
.
__getitem__
(
keyidx
)
if
isinstance
(
elem
,
(
dict
,
list
)):
return
__class__
(
self
,
elem
)
else
:
return
elem
def
__setitem__
(
self
,
keyidx
,
v
):
self
.
_collection
.
__setitem__
(
keyidx
,
v
)
self
.
_property_updated
(
self
)
"""
Some Quality-of-life improvements for introspecting the wrappers
"""
def
__str__
(
self
):
return
str
(
self
.
_collection
)
def
__repr__
(
self
):
return
"
%s(%s)
"
%
(
__class__
.
__name__
,
repr
(
self
.
_collection
))
class
PropWrapper
(
ChangeWrapper
):
"""
Top-level property that runs setProperty (network send) on change updates
"""
def
__init__
(
self
,
lsc
,
propname
,
incollection
):
self
.
_leversc
=
lsc
self
.
_propname
=
propname
super
(
__class__
,
self
).
__init__
(
self
,
incollection
)
def
unwrap
(
self
):
"""
Return an unwrapped version of this property (that can be edited without network overhead)
"""
return
self
.
_collection
def
_property_updated
(
self
,
childprop
):
self
.
_leversc
.
setProperty
(
self
.
_propname
,
self
.
_collection
)
def
__str__
(
self
):
return
str
(
self
.
_collection
)
def
__repr__
(
self
):
return
"
%s(%s)
"
%
(
__class__
.
__name__
,
repr
(
self
.
_collection
))
# retrieves/sets viewParams, renderParams, uiParams, etc....
# retrieves/sets viewParams, renderParams, uiParams, etc....
def
setProperty
(
self
,
propertyName
,
propertyStruct
):
def
setProperty
(
self
,
propertyName
,
propertyStruct
):
if
isinstance
(
propertyStruct
,
PropWrapper
):
propertyStruct
=
propertyStruct
.
unwrap
()
URL
=
self
.
_leversc_url
(
"
/
"
+
propertyName
)
URL
=
self
.
_leversc_url
(
"
/
"
+
propertyName
)
response
=
requests
.
post
(
URL
,
json
=
propertyStruct
)
response
=
requests
.
post
(
URL
,
json
=
propertyStruct
)
...
@@ -13,4 +76,4 @@ def getProperty(self,propertyName):
...
@@ -13,4 +76,4 @@ def getProperty(self,propertyName):
if
'
list
'
==
type
(
property
):
if
'
list
'
==
type
(
property
):
# view and render params come as 1 element list
# view and render params come as 1 element list
property
=
property
[
0
]
property
=
property
[
0
]
return
property
return
PropWrapper
(
self
,
propertyName
,
property
)
This diff is collapsed.
Click to expand it.
src/Python/leversc.py
+
1
−
1
View file @
ea12b7f3
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