def main():
print('=== starting Backlight Indicator ===')
if dbus.SessionBus().request_name('es.atareao.BacklightIndicator') != \
dbus.bus.REQUEST_NAME_REPLY_PRIMARY_OWNER:
print("application already running")
exit(0)
Notify.init('BacklightIndicator')
BacklightIndicator()
print('=== started Backlight Indicator === ')
Gtk.main()
python类SessionBus()的实例源码
def notify(summary, body='', app_name='', app_icon='',
timeout=DEFAULT_TIMEOUT, actions=[], hints=[], replaces_id=0):
_bus_name = 'org.freedesktop.Notifications'
_object_path = '/org/freedesktop/Notifications'
_interface_name = _bus_name
session_bus = dbus.SessionBus()
obj = session_bus.get_object(_bus_name, _object_path)
interface = dbus.Interface(obj, _interface_name)
interface.Notify(app_name, replaces_id, app_icon,
summary, body, actions, hints, timeout)
# If run as a script, just display the argv as summary
def notify(summary, body='', app_name='', app_icon='',
timeout=DEFAULT_TIMEOUT, actions=[], hints=[], replaces_id=0):
_bus_name = 'org.freedesktop.Notifications'
_object_path = '/org/freedesktop/Notifications'
_interface_name = _bus_name
session_bus = dbus.SessionBus()
obj = session_bus.get_object(_bus_name, _object_path)
interface = dbus.Interface(obj, _interface_name)
interface.Notify(app_name, replaces_id, app_icon,
summary, body, actions, hints, timeout)
# If run as a script, just display the argv as summary
def __init__(self, ui, home, tr_ay, new_tr):
global tray, new_tray_widget
tray = tr_ay
new_tray_widget = new_tr
bus = dbus.service.BusName(
AW_MPRIS_BUS_NAME,
bus=dbus.SessionBus())
super().__init__(bus, MPRIS_OBJECT_PATH)
self._properties = dbus.Dictionary({
'DesktopEntry': 'kawaii-player',
'Identity': 'kawaii-player',
}, signature='sv')
self._player_properties = dbus.Dictionary({
'Metadata': dbus.Dictionary({
'mpris:artUrl': '',
'xesam:artist': ['None'],
'xesam:title': 'None',
'xesam:album': 'None'
}, signature='sv', variant_level=1),
'CanGoNext': True,
'CanGoPrevious': True,
'CanPause': True,
'CanPlay': True,
'CanControl': True,
'CanStop': True,
}, signature='sv', variant_level=2)
self.ui = ui
self.home = home
def linux_status():
try:
session_bus = dbus.SessionBus()
spotify_bus = session_bus.get_object("org.mpris.MediaPlayer2.spotify",
"/org/mpris/MediaPlayer2")
spotify_properties = dbus.Interface(spotify_bus,
"org.freedesktop.DBus.Properties")
status = spotify_properties.Get("org.mpris.MediaPlayer2.Player",
"PlaybackStatus")
return status
except:
return "Paused"
def song_info_linux():
if linux_status() == "Playing":
session_bus = dbus.SessionBus()
spotify_bus = session_bus.get_object("org.mpris.MediaPlayer2.spotify",
"/org/mpris/MediaPlayer2")
spotify_properties = dbus.Interface(spotify_bus,
"org.freedesktop.DBus.Properties")
metadata = spotify_properties.Get(
"org.mpris.MediaPlayer2.Player", "Metadata")
song_info = metadata['xesam:title']
return song_info
else:
return "There is nothing playing at this moment"
def artist_info_linux():
if linux_status() == "Playing":
session_bus = dbus.SessionBus()
spotify_bus = session_bus.get_object("org.mpris.MediaPlayer2.spotify",
"/org/mpris/MediaPlayer2")
spotify_properties = dbus.Interface(spotify_bus,
"org.freedesktop.DBus.Properties")
metadata = spotify_properties.Get(
"org.mpris.MediaPlayer2.Player", "Metadata")
artist_info = metadata['xesam:artist'][0]
return artist_info
else:
return "There is nothing playing at this moment"
def next():
if platform.system() == 'Linux':
bus = dbus.SessionBus()
proxy = bus.get_object(
'org.mpris.MediaPlayer2.spotify', '/org/mpris/MediaPlayer2')
interface = dbus.Interface(
proxy, dbus_interface='org.mpris.MediaPlayer2.Player')
interface.Next()
elif platform.system() == 'Windows':
win32api.keybd_event(Media_Next, hwcode(Media_Next))
def previous():
if platform.system() == 'Linux':
bus = dbus.SessionBus()
proxy = bus.get_object(
'org.mpris.MediaPlayer2.spotify', '/org/mpris/MediaPlayer2')
interface = dbus.Interface(
proxy, dbus_interface='org.mpris.MediaPlayer2.Player')
interface.Previous()
elif platform.system() == 'Windows':
win32api.keybd_event(Media_Previous, hwcode(Media_Previous))
def play():
if platform.system() == 'Linux':
bus = dbus.SessionBus()
proxy = bus.get_object(
'org.mpris.MediaPlayer2.spotify', '/org/mpris/MediaPlayer2')
interface = dbus.Interface(
proxy, dbus_interface='org.mpris.MediaPlayer2.Player')
interface.PlayPause()
elif platform.system() == 'Windows':
win32api.keybd_event(Media_Pause, hwcode(Media_Pause))
def __init__(self):
self.tw = TaskWarrior()
builder.add_from_file("gui/timeout.glade")
self.wTimeout = builder.get_object("wTimeout")
self.pbTimeout = builder.get_object("pbTimeout")
self.wContinue = builder.get_object("wContinue")
self.lsbReminders = builder.get_object("lsbReminders")
self.bus = dbus.SessionBus()
self.session_bus = self.bus.get_object('org.liloman.pomodoro', "/daemon")
self.interface = dbus.Interface(self.session_bus, "org.liloman.pomodoroInterface")
################
# Set events #
################
self.btYes = builder.get_object("btYes")
self.btYes.connect("clicked",self.onYesPressed)
self.btNo = builder.get_object("btNo")
self.btNo.connect("clicked",self.onNoPressed)
self.wTimeout.connect("delete-event",self.onDeleteWindow)
self.btBack = builder.get_object("btBackWork")
self.btBack.connect("clicked",self.onBackWorkPressed)
self.pbTimeout = builder.get_object("pbTimeout")
DATEFORMAT='%d/%m/%Y %H:%M'
for task in self.tw.tasks.filter('+READY +reminder'):
#get all fields in task
task.refresh()
self.addReminder(task['description'],task['due'].strftime(DATEFORMAT))
###############
# Reminders #
###############
def doCommand(self,comm):
self.com = comm
#Quit daemon and systray
if self.com == "quit":
#close systray when closing the daemon as well
self.interface.do_quit(True)
print("pomodoro daemon halted")
# Show the change task gui
elif self.com == "systray":
# use busConnection better than bus = dbus.SessionBus() to work with systemd for example
self.bus = dbus.bus.BusConnection(self.dbus_path)
self.session_bus = self.bus.get_object('org.liloman.pomodoro.systray', "/systray")
systray = dbus.Interface(self.session_bus, "org.liloman.pomodoro.systrayInterface")
systray.show_change_task()
# Start a uuid task
elif self.com == "do_start":
if len(sys.argv) != 3:
print("must pass a valid uuid")
sys.exit(1)
dic = dbus.Dictionary({'uuid': sys.argv[2] , 'resume': 'No' } , signature = 'ss' )
try:
print ("reply:"+self.interface.do_start(dic)[0])
except:
print("Incorrect uuid:"+sys.argv[2]+" .The task couldn't be started")
# Do any other command
else:
print(u''.join(self.interface.do_fsm(self.com)[0]).encode('utf-8').strip())
def __init__(self, rc = '~/.task'):
self.tw = TaskWarrior(data_location=rc, create=True)
self.status_icon = Gtk.StatusIcon()
self.status_icon.set_from_file("images/iconStarted-0.png")
self.status_icon.connect("popup-menu", self.right_click_event)
self.status_icon.connect("activate", self.left_click_event)
# systray daemon
name = dbus.service.BusName(self.bus_name, bus=dbus.SessionBus(),do_not_queue=True, replace_existing=False, allow_replacement=False )
dbus.service.Object.__init__(self, name, '/systray')
# client for daemon
bus = dbus.SessionBus(private = True)
daemon_client = bus.get_object('org.liloman.pomodoro', "/daemon")
self.interface = dbus.Interface(daemon_client, "org.liloman.pomodoroInterface")
def check_instance(self):
'''
Check whether another instance of the setup tool is running already
'''
if (dbus.SessionBus().request_name("org.ibus.typingbooster")
!= dbus.bus.REQUEST_NAME_REPLY_PRIMARY_OWNER):
self.__run_message_dialog(
_("Another instance of this app is already running."),
Gtk.MessageType.ERROR)
sys.exit(1)
else:
return False
def __init__(self):
bus_name = dbus.service.BusName(
'org.ibus.typingbooster', bus=dbus.SessionBus())
dbus.service.Object.__init__(self, bus_name, '/org/ibus/typingbooster')
def __init__(self):
busname = dbus.service.BusName('org.documentroot.AAuname',
bus=dbus.SessionBus())
dbus.service.Object.__init__(self, busname, '/AAuname')
def __init__(self, sony_av_indicator, device_service, state_service, command_service):
threading.Thread.__init__(self)
self.sony_av_indicator = sony_av_indicator
self.device_service = device_service
self.state_service = state_service
self.command_service = command_service
self.properties = {
ROOT_INTERFACE: self._get_root_iface_properties(),
PLAYER_INTERFACE: self._get_player_iface_properties()
}
self.main_loop = dbus.mainloop.glib.DBusGMainLoop(set_as_default = True)
# self.main_loop = GObject.MainLoop()
self.bus = dbus.SessionBus(mainloop = self.main_loop)
self.bus_name = self._connect_to_dbus()
dbus.service.Object.__init__(self, self.bus_name, OBJECT_PATH)
def _connect_to_dbus(self):
# bus_type = self.config['mpris']['bus_type']
self.bus = dbus.SessionBus()
bus_name = dbus.service.BusName(BUS_NAME, self.bus)
return bus_name
def __init__(self, window):
self.window = window
self.session = dbus.SessionBus()
self.menu_items = dict()
self.menu_actions = dict()
self.explore_menu_paths()
self.explore_menu_items()
def reboot(self, menu, widget):
session_bus = dbus.SessionBus()
obj = session_bus.get_object('org.gnome.SessionManager','/org/gnome/SessionManager')
interface = dbus.Interface(obj,'org.gnome.SessionManager')
interface.RequestReboot()
self.ukuiMenuWin.hide()
Gdk.flush()