mirror of
https://github.com/zoriya/astal.git
synced 2026-06-02 02:05:09 +00:00
Added examples for python and lua
This commit is contained in:
+29
-6
@@ -63,24 +63,47 @@ astal-apps --help
|
||||
:::code-group
|
||||
|
||||
```js [<i class="devicon-javascript-plain"></i> JavaScript]
|
||||
import Apps from "gi://AstalApps"
|
||||
import Apps from "gi://AstalApps";
|
||||
|
||||
const apps = new Apps.Apps({
|
||||
includeEntry: true,
|
||||
includeExecutable: true,
|
||||
})
|
||||
includeEntry: true,
|
||||
includeExecutable: true,
|
||||
});
|
||||
|
||||
print(apps.fuzzy_query("spotify")
|
||||
.map(app => app.name)
|
||||
.join("\n"))
|
||||
|
||||
```
|
||||
|
||||
```py [<i class="devicon-python-plain"></i> Python]
|
||||
# Not yet documented, contributions are appreciated
|
||||
import gi
|
||||
|
||||
gi.require_version("AstalApps", "0.1")
|
||||
|
||||
from gi.repository import AstalApps
|
||||
|
||||
apps = AstalApps.Apps(include_entry = True, include_executable = True )
|
||||
|
||||
match = apps.fuzzy_query("obsidian")
|
||||
print("\n".join(app.get_name() for app in match))
|
||||
```
|
||||
|
||||
```lua [<i class="devicon-lua-plain"></i> Lua]
|
||||
-- Not yet documented, contributions are appreciated
|
||||
local lgi = require("lgi")
|
||||
|
||||
local AstalApps = lgi.require("AstalApps", "0.1")
|
||||
|
||||
local apps = AstalApps.Apps({
|
||||
include_entry = true,
|
||||
include_executable = true,
|
||||
})
|
||||
|
||||
local match = apps:fuzzy_query("lutris")
|
||||
|
||||
for _, app in ipairs(match) do
|
||||
print(app.name)
|
||||
end
|
||||
```
|
||||
|
||||
```vala [<i class="devicon-vala-plain"></i> Vala]
|
||||
|
||||
+26
-2
@@ -84,11 +84,35 @@ await Auth.Pam.authenticate("password")
|
||||
```
|
||||
|
||||
```py [<i class="devicon-python-plain"></i> Python]
|
||||
# Not yet documented
|
||||
import gi
|
||||
|
||||
gi.require_version("AstalAuth", "0.1")
|
||||
|
||||
from gi.repository import AstalAuth
|
||||
|
||||
def callback(_, task) -> None:
|
||||
try:
|
||||
AstalAuth.Pam.authenticate_finish(task)
|
||||
print("success")
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
AstalAuth.Pam.authenticate("password", callback)
|
||||
```
|
||||
|
||||
```lua [<i class="devicon-lua-plain"></i> Lua]
|
||||
-- Not yet documented
|
||||
local lgi = require("lgi")
|
||||
|
||||
local AstalAuth = lgi.require("AstalAuth", "0.1")
|
||||
|
||||
AstalAuth.Pam.authenticate("password", function(_, task)
|
||||
local status, err = AstalAuth.Pam.authenticate_finish(task)
|
||||
if status == 0 then
|
||||
print("success")
|
||||
else
|
||||
print(err)
|
||||
end
|
||||
end)
|
||||
```
|
||||
|
||||
```vala [<i class="devicon-vala-plain"></i> Vala]
|
||||
|
||||
@@ -69,17 +69,28 @@ astal-battery --help
|
||||
```js [<i class="devicon-javascript-plain"></i> JavaScript]
|
||||
import Battery from "gi://AstalBattery";
|
||||
|
||||
const battery = Battery.get_default()
|
||||
const battery = Battery.get_default();
|
||||
|
||||
console.log(battery.percentage)
|
||||
console.log(battery.percentage);
|
||||
```
|
||||
|
||||
```py [<i class="devicon-python-plain"></i> Python]
|
||||
# Not yet documented
|
||||
import gi
|
||||
gi.require_version("AstalBattery", "0.1")
|
||||
|
||||
from gi.repository import AstalBattery
|
||||
|
||||
battery = AstalBattery.get_default()
|
||||
|
||||
print(battery.get_percentage())
|
||||
```
|
||||
|
||||
```lua [<i class="devicon-lua-plain"></i> Lua]
|
||||
-- Not yet documented
|
||||
local lgi = require("lgi")
|
||||
local AstalBattery = lgi.require("AstalBattery", "0.1")
|
||||
|
||||
local battery = AstalBattery.get_default()
|
||||
print(battery.percentage)
|
||||
```
|
||||
|
||||
```vala [<i class="devicon-vala-plain"></i> Vala]
|
||||
|
||||
@@ -71,17 +71,33 @@ bluetoothctl --help
|
||||
```js [<i class="devicon-javascript-plain"></i> JavaScript]
|
||||
import Bluetooth from "gi://AstalBluetooth";
|
||||
|
||||
const bluetooth = Bluetooth.get_default()
|
||||
const bluetooth = Bluetooth.get_default();
|
||||
|
||||
console.log(bluetooth.get_devices().map(d => d.name))
|
||||
console.log(bluetooth.get_devices().map((d) => d.name));
|
||||
```
|
||||
|
||||
```py [<i class="devicon-python-plain"></i> Python]
|
||||
# Not yet documented
|
||||
import gi
|
||||
|
||||
gi.require_version("AstalBluetooth", "0.1")
|
||||
|
||||
from gi.repository import AstalBluetooth
|
||||
|
||||
bluetooth = AstalBluetooth.get_default()
|
||||
|
||||
print("\n".join(d.get_name() for d in bluetooth.get_devices()))
|
||||
```
|
||||
|
||||
```lua [<i class="devicon-lua-plain"></i> Lua]
|
||||
-- Not yet documented
|
||||
local lgi = require("lgi")
|
||||
|
||||
local AstalBluetooth = lgi.require("AstalBluetooth", "0.1")
|
||||
|
||||
local bluetooth = AstalBluetooth.get_default()
|
||||
|
||||
for _, d in ipairs(bluetooth.devices) do
|
||||
print(d.name)
|
||||
end
|
||||
```
|
||||
|
||||
```vala [<i class="devicon-vala-plain"></i> Vala]
|
||||
|
||||
@@ -64,17 +64,33 @@ astal-hyprland # starts monitoring
|
||||
```js [<i class="devicon-javascript-plain"></i> JavaScript]
|
||||
import Hyprland from "gi://AstalHyprland";
|
||||
|
||||
const hyprland = Hyprland.get_default()
|
||||
const hyprland = Hyprland.get_default();
|
||||
|
||||
console.log(hyprland.get_clients().map(c => c.title))
|
||||
console.log(hyprland.get_clients().map((c) => c.title));
|
||||
```
|
||||
|
||||
```py [<i class="devicon-python-plain"></i> Python]
|
||||
# Not yet documented
|
||||
import gi
|
||||
|
||||
gi.require_version("AstalHyprland", "0.1")
|
||||
|
||||
from gi.repository import AstalHyprland
|
||||
|
||||
hyprland = AstalHyprland.get_default()
|
||||
|
||||
print("\n".join(c.get_title() for c in hyprland.get_clients()))
|
||||
```
|
||||
|
||||
```lua [<i class="devicon-lua-plain"></i> Lua]
|
||||
-- Not yet documented
|
||||
local lgi = require("lgi")
|
||||
|
||||
local AstalHyprland = lgi.require("AstalHyprland", "0.1")
|
||||
|
||||
local hyprland = AstalHyprland.get_default()
|
||||
|
||||
for _, c in ipairs(hyprland.clients) do
|
||||
print(c.title)
|
||||
end
|
||||
```
|
||||
|
||||
```vala [<i class="devicon-vala-plain"></i> Vala]
|
||||
|
||||
+21
-5
@@ -68,18 +68,34 @@ astal-mpris --help
|
||||
```js [<i class="devicon-javascript-plain"></i> JavaScript]
|
||||
import Mpris from "gi://AstalMpris";
|
||||
|
||||
const spotify = Mpris.Player.new("spotify")
|
||||
const spotify = Mpris.Player.new("spotify");
|
||||
|
||||
if (spotify.available)
|
||||
console.log(spotify.title)
|
||||
if (spotify.available) console.log(spotify.title);
|
||||
```
|
||||
|
||||
```py [<i class="devicon-python-plain"></i> Python]
|
||||
# Not yet documented
|
||||
import gi
|
||||
|
||||
gi.require_version("AstalMpris", "0.1")
|
||||
|
||||
from gi.repository import AstalMpris
|
||||
|
||||
spotify = AstalMpris.Player.new("spotify")
|
||||
|
||||
if spotify.get_available():
|
||||
print(spotify.get_title())
|
||||
```
|
||||
|
||||
```lua [<i class="devicon-lua-plain"></i> Lua]
|
||||
-- Not yet documented
|
||||
local lgi = require("lgi")
|
||||
|
||||
local AstalMpris = lgi.require("AstalMpris", "0.1")
|
||||
|
||||
local spotify = AstalMpris.Player.new("spotify")
|
||||
|
||||
if spotify.available then
|
||||
print(spotify.title)
|
||||
end
|
||||
```
|
||||
|
||||
```vala [<i class="devicon-vala-plain"></i> Vala]
|
||||
|
||||
@@ -66,17 +66,31 @@ nmcli --help
|
||||
```js [<i class="devicon-javascript-plain"></i> JavaScript]
|
||||
import Network from "gi://AstalNetwork";
|
||||
|
||||
const network = Network.get_default()
|
||||
const network = Network.get_default();
|
||||
|
||||
console.log(network.wifi.ssid)
|
||||
console.log(network.wifi.ssid);
|
||||
```
|
||||
|
||||
```py [<i class="devicon-python-plain"></i> Python]
|
||||
# Not yet documented
|
||||
import gi
|
||||
|
||||
gi.require_version("AstalNetwork", "0.1")
|
||||
|
||||
from gi.repository import AstalNetwork
|
||||
|
||||
network = AstalNetwork.get_default()
|
||||
|
||||
print(network.get_wifi().get_ssid())
|
||||
```
|
||||
|
||||
```lua [<i class="devicon-lua-plain"></i> Lua]
|
||||
-- Not yet documented
|
||||
local lgi = require("lgi")
|
||||
|
||||
local AstalNetwork = lgi.require("AstalNetwork", "0.1")
|
||||
|
||||
local network = AstalNetwork.get_default()
|
||||
|
||||
print(network.wifi.ssid)
|
||||
```
|
||||
|
||||
```vala [<i class="devicon-vala-plain"></i> Vala]
|
||||
|
||||
@@ -68,20 +68,41 @@ astal-notifd --help
|
||||
```js [<i class="devicon-javascript-plain"></i> JavaScript]
|
||||
import Notifd from "gi://AstalNotifd";
|
||||
|
||||
const notifd = Notifd.get_default()
|
||||
const notifd = Notifd.get_default();
|
||||
|
||||
notifd.connect("notified", (_, id) => {
|
||||
const n = notifd.get_notification(id)
|
||||
console.log(n.summary, n.body)
|
||||
})
|
||||
const n = notifd.get_notification(id);
|
||||
console.log(n.summary, n.body);
|
||||
});
|
||||
```
|
||||
|
||||
```py [<i class="devicon-python-plain"></i> Python]
|
||||
# Not yet documented
|
||||
import gi
|
||||
|
||||
gi.require_version("AstalNotifd", "0.1")
|
||||
|
||||
from gi.repository import AstalNotifd
|
||||
|
||||
notifd = AstalNotifd.get_default()
|
||||
|
||||
def on_notified(_, id):
|
||||
n = notifd.get_notification(id)
|
||||
print(n.get_body(), n.get_body())
|
||||
|
||||
notifd.connect("notified", on_notified)
|
||||
```
|
||||
|
||||
```lua [<i class="devicon-lua-plain"></i> Lua]
|
||||
-- Not yet documented
|
||||
local lgi = require("lgi")
|
||||
|
||||
local AstalNotifd = lgi.require("AstalNotifd", "0.1")
|
||||
|
||||
local notifd = AstalNotifd.get_default()
|
||||
|
||||
notifd.on_notified = function(_, id)
|
||||
local n = notifd.get_notification(id)
|
||||
print(n.body, n.summary)
|
||||
end
|
||||
```
|
||||
|
||||
```vala [<i class="devicon-vala-plain"></i> Vala]
|
||||
|
||||
@@ -69,17 +69,31 @@ astal-power-profiles --help
|
||||
```js [<i class="devicon-javascript-plain"></i> JavaScript]
|
||||
import PowerProfiles from "gi://AstalPowerProfiles";
|
||||
|
||||
const powerprofiles = PowerProfiles.get_default()
|
||||
const powerprofiles = PowerProfiles.get_default();
|
||||
|
||||
console.log(powerprofiles.activeProfile)
|
||||
console.log(powerprofiles.activeProfile);
|
||||
```
|
||||
|
||||
```py [<i class="devicon-python-plain"></i> Python]
|
||||
# Not yet documented
|
||||
import gi
|
||||
|
||||
gi.require_version("AstalPowerProfiles", "0.1")
|
||||
|
||||
from gi.repository import AstalPowerProfiles
|
||||
|
||||
powerprofiles = AstalPowerProfiles.get_default()
|
||||
|
||||
print(powerprofiles.get_active_profile())
|
||||
```
|
||||
|
||||
```lua [<i class="devicon-lua-plain"></i> Lua]
|
||||
-- Not yet documented
|
||||
local lgi = require("lgi")
|
||||
|
||||
local AstalPowerProfiles = lgi.require("AstalPowerProfiles", "0.1")
|
||||
|
||||
local powerprofiles = AstalPowerProfiles.get_default()
|
||||
|
||||
print(powerprofiles.active_profile)
|
||||
```
|
||||
|
||||
```vala [<i class="devicon-vala-plain"></i> Vala]
|
||||
|
||||
+23
-3
@@ -62,15 +62,35 @@ astal-river --help
|
||||
:::code-group
|
||||
|
||||
```js [<i class="devicon-javascript-plain"></i> JavaScript]
|
||||
// Not yet documented
|
||||
import River from "gi://AstalRiver";
|
||||
|
||||
const river = River.get_default();
|
||||
|
||||
console.log(river.get_outputs().map((o) => o.name));
|
||||
```
|
||||
|
||||
```py [<i class="devicon-python-plain"></i> Python]
|
||||
# Not yet documented
|
||||
import gi
|
||||
|
||||
gi.require_version("AstalRiver", "0.1")
|
||||
|
||||
from gi.repository import AstalRiver
|
||||
|
||||
river = AstalRiver.get_default()
|
||||
|
||||
print("\n".join(o.get_name() for o in river.get_outputs()))
|
||||
```
|
||||
|
||||
```lua [<i class="devicon-lua-plain"></i> Lua]
|
||||
-- Not yet documented
|
||||
local lgi = require("lgi")
|
||||
|
||||
local AstalRiver = lgi.require("AstalRiver", "0.1")
|
||||
|
||||
local river = AstalRiver.River.get_default()
|
||||
|
||||
for _, o in ipairs(river.outputs) do
|
||||
print(o.name)
|
||||
end
|
||||
```
|
||||
|
||||
```vala [<i class="devicon-vala-plain"></i> Vala]
|
||||
|
||||
+21
-5
@@ -62,19 +62,35 @@ astal-tray --help
|
||||
:::code-group
|
||||
|
||||
```js [<i class="devicon-javascript-plain"></i> JavaScript]
|
||||
import Tray from "gi://AstalTray"
|
||||
import Tray from "gi://AstalTray";
|
||||
|
||||
const tray = Tray.get_default()
|
||||
const tray = Tray.get_default();
|
||||
|
||||
console.log(tray.get_items().map(i => i.title))
|
||||
console.log(tray.get_items().map((i) => i.title));
|
||||
```
|
||||
|
||||
```py [<i class="devicon-python-plain"></i> Python]
|
||||
# Not yet documented
|
||||
import gi
|
||||
|
||||
gi.require_version("AstalTray", "0.1")
|
||||
|
||||
from gi.repository import AstalTray
|
||||
|
||||
tray = AstalTray.get_default()
|
||||
|
||||
print("\n".join(i.title for i in tray.get_items()))
|
||||
```
|
||||
|
||||
```lua [<i class="devicon-lua-plain"></i> Lua]
|
||||
-- Not yet documented
|
||||
local lgi = require("lgi")
|
||||
|
||||
local AstalTray = lgi.require("AstalTray", "0.1")
|
||||
|
||||
local tray = AstalTray.get_default()
|
||||
|
||||
for _, i in ipairs(tray.items) do
|
||||
print(i.title)
|
||||
end
|
||||
```
|
||||
|
||||
```vala [<i class="devicon-vala-plain"></i> Vala]
|
||||
|
||||
@@ -66,17 +66,31 @@ wpctl --help
|
||||
```js [<i class="devicon-javascript-plain"></i> JavaScript]
|
||||
import Wp from "gi://AstalWp";
|
||||
|
||||
const audio = Wp.get_default_wp().audio
|
||||
const audio = Wp.get_default_wp().audio;
|
||||
|
||||
console.log(audio.volume)
|
||||
console.log(audio.default_speaker.volume);
|
||||
```
|
||||
|
||||
```py [<i class="devicon-python-plain"></i> Python]
|
||||
# Not yet documented
|
||||
import gi
|
||||
|
||||
gi.require_version("AstalWp", "0.1")
|
||||
|
||||
from gi.repository import AstalWp
|
||||
|
||||
audio = AstalWp.get_default_wp().get_audio()
|
||||
|
||||
print(audio.get_default_speaker().get_volume())
|
||||
```
|
||||
|
||||
```lua [<i class="devicon-lua-plain"></i> Lua]
|
||||
-- Not yet documented
|
||||
local lgi = require("lgi")
|
||||
|
||||
local AstalWp = lgi.require("AstalWp", "0.1")
|
||||
|
||||
local audio = AstalWp.get_default_wp().audio
|
||||
|
||||
print(audio.default_speaker.volume)
|
||||
```
|
||||
|
||||
```vala [<i class="devicon-vala-plain"></i> Vala]
|
||||
|
||||
Reference in New Issue
Block a user