Debian 12에서 잘 쓰던게 13으로 올리니 안 되는 게 있다.
NumLock 상태를 보여주는 LED가 키보드에 없어서 프로그램 하나 설치해서 쓰던 게 있었는데... 그 프로그램에 13에서 안 된다.
대안 프로그램을 찾았다. lks-indicator
그런데 이 프로그램은 NumLock 켜지면 빨간색 꺼지면 녹색을 표시해준다.
내 맘에 안 들어서 켜지면 녹색, 꺼지면 빨간색으로 되게 살짝 바꿈.
바꾼 부분에 Sebul Change 라고 코멘트.
소스 코드를 여기에 그대로 붙이니 이상하게 나오네.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
###########################################################
# Author: Serg Kolo <1047481448@qq.com>
# Date: July 16, 2012
# Purpose: Simple indicator of Caps, Num, and Scroll Lock
# keys for Ubuntu
#
# Written for: http://askubuntu.com/q/796985/295286
# Tested on: Ubuntu 16.04 LTS
# Color changed by Sebul See below. Tested on Debian 13. Sep 14, 2025
###########################################################
#
# Licensed under The MIT License (MIT).
# See included LICENSE file or the notice below.
#
# Copyright © 2016 Sergiy Kolodyazhnyy <1047481448@qq.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the 'Software'), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import gi
gi.require_version('AyatanaAppIndicator3', '0.1')
from gi.repository import GLib as glib
from gi.repository import AyatanaAppIndicator3 as appindicator
from gi.repository import Gtk as gtk
import os
import subprocess
import argparse
class LockKeyStatusIndicator(object):
def __init__(self, show_all=False, ignore_keys=None, monochrome=False):
self.app = appindicator.Indicator.new('LKS', '',
appindicator.IndicatorCategory.APPLICATION_STATUS)
self.app.set_status(appindicator.IndicatorStatus.ACTIVE)
self.monochrome = monochrome
self.show_all = show_all
self.app_menu = gtk.Menu()
self.quit_app = gtk.MenuItem('Quit')
self.quit_app.connect('activate', self.quit)
self.quit_app.show()
self.app_menu.append(self.quit_app)
if ignore_keys is None:
self.ignore_keys = []
else:
self.ignore_keys = ignore_keys
self.app.set_menu(self.app_menu)
self.app_path = os.path.dirname(os.path.realpath(__file__))
self.icon_path = self.app_path
if self.app_path == '/usr/bin':
self.icon_path = '/usr/share/lks-indicator/'
else:
self.icon_path = self.app_path
self.red_icon = os.path.join(self.icon_path, 'red.png')
self.green_icon = os.path.join(self.icon_path, 'green.png')
self.monochrome_icon = os.path.join(self.icon_path, 'lks-icon-monochrome.png')
self.update_label()
def run(self):
try:
gtk.main()
except KeyboardInterrupt:
pass
def quit(self, data=None):
gtk.main_quit()
def run_cmd(self, cmdlist):
try:
stdout = subprocess.check_output(cmdlist)
except subprocess.CalledProcessError:
pass
else:
if stdout is not None:
return stdout.decode('utf-8').rstrip('\n')
def key_status(self):
label = ''
status = []
keys = {
'3' : 'C',
'7' : 'N',
'11' : 'S'
}
for line in self.run_cmd(['xset', 'q']).split('\n') :
if 'Caps Lock:' in line:
status = line.split()
for index in 3, 7, 11:
if keys[str(index)] in self.ignore_keys:
pass
elif status[index] == 'on':
label += ' [' + keys[str(index)] + '] '
elif self.show_all:
label += keys[str(index)]
return label
def update_label(self):
label_text = self.key_status()
if not self.monochrome:
if '[' in label_text:
self.app.set_icon(self.green_icon) # Sebul change
else:
self.app.set_icon(self.red_icon) # Sebul change
else:
self.app.set_icon(self.monochrome_icon)
label_text = label_text.replace('[C]',u'\u24B8')
label_text = label_text.replace('[N]',u'\u24C3')
label_text = label_text.replace('[S]',u'\u24C8')
self.app.set_label(label_text, '')
glib.timeout_add_seconds(1, self.set_app_label)
def set_app_label(self):
self.update_label()
def main():
arg_parser = argparse.ArgumentParser(
description='''lks-indicator - Indicates on/off status of Lock keys.''',
formatter_class=argparse.RawTextHelpFormatter)
arg_parser.add_argument(
'--show-all', action='store_true',
help='Show all keys in label', required=False)
arg_parser.add_argument(
'-m','--monochrome', action='store_true',
help='Use monochrome icon')
arg_parser.add_argument(
'--ignore-keys', type=str,
help='Ignore specified keys (C, N or S)',
nargs='+', required=False)
args = arg_parser.parse_args()
indicator = LockKeyStatusIndicator(
show_all=args.show_all,
ignore_keys=args.ignore_keys,
monochrome=args.monochrome)
indicator.run()
if __name__ == '__main__':
main()
댓글 없음:
댓글 쓰기