Skip to content

Commit f513dde

Browse files
authored
Add files via upload
1 parent 77d31e3 commit f513dde

File tree

2 files changed

+100
-23
lines changed

2 files changed

+100
-23
lines changed

wacom-gui/pad.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,13 @@ def boxdelete(self, box):
5353
def load_dconf(self):
5454
with open(os.path.join(self.cwd, 'custom.json'), 'r') as f:
5555
hotkeys = json.load(f)
56-
with open(os.path.expanduser("~/.wacom-gui/custom.json"), 'r') as f:
57-
custom = json.load(f)
58-
for key in hotkeys.keys():
59-
if key in custom.keys():
60-
del custom[key]
61-
hotkeys.update(custom)
56+
if os.path.exists(os.path.expanduser("~/.wacom-gui/custom.json")):
57+
with open(os.path.expanduser("~/.wacom-gui/custom.json"), 'r') as f:
58+
custom = json.load(f)
59+
for key in hotkeys.keys():
60+
if key in custom.keys():
61+
del custom[key]
62+
hotkeys.update(custom)
6263
os_custom = self._load_keyboard_shortcuts()
6364
for key, data in hotkeys.items():
6465
if data['dconf'] != '':

wacom-gui/wacom-gui.py

+93-17
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import os
88
from os.path import expanduser
99
import json
10+
import subprocess
11+
import re
1012
import argparse
1113
from wacom_data import Tablets
1214
import wacom_menu
@@ -235,12 +237,12 @@ def getConfigs(self, idx):
235237
with open("%s/device_default" % conf_path, 'r') as f:
236238
device = json.load(f)
237239
# config file exists, use it
238-
if str(dev_id) in device.keys() and device[str(dev_id)] in self.configs[dev].keys():
239-
self.config = device[str(dev_id)]
240+
if str(dev_id) in device.keys() and device[str(dev_id)]['config'] in self.configs[dev].keys():
241+
self.config = device[str(dev_id)]['config']
240242
# set defaults in tablet_data, if it's detected
241243
for idx in device.keys():
242244
try:
243-
self.tablet_data.tablets[self.dev][int(idx)]['config'] = device[idx]
245+
self.tablet_data.tablets[self.dev][int(idx)]['config'] = device[idx]['config']
244246
except Exception as e:
245247
pass
246248
self.configLayout.addButton(
@@ -407,9 +409,18 @@ def updateConfigs(self):
407409
if self.dev is not None:
408410
for idx, tablet in enumerate(self.tablet_data.tablets[self.dev]):
409411
if 'config' in tablet.keys():
410-
default[idx] = tablet['config']
412+
# check if toggle enabled
413+
toggle = 0
414+
if 'pad' in self.configs[self.dev][tablet['config']]:
415+
for button in self.configs[self.dev][tablet['config']]['pad']['buttons'].keys():
416+
if self.configs[self.dev][tablet['config']]['pad']['buttons'][button] == 'lhyper z':
417+
toggle = 1
418+
break
419+
default[idx] = {'config': tablet['config'],
420+
'toggle': toggle}
411421
else:
412-
default[idx] = 'default'
422+
default[idx] = {'config': 'default',
423+
'toggle': 0}
413424
conf_path = os.path.join("%s/.wacom-gui" % expanduser("~"), self.dev)
414425
conf_file = os.path.join(conf_path, 'device_default')
415426
with open(conf_file, 'w') as outfile:
@@ -422,15 +433,6 @@ def quickLoad(self):
422433
self.tabletSelect(idx)
423434
sys.exit()
424435

425-
def toggleDisplay(self):
426-
self.toggle = True
427-
for idx, button in enumerate(self.tabletButtons.btn_grp.buttons()):
428-
self.tabletSelect(idx)
429-
if self.pad.is_toggle():
430-
self.stylus.mapping.toggle_next()
431-
self.updateConfigs()
432-
sys.exit()
433-
434436
def closeEvent(self, event):
435437
self.updateConfigs()
436438
event.accept()
@@ -648,15 +650,89 @@ def loadToggleShortcut():
648650
os.popen("setxkbmap -option '" + keys + "'")
649651

650652

653+
def toggleDisplay():
654+
# get tablets
655+
tablet_data = Tablets()
656+
# get displays
657+
displays = {}
658+
cmd = "xdpyinfo | grep 'dimensions:'"
659+
p = subprocess.Popen(cmd, shell=True, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
660+
output = p.communicate()[0]
661+
pattern = r"\s+\S+\s+(\d+)x(\d+)"
662+
full = re.match(pattern, output).groups()
663+
displays['Full'] = {'cmd': "%sx%s+0+0" % (full[0], full[1]),
664+
'x': full[0],
665+
'y': full[1],
666+
'xoff': 0,
667+
'yoff': 0}
668+
cmd = "xdpyinfo -ext all | grep head"
669+
p = subprocess.Popen(cmd, shell=True, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
670+
output = p.communicate()[0]
671+
pattern = r"\s+(\S+)\s+#(\d+):\s+(\d+)x(\d+)\D+(\d+),(\d+)"
672+
heads = re.findall(pattern, output)
673+
for head in heads:
674+
info = list(head)
675+
displays['%s-%s' % (info[0].upper(), info[1])] = {'cmd': '%sx%s+%s+%s' %
676+
(info[2], info[3], info[4], info[5]),
677+
'x': int(info[2]),
678+
'y': int(info[3]),
679+
'xoff': int(info[4]),
680+
'yoff': int(info[5])}
681+
displays['Partial...'] = {'cmd': "%sx%s+0+0" % (full[0], full[1]),
682+
'x': full[0],
683+
'y': full[1],
684+
'xoff': 0,
685+
'yoff': 0}
686+
for dev in tablet_data.tablets.keys():
687+
path = os.path.join(expanduser("~"), ".wacom-gui/%s" % dev)
688+
config_name = None
689+
if os.path.exists(os.path.join(path, 'device_default')):
690+
with open(os.path.join(path, 'device_default'), 'r') as f:
691+
config_name = json.load(f)
692+
if config_name is not None:
693+
for dev_id, data in enumerate(tablet_data.tablets[dev]):
694+
if config_name[str(dev_id)]['toggle'] == 1:
695+
if os.path.exists(os.path.join(path, "%s.json" % config_name[str(dev_id)]['config'])):
696+
with open(os.path.join(path, "%s.json" % config_name[str(dev_id)]['config']), 'r') as f:
697+
config = json.load(f)
698+
if 'mapping' in config['stylus'].keys():
699+
if 'maptooutput' in config['stylus']['mapping'].keys():
700+
cur_display = config['stylus']['mapping']['maptooutput']
701+
disp_list = sorted(displays.keys())
702+
idx = disp_list.index(cur_display)
703+
if idx + 1 <= displays.keys().__len__():
704+
idx = idx + 1
705+
if displays[disp_list[idx]]['cmd'] == displays[disp_list[0]]['cmd']:
706+
idx = 0
707+
else:
708+
idx = 0
709+
# update config
710+
config['stylus']['mapping']['maptooutput'] = disp_list[idx]
711+
conf_file = os.path.join(path, "%s.json" % config_name[str(dev_id)]['config'])
712+
if os.path.exists(conf_file):
713+
os.rename(conf_file, "%s.bak" % conf_file)
714+
with open(conf_file, 'w') as outfile:
715+
json.dump(config, outfile, sort_keys=True,
716+
indent=4, separators=(',', ': '))
717+
# update mapping
718+
sid = tablet_data.tablets[dev][dev_id]['stylus']['id']
719+
eid = tablet_data.tablets[dev][dev_id]['eraser']['id']
720+
coords = displays[disp_list[idx]]['cmd']
721+
cmd = "xsetwacom --set %s maptooutput %s" % (sid, coords)
722+
os.popen(cmd)
723+
cmd = "xsetwacom --set %s maptooutput %s" % (eid, coords)
724+
os.popen(cmd)
725+
sys.exit()
726+
651727
def main():
652728
loadToggleShortcut()
653729
app = QApplication(sys.argv)
654-
form = WacomGui()
655730
opts = parseArgs()
731+
if opts.toggle:
732+
toggleDisplay()
733+
form = WacomGui()
656734
if opts.load:
657735
form.quickLoad()
658-
if opts.toggle:
659-
form.toggleDisplay()
660736
form.show()
661737
sys.exit(app.exec_())
662738

0 commit comments

Comments
 (0)