Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import os
- import pygtk
- pygtk.require('2.0')
- import gtk
- import time
- import string
- class StatusIcc:
- #menu handlers
- #quit program
- def quit_cb(self,widget, data = None):
- if data:
- data.set_visible(False)
- gtk.main_quit()
- #show menu
- def popup_menu_cb(self, widget, button, time, data = None):
- if button == 3:
- if data:
- data.show_all()
- data.popup(None, None, None, 3, time)
- pass
- #about
- def about(self,widget):
- dia = gtk.AboutDialog()
- dia.set_name("Scroter")
- dia.set_program_name("Scroter")
- dia.set_authors('paxman\n')
- dia.set_version("0.5")
- dia.run()
- dia.destroy()
- #settings
- def settings(self,widget):
- # create a new window
- window = gtk.Window(gtk.WINDOW_TOPLEVEL)
- window.set_size_request(380, 100)
- window.set_title("Scroter settings")
- #window.connect("delete_event", lambda w,e: gtk.main_quit())
- #get settings
- settings = self.read_settings()
- vbox = gtk.VBox(False, 0)
- window.add(vbox)
- vbox.show()
- hbox = gtk.HBox(False, 0)
- vbox.add(hbox)
- hbox.show()
- label = gtk.Label("Quality of image, in %:")
- hbox.pack_start(label, True, True, 0)
- label.show()
- quality = gtk.Entry()
- quality.set_max_length(50)
- quality.set_text(settings[0])
- hbox.pack_start(quality, True, True, 0)
- quality.show()
- hbox = gtk.HBox(False, 0)
- vbox.add(hbox)
- hbox.show()
- label = gtk.Label("Console image viewer command:")
- hbox.pack_start(label, True, True, 0)
- label.show()
- viewer = gtk.Entry()
- viewer.set_max_length(50)
- viewer.set_text(settings[1])
- hbox.pack_start(viewer, True, True, 0)
- viewer.show()
- button = gtk.Button(stock=gtk.STOCK_SAVE)
- button.connect("clicked",self.write_settings,window,quality,viewer)
- vbox.pack_start(button, True, True, 0)
- button.set_flags(gtk.CAN_DEFAULT)
- button.grab_default()
- button.show()
- window.show()
- #handlers
- #get whole screen
- def get_all(self, widget):
- # grab the screenshot
- self.grab_it("")
- #get selected window
- def get_window(self, widget):
- # grab the screenshot
- #TODO: w/o, w/ border
- self.grab_it("-s")
- #get selected area
- def get_area(self, widget):
- # grab the screenshot
- self.grab_it("-s")
- #helpet functions
- def get_temp_file_name(self):
- # create a unique image file name based on the application PID
- #return random image name?
- imageName = "/tmp/scrotshot.png"
- # return the result
- return imageName
- def grab_it(self, commandParameters):
- #delay? do users really need that?
- #delay = 0
- #check if directory for images exists
- if not os.path.exists(os.path.expanduser("~/scroter")):
- os.system("mkdir -p ~/scroter")
- #name of image - current time
- imagename = time.strftime("%Y-%m-%d_%H-%M-%S")
- # grab the screenshot and move it to user home directory
- os.system("scrot ~/scroter/"+ imagename+".png" + " " + commandParameters)
- # change image's permissions
- os.system("chmod 0600 ~/scroter/"+ imagename+".png")
- #open image with image viewer
- #TODO: settings -> change viewer
- os.system("gpicview ~/scroter/"+ imagename+".png")
- def checkSettingsFile(self):
- if not os.path.exists(os.path.expanduser("~/.scroter")):
- os.system("touch ~/.scroter")
- file = open(os.path.expanduser("~/.scroter"),"w")
- file.write("75\n")
- file.write("gpicview")
- file.flush()
- file.close()
- def write_settings(self,widget,window,quality,viewer):
- file = open(os.path.expanduser("~/.scroter"),"w")
- print quality.get_text() + " " + viewer.get_text()
- file.write(quality.get_text()+"\n")
- file.write(viewer.get_text())
- file.flush()
- file.close()
- window.hide()
- def read_settings(self):
- settings = []
- file = open(os.path.expanduser("~/.scroter"),"r")
- settings.append(string.rstrip(file.readline()))
- settings.append(string.rstrip(file.readline()))
- file.close()
- return settings
- def __init__ (self):
- statusIcon = gtk.StatusIcon()
- #check if settings file exists; if not, make one
- self.checkSettingsFile()
- menu = gtk.Menu()
- menu_items = (
- ("Area", self.get_area),
- ("Window", self.get_window),
- ("All", self.get_all),
- None,
- ("Settings", self.settings),
- ("About", self.about),
- ("Exit", self.quit_cb),
- );
- for i in menu_items:
- if i is None:
- menu.append(gtk.SeparatorMenuItem());
- else:
- menu_items = gtk.MenuItem( i[0] );
- menu_items.connect('activate', i[1] );
- menu.append( menu_items );
- #image by Iconspedia (http://www.iconspedia.com/icon/digital-camera-610.html , http://mugenb16.deviantart.com/art/Massive-Media-Icons-Win-48654751)
- statusIcon.set_from_file("camera.png")
- statusIcon.set_tooltip("Scroter - scrot frontend")
- statusIcon.connect('popup-menu', self.popup_menu_cb,menu)
- statusIcon.set_visible(True)
- gtk.main()
- if __name__ == "__main__":
- statusicon = StatusIcc()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement