Reputation: 133
While building a simple GUI video downloader in python and with Glade3 I am stuck with pasting into a text entry box using an icon.
The application, and paste icon.
The python code:
# !/usr/python
import sys
import os
import subprocess as sp
try:
from gi.repository import Gtk, Gdk
except:
print('Gtk not available')
sys.exit(1)
try:
import pyGtk
pyGtk.require('2.0')
except:
pass
class VideoDownloader:
def on_mainwindow_destroy(self, object, data=None):
print "quit with cancel"
Gtk.main_quit()
def __init__(self):
self.gladefile = "lib/videodownloder.glade"
self.builder = Gtk.Builder()
self.builder.add_from_file(self.gladefile)
self.builder.connect_signals(self)
self.go = self.builder.get_object
self.window = self.go("mainwindow")
self.window.show()
self.okbtn = self.go("okbutton")
self.cancelbtn = self.go("cancelbutton")
#self.restartswitch = self.go("restartswitch")
self.contswitch = self.go("contswitch")
self.vlcswitch = self.go("vlcswitch")
self.urlentry = self.go("urlentry")
self.filechooser = self.go("filechooser")
self.clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
def on_urlentry_activate(self, widget):
url = self.urlentry.get_text()
print("the url is:" + url)
def on_urlentry_icon_press(self):
text = self.clipboard.set_text(self.urlentry.get_text(), -1)
print("the urlentry paste icon was clicked | 'text' ")
def on_urlentry_icon_press(self):
text = self.clipboard.wait_for_text()
print("the urlentry paste icon was clicked | 'text' ")
if text != None:
self.urlentry.set_text(text)
print(" 'text' has been pasted to the urlentry")
else:
print("No text on the clipboard")
def on_filechooser_file_activated(self, widget):
myfile = self.filechooser.get_uri()
print("the file is: " + myfile)
def on_vlcswitch_activate(self, widget):
print("VLC Switch has been activated")
def on_contswitch_activate(self, widget):
print("Continue switch has been acivated")
def on_quitbutton_clicked(self, button):
print("quit with the close button")
Gtk.main_quit()
def on_okbutton_clicked(self, button):
myfile = self.filechooser.get_uri()
url = self.urlentry.get_text()
wgetcmd = ("wget -O 'myfile ' 'url' ")
print("ok button has been clicked")
print("wget will now be run with your args: " +myfile+url)
os.system(wgetcmd)
if __name__ == "__main__":
print("videodownloader is running")
notify = os.system("notify-send --expire-time=5000 --icon='img/vid-down-logo.png' --app-name=VideoDownloader 'VideoDownloader' 'The VideoDownloader app is now running and ready!'")
notify
main = VideoDownloader()
Gtk.main()
print("videodownloader has stopped running")
When I run the code it mostly works but when I click the paste icon I get an error:
TypeError: on_urlentry_icon_press() takes exactly 1 argument (4 given)
I am fairly new to python and glade so I am probably making an elementary mistake but I do not know what is wrong and what the error means. I have searched but found only advice that didn't help.
Such as this..
Any suggestions on how to fix this please?
Upvotes: 1
Views: 822
Reputation: 2258
Your current on_urlentry_icon_press
method only takes the self
argument but it should take more than one because it is connected to the icon-press
signal.
In the documentation you can see that it takes:
So it should look like this:
def on_urlentry_icon_press(self, entry, position, event):
print('urlentry icon clicked')
Upvotes: 2