User Controls
Toucher - My First Python Program/For Laptops With Touchscreens(Linux)
-
2017-03-12 at 3:32 AM UTCHere is a little program I made that consists of 33 lines of code. It requires Python and some commonly available Python modules. The program allows a person to easily turn off their touchpad so that it will not get in the way while typing. I really needed it for my Surface Pro 3 because every time I was typing in the code, my god damn fucking hands would hit that little mother fucking pad, PLACING THE GOD DAMN FUCKING CURSOR SOMEWHERE ELSE AND FUCKING PISSING ME OFF GOD DAMN IT!!! So it basically lets a person easily turn it on and off with a quick click and selection.
In order to use, you type 'xinput list' and then find the name of your devices touchpad input. Then you replace the part in the code below that says "My-Laptops-Touch-Pad-Id" with your devices identification.
On Ubuntu, you can type "Startup Applications" into the Dash and add this as a startup application(you'll have to place "python " before the location of the .py file in the 'Command' field).
Here she is...
#!/usr/bin/env
import os, gtk, appindicator, subprocess, StringIO
def main():
indicator = appindicator.Indicator("Toucher", '/home/me/py/toucher.png', appindicator.CATEGORY_APPLICATION_STATUS)
indicator.set_status(appindicator.STATUS_ACTIVE)
indicator.set_menu(build_menu())
gtk.main()
def build_menu():
menu = gtk.Menu()
onItem = gtk.MenuItem("ON")
onItem.connect("activate", on, "On")
menu.append(onItem)
offItem = gtk.MenuItem("OFF")
offItem.connect("activate", off, "Off")
menu.append(offItem)
menu.show_all()
return menu
def getInt():
s = StringIO.StringIO(subprocess.check_output("xinput list", shell=True))
for line in s:
if "My-Laptops-Touch-Pad-Id" in line:
return line.split('id=')[1].split('\t')[0]
def on(self, wtf):
subprocess.call("xinput --enable " + getInt(), shell=True)
def off(self, wtf):
subprocess.call("xinput --disable " + getInt(), shell=True)
if 1 == 1:main()
Here is the icon...
http://www.angelfire.com/un/sbt/images/toucher.png
I didn't know what to put in for the arguments in the 'on' and 'off' functions, so I just put in wtf.
Rate it. -
2017-03-12 at 4:10 AM UTCI think you're supposed to add your python version to the shebang line. I mean linux knows where python lives it just doesn't know which version you want to use if you have both installed and your code might fail on either 2.7 or 3.x depending on the syntax.
Also why do your on and off method have a `self` argument? They aren't in a class, your methods aren't decorated and i don't know enough about Python to be able to tell if your on and off methods are static or not.
Also. Why do you write `if 1 == 1:main()`. 1 == 1 will always evaluate to true right? So no matter what you want to call `main()`. So why not just call it by just typing `main()` also shorthands like that look weird in python. Also it doesn't look to me like you need to pass any arguments to the on and off methods.
So like, in general when we pass an argument to a method/function if we want to do something with the value of the argument right? And have the the function return something based on the argument that is given.
I like to think of an argument in a function as a variable. We need the value of these variables to have the function return output based on our input. Consider this.
from selenium import webdriver
print "\nWould you like the program to proxy its connection?"
query = raw_input("[Y]es/[N]o: ")
if query == 'y':
IP = raw_input("\nPlease enter the proxy host IP: ")
PORT = raw_input("\nPlease enter the proxy port: ")
set_proxy = True
elif query == 'n':
print "\n[+]Establishing unproxied connection..."
set_proxy = False
else:
print "\n[!]Unhandled option, defaulting to unproxied connection..."
set_proxy = False
# Web Driver Proxy
def proxy(PROXY_HOST,PROXY_PORT):
fp = webdriver.FirefoxProfile()
print "[+]Proxy host set to: " + PROXY_HOST
print "[+]Proxy port set to: " + PROXY_PORT
print "\n[+]Establishing connection..."
fp.set_preference("network.proxy.type", 1)
fp.set_preference("network.proxy.http",PROXY_HOST)
fp.set_preference("network.proxy.http_port",int(PROXY_PORT))
fp.set_preference("general.useragent.override","'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36'")
fp.update_preferences()
return webdriver.Firefox(firefox_profile=fp)
if set_proxy == True:
driver = proxy(IP, PORT)
else:
driver = webdriver.Firefox()
So what the proxy() function will return is dependent on the input of the user. Your on/off functions/methods don't need any input to do what they do, or at least so it seems to me. And it's well within the realm of possibility that i am wrong.
All in all you code pretty neatly in python. So bonus points for readability. -
2017-03-12 at 6:25 AM UTC
Originally posted by Sophie I think you're supposed to add your python version to the shebang line. I mean linux knows where python lives it just doesn't know which version you want to use if you have both installed and your code might fail on either 2.7 or 3.x depending on the syntax.
2.7
Originally posted by Sophie Also why do your on and off method have a `self` argument? They aren't in a class, your methods aren't decorated and i don't know enough about Python to be able to tell if your on and off methods are static or not.
That's how one of the examples I found had it set up. I thought I was due to it being a menu button. What else would I put there so that it'll work? I toyed around with it but that's what worked and that's what was in the example I found.
Also, I had thought you were the Py-Guy around here. What is your primary programming language?
Originally posted by Sophie Also. Why do you write `if 1 == 1:main()`. 1 == 1 will always evaluate to true right? So no matter what you want to call `main()`. So why not just call it by just typing `main()` also shorthands like that look weird in python. Also it doesn't look to me like you need to pass any arguments to the on and off methods.
So true about just placing 'main()' there. I think I came up with the idea from an example and the example most likely had something that changed a variable to shut of the program but I just quickly made what I knew was an infinite loop without really thinking about it.
As far as the arguments, two are definitely needed. I believe one has to be 'self' due to it being a menu button. I could be wrong though. -
2017-03-12 at 12:10 PM UTC
Originally posted by SBTlauien 2.7
That's how one of the examples I found had it set up. I thought I was due to it being a menu button. What else would I put there so that it'll work? I toyed around with it but that's what worked and that's what was in the example I found.
Also, I had thought you were the Py-Guy around here. What is your primary programming language?
Well, i know some Python but i would say i am far from an expert. I would consider myself intermediate at best. I know not of the nuances of function definitions and whatnot, just in my experience, when i write i function i never have to pass a `self` argument. The only place i see it is when a function is part of a class for instance in a library.
Originally posted by SBTlauien So true about just placing 'main()' there. I think I came up with the idea from an example and the example most likely had something that changed a variable to shut of the program but I just quickly made what I knew was an infinite loop without really thinking about it.
As far as the arguments, two are definitely needed. I believe one has to be 'self' due to it being a menu button. I could be wrong though.
>I believe one has to be 'self' due to it being a menu button.
That may be true but what makes it so a menu button is special case? IDK.
Also there is an easier way to write an infinite loop. As far as i know, 1 == 1:main() will simply evaluate to true once. And call the function. while loops go on forever, or at least as long as the conditions of the loop are met.
while True:
# stuff goes here
Post last edited by Sophie at 2017-03-12T12:18:39.574892+00:00 -
2017-03-12 at 12:12 PM UTCMy primary programming language is Python. But like i have mentioned before, i have no official training in IT and programming and computer science. Basically i just learn as i go lol.
-
2017-03-13 at 2:25 AM UTC
-
2017-03-13 at 2:27 AM UTC
-
2017-03-13 at 2:31 AM UTCJava related:
-
2017-03-13 at 2:34 AM UTC
Originally posted by Sophie Eeww Java. Also yeah i should become a C Geek as well. But i also want to learn R for some reason.
Why doesn't anyone seem to like Java? I actually like it a lot for some reason, mainly for Android, but also because it seems to have a lot of libraries and sample code, and it seems to network nicely(except the lack of being able to craft packets without a library). Not to long ago, someone else put me down for learning Java. -
2017-03-13 at 2:41 AM UTC
Originally posted by SBTlauien Why doesn't anyone seem to like Java? I actually like it a lot for some reason, mainly for Android, but also because it seems to have a lot of libraries and sample code, and it seems to network nicely(except the lack of being able to craft packets without a library). Not to long ago, someone else put me down for learning Java.
Well for one, Java code looks like shit and Python looks nice and neat.
>Lots of libraries
Bro... Python has ALL the libraries, all of them it's true.
Also, i hear Java is very much not secure.
-
2017-03-13 at 2:46 AM UTC
Originally posted by Sophie Also, i hear Java is very much not secure.
I always thought that was more about people using Java in their browsers. I don't personally use Java in my browser.
Also, I disagree on the syntax. I like the way Java looks. It looks similar to C, which I am liking. I think we can both agree that C and Assembly are basically the most important programming languages one can learn. -
2017-03-13 at 2:48 AM UTC