Skip to content

Commit

Permalink
Runs with python3 + pyqt5
Browse files Browse the repository at this point in the history
  • Loading branch information
battlesnake authored and helge000 committed Apr 22, 2022
1 parent 98b5237 commit c56ddc8
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 30 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# I've hacked this to run with Python 3 and PyQt5.

I'm not a Python developer, so don't expect the migration to look pretty.

Also fixed a bug in scanning for `Name=` key, which was preventing one of my tablets from being detected.

# wacom-gui

Python/PyQt Wacom GUI for MATE/KDE
Expand Down
2 changes: 1 addition & 1 deletion wacom-gui/hotkeys.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ def __init__(self, devid, blabel, bid, cmd):
self.button = Hotkey(devid, blabel, bid, cmd)
self.layout = QVBoxLayout(self)
self.layout.setAlignment(Qt.AlignLeft)
self.layout.setMargin(0)
# self.layout.setMargin(0)
self.layout.addWidget(self.button.btn)
self.layout.addWidget(self.button.label)
self.setMaximumSize(120, 40)
Expand Down
10 changes: 5 additions & 5 deletions wacom-gui/pad.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def load_dconf(self):
f.close()
os.popen("dconf load /org/mate/desktop/keybindings/ < %s" % config)
except Exception as e:
print e
print(e)

# This doesn't actually 'load' kde, but merely replicates the logic of the
# load_dconf (MATE) path in the KDE path. This code that ensures
Expand All @@ -130,7 +130,7 @@ def _load_keyboard_shortcuts(self):
custom = {}
p = subprocess.Popen("dconf dump /org/mate/desktop/keybindings/", shell=True, stdout=subprocess.PIPE)
p.wait()
output = p.communicate()[0].split('\n')
output = p.communicate()[0].decode('utf-8').split('\n')
for line in output:
if '[custom' in line:
entry = line[1:-1]
Expand Down Expand Up @@ -160,7 +160,7 @@ def init_keys(self, dev_id, image, buttons, cmds):
but_loc = {}
for bid in sorted(buttons.keys()):
but_loc[bid] = buttons[bid]['pos']
for bid, value in sorted(but_loc.iteritems(), key=lambda (k, v): (v, k)):
for bid, value in sorted(but_loc.items(), key=lambda t: (t[1], t[0])):
if cmds.__len__() == 0:
keystroke = "Default"
else:
Expand Down Expand Up @@ -355,14 +355,14 @@ def init(self, dev_id, settings):
text = "%s - %s" % (control, data[fingers][control]['text'])
self.guide.addWidget(GuideWidget(data[fingers][control]['icon'], text))
except Exception as e:
print e
print (e)
group = QGroupBox("Touch Controls")
group.setFixedSize(290, 80)
group.setLayout(touch)
gesture = QGroupBox("Gesture Controls List")
gesture.setLayout(self.guide)
gesture.setContentsMargins(6, 6, 6, 6)
self.layout.setMargin(0)
# self.layout.setMargin(0)
self.layout.addWidget(group, 0, 0, 1, 1, Qt.AlignTop)
self.layout.addWidget(gesture, 0, 1, 5, 1, Qt.AlignVCenter)
self.layout.addWidget(self.taptime, 1, 0, 1, 1, Qt.AlignTop)
Expand Down
2 changes: 1 addition & 1 deletion wacom-gui/pressure.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def mouseMoveEvent(self, event):
def mouseReleaseEvent(self, event):
self.tracking = None
if self.sensor == None:
print "Need device to be set"
print ("Need device to be set")
else:
accuratePts = str((self.points[0][0] - 50)/2) + " " + str(100 - ((self.points[0][1] -50)/2)) + \
" " + str((self.points[1][0] - 50)/2) + " " + str(100 - ((self.points[1][1] -50)/2))
Expand Down
4 changes: 2 additions & 2 deletions wacom-gui/stylus.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ def get_displays(self):
displays = {}
cmd = "xdpyinfo | grep 'dimensions:'"
p = subprocess.Popen(cmd, shell=True, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
output = p.communicate()[0]
output = p.communicate()[0].decode('utf-8')
pattern = r"\s+\S+\s+(\d+)x(\d+)"
full = re.match(pattern, output).groups()
displays['Full'] = {'cmd': "%sx%s+0+0" % (full[0], full[1]),
Expand All @@ -629,7 +629,7 @@ def get_displays(self):
'yoff': 0}
cmd = "xdpyinfo -ext all | grep head"
p = subprocess.Popen(cmd, shell=True, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
output = p.communicate()[0]
output = p.communicate()[0].decode('utf-8')
pattern = r"\s+(\S+)\s+#(\d+):\s+(\d+)x(\d+)\D+(\d+),(\d+)"
heads = re.findall(pattern, output)
for head in heads:
Expand Down
7 changes: 5 additions & 2 deletions wacom-gui/wacom-gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
from pad import Pad, Touch
from stylus import Stylus

def QString(s):
return s

class WacomGui(QMainWindow, wacom_menu.Ui_MainWindow):
buttonClicked = pyqtSignal(int)
def __init__(self, parent=None):
Expand Down Expand Up @@ -197,7 +200,7 @@ def verifyConfigRemove(self):
try:
os.remove(conf_path)
except Exception as e:
print e
print(e)
del self.configs[self.dev][self.config]
self.getConfigs(0)

Expand Down Expand Up @@ -510,7 +513,7 @@ def addButton(self, label, wid=0, dev=0, dev_id=0, icon=None, isize=48, hide=Fal
self.buttons[(idx, 1)] = dev
self.buttons[(idx, 2)] = wid
self.buttons[(idx, 3)] = dev_id
self.buttons[(idx, 0)].clicked[()].connect(self.buttonMapper.map)
self.buttons[(idx, 0)].clicked.connect(self.buttonMapper.map)
if label.split("Wacom ").__len__() == 2:
self.buttons[(idx, 0)].setText(QString(label[6:]))
else:
Expand Down
29 changes: 10 additions & 19 deletions wacom-gui/wacom_data.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/python3
# -*- coding: utf-8 -*-

############################################
Expand All @@ -20,6 +20,7 @@
import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *


class Tablets:
Expand All @@ -36,7 +37,7 @@ def __init__(self):
def get_connected_tablets(self):
# check if tablet is actually detected
p = subprocess.Popen("xsetwacom --list devices", shell=True, stdout=subprocess.PIPE)
dev_names = p.communicate()[0].split('\n')
dev_names = p.communicate()[0].decode('utf-8').split('\n')
# all devices must have a pad, use this as unique identifier
detected = {}
attr = {'type: TOUCH': 'touch',
Expand All @@ -46,8 +47,6 @@ def get_connected_tablets(self):
'type: PAD': 'pad'}
try:
for dev in dev_names:
if dev == '':
break
dev_attr = dev.rstrip().split("\t")
name = dev.rsplit(' %s' % attr[dev_attr[2]], 1)[0]
if name[-3:] in ["Pen", "Pad"]:
Expand All @@ -64,7 +63,7 @@ def get_connected_tablets(self):
pass
self.__get_libwacom_data()
self.tablets = {}
for device, inputs in detected.iteritems():
for device, inputs in detected.items():
if device[-4:] == '(WL)':
dev_type = device[:-5]
else:
Expand All @@ -83,14 +82,11 @@ def get_connected_tablets(self):
if dev_type.startswith('Wacom Intuos Pro') :
if dev_type not in self.device_data.keys():
dev_type = dev_type.replace("Pro", "Pro 2")
# One Wacom hack
if dev_type == 'Wacom One by Wacom S':
dev_type = 'One by Wacom (small)'
devID = self.device_data[dev_type]['devID']
if self.device_data[dev_type]['devID'] not in self.tablets.keys():
self.tablets[devID] = []
# assume if it's the same device it has the same inputs for all connected
if 'pad' in detected[device]:
if 'pad' in detected[device] :
dev_count = detected[device]['pad']['id'].__len__()
else :
dev_count = 1
Expand Down Expand Up @@ -119,7 +115,7 @@ def get_connected_tablets(self):
def __get_libwacom_data(self):
p = subprocess.Popen("libwacom-list-local-devices --database %s" % self.db_path, shell=True,
stdout=subprocess.PIPE)
output = p.communicate()[0].split('\n')
output = p.communicate()[0].decode('utf-8').split('\n')
cur_device = None
buttons = False
for line in output:
Expand Down Expand Up @@ -261,9 +257,7 @@ def pretty_svg(self, device):
svg = '%s\n\t\t<path' % svg
# get attr
for attr in elem.attrib:
#TODO: this fix path problem?
if not attr.startswith("{"):
svg = "%s\n\t\t\t%s=\"%s\"" % (svg, attr, elem.attrib[attr])
svg = "%s\n\t\t\t%s=\"%s\"" % (svg, attr, elem.attrib[attr])
svg = "%s\n\t\t\tfill=\"none\" />" % svg
if elem.attrib['id'] in self.device_data[device]['pad']['buttons'].keys():
but_info = self.device_data[device]['pad']['buttons'][elem.attrib['id']]
Expand Down Expand Up @@ -346,9 +340,9 @@ def pretty_svg(self, device):
if True:
# if not os.path.isfile("/tmp/%s" % self.device_data[device]['svg']):
# shift every line to eliminate extra vertical whitespace...
svg_write = ''
yshift = ymin - 20
if yshift > 0:
svg_write = ''
for line in svg.split('\n'):
if 'sodipodi' in line:
line = "sodipodi:%s" % line.split('}')[1]
Expand All @@ -373,8 +367,7 @@ def pretty_svg(self, device):
svg_write = "%s\n%s" % (svg_write, d)
else:
svg_write = "%s\n%s" % (svg_write, line)
if svg_write != '':
svg = svg_write
svg = svg_write
# shift x values if it is too wide
if xmax >= 500:
xshift = 300 # shift over by 200 units in the x coord
Expand Down Expand Up @@ -425,8 +418,6 @@ def pretty_svg(self, device):
fill="#111111"/>
</g>%s""" % (xmax - 290, (ymax -yshift) + 20, xmax - 290, (ymax -yshift) + 20, svg_write)
else:
if not svg.strip().startswith("<g>"):
svg = "<g>%s" % svg
svg = """<svg
style="color:#000000;stroke:#7f7f7f;fill:#222222;stroke-width:.5;font-size:8"
width="%s"
Expand All @@ -441,7 +432,7 @@ def pretty_svg(self, device):
height="%s"
stroke="none"
fill="#111111"/>
</g>%s""" % (xmax + 50, (ymax - yshift) + 20, xmax + 50, (ymax - yshift) + 20, svg)
</g>%s""" % (xmax + 50, (ymax - yshift) + 20, xmax + 50, (ymax - yshift) + 20, svg_write)
f = open("/tmp/%s" % self.device_data[device]['svg'], "w")
f.write(svg)
f.close()
Expand Down

0 comments on commit c56ddc8

Please sign in to comment.