Created
June 29, 2010 12:59
-
-
Save airtonix/457169 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# | |
# | |
# | |
# | |
# | |
import os, stat, gtk | |
class BatchPrintConfirmationWindow: | |
""" Class doc """ | |
def __init__ (self,input): | |
""" Class initialiser """ | |
self.window = gtk.Window() | |
self.COL_FILENAME = 0 | |
self.COL_FILEICON = 1 | |
self.COL_FILESIZE = 2 | |
self.COL_TICKBOX = 3 | |
self.file_data = gtk.TreeStore(str, gtk.gdk.Pixbuf, int, bool) | |
self.read_stdin(input,self.file_data) | |
self.render() | |
def render (self): | |
""" Function doc """ | |
# the tickbox column | |
AppTitle = gtk.Label() | |
AppTitle.set_text("Print Files") | |
BooleanColumn = gtk.TreeViewColumn("Print") | |
BooleanColumn_cellTick = gtk.CellRendererToggle() | |
BooleanColumn.add_attribute(BooleaanColumn_cellTick, 'active', self.COL_TICKBOX) | |
#BooleanColumn_cellTick.connect("toggled", self.callback_column_tick_item, self.file_data) | |
BooleanColumn.pack_start(BooleanColumn_cellTick, True) | |
BooleanColumn.set_clickable(True) | |
BooleanColumn.connect("clicked", self.callback_column_tick, "Tick Column") | |
# the filename column | |
FileColumn = gtk.TreeViewColumn("File") | |
FileColumn_cellImg = gtk.CellRendererPixbuf() | |
FileColumn.pack_start(FileColumn_cellImg, False) | |
FileColumn.add_attribute(FileColumn_cellImg, "pixbuf", 1) | |
FileColumn.set_clickable(True) | |
FileColumn.connect("clicked", self.callback_column_file, "File Column") | |
FileColumn_cellText = gtk.CellRendererText() | |
#FileColumn_cellText.connect("clicked", self.callback_column_file_item, "File Item") | |
FileColumn.pack_start(FileColumn_cellText, True) | |
FileColumn.add_attribute(FileColumn_cellText, "text", 0) | |
TreeView = gtk.TreeView(self.file_data) | |
TreeView.append_column(BooleanColumn) | |
TreeView.append_column(FileColumn) | |
Scroller = gtk.ScrolledWindow() | |
Scroller.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) | |
Scroller.add(TreeView) | |
Buttons = gtk.HBox(spacing=5) | |
button_Print = gtk.Button() | |
button_Print.set_use_stock(1) | |
button_Print.connect("clicked", self.callback_button_print, "Print Button") | |
image_Print = gtk.Image() | |
image_Print.set_from_stock("gtk-print", gtk.ICON_SIZE_BUTTON) | |
button_Print.set_image(image_Print) | |
Buttons.pack_start(button_Print, False) | |
button_Cancel = gtk.Button() | |
button_Cancel.connect("clicked", self.callback_button_cancel, "Cancel Button") | |
button_Cancel.set_use_stock(1) | |
image_Cancel = gtk.Image() | |
image_Cancel.set_from_stock("gtk-cancel", gtk.ICON_SIZE_BUTTON) | |
button_Cancel.set_image(image_Cancel) | |
Buttons.pack_start(button_Cancel, False) | |
layout = gtk.VBox(spacing=5) | |
layout.pack_start(AppTitle, False) | |
layout.pack_start(Scroller, True, True) | |
layout.pack_start(Buttons, False, True) | |
self.window = gtk.Window() | |
self.window.connect("destroy", gtk.main_quit) | |
self.window.set_position(gtk.WIN_POS_CENTER_ALWAYS) | |
self.window.resize(256,320) | |
self.window.realize() | |
self.window.add(layout) | |
self.window.show_all() | |
gtk.main() | |
def get_file_type_icon (self,file): | |
""" sniffs the mime type of the file and returns the gtk-icon name to use""" | |
output = "" | |
return output | |
def callback_column_tick (self, widget, data): | |
""" Function doc """ | |
print("%s was pushed" % data) | |
def callback_column_tick_item (self, cell, path, model ): | |
""" Function doc """ | |
model[path][self.COL_TICKBOX] = not model[path][self.COL_TICKBOX] | |
print "Toggle '%s' to: %s" % (model[path][self.COL_FILENAME], model[path][self.COL_TICKBOX],) | |
return | |
def callback_column_file (self, widget, data): | |
""" Function doc """ | |
print("%s was pushed" % data) | |
def callback_column_file_item (self, widget, data): | |
""" Function doc """ | |
print("%s was pushed" % data) | |
def callback_button_cancel(self, widget, data): | |
print("%s was pushed" % data) | |
def callback_button_print(self, widget, data): | |
print("%s was pushed" % data) | |
def dirwalk(self, path, store, parent=None, useFiles=False): | |
for f in os.listdir(path): | |
if ".pyc" not in f and not f.startswith("."): | |
fullname = os.path.join(path, f) | |
fdata = os.stat(fullname) | |
is_folder = stat.S_ISDIR(fdata.st_mode) | |
if(not is_folder and not useFiles) : | |
continue | |
img = gtk.icon_theme_get_default().load_icon( | |
"folder" if is_folder else "document", | |
gtk.ICON_SIZE_MENU, 0) | |
li = store.append(parent, [f, img, fdata.st_size, is_folder]) | |
if is_folder: self.dirwalk(fullname, store, li, useFiles) | |
def read_stdin(self,stdin,store) : | |
""" Reads program input, populates self.file_data with files """ | |
for file in stdin : | |
fdata = os.stat(file) | |
is_folder = stat.S_ISDIR(fdata.st_mode) | |
img = gtk.icon_theme_get_default().load_icon( | |
"folder" if is_folder else "document", | |
gtk.ICON_SIZE_MENU, 0) | |
if not is_folder : | |
store.append(None, [file, img, fdata.st_size, True]) | |
if __name__ == "__main__" : | |
PATH = os.path.dirname( os.path.realpath( __file__ )) | |
files = os.listdir(PATH) | |
BatchPrintConfirmationWindow(files) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment