diff --git a/Changelog b/Changelog index 0e78a67..6dd608a 100644 --- a/Changelog +++ b/Changelog @@ -1,8 +1,9 @@ -2016-01-23 version 0.2.2 +2016-01-25 version 0.2.2 1.添加新音效(爆裂鼓手) 2.修改界面,现在显示中文 3.修改音效显示名称 4.修复一个键盘监测bug +5.再次运行程序自动打开设置界面 2015-10-31 version 0.2.1 1.修复错误弹出更新提示的bug diff --git a/screenshot/tickeys_v0.2.2.png b/screenshot/tickeys_v0.2.2.png new file mode 100644 index 0000000..2afc6ed Binary files /dev/null and b/screenshot/tickeys_v0.2.2.png differ diff --git a/tickeys/CLI.py b/tickeys/CLI.py index 3ee1a8b..752ae82 100644 --- a/tickeys/CLI.py +++ b/tickeys/CLI.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # coding: utf-8 import cmd -from KeyboardHandler import KeyboardHandler +from keyboardHandler import KeyboardHandler from logger import logger from __init__ import __version__ import sys diff --git a/tickeys/GUI.py b/tickeys/GUI.py index ec52175..0af6982 100644 --- a/tickeys/GUI.py +++ b/tickeys/GUI.py @@ -4,9 +4,9 @@ from kivy.uix.spinner import Spinner from kivy.uix.boxlayout import BoxLayout from kivy.uix.gridlayout import GridLayout -from KeyboardHandler import KeyboardHandler +from keyboardHandler import KeyboardHandler from kivy.lang import Builder -from StartupHandler import add_startup_linux, check_startup_file, delete_startup_linux +from startupHandler import add_startup_linux, check_startup_file, delete_startup_linux from logger import logger from config import Configer from __init__ import __version__, debug_mode @@ -15,6 +15,9 @@ import os import commands import webbrowser + +from windowManager import hide_terminal, hide_GUI, save_GUI_window_id + reload(sys) sys.setdefaultencoding("utf-8") @@ -259,44 +262,14 @@ class Main(GridLayout): def __init__(self, *args, **kwargs): self.Configer = Configer() super(Main, self).__init__(**kwargs) - self.terminalId = args[0] if args else None - self.GUIID = None - # tool works preget - if self.terminalId: - stat, GUIID = commands.getstatusoutput('xdotool getactivewindow') - if stat == 0: - self.GUIID = GUIID - # hide itself - # commands.getstatusoutput( - # 'xdotool getactivewindow windowminimize') - self.hide_GUI() + save_GUI_window_id() + self.Hide() self.detecter = KeyboardHandler() self.detecter.start_detecting() - self.detecter.GUIID = self.GUIID if not debug_mode: - self.hide_terminal() + hide_terminal() show_notify() - # @property - # def detecter(self): - # return self.detecter - - def hide_terminal(self): - if not self.terminalId: - return - commands.getstatusoutput( - "xdotool windowactivate --sync %s" % self.terminalId) - commands.getstatusoutput( - "xdotool getactivewindow windowunmap") - # if want to show terminal use windowminimize - - def hide_GUI(self): - try: - commands.getstatusoutput( - 'xdotool windowunmap --sync %s' % self.GUIID) - except Exception,e: - logger.error(str(e)) - def Exit(self): self.detecter.stop_detecting() # Show the terminal @@ -309,17 +282,16 @@ def Exit(self): def Hide(self): if not debug_mode: - self.hide_GUI() + hide_GUI() class TickeysApp(App): def __init__(self, *args, **kwargs): super(TickeysApp, self).__init__(**kwargs) - self.terminalId = args[0] if args else None def build(self): self.icon = 'tickeys.png' - root = Main(self.terminalId) + root = Main() return root def on_stop(self): diff --git a/tickeys/__init__.py b/tickeys/__init__.py index c7a5dce..131eba0 100644 --- a/tickeys/__init__.py +++ b/tickeys/__init__.py @@ -1,7 +1,7 @@ __author__ = 'Huang Xiongbiao' __email__ = 'billo@qq.com' __version__ = '0.2.2' -debug_mode = True +debug_mode = False from run import main diff --git a/tickeys/KeyboardHandler.py b/tickeys/keyboardHandler.py similarity index 91% rename from tickeys/KeyboardHandler.py rename to tickeys/keyboardHandler.py index c1dc6ef..1f930d7 100644 --- a/tickeys/KeyboardHandler.py +++ b/tickeys/keyboardHandler.py @@ -5,10 +5,12 @@ import threading from evdev import InputDevice from select import select -from SoundPlayer import SoundPlayer +from soundPlayer import SoundPlayer from logger import logger import commands +from windowManager import show_GUI + __author__ = 'Huang xiongbiao(billo@qq.com)' # input device file path @@ -24,7 +26,6 @@ def __init__(self): self.inputRecord = [] self.hotKey = [16, 30, 44, 2, 3, 4] # QAZ123 self.sp = SoundPlayer() - self.GUIID = None self.show_device() # list all event's name and its device @@ -48,17 +49,6 @@ def set_pitch(self, pitch): def get_player_infor(self): return self.sp.get_infor() - @property - def GUIID(self): - return self.GUIID - - def show_GUI(self): - if not self.GUIID: - return - # command = "xdotool windowactivate --sync %s" % self.GUIID - command = "xdotool windowmap --sync %s && xdotool windowactivate --sync %s" % (self.GUIID, self.GUIID) - commands.getstatusoutput(command) - # new way to find keyboard # return with a list of keyboard's event def find_keyboard(self): @@ -127,7 +117,7 @@ def check_show_window(self, keycode): self.inputRecord.append(keycode) logger.debug(self.inputRecord) if len(self.inputRecord) == 6: - self.show_GUI() + show_GUI() self.inputRecord = [] else: self.inputRecord = [] diff --git a/tickeys/run.py b/tickeys/run.py index 421f7cb..1c8f133 100644 --- a/tickeys/run.py +++ b/tickeys/run.py @@ -3,12 +3,12 @@ from logger import logger import sys import os -import commands import json -import requests from threading import Thread -__version__ = '0.2.1' +from windowManager import save_terminal_window_id, check_tickeys_running_status + +__version__ = '0.2.2' __author__ = 'Huang xiongbiao(billo@qq.com)' @@ -17,13 +17,8 @@ def run_GUI(): Thread(target=check_update, args=()).start() check_system() try: - stat, terminalId = commands.getstatusoutput('xdotool getactivewindow') from GUI import TickeysApp - if stat == 0: - TickeysApp(terminalId).run() - else: - TickeysApp().run() - + TickeysApp().run() except Exception, e: logger.info("Run GUI Fail, use CLI instead..Fail msg:%s" % str(e)) run_CLI() @@ -48,6 +43,7 @@ def check_root(): def check_update(): try: + import requests logger.info("Version checking...") r = requests.get("http://billbill.sinaapp.com/tickeys") returnInfor = json.loads(r.text) @@ -92,6 +88,9 @@ def print_help_msg(): def main(): logger.debug("Tickeys start........") + is_running = check_tickeys_running_status() + if is_running: + return if len(sys.argv) == 1: run_GUI() elif len(sys.argv) == 2: diff --git a/tickeys/SoundPlayer.py b/tickeys/soundPlayer.py similarity index 100% rename from tickeys/SoundPlayer.py rename to tickeys/soundPlayer.py diff --git a/tickeys/StartupHandler.py b/tickeys/startupHandler.py similarity index 100% rename from tickeys/StartupHandler.py rename to tickeys/startupHandler.py diff --git a/tickeys/windowManager.py b/tickeys/windowManager.py new file mode 100644 index 0000000..4e4ed04 --- /dev/null +++ b/tickeys/windowManager.py @@ -0,0 +1,80 @@ +# coding: utf-8 +import commands + +from logger import logger + + +def save_terminal_window_id(): + try: + stat, terminalId = commands.getstatusoutput('xdotool getactivewindow') + assert stat == 0 + with open("/tmp/tickeys_terminal_window_id", "w+") as f: + f.write(terminalId) + except Exception, e: + logger.error("Save terminal window id fail:" + str(e)) + + +def read_terminal_window_id(): + with open("/tmp/tickeys_terminal_window_id", "r") as f: + return f.read() + + +def hide_terminal(): + try: + terminalId = read_terminal_window_id() + if not terminalId: + return + commands.getstatusoutput( + "xdotool windowactivate --sync %s" % terminalId) + commands.getstatusoutput( + "xdotool getactivewindow windowunmap") + except Exception,e: + logger.error(str(e)) + + +def save_GUI_window_id(): + try: + stat, GUIID = commands.getstatusoutput('xdotool getactivewindow') + assert stat == 0 + with open("/tmp/tickeys_GUI_window_id", "w+") as f: + f.write(GUIID) + except Exception, e: + logger.error("Save GUI window id fail:" + str(e)) + + +def read_GUI_window_id(): + with open("/tmp/tickeys_GUI_window_id", "r") as f: + return f.read() + + +def hide_GUI(): + try: + GUIID = read_GUI_window_id() + commands.getstatusoutput( + 'xdotool windowunmap --sync %s' % GUIID) + except Exception,e: + logger.error(str(e)) + + +def show_GUI(): + try: + GUIID = read_GUI_window_id() + if not GUIID: + return + # read window ids + command = "xdotool windowmap --sync %s && xdotool windowactivate --sync %s" % (GUIID, GUIID) + stat, output = commands.getstatusoutput(command) + return str(stat) + except Exception, e: + logger.error(str(e)) + return '256' + +def check_tickeys_running_status(): + save_terminal_window_id() + stat = show_GUI() + if stat != "0": + return False + else: + print "Tickeys is already running, show it" + hide_terminal() + return True