diff -Nru hinge-0.0.1+bzr7~ubuntu12.04.1/debian/bzr-builder.manifest hinge-0.0.1+bzr9~ubuntu12.04.1/debian/bzr-builder.manifest --- hinge-0.0.1+bzr7~ubuntu12.04.1/debian/bzr-builder.manifest 2014-01-02 18:51:47.000000000 +0000 +++ hinge-0.0.1+bzr9~ubuntu12.04.1/debian/bzr-builder.manifest 2014-01-21 19:35:09.000000000 +0000 @@ -1,3 +1,3 @@ -# bzr-builder format 0.3 deb-version {debupstream}+bzr7 -lp:~felixhaller/+junk/hinge revid:ich@ein-freier-mensch.de-20131231160110-g15dn98029zjos4q +# bzr-builder format 0.3 deb-version {debupstream}+bzr9 +lp:~felixhaller/+junk/hinge revid:ich@ein-freier-mensch.de-20140121193125-ceoxxr02a2i9ai49 merge packaging lp:~felixhaller/+junk/hinge_build revid:ich@ein-freier-mensch.de-20131231155958-onh8y39uukk2zfdr diff -Nru hinge-0.0.1+bzr7~ubuntu12.04.1/debian/changelog hinge-0.0.1+bzr9~ubuntu12.04.1/debian/changelog --- hinge-0.0.1+bzr7~ubuntu12.04.1/debian/changelog 2014-01-02 18:51:47.000000000 +0000 +++ hinge-0.0.1+bzr9~ubuntu12.04.1/debian/changelog 2014-01-21 19:35:09.000000000 +0000 @@ -1,8 +1,8 @@ -hinge (0.0.1+bzr7~ubuntu12.04.1) precise; urgency=low +hinge (0.0.1+bzr9~ubuntu12.04.1) precise; urgency=low * Auto build. - -- Felix Haller Thu, 02 Jan 2014 18:51:47 +0000 + -- Felix Haller Tue, 21 Jan 2014 19:35:09 +0000 convertible-tool (0.0.1-1) UNRELEASED; urgency=low diff -Nru hinge-0.0.1+bzr7~ubuntu12.04.1/hinge hinge-0.0.1+bzr9~ubuntu12.04.1/hinge --- hinge-0.0.1+bzr7~ubuntu12.04.1/hinge 2014-01-02 18:51:47.000000000 +0000 +++ hinge-0.0.1+bzr9~ubuntu12.04.1/hinge 2014-01-21 19:35:09.000000000 +0000 @@ -29,67 +29,110 @@ def main(argv): - if (len(sys.argv) > 1): + if (len(sys.argv) < 2): + printHelp() + else: CLIArgs = sys.argv[1:] try: - opts, args = getopt.getopt(CLIArgs,"hO:odfT:twnr:",["flip", "daemon", "help", "Touch=", - "toogle-touch", "Hover-click=", "toggle-hover-click", - "writing", "normal", "Rotate="]) + opts, args = getopt.getopt(CLIArgs, + "hO:odfT:tW:wnr:", + ["flip", + "daemon", + "help", + "Touch=", + "toggle-touch", + "Hover-click=", + "toggle-hover-click", + "writing=", + "toggle-writing", + "normal", + "Rotate=" + ] + ) except getopt.GetoptError: - printHelp() - sys.exit(2) + printHelp(2) for opt, arg in opts: if opt in ("-h", "--help"): printHelp() - sys.exit() elif opt in ("-d", "--daemon"): Daemon() elif opt in ("-f", "--flip"): System().rotateDevices() elif opt in ("-r", "--Rotate"): - if arg in ("normal","left","right","inverted"): - System().rotateDevices(mode={"normal":0,"left":1,"inverted":2,"right":3}[arg]) + if arg in ("normal", "left", "right", "inverted"): + System().rotateDevices(mode={"normal": 0, "left": 1, "inverted": 2, "right": 3}[arg]) else: - printHelp() - sys.exit(2) + printHelp(2) elif opt in ("-T", "--Touch"): if arg in ("on", "off"): System().tglFingerTouch(mode=arg) else: - printHelp() - sys.exit(2) + printHelp(2) elif opt in ("-t", "--toggle-touch"): System().tglFingerTouch() elif opt in ("-O", "--Hover-click"): if arg in ("on", "off"): - System().tglHoverClick(mode={"off":"0","on":"1"}[arg]) + System().tglHoverClick(mode={"off": "0", "on": "1"}[arg]) else: - printHelp() - sys.exit(2) + printHelp(2) elif opt in ("-o", "--toggle-hover-click"): System().tglHoverClick() - elif opt in ("-w", "--writing"): + elif opt in ("-W", "--writing"): + s = System() + if arg in ("on", "off"): + writingMode(s, arg) + else: + printHelp(2) + elif opt in ("-w", "--toggle-writing"): s = System() - s.tglHoverClick(mode="1") - s.tglFingerTouch(mode="off") - s.rotateDevices() + writingMode(s) elif opt in ("-n", "--normal"): s = System() - s.rotateDevices(mode=0) - s.tglHoverClick(mode="0") - s.tglFingerTouch(mode="on") + normalMode(s) - else: - printHelp() -def printHelp(): - print( - '''convertible-tool 0.0.1 -2013 Felix Haller -You can use this tool either as a CLI to perform some actions, or start -it as a daemon with an indicator/systray menu. +def writingMode(sysObj, arg=None): + """ + This is a helper function to make it possible to toggle the writing mode + (my favorite). + The decision which mode to choose depends on the current display orientation. + Only if it's in the "normal" state the writing mode will be applied. any other state + will lead to the normal (-n) mode to be applied. + + :param sysObj: has to be an instance of hinge_modules.System.System() + :param arg: either "on" or "off" or nothing for toggeling + """ + if arg is None: + if sysObj.display.getOrientation() == b'normal': + arg = "on" + else: + normalMode(sysObj) + return + sysObj.tglHoverClick(mode={"on": "1", "off": "0"}[arg]) + sysObj.tglFingerTouch(mode={"on": "off", "off": "on"}[arg]) + sysObj.rotateDevices(mode={"off": 0, "on": 2}[arg]) + + +def normalMode(sysObj): + """ + Activates the normal mode: + - normal display/input devices orientation + - HoverClick disabled + - Touch input enabled + + :param sysObj: has to be an instance of hinge_modules.System.System() + """ + sysObj.rotateDevices(mode=0) + sysObj.tglHoverClick(mode="0") + sysObj.tglFingerTouch(mode="on") + + +def printHelp(errCode=0): + print( +''' +Usage: hinge [options] -parameters: +options: -d start daemon -f, --flip flip the rotation of the screen (rotate 180°) -T, --Touch on,off enable/disable finger touch input @@ -99,8 +142,12 @@ -n, --normal reset settings to default -r, --rotate set a specific orientation (absolute) possible values: normal, left, right, inverted --w, --writing turn 180°, disable touch input, enable hover click +-W, --writing on,off enables/disables writing-mode + (turn to "inverted", disable touch input, + enable hover click) +-w, --toggle-writing toggle writing-mode ''') + sys.exit(errCode) if __name__ == "__main__": main(sys.argv) diff -Nru hinge-0.0.1+bzr7~ubuntu12.04.1/hinge_modules/Daemon.py hinge-0.0.1+bzr9~ubuntu12.04.1/hinge_modules/Daemon.py --- hinge-0.0.1+bzr7~ubuntu12.04.1/hinge_modules/Daemon.py 2014-01-02 18:51:47.000000000 +0000 +++ hinge-0.0.1+bzr9~ubuntu12.04.1/hinge_modules/Daemon.py 2014-01-21 19:35:09.000000000 +0000 @@ -8,7 +8,3 @@ self.system = System(self.gui) self.gui.show() - - - - diff -Nru hinge-0.0.1+bzr7~ubuntu12.04.1/hinge_modules/GUI.py hinge-0.0.1+bzr9~ubuntu12.04.1/hinge_modules/GUI.py --- hinge-0.0.1+bzr7~ubuntu12.04.1/hinge_modules/GUI.py 2014-01-02 18:51:47.000000000 +0000 +++ hinge-0.0.1+bzr9~ubuntu12.04.1/hinge_modules/GUI.py 2014-01-21 19:35:09.000000000 +0000 @@ -2,6 +2,7 @@ from gi.repository import Gtk from gi.repository import AppIndicator3 +import sys,signal class GUI(): @@ -73,4 +74,4 @@ def show(self): - Gtk.main() \ No newline at end of file + Gtk.main() diff -Nru hinge-0.0.1+bzr7~ubuntu12.04.1/hinge_modules/Helper.py hinge-0.0.1+bzr9~ubuntu12.04.1/hinge_modules/Helper.py --- hinge-0.0.1+bzr7~ubuntu12.04.1/hinge_modules/Helper.py 2014-01-02 18:51:47.000000000 +0000 +++ hinge-0.0.1+bzr9~ubuntu12.04.1/hinge_modules/Helper.py 2014-01-21 19:35:09.000000000 +0000 @@ -1,25 +1,32 @@ __author__ = 'Felix Haller' -from subprocess import check_call, Popen, PIPE +from subprocess import check_call, CalledProcessError + class Helper(): - @staticmethod - def sendSystemCall(command: str, *args: str): - """ - handles systems calls - """ - - cmdLine = [] - - cmdLine.append(command) - - for arg in args: - cmdLine.append(arg) - - if ("debug1" == "debug"): - print("executing system command: ", end="") - for part in cmdLine: - #@todo: Warum zur Hölle verschwindet die Ausgabe, wenn ich hinter den Part auch ein end="" packe? - print(part) + @staticmethod + def sendSystemCall(command: str, *args: str): + """ + handles systems calls + """ + cmdLine = [] + cmdLine.append(command) + + for arg in args: + cmdLine.append(arg) + + if "debug1" == "debug": + print("executing system command: ", end="") + for part in cmdLine: + #@todo: Warum zur Hölle verschwindet die Ausgabe, wenn ich hinter den Part auch ein end="" packe? + print(part) + try: + check_call(cmdLine) + return True + except CalledProcessError as ex: + print(ex) + return False + except FileNotFoundError: + return False + - check_call(cmdLine) diff -Nru hinge-0.0.1+bzr7~ubuntu12.04.1/hinge_modules/Stylus.py hinge-0.0.1+bzr9~ubuntu12.04.1/hinge_modules/Stylus.py --- hinge-0.0.1+bzr7~ubuntu12.04.1/hinge_modules/Stylus.py 2014-01-02 18:51:47.000000000 +0000 +++ hinge-0.0.1+bzr9~ubuntu12.04.1/hinge_modules/Stylus.py 2014-01-21 19:35:09.000000000 +0000 @@ -1,5 +1,6 @@ from hinge_modules.WacomDevice import WacomDevice from hinge_modules.Helper import Helper +from subprocess import Popen, PIPE __author__ = 'Felix Haller' @@ -12,19 +13,22 @@ def isHover(self): status = None - output = Popen(["xinput", "list-props", self.name], stdout=PIPE).communicate()[0] + output = Popen(["xinput", "list-props", self._name], stdout=PIPE).communicate()[0] for line in output.split(b'\n'): if b'Wacom Hover Click' in line: status = int(line.split(b':')[1].decode("UTF-8").strip()) - if (status == 1): - return(True) - elif (status == 0): - return(False) + if status == 1: + return True + elif status == 0: + return False else: #@todo sollte hier auch irgendeinen return code geben - print("can not get hover-click status of" + self.name) + print("can not get hover-click status of" + self._name) def setHoverClick(self, mode): - Helper.sendSystemCall('xinput', 'set-prop', self.name, 'Wacom Hover Click', mode) \ No newline at end of file + if Helper.sendSystemCall('xinput', 'set-prop', self._name, 'Wacom Hover Click', mode): + pass + else: + print("Error when trying to set Hover click") diff -Nru hinge-0.0.1+bzr7~ubuntu12.04.1/hinge_modules/System.py hinge-0.0.1+bzr9~ubuntu12.04.1/hinge_modules/System.py --- hinge-0.0.1+bzr7~ubuntu12.04.1/hinge_modules/System.py 2014-01-02 18:51:47.000000000 +0000 +++ hinge-0.0.1+bzr9~ubuntu12.04.1/hinge_modules/System.py 2014-01-21 19:35:09.000000000 +0000 @@ -1,21 +1,21 @@ -__author__ = 'Felix Haller' - from subprocess import check_call, Popen, PIPE +import sys, signal from hinge_modules.Eraser import Eraser from hinge_modules.Stylus import Stylus from hinge_modules.Touch import Touch from hinge_modules.XDevice import XDevice +__author__ = 'Felix Haller' + class System(): """ This class handles everything that has to do with the system in general. - Actually it is our "Controller" in a MCV - Concept Model. + Actually it is our "controller" in a MCV - Concept Model. """ - def __init__(self, gui=None): - """4 + """ It's possible to create a System object with or without having a GUI() object. If one is given the Menus will be created depending on which features the System supports and what devices it has. @@ -25,19 +25,25 @@ """ self.display = XDevice() self.devices = [] - self.touchDev = None - self.eraserDev = None - self.stylusDev = None + self._touchDev = None + self._eraserDev = None + self._stylusDev = None self.retrDeviceNames() self.gui = gui if self.gui is not None: self.addMenusToGUI() + + def retrDeviceNames(self): """ Get the details of all connected Wacom Devices by using the "xsetwacom" command. """ - output = Popen(["xsetwacom", "--list", "devices"], stdout=PIPE).communicate()[0] + try: + output = Popen(["xsetwacom", "--list", "devices"], stdout=PIPE).communicate()[0] + except FileNotFoundError: + print("'xsetwacom' command not found.") + sys.exit(-1) devices_raw = output.rstrip().split(b'\n') devices = [] @@ -48,14 +54,15 @@ for entry in devices: if 'STYLUS' in entry[2].decode("utf-8"): - self.stylusDev = Stylus(entry[0].rstrip().decode("UTF-8")) - self.devices.append(self.stylusDev) + self._stylusDev = Stylus(entry[0].rstrip().decode("UTF-8")) + self.devices.append(self._stylusDev) elif 'ERASER' in entry[2].decode("utf-8"): - self.eraserDev = Eraser(entry[0].rstrip().decode("UTF-8")) - self.devices.append(self.eraserDev) + self._eraserDev = Eraser(entry[0].rstrip().decode("UTF-8")) + self.devices.append(self._eraserDev) elif 'TOUCH' in entry[2].decode("utf-8"): - self.touchDev = Touch(entry[0].rstrip().decode("UTF-8")) - self.devices.append(self.touchDev) + self._touchDev = Touch(entry[0].rstrip().decode("UTF-8")) + self.devices.append(self._touchDev) + def rotateDevices(self, menuItem=None, mode=None): """ @@ -73,7 +80,7 @@ :param mode: 0, 1, 2 or 3 for normal, left, inverted or right orientation :type mode: int """ - if mode == None: + if mode is None: #entering automatic mode if self.display.getOrientation() == b'normal': mode = 2 @@ -82,22 +89,23 @@ for device in self.devices: device.rotate(mode) + def addMenusToGUI(self): """ Add rotate entry if there is any device (X, stylus, etc...) however....there should be at least the XDevice. """ - if (len(self.devices) > 0): + if len(self.devices) > 0: self.gui.addMenuEntry(self.gui.menu, "rotate 180°").connect("activate", self.rotateDevices) else: self.gui.setHeaderLabel("Error: no devices found") # if there is a touch device add an menu to en/disable the touch input - if (self.touchDev != None): + if self.hasTouchDev(): self.gui.addMenuEntry(self.gui.menu, "toggle Touch").connect("activate", self.tglFingerTouch) - if (self.stylusDev != None): + if self.hasStylusDev(): self.gui.addMenuEntry(self.gui.menu, "toggle Hover-Click").connect("activate", self.tglHoverClick) @@ -111,15 +119,16 @@ :type mode: str """ - if self.touchDev != None: - if mode == None: - status = self.touchDev.isEnabled() + if self.hasTouchDev(): + if mode is None: + status = self._touchDev.isEnabled() if status: - self.touchDev.turn("off") - elif status == False: - self.touchDev.turn("on") + self._touchDev.turn("off") + else: + self._touchDev.turn("on") else: - self.touchDev.turn(mode) + self._touchDev.turn(mode) + def tglHoverClick(self, menuItem=None, mode:str=None): """ @@ -130,12 +139,24 @@ :param mode: turn it "on" or "off" :type mode: str """ - if self.stylusDev != None: - if mode == None: - status = self.stylusDev.isHover() + if self.hasStylusDev(): + if mode is None: + status = self._stylusDev.isHover() if status: - self.stylusDev.setHoverClick("0") - elif status == False: - self.stylusDev.setHoverClick("1") + self._stylusDev.setHoverClick("0") + elif not status: + self._stylusDev.setHoverClick("1") else: - self.stylusDev.setHoverClick(mode) \ No newline at end of file + self._stylusDev.setHoverClick(mode) + + + def hasStylusDev(self): + return (self._stylusDev is not None) + + + def hasEraserDev(self): + return (self._eraserDev is not None) + + + def hasTouchDev(self): + return (self._touchDev is not None) \ No newline at end of file diff -Nru hinge-0.0.1+bzr7~ubuntu12.04.1/hinge_modules/Touch.py hinge-0.0.1+bzr9~ubuntu12.04.1/hinge_modules/Touch.py --- hinge-0.0.1+bzr7~ubuntu12.04.1/hinge_modules/Touch.py 2014-01-02 18:51:47.000000000 +0000 +++ hinge-0.0.1+bzr9~ubuntu12.04.1/hinge_modules/Touch.py 2014-01-21 19:35:09.000000000 +0000 @@ -1,7 +1,9 @@ +# -*- coding: utf-8 -*- from hinge_modules.WacomDevice import WacomDevice __author__ = 'Felix Haller' + class Touch(WacomDevice): def __init__(self, name: str): WacomDevice.__init__(self, name) \ No newline at end of file diff -Nru hinge-0.0.1+bzr7~ubuntu12.04.1/hinge_modules/WacomDevice.py hinge-0.0.1+bzr9~ubuntu12.04.1/hinge_modules/WacomDevice.py --- hinge-0.0.1+bzr7~ubuntu12.04.1/hinge_modules/WacomDevice.py 2014-01-02 18:51:47.000000000 +0000 +++ hinge-0.0.1+bzr9~ubuntu12.04.1/hinge_modules/WacomDevice.py 2014-01-21 19:35:09.000000000 +0000 @@ -1,18 +1,23 @@ __author__ = 'Felix Haller' from hinge_modules.Helper import * +from subprocess import Popen, PIPE + class WacomDevice: def __init__(self, name: str): - self.name = name - self.rotModes = ["none", "ccw", "half", "cw"] + self._name = name + self._rotModes = ["none", "ccw", "half", "cw"] + + + @property + def name(self): + return self._name - def getDeviceName(self): - return (self.name) def rotate(self, mode:int): - Helper.sendSystemCall('xsetwacom', '--set', self.name, 'rotate', self.rotModes[mode]) + Helper.sendSystemCall('xsetwacom', '--set', self._name, 'rotate', self._rotModes[mode]) def getOrientation(self): """ @@ -21,13 +26,16 @@ pass def turn(self, mode): - Helper.sendSystemCall('xsetwacom', '--set', self.name, 'touch', mode) + Helper.sendSystemCall('xsetwacom', '--set', self._name, 'touch', mode) def isEnabled(self): - status = Popen(["xsetwacom", "--get", self.name, "touch"], stdout=PIPE).communicate()[0].decode("UTF-8").strip() - if (status == "on"): - return(True) - elif (status == "off"): - return(False) + try: + status = Popen(["xsetwacom", "--get", self._name, "touch"], stdout=PIPE).communicate()[0].decode("UTF-8").strip() + except: + print("could not get enabled/disabled status of " + self._name) + return False + + if status == "on": + return True else: - print("can not get enabled/disabled status of" + self.name) \ No newline at end of file + return False \ No newline at end of file diff -Nru hinge-0.0.1+bzr7~ubuntu12.04.1/rotate-script.sh hinge-0.0.1+bzr9~ubuntu12.04.1/rotate-script.sh --- hinge-0.0.1+bzr7~ubuntu12.04.1/rotate-script.sh 2014-01-02 18:51:47.000000000 +0000 +++ hinge-0.0.1+bzr9~ubuntu12.04.1/rotate-script.sh 1970-01-01 00:00:00.000000000 +0000 @@ -1,28 +0,0 @@ -#!/bin/bash - -rotation="$(xrandr -q --verbose | grep 'connected' | egrep -o '\) (normal|left|inverted|right) \(' | egrep -o '(normal|left|inverted|right)')" -stylus="Wacom ISDv4 E6 Pen stylus" -touch="Wacom ISDv4 E6 Finger touch" -eraser="Wacom ISDv4 E6 Pen eraser" - - - -case "$rotation" in - normal) - # rotate 180 - xrandr -o inverted - xsetwacom set "$stylus" rotate HALF - xsetwacom set "$touch" rotate HALF - xsetwacom set "$eraser" rotate HALF - xsetwacom set "$touch" touch off - xinput set-prop "$stylus" "Wacom Hover Click" 1 - ;; - inverted) - # rotate to normal - xrandr -o normal - xsetwacom set "$stylus" rotate none - xsetwacom set "$touch" rotate none - xsetwacom set "$eraser" rotate none - xsetwacom set "$touch" touch on - ;; -esac