forked from wenhsinjen/ptxconf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathptxconf.py
executable file
·177 lines (150 loc) · 6.97 KB
/
ptxconf.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#! /usr/bin/python
import ptxconftools
from ptxconftools import ConfController
from ptxconftools.gtk import MonitorSelector
import pygtk
import appindicator
pygtk.require('2.0')
import gtk
import os
iconpath = os.path.dirname( ptxconftools.__file__ )+"/iconStyle03_256.png"
class PTXConfUI():
def __init__(self):
# create systray interface
self.systray = appindicator.Indicator( "testname", iconpath, appindicator.CATEGORY_APPLICATION_STATUS)
self.systray.set_status(appindicator.STATUS_ACTIVE)
# construct menu
menu = gtk.Menu()
mitem = gtk.MenuItem("configure")
menu.append(mitem)
mitem.connect("activate", self.createConfigWindow)
mitem.show()
mitem = gtk.MenuItem("exit")
menu.append(mitem)
mitem.connect("activate", self.exit_program)
mitem.show()
# attach menu to out system tray
self.systray.set_menu(menu)
# instantiate confcontroller
self.myConf = ConfController()
# def resetAllConfig(self, callback_data=None):
# self.myConf.resetAllDeviceConfig()
def getActiveInput(self):
a = self.window.ptDropdown.get_active_text()
b = self.window.ptDropdown.get_active()
if b > 0:
return a
def getSelectedMonitor(self, callback_data=None):
a = self.window.monitorDropdown.get_active_text()
b = self.window.monitorDropdown.get_active()
if b > 0:
return a
def mapTabletToMonitor(self, callback_data=None):
# find ids for the right input device
pen = self.getActiveInput()
# get the display width, screen_width and screen_offset for CTMGenerator function to calculate matrix
monitor = self.getSelectedMonitor()
# call API with these settings
self.myConf.setPT2Monitor(pen, monitor)
def exit_program(self, callback_data=None):
# This function kills the program PTXConf.
# Can be called from 2 places, 1 from the appindicator dropdown menu "Exit",
# another from the config popup window "Exit" button.
gtk.main_quit()
def createConfigWindow(self, callback_data=None):
# first refress all monitor and touch/pen information
self.myConf.refresh()
# This creats a popup window for more detailed configuration if user find necessary.
# Still incomplete at the moment.
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.set_position(gtk.WIN_POS_CENTER)
self.window.set_border_width(20)
self.window.set_title("PTXConf")
self.window.connect("destroy", self.destroyConfigWindow)
button_apply = gtk.Button("Apply")
button_close = gtk.Button("Close")
button_close.connect("clicked", self.destroyConfigWindow)
vbox = gtk.VBox(spacing=20)
hbox = gtk.HBox(spacing=20)
vboxLeft = gtk.VBox(spacing=6)
vboxRight = gtk.VBox(spacing=6)
hboxForButtons = gtk.HBox()
hboxForButtonsLeft = gtk.HBox(spacing=30)
hboxForButtonsRight = gtk.HBox(spacing=10)
labelEmptySpace01 = gtk.Label()
labelEmptySpace02 = gtk.Label()
label01 = gtk.Label("pointer device")
label02 = gtk.Label("monitor")
# create monitor selector widget
monSelector = MonitorSelector(self.myConf.monitorIds)
# dropdown menus 1 and 2, users choose what input device map to what monitor.
# creat and set up dopdownmenu 1: user select from a list of connected pen input deivces.
ptDropdown = gtk.combo_box_new_text()
ptDropdown.set_tooltip_text("choose an input device to configure")
# getting the list of names of the input device
# set up the dropdown selection for input devices
ptDropdown.append_text('Select input device:')
for i in self.myConf.penTouchIds:
ptDropdown.append_text(i)
ptDropdown.set_active(0)
# ptDropdown.connect("changed", self.getActiveInput)
# creat and set up dopdownmenu 2: user select from a list of connected display/output deivces.
monitorDropdown = gtk.combo_box_new_text()
monitorDropdown.set_tooltip_text("choose a monitor to map the input to")
# getting the list of display names
# set up the dropdown selection for monitors
monitorDropdown.append_text('Select a monitor:')
monitorDropdown.mons = self.myConf.monitorIds.keys()
for key in monitorDropdown.mons:
monitorDropdown.append_text(key)
monitorDropdown.set_active(0)
monitorDropdown.handler_id_changed = monitorDropdown.connect("changed", self.monDropdownCallback)
# connect apply button to function
button_apply.connect("clicked", self.mapTabletToMonitor)
# inserting all widgets in place
vboxLeft.pack_start(label01)
vboxLeft.pack_start(label02)
vboxRight.pack_start(ptDropdown)
vboxRight.pack_start(monitorDropdown)
hboxForButtonsLeft.pack_start(button_apply)
hboxForButtonsLeft.pack_start(labelEmptySpace01)
hboxForButtonsRight.pack_start(labelEmptySpace02)
hboxForButtonsRight.pack_start(button_close)
hboxForButtons.pack_start(hboxForButtonsLeft)
hboxForButtons.pack_start(hboxForButtonsRight)
vbox.pack_start(monSelector, expand=False)
hbox.pack_start(vboxLeft)
hbox.pack_start(vboxRight)
vbox.pack_start(hbox)
vbox.pack_start(hboxForButtons)
self.window.add(vbox)
self.window.show_all()
# store convenient handle to drop down boxes
self.window.monitorSelector = monSelector
self.window.monitorSelector.connect('button-press-event', self.monSelectorCallback)
self.window.ptDropdown = ptDropdown
self.window.monitorDropdown = monitorDropdown
def monDropdownCallback(self, calback_data=None):
# update MonitorSelector
mon = self.window.monitorDropdown.get_active_text()
if mon in self.window.monitorSelector.moninfo:
self.window.monitorSelector.set_active_mon(mon)
def monSelectorCallback(self, widget, event):
# get mon selector selection
monSelection = self.window.monitorSelector.get_active_mon()
# if different than drop down, update drop down
if monSelection != self.window.monitorDropdown.get_active_text():
# lookup this monitor index in drop down and set it...
idx = self.window.monitorDropdown.mons.index(monSelection)
# careful to disable dropdown changed callback while doing this
hid = self.window.monitorDropdown.handler_id_changed
self.window.monitorDropdown.handler_block(hid)
self.window.monitorDropdown.set_active(idx+1)
self.window.monitorDropdown.handler_unblock(hid)
def destroyConfigWindow(self, callback_data=None):
# close the popup window, app will still be docked on top menu bar.
self.window.destroy()
def main(self):
gtk.main()
p = PTXConfUI()
p.main()