Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:inirudebwoy
synapticsconfig
SynapticsConfig.py
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File SynapticsConfig.py of Package synapticsconfig
#!/usr/bin/env python # -*- coding: utf-8 -*- #SynapticsConfig ver.0.1.5 """ Copyright 2009 Michal Klich This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. You may contact author of this software by email michal@michalklich.com """ import sys, os, subprocess from functools import partial from PyQt4.QtCore import * from PyQt4.QtGui import * from main_window_ui import Ui_MainWindow from dialogs import FileExistsDlg from dialogs import FileCreatedDlg from dialogs import RestartHald # class of global variables necessery for multilanguage as well as creating config text # This had to be created this way because of access issues to some global variables when they were declared # with no class at all. I guess this is the right way to do this class GlobalVariables: """Class that holds Global Variables. option_list = list of available strings added to config file file_start = few starting lines for 10-synaptics.fdi file file_end = few ending lines config_string = list that holds all options checked by user """ def __init__(self): self.config_string = [] #list that holds all options checked by user, for global usage # dictionary with list of available options, for future releases this can be extended self.option_list = {"OneFingerTappingCheckBox" : "<merge key=\"input.x11_options.TapButton1\" type=\"string\">1</merge>" , "TwoFingersTappingCheckBox" : "<merge key=\"input.x11_options.TapButton2\" type=\"string\">3</merge>" , "ThreeFingersTappingCheckBox" : "<merge key=\"input.x11_options.TapButton3\" type=\"string\">2</merge>" , "HorizontalScrollingCheckBox" : "<merge key=\"input.x11_options.HorizEdgeScroll\" type=\"string\">True</merge>" , "VerticalScrollingCheckBox" : "<merge key=\"input.x11_options.VertEdgeScroll\" type=\"string\">True</merge>" , "TwoFingersHorizontalScrollingCheckBox" : "<merge key=\"input.x11_options.HorizTwoFingerScroll\" type=\"string\">True</merge>" , "TwoFingersVerticalScrollingCheckBox" : "<merge key=\"input.x11_options.VertTwoFingerScroll\" type=\"string\">True</merge>" , "Touchpad0" : "<merge key=\"input.x11_options.TouchpadOff\" type=\"string\">0</merge>" , "Touchpad1" : "<merge key=\"input.x11_options.TouchpadOff\" type=\"string\">1</merge>" , "Touchpad2" : "<merge key=\"input.x11_options.TouchpadOff\" type=\"string\">2</merge>" , "LockedDragsCheckBox" : "<merge key=\"input.x11_options.LockedDrags\" type=\"string\">True</merge>" , "LockedDragTimeout" : "<merge key=\"input.x11_options.LockedDragTimeout\" type=\"string\">%d</merge>", "LeftEdge" : "<merge key=\"input.x11_options.LeftEdge\" type=\"string\">%d</merge>", "RightEdge" : "<merge key=\"input.x11_options.RightEdge\" type=\"string\">%d</merge>", "TopEdge" : "<merge key=\"input.x11_options.TopEdge\" type=\"string\">%d</merge>", "BottomEdge" : "<merge key=\"input.x11_options.BottomEdge\" type=\"string\">%d</merge>", "FingerLow" : "<merge key=\"input.x11_options.FingerLow\" type=\"string\">%d</merge>", "FingerHigh" : "<merge key=\"input.x11_options.FingerHigh\" type=\"string\">%d</merge>", "FingerPress" : "<merge key=\"input.x11_options.FingerPress\" type=\"string\">%d</merge>", "MaxTapTime" : "<merge key=\"input.x11_options.MaxTapTime\" type=\"string\">%d</merge>", "BMaxTapMove" : "<merge key=\"input.x11_options.BMaxTapMove\" type=\"string\">%d</merge>", "MaxDoubleTapTime" : "<merge key=\"input.x11_options.MaxDoubleTapTime\" type=\"string\">%d</merge>", "ClickTime" : "<merge key=\"input.x11_options.ClickTime\" type=\"string\">%d</merge>"} #list of available options, for global usage # Next two strings are for creating full 10-synaptics.fdi file as they enclose beggining and end of file self.file_start = """<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> <!-- File created with SynapticsConfig, website: http://www.michalklich.com --> <!-- DO NOT EDIT THIS FILE IN PLACE. This file will be overwritten with the next update. If you need to add custom options, copy the file into /etc/hal/fdi/policy/ first. See https://fedoraproject.org/wiki/Input_device_configuration --> <deviceinfo version=\"0.2\"> <device> <match key=\"info.capabilities\" contains=\"input.touchpad\"> \t""" #First lines of 10-synaptics.fdi file self.file_end = """ </match> </device> </deviceinfo> """ #End of 10-synaptics.fdi file class MyForm(QMainWindow): def __init__(self, parent=None): # declaration of Global Variables class global GL GL = GlobalVariables() QWidget.__init__(self, parent) self.ui = Ui_MainWindow() self.ui.setupUi(self) normalPath = os.path.abspath("10-synaptics.fdi") installPath = "/etc/hal/fdi/policy/10-synaptics.fdi" # connecting signals QObject.connect(self.ui.OneFingerTappingCheckBox, SIGNAL("stateChanged(int)"), self.CheckBoxChange) QObject.connect(self.ui.TwoFingersTappingCheckBox, SIGNAL("stateChanged(int)"), self.CheckBoxChange) QObject.connect(self.ui.ThreeFingersTappingCheckBox, SIGNAL("stateChanged(int)"), self.CheckBoxChange) QObject.connect(self.ui.HorizontalScrollingCheckBox, SIGNAL("stateChanged(int)"), self.CheckBoxChange) QObject.connect(self.ui.VerticalScrollingCheckBox, SIGNAL("stateChanged(int)"), self.CheckBoxChange) QObject.connect(self.ui.TwoFingersHorizontalScrollingCheckBox, SIGNAL("stateChanged(int)"), self.CheckBoxChange) QObject.connect(self.ui.TwoFingersVerticalScrollingCheckBox, SIGNAL("stateChanged(int)"), self.CheckBoxChange) QObject.connect(self.ui.CreateFileButton, SIGNAL("clicked()"), partial(self.CreateFile, normalPath)) QObject.connect(self.ui.TouchpadOffCheckBox, SIGNAL("stateChanged(int)"), self.TouchpadOffChkBxChange) QObject.connect(self.ui.actionAbout_SynapticsConfig, SIGNAL("activated()"), self.ShowAboutBox) QObject.connect(self.ui.LockedDragsCheckBox, SIGNAL("stateChanged(int)"), self.LockedDragsChkBxChange) QObject.connect(self.ui.LockedDragTimeoutSpinBox, SIGNAL("valueChanged(int)"), self.SpinBoxChange) QObject.connect(self.ui.installPushButton, SIGNAL("clicked()"), partial(self.CreateFile, installPath)) QObject.connect(self.ui.restartHaldPushButton, SIGNAL("clicked()"), self.RestartHald) QObject.connect(self.ui.LeftEdgeSpinBox, SIGNAL("valueChanged(int)"), self.SpinBoxChange) QObject.connect(self.ui.RightEdgeSpinBox, SIGNAL("valueChanged(int)"), self.SpinBoxChange) QObject.connect(self.ui.TopEdgeSpinBox, SIGNAL("valueChanged(int)"), self.SpinBoxChange) QObject.connect(self.ui.BottomEdgeSpinBox, SIGNAL("valueChanged(int)"), self.SpinBoxChange) QObject.connect(self.ui.FingerLowSpinBox, SIGNAL("valueChanged(int)"), self.SpinBoxChange) QObject.connect(self.ui.FingerHighSpinBox, SIGNAL("valueChanged(int)"), self.SpinBoxChange) QObject.connect(self.ui.FingerPressSpinBox, SIGNAL("valueChanged(int)"), self.SpinBoxChange) QObject.connect(self.ui.MaxTapTimeSpinBox, SIGNAL("valueChanged(int)"), self.SpinBoxChange) QObject.connect(self.ui.BMaxTapMoveSpinBox, SIGNAL("valueChanged(int)"), self.SpinBoxChange) QObject.connect(self.ui.MaxDoubleTapTimeSpinBox, SIGNAL("valueChanged(int)"), self.SpinBoxChange) QObject.connect(self.ui.ClickTimeSpinBox, SIGNAL("valueChanged(int)"), self.SpinBoxChange) # checking prvileges and disabling buttons if os.geteuid() == 0: self.ui.installPushButton.setEnabled(True) self.ui.restartHaldPushButton.setEnabled(True) else: self.ui.installPushButton.setEnabled(False) self.ui.installPushButton.setToolTip(QApplication.translate("MainWindow", "Button disabled, please run SynapticsConfig as root.", None, QApplication.UnicodeUTF8)) self.ui.restartHaldPushButton.setEnabled(False) self.ui.restartHaldPushButton.setToolTip(QApplication.translate("MainWindow", "Button disabled, please run SynapticsConfig as root.", None, QApplication.UnicodeUTF8)) def CheckBoxChange(self, checkBoxStatus): """ Function takes signal emitted by simple two-state checkbox find in form and adds respective value to config file """ global GL senderObject = self.sender().objectName() # name of object that emitted signal is assigned to senderObject # simple checking if checkbox is checked or not. For some reason after creating this function checkboxes # states are 2 or 0 not True or False. Dunno. if checkBoxStatus == 2: MyForm.InsertKey(self, GL.option_list[str(senderObject)]) # senderObject had to be converted with str() because of unicode else: MyForm.RemoveKey(self, GL.option_list[str(senderObject)]) def InsertKey(self, stringConfig): """Inserts key to config_string without checking if such key exists""" GL.config_string.append(stringConfig) MyForm.FillLabel(self, GL.config_string) def RemoveKey(self, stringConfig): """Removes desired config line from config_string and updates label with FillLabel function""" #Did that with try and except as it is tristate checkbox and RemoveKey function tries to remove #keys that does not exist global GL try: GL.config_string.remove(stringConfig) MyForm.FillLabel(self, GL.config_string) #Deeeerty trick except: pass def FillLabel(self, list): """ Fills label in form with config_string list """ global GL self.ui.fileView.setText(GL.file_start + "\n\t".join(list) + GL.file_end) # join with addition of new line and tabulator def TouchpadOffChkBxChange(self, checkBoxState): """Function run when checkbox TouchpadOff is changed, if signal stateChanged is triggered. This checkbox has three states""" global GL if checkBoxState == 0: MyForm.InsertKey(self, GL.option_list["Touchpad0"]) MyForm.RemoveKey(self, GL.option_list["Touchpad1"]) MyForm.RemoveKey(self, GL.option_list["Touchpad2"]) self.ui.TouchpadOffLabel.setText(self.tr("Touchpad is on")) self.ui.tabWidget.setEnabled(True) elif checkBoxState == 1: MyForm.InsertKey(self, GL.option_list["Touchpad1"]) MyForm.RemoveKey(self, GL.option_list["Touchpad0"]) MyForm.RemoveKey(self, GL.option_list["Touchpad2"]) self.ui.TouchpadOffLabel.setText(self.tr("Touchpad is off")) self.ui.tabWidget.setEnabled(False) elif checkBoxState == 2: MyForm.InsertKey(self, GL.option_list["Touchpad2"]) MyForm.RemoveKey(self, GL.option_list["Touchpad0"]) MyForm.RemoveKey(self, GL.option_list["Touchpad1"]) self.ui.TouchpadOffLabel.setText(self.tr("Only tapping and scrolling are off")) self.ui.tabWidget.setEnabled(False) def LockedDragsChkBxChange(self, checkBoxState): """Function run when checkbox LockedDrags is changed, if signal stateChanged is triggered. This checkbox enables or disables LockedDragsTimeoutSpinBox. It also removes when disabled config line added by spinbox""" global GL if checkBoxState == 2: MyForm.InsertKey(self, GL.option_list["LockedDragsCheckBox"]) # Manual insert of option_list for LockedDragTimeout as it has to get value of spinbox # I know that it does not look promising but it works :) GL.config_string.append(GL.option_list["LockedDragTimeout"] % self.ui.LockedDragTimeoutSpinBox.value()) MyForm.FillLabel(self, GL.config_string) self.ui.LockedDragTimeoutSpinBox.setEnabled(True) else: self.ui.LockedDragTimeoutSpinBox.setEnabled(False) MyForm.RemoveKey(self, GL.option_list["LockedDragsCheckBox"]) # Very nasty removing of line with LockedDragTimeout. Had to be this way as it has 10000 different states as # spinbox has max limit 10000. This needs to be corrected somehow! for line in GL.config_string: if "LockedDragTimeout" in line: GL.config_string.pop(GL.config_string.index(line)) MyForm.FillLabel(self, GL.config_string) def SpinBoxChange(self, spinBoxValue): global GL # Searching in config_string for occurence of line with LockedDragTimeout # sender is holding name of spinbox that sent signal # index is holding information if option for selected spinbox already # exists inside of config_string. Value -1 means that there is no such option selected. sender = self.sender().objectName().remove("SpinBox", Qt.CaseInsensitive) index = -1 for line in GL.config_string: if str(sender) in line: index = GL.config_string.index(line) GL.config_string[index] = GL.option_list[str(sender)] % spinBoxValue MyForm.FillLabel(self, GL.config_string) # This means that option needs to ba added to conifg_string if index == -1: MyForm.InsertKey(self, (GL.option_list[str(sender)] % spinBoxValue)) # when spinbox is set to 0 it removes option from config_string if spinBoxValue == 0: MyForm.RemoveKey(self, GL.option_list[str(sender)] % spinBoxValue) def RestartHald(self): """ Function that deals with restarting haldaemon. It opens dialog RestartHald as this action requires confirmation. """ dialog = RestartHald(self) if dialog.exec_(): command = "/sbin/service haldaemon restart" proc = subprocess.Popen(command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE) output = proc.stdout.readline() proc.communicate() else: return def CreateFile(self, path): """Function that creates file from selected options and prompts out messagebox if file is created or if it is not""" global GL try: #TODO #add check if file is empty and block tries of saving empty file filetext = GL.file_start + "\n\t".join(GL.config_string) + GL.file_end #variable that holds whole file that needs to be saved if os.path.exists(path): dialog = FileExistsDlg(path ,self) if dialog.exec_(): options_file = open(path, 'w') options_file.write(filetext) options_file.close() fileCreated = FileCreatedDlg(path, filetext, self) fileCreated.exec_() else: return else: options_file = open(path, 'w') options_file.write(filetext) options_file.close() fileCreated = FileCreatedDlg(path, filetext, self) fileCreated.exec_() except IOError: # qmessagebox for IOError box = QMessageBox(self) box.setWindowTitle(self.tr("Error IO")) box.setText(self.tr("File not found.")) box.exec_() except BaseException, e: # unhandled exception qmessagebox box = QMessageBox(self) box.setWindowTitle(self.tr("Unhandled exception")) #box.setText(self.tr("File has not been created. Unhandled exception occured.")) box.setText(unicode(e)) box.exec_() def ShowAboutBox(self): """about SynapticsConfig Author, used languages, software license and shit """ box = QMessageBox.about(self, self.tr("About SynapticsConfig"), self.tr("SynapticsConfig was created using Python and PyQT4. \nSoftware is distributed under GPLv3 license \nCopyright 2009 Michal Klich \n\nHome website of software is www.michalklich.com\synapticsconfig.") ) if __name__ == "__main__": app = QApplication(sys.argv) # Translation loading, locale returns locale setting from OS, which is pl_PL for polish, en_US for american english etc. locale = QLocale.system().name() appTranslator = QTranslator() if appTranslator.load("/usr/share/SynapticsConfig_" + locale): app.installTranslator(appTranslator) myapp = MyForm() myapp.show() sys.exit(app.exec_())
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor