Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
#
#
from __future__ import absolute_import, division, print_function, unicode_literals
from gi.repository import GObject, Gtk
GObject.threads_init()
_LARGE_SIZE = 64
Gtk.IconSize.LARGE = Gtk.icon_size_register('large', _LARGE_SIZE, _LARGE_SIZE)
# Gtk.IconSize.XLARGE = Gtk.icon_size_register('x-large', _LARGE_SIZE * 2, _LARGE_SIZE * 2)
from . import notify, status_icon, main_window, pair_window, action
from solaar import NAME
APP_ICON = { 1: NAME, 2: NAME + '-mask', 0: NAME + '-init', -1: NAME + '-fail' }
def get_battery_icon(level):
if level < 0:
return 'battery_unknown'
return 'battery_%03d' % (10 * ((level + 5) // 10))
_ICON_SETS = {}
def device_icon_set(name, kind=None):
icon_set = _ICON_SETS.get(name)
if icon_set is None:
icon_set = Gtk.IconSet.new()
_ICON_SETS[name] = icon_set
# yield ('Codename', device.codename)
yield (_("Index"), device.number)
yield (_("Wireless PID"), device.wpid)
hid_version = device.protocol
yield (_("Protocol"), 'HID++ %1.1f' % hid_version if hid_version else _('Unknown'))
if read_all and device.polling_rate:
yield (_("Polling rate"), _('%(rate)d ms (%(rate_hz)dHz)') % { 'rate': device.polling_rate, 'rate_hz': 1000 // device.polling_rate })
if read_all or not device.online:
yield (_("Serial"), device.serial)
else:
yield (_("Serial"), '...')
if read_all:
for fw in list(device.firmware):
yield (' ' + _(str(fw.kind)), (fw.name + ' ' + fw.version).strip())
elif device.kind is None or device.online:
yield (' %s' % _("Firmware"), '...')
flag_bits = device.status.get(_K.NOTIFICATION_FLAGS)
if flag_bits is not None:
flag_names = ('(%s)' % _("none"),) if flag_bits == 0 else _hidpp10.NOTIFICATION_FLAG.flag_names(flag_bits)
yield (_("Notifications"), ('\n%15s' % ' ').join(flag_names))
# If read_all is False, only return stuff that is ~100% already
# cached, and involves no HID++ calls.
if device.kind is None:
yield (_("Path"), device.path)
# 046d is the Logitech vendor id
yield (_("USB id"), '046d:' + device.product_id)
if read_all:
yield (_("Serial"), device.serial)
else:
yield (_("Serial"), '...')
else:
# yield ('Codename', device.codename)
yield (_("Index"), device.number)
yield (_("Wireless PID"), device.wpid)
hid_version = device.protocol
yield (_("Protocol"), 'HID++ %1.1f' % hid_version if hid_version else _('Unknown'))
if read_all and device.polling_rate:
yield (_("Polling rate"), _('%(rate)d ms (%(rate_hz)dHz)') % { 'rate': device.polling_rate, 'rate_hz': 1000 // device.polling_rate })
if read_all or not device.online:
yield (_("Serial"), device.serial)
else:
yield (_("Serial"), '...')
if read_all:
for fw in list(device.firmware):
yield (' ' + _(str(fw.kind)), (fw.name + ' ' + fw.version).strip())
elif device.kind is None or device.online:
yield (' %s' % _("Firmware"), '...')
# cached, and involves no HID++ calls.
if device.kind is None:
yield (_("Path"), device.path)
# 046d is the Logitech vendor id
yield (_("USB id"), '046d:' + device.product_id)
if read_all:
yield (_("Serial"), device.serial)
else:
yield (_("Serial"), '...')
else:
# yield ('Codename', device.codename)
yield (_("Index"), device.number)
yield (_("Wireless PID"), device.wpid)
hid_version = device.protocol
yield (_("Protocol"), 'HID++ %1.1f' % hid_version if hid_version else _('Unknown'))
if read_all and device.polling_rate:
yield (_("Polling rate"), _('%(rate)d ms (%(rate_hz)dHz)') % { 'rate': device.polling_rate, 'rate_hz': 1000 // device.polling_rate })
if read_all or not device.online:
yield (_("Serial"), device.serial)
else:
yield (_("Serial"), '...')
if read_all:
for fw in list(device.firmware):
yield (' ' + _(str(fw.kind)), (fw.name + ' ' + fw.version).strip())
elif device.kind is None or device.online:
yield (' %s' % _("Firmware"), '...')
try:
import solaar.ui as ui
import solaar.listener as listener
listener.setup_scanner(ui.status_changed, ui.error_dialog)
import solaar.upower as _upower
if args.restart_on_wake_up:
_upower.watch(listener.start_all, listener.stop_all)
else:
_upower.watch(listener.ping_all)
# main UI event loop
ui.run_loop(listener.start_all, listener.stop_all)
except Exception as e:
import sys
sys.exit('%s: error: %s' % (NAME.lower(), e))
def init():
Gtk.Window.set_default_icon_name(NAME.lower())
Gtk.Window.set_default_icon_from_file(_icons.icon_file(NAME.lower()))
global _model, _tree, _details, _info, _empty, _window
_model = Gtk.TreeStore(*_COLUMN_TYPES)
_tree = _create_tree(_model)
_details = _create_details_panel()
_info = _create_info_panel()
_empty = _create_empty_panel()
_window = _create()
def run(cli_args=None, hidraw_path=None):
if cli_args:
action = cli_args[0]
args = _cli_parser.parse_args(cli_args)
else:
args = _cli_parser.parse_args()
# Python 3 has an undocumented 'feature' that breaks parsing empty args
# http://bugs.python.org/issue16308
if not 'cmd' in args:
_cli_parser.print_usage(_sys.stderr)
_sys.stderr.write('%s: error: too few arguments\n' % NAME.lower())
_sys.exit(2)
action = args.action
assert action in actions
try:
c = list(_receivers(hidraw_path))
if not c:
raise Exception('Logitech receiver not found')
from importlib import import_module
m = import_module('.' + action, package=__name__)
m.run(c, args, _find_receiver, _find_device)
except AssertionError as e:
from traceback import extract_tb
tb_last = extract_tb(_sys.exc_info()[2])[-1]
_sys.exit('%s: assertion failed: %s line %d' % (NAME.lower(), tb_last[0], tb_last[1]))
_sys.exit(2)
action = args.action
assert action in actions
try:
c = list(_receivers(hidraw_path))
if not c:
raise Exception('Logitech receiver not found')
from importlib import import_module
m = import_module('.' + action, package=__name__)
m.run(c, args, _find_receiver, _find_device)
except AssertionError as e:
from traceback import extract_tb
tb_last = extract_tb(_sys.exc_info()[2])[-1]
_sys.exit('%s: assertion failed: %s line %d' % (NAME.lower(), tb_last[0], tb_last[1]))
except Exception as e:
_sys.exit('%s: error: %s' % (NAME.lower(), e))
if args.action:
# if any argument, run comandline and exit
return _cli.run(args.action, args.hidraw_path)
gi = _require('gi', 'python-gi')
gi.require_version('Gtk', '3.0')
_require('gi.repository.Gtk', 'gir1.2-gtk-3.0')
try:
import solaar.ui as ui
import solaar.listener as listener
listener.setup_scanner(ui.status_changed, ui.error_dialog)
import solaar.upower as _upower
if args.restart_on_wake_up:
_upower.watch(listener.start_all, listener.stop_all)
else:
_upower.watch(listener.ping_all)
# main UI event loop
ui.run_loop(listener.start_all, listener.stop_all)
except Exception as e:
import sys
sys.exit('%s: error: %s' % (NAME.lower(), e))
return _cli.run(args.action, args.hidraw_path)
gi = _require('gi', 'python-gi')
gi.require_version('Gtk', '3.0')
_require('gi.repository.Gtk', 'gir1.2-gtk-3.0')
try:
import solaar.ui as ui
import solaar.listener as listener
listener.setup_scanner(ui.status_changed, ui.error_dialog)
import solaar.upower as _upower
if args.restart_on_wake_up:
_upower.watch(listener.start_all, listener.stop_all)
else:
_upower.watch(listener.ping_all)
# main UI event loop
ui.run_loop(listener.start_all, listener.stop_all)
except Exception as e:
import sys
sys.exit('%s: error: %s' % (NAME.lower(), e))