55gi .require_version ('XApp' , '1.0' )
66from gi .repository import Gio , GLib , GObject , Gtk
77import sys
8+ import subprocess
89import signal
910import json
1011from pathlib import Path
@@ -29,13 +30,10 @@ def __init__(self):
2930 self .window = Gtk .Window ()
3031 self .window .set_default_size (300 , 400 )
3132 self .window .connect ("destroy" , self .on_window_destroy )
32- self .window_box = Gtk .Box (orientation = Gtk .Orientation .VERTICAL )
33- self .main_box = Gtk .Box (orientation = Gtk .Orientation .HORIZONTAL ,
33+ self .main_box = Gtk .Box (orientation = Gtk .Orientation .VERTICAL ,
3434 margin = 6 ,
3535 spacing = 0 )
3636
37- self .window_box .pack_start (self .main_box , True , True , 0 )
38-
3937 # list stuff
4038 sw_frame = Gtk .Frame ()
4139 sw = Gtk .ScrolledWindow (hadjustment = None , vadjustment = None )
@@ -49,9 +47,13 @@ def __init__(self):
4947
5048 sw .add (self .list_box )
5149
52- self .main_box .pack_start (sw_frame , True , True , 6 )
53- self .window .add (self .window_box )
50+ self .main_box .pack_start (sw_frame , True , True , 3 )
51+
52+ self .toggle_button = Gtk .Button (label = "Toggle Keyboard" )
53+ self .toggle_button .connect ("clicked" , self .toggle_keyboard )
54+ self .main_box .pack_start (self .toggle_button , False , False , 3 )
5455
56+ self .window .add (self .main_box )
5557 self .window .show_all ()
5658
5759 self .input_source_settings = Gio .Settings .new ("org.cinnamon.desktop.input-sources" )
@@ -61,6 +63,9 @@ def __init__(self):
6163 self .shortname_size_group = Gtk .SizeGroup (mode = Gtk .SizeGroupMode .HORIZONTAL )
6264 self .load_layouts ()
6365
66+ def toggle_keyboard (self , button , data = None ):
67+ subprocess .run (["cinnamon-dbus-command" , "ToggleKeyboard" ])
68+
6469 def load_layouts (self ):
6570 for file in Path .cwd ().iterdir ():
6671 if file .suffix != ".json" :
0 commit comments