Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
gajim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Contributor analytics
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
mesonium
gajim
Commits
be8659e7
Commit
be8659e7
authored
2 years ago
by
Philipp Hörist
Browse files
Options
Downloads
Patches
Plain Diff
chore: Script: Add type annotations
parent
0f3a42fd
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
scripts/generate_ui_types.py
+6
-5
6 additions, 5 deletions
scripts/generate_ui_types.py
with
6 additions
and
5 deletions
scripts/
dev/
generate_ui_types.py
→
scripts/generate_ui_types.py
+
6
−
5
View file @
be8659e7
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
# Reads all .ui files and creates builder.pyi
# Reads all .ui files and creates builder.pyi
# Excecute this script from the repo root dir
# Excecute this script from the repo root dir
from
io
import
TextIOWrapper
from
pathlib
import
Path
from
pathlib
import
Path
from
xml.etree
import
ElementTree
as
ET
from
xml.etree
import
ElementTree
as
ET
...
@@ -41,22 +42,22 @@ def get_builder(file_name: Literal['%s'], widgets: list[str] = ...) -> %s: ...''
...
@@ -41,22 +42,22 @@ def get_builder(file_name: Literal['%s'], widgets: list[str] = ...) -> %s: ...''
def get_builder(file_name: str, widgets: list[str] = ...) -> Builder: ...
'''
def get_builder(file_name: str, widgets: list[str] = ...) -> Builder: ...
'''
def
make_class_name
(
path
)
:
def
make_class_name
(
path
:
Path
)
->
str
:
name
=
path
.
name
.
removesuffix
(
'
.ui
'
)
name
=
path
.
name
.
removesuffix
(
'
.ui
'
)
names
=
name
.
split
(
'
_
'
)
names
=
name
.
split
(
'
_
'
)
names
=
map
(
lambda
x
:
x
.
capitalize
(),
names
)
names
=
map
(
lambda
x
:
x
.
capitalize
(),
names
)
return
''
.
join
(
names
)
+
'
Builder
'
return
''
.
join
(
names
)
+
'
Builder
'
def
parse
(
path
,
file
)
:
def
parse
(
path
:
Path
,
file
:
TextIOWrapper
)
->
str
:
print
(
'
read
'
,
path
)
print
(
'
read
'
,
path
)
lines
=
[]
lines
:
list
[
str
]
=
[]
tree
=
ET
.
parse
(
path
)
tree
=
ET
.
parse
(
path
)
for
node
in
tree
.
iter
(
tag
=
'
object
'
):
for
node
in
tree
.
iter
(
tag
=
'
object
'
):
id_
=
node
.
attrib
.
get
(
'
id
'
)
id_
=
node
.
attrib
.
get
(
'
id
'
)
if
id_
is
None
:
if
id_
is
None
:
continue
continue
klass
=
node
.
attrib
.
get
(
'
class
'
)
klass
=
node
.
attrib
[
'
class
'
]
if
klass
.
startswith
(
'
GtkSource
'
):
if
klass
.
startswith
(
'
GtkSource
'
):
klass
=
f
'
GtkSource.
{
klass
.
removeprefix
(
"
GtkSource
"
)
}
'
klass
=
f
'
GtkSource.
{
klass
.
removeprefix
(
"
GtkSource
"
)
}
'
elif
klass
.
startswith
(
'
Atk
'
):
elif
klass
.
startswith
(
'
Atk
'
):
...
@@ -78,7 +79,7 @@ def parse(path, file):
...
@@ -78,7 +79,7 @@ def parse(path, file):
return
klass_name
return
klass_name
builder_names
=
[]
builder_names
:
list
[
tuple
[
str
,
str
]]
=
[]
with
out_path
.
open
(
mode
=
'
w
'
,
encoding
=
'
utf8
'
)
as
file
:
with
out_path
.
open
(
mode
=
'
w
'
,
encoding
=
'
utf8
'
)
as
file
:
file
.
write
(
IMPORTS
)
file
.
write
(
IMPORTS
)
...
...
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