Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
I
ingame
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vladislav
ingame
Commits
53dc9a1a
Commit
53dc9a1a
authored
Apr 07, 2024
by
Georgiy Yankovskiy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simple game list
parent
4c0b8d14
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
196 additions
and
33 deletions
+196
-33
Tabs.qml
qml/components/Tabs.qml
+59
-19
Game.qml
qml/delegates/Game.qml
+45
-0
game_icon.png
qml/images/game_icon.png
+0
-0
main.py
src/main.py
+7
-4
App.py
src/models/App.py
+39
-10
GamesModel.py
src/models/GamesModel.py
+46
-0
No files found.
qml/components/Tabs.qml
View file @
53dc9a1a
import
QtQuick
import
QtQuick
.
Controls
as
C
import
QtQuick
.
Layouts
import
"../delegates"
import
"../constants/tabs.js"
as
TabConstants
Rectangle
{
// PROPERTIES
property
string
currentTab
:
TabConstants
.
systemManagementTab
...
...
@@ -13,6 +17,9 @@ Rectangle {
height
:
480
color
:
"#ffffff"
// onWidthChanged: { console.log("Window Width changed: " + width) }
// onHeightChanged: { console.log("Window Height changed: " + height)}
// COMPONENTS
Grid
{
...
...
@@ -38,26 +45,51 @@ Rectangle {
Rectangle
{
color
:
"magenta"
;
width
:
10
;
height
:
10
}
}
Grid
{
id
:
gamesGrid
visible
:
tabs
.
currentTab
==
TabConstants
.
gamesTab
columns
:
3
spacing
:
2
anchors.left
:
parent
.
left
anchors.right
:
parent
.
right
anchors.top
:
parent
.
top
anchors.
bottom
:
parent
.
bottom
C.ScrollView
{
visible
:
tabs
.
currentTab
==
TabConstants
.
gamesTab
id
:
gamesScroller
anchors.
fill
:
parent
anchors.topMargin
:
60
anchors.rightMargin
:
0
anchors.leftMargin
:
0
anchors.bottomMargin
:
0
clip
:
true
Text
{
id
:
text2
text
:
qsTr
(
"Text"
)
font.pixelSize
:
12
GridLayout
{
id
:
gamesGrid
readonly
property
int
elementWidth
:
256
+
gamesGrid
.
rowSpacing
*
2
anchors.left
:
parent
.
left
anchors.right
:
parent
.
right
anchors.top
:
parent
.
top
anchors.bottom
:
parent
.
bottom
// columns: Math.max(Math.floor(parent.width / elementWidth), 1)
// rows: Math.max(Math.ceil(children.length / columns), 1)
columns
:
Math
.
max
(
Math
.
floor
(
gamesScroller
.
width
/
elementWidth
),
1
)
rows
:
Math
.
max
(
Math
.
ceil
(
children
.
length
/
columns
),
1
)
anchors.rightMargin
:
8
anchors.leftMargin
:
8
anchors.bottomMargin
:
8
anchors.topMargin
:
8
rowSpacing
:
8
columnSpacing
:
rowSpacing
Repeater
{
// Layout.fillHeight: true
// Layout.fillWidth: true
model
:
core_app
.
games
Game
{
title
:
model
.
name
exec
:
model
.
exec
icon
:
model
.
icon
// width: gamesGrid.elementWidth
// height: gamesGrid.elementHeight
// icon: core_app.games.icon
// exec: core_app.games.exec
}
}
}
}
...
...
@@ -100,8 +132,10 @@ Rectangle {
text
:
"Games"
onClicked
:
function
(){
tabs
.
currentTab
=
TabConstants
.
gamesTab
;
if
(
app
===
undefined
)
return
;
app
.
get_games
();
//if(core_app === undefined) return;
//console.log("core_app found");
//app.get_games();
// tabs.changeTab();
// console.log(tabs.currentTab);
}
...
...
@@ -111,3 +145,9 @@ Rectangle {
}
/*##^##
Designer {
D{i:0}D{i:1;invisible:true}
}
##^##*/
qml/delegates/Game.qml
0 → 100644
View file @
53dc9a1a
import
QtQuick
Rectangle
{
property
string
title
:
"Generic title"
property
string
icon
:
""
property
string
exec
:
""
id
:
game
width
:
256
height
:
256
color
:
"#efefef"
radius
:
5
border.width
:
1
Image
{
id
:
image
anchors.left
:
parent
.
left
anchors.right
:
parent
.
right
anchors.top
:
parent
.
top
anchors.bottom
:
parent
.
bottom
source
:
game
.
icon
anchors.rightMargin
:
8
anchors.bottomMargin
:
47
anchors.leftMargin
:
8
anchors.topMargin
:
8
fillMode
:
Image
.
PreserveAspectFit
}
Text
{
id
:
title
y
:
439
height
:
33
text
:
game
.
title
anchors.left
:
parent
.
left
anchors.right
:
parent
.
right
anchors.bottom
:
parent
.
bottom
font.pixelSize
:
22
horizontalAlignment
:
Text
.
AlignHCenter
anchors.rightMargin
:
8
anchors.leftMargin
:
8
anchors.bottomMargin
:
8
}
}
qml/images/game_icon.png
0 → 100644
View file @
53dc9a1a
1.26 KB
src/main.py
View file @
53dc9a1a
# This Python file uses the following encoding: utf-8
import
sys
from
pathlib
import
Path
...
...
@@ -6,6 +5,7 @@ from PySide6.QtGui import QGuiApplication
from
PySide6.QtQml
import
QQmlApplicationEngine
from
src.models.App
import
App
from
src.models.GamesModel
import
GamesModel
# TODO: add VirtualKeyboard
...
...
@@ -13,10 +13,13 @@ if __name__ == "__main__":
app
=
QGuiApplication
(
sys
.
argv
)
qml_file
=
Path
(
__file__
)
.
resolve
()
.
parent
/
"../qml/qml.qml"
engine
=
QQmlApplicationEngine
()
app_model
=
App
()
context
=
engine
.
rootContext
()
context
.
setContextProperty
(
"core_app"
,
app_model
)
engine
.
load
(
qml_file
)
if
not
engine
.
rootObjects
():
sys
.
exit
(
-
1
)
appModel
=
App
()
context
=
engine
.
rootContext
()
context
.
setContextProperty
(
"app"
,
appModel
)
sys
.
exit
(
app
.
exec
())
src/models/App.py
View file @
53dc9a1a
...
...
@@ -2,6 +2,10 @@ from PySide6 import QtCore
from
os.path
import
expanduser
import
glob
from
desktop_parser
import
DesktopFile
import
os.path
from
pathlib
import
Path
from
PySide6.QtCore
import
Property
,
Signal
,
Slot
,
QObject
from
src.models.GamesModel
import
Game
,
GamesModel
class
GameShortcut
:
...
...
@@ -14,6 +18,7 @@ class GameShortcut:
class
App
(
QtCore
.
QObject
):
def
__init__
(
self
):
super
()
.
__init__
()
self
.
games_model
=
GamesModel
()
self
.
home
=
expanduser
(
'~'
)
self
.
config_location
=
'/.config/PortProton.conf'
self
.
portproton_location
=
''
...
...
@@ -23,20 +28,44 @@ class App(QtCore.QObject):
try
:
with
open
(
self
.
home
+
self
.
config_location
,
'r'
)
as
file
:
self
.
portproton_location
=
file
.
read
()
.
strip
()
print
(
f
'Current PortProton location: {self.portproton_location}'
)
print
(
f
'Current PortProton location: {self.portproton_location}'
)
self
.
games_model
.
clear
()
files
=
glob
.
glob
(
f
"{self.portproton_location}/*.desktop"
)
# for val in files:
# print(val)
# desktop_file = DesktopFile.from_file("path/to/file.desktop")
for
val
in
files
:
desktop_file
=
DesktopFile
.
from_file
(
val
)
data
=
desktop_file
.
data
entry
=
data
[
'Desktop Entry'
]
name
=
entry
[
'Name'
]
or
'generic'
exec
=
'Exec'
in
entry
and
entry
[
'Exec'
]
or
''
icon
=
entry
[
'Icon'
]
assert
(
isinstance
(
name
,
str
)
and
isinstance
(
exec
,
str
)
and
isinstance
(
icon
,
str
))
exec_split
=
exec
.
split
(
' '
)
# Ignore extra non-related desktop entries
if
(
len
(
exec_split
)
<=
1
or
(
'data/scripts/start.sh'
not
in
exec_split
[
1
]
or
'
%
F'
in
exec_split
[
-
1
])):
continue
# TODO parse product name
icon
=
(
os
.
path
.
isfile
(
icon
)
and
icon
or
os
.
path
.
realpath
(
f
"{Path(__file__).resolve().parent}../../../qml/images/game_icon.png"
))
self
.
games_model
.
add_game
(
Game
(
name
=
name
,
icon
=
icon
,
exec
=
exec
))
except
FileNotFoundError
:
print
(
'File not found'
)
except
Exception
:
print
(
'An error occurred'
)
except
Exception
as
e
:
print
(
'An error occurred'
,
e
)
pass
### SLOTS ###
@
QtCore.Slot
(
)
def
g
et_g
ames
(
self
):
pass
@
Property
(
QObject
,
constant
=
True
)
def
games
(
self
):
return
self
.
games_model
src/models/GamesModel.py
0 → 100644
View file @
53dc9a1a
import
typing
from
dataclasses
import
dataclass
,
fields
from
PySide6.QtCore
import
QAbstractListModel
,
QModelIndex
,
Qt
,
QByteArray
@dataclass
class
Game
:
name
:
str
=
''
exec
:
str
=
''
icon
:
str
=
''
class
GamesModel
(
QAbstractListModel
):
def
__init__
(
self
):
super
()
.
__init__
()
self
.
_list
=
[]
def
data
(
self
,
index
:
QModelIndex
,
role
:
int
=
Qt
.
DisplayRole
)
->
typing
.
Any
:
if
0
<=
index
.
row
()
<
self
.
rowCount
():
student
=
self
.
_list
[
index
.
row
()]
name
=
self
.
roleNames
()
.
get
(
role
)
if
name
:
return
getattr
(
student
,
name
.
decode
())
def
roleNames
(
self
)
->
dict
[
int
,
QByteArray
]:
d
=
{}
for
i
,
field
in
enumerate
(
fields
(
Game
)):
d
[
Qt
.
DisplayRole
+
i
]
=
field
.
name
.
encode
()
return
d
def
rowCount
(
self
,
index
:
QModelIndex
=
QModelIndex
())
->
int
:
return
len
(
self
.
_list
)
def
add_game
(
self
,
game
:
Game
)
->
None
:
self
.
beginInsertRows
(
QModelIndex
(),
self
.
rowCount
(),
self
.
rowCount
())
self
.
_list
.
append
(
game
)
self
.
endInsertRows
()
def
clear
(
self
)
->
None
:
self
.
beginInsertRows
(
QModelIndex
(),
self
.
rowCount
(),
self
.
rowCount
())
self
.
_list
=
[]
self
.
endInsertRows
()
pass
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