diff --git a/DrPrint b/DrPrint
index 4eed144..ce877e4 100755
--- a/DrPrint
+++ b/DrPrint
@@ -6,10 +6,22 @@ from DrPrintBackend import Backend
if __name__ == "__main__":
+
+ ## Load the Backend that will perform
+ ## all the hard work without being seen
+ ## by the end user. That is -- the sad
+ ## story of every backend.
backend = Backend()
+ ## ...and then the main win! The one
+ ## that will try to attract end user
+ ## with her .. ( find a good word )
+ ## P.S.: We give her a backend, without
+ ## it she will be useless.
mw = MainWin(backend)
+ ## Show all :)
mw.show()
+ ## ..and let's go!
gtk.main()
diff --git a/DrPrintBackend.py b/DrPrintBackend.py
index 5714359..787c6bb 100644
--- a/DrPrintBackend.py
+++ b/DrPrintBackend.py
@@ -1,5 +1,5 @@
## Some useful function to help DrPrint to
-## print
+# -*- coding: utf-8 -*-
import paramiko
@@ -25,8 +25,19 @@ class Backend():
print "Printing %s" % filename
f = open(filename, 'r')
+
+ # Questo è inevitabile.. :)
+ cmd = "lpr -P%s " % printer
+
+ cmd_opts = ""
+
+ if not page_per_page == 1:
+ cmd_opts += "number-up=%s " % str(page_per_page)
+
+ if not cmd_opts == "":
+ cmd = cmd + "-o %s" % cmd_opts
- channel.exec_command("lpr -P%s" % printer)
+ channel.exec_command(cmd)
channel.sendall( f.read() )
f.close()
channel.close()
diff --git a/DrPrintGui/Input.py b/DrPrintGui/Input.py
index 806416a..6bda858 100644
--- a/DrPrintGui/Input.py
+++ b/DrPrintGui/Input.py
@@ -20,6 +20,44 @@ class PasswordField(gtk.Entry):
self.set_text ("Password")
self.set_visibility(False)
+class AuthBlock(gtk.HBox):
+
+ def __init__(self, default_spacing):
+
+ gtk.HBox.__init__(self)
+
+ self.user_field = UsernameField()
+ self.password_field = PasswordField()
+
+ vbox1 = gtk.VBox()
+ vbox2 = gtk.VBox()
+
+ label = gtk.Label("Utente")
+ vbox1.pack_start( label )
+ label.show()
+
+ label = gtk.Label("Password")
+ vbox1.pack_start( label )
+ label.show()
+
+ vbox2.pack_start(self.user_field)
+ vbox2.pack_start(self.password_field)
+
+ self.user_field.show()
+ self.password_field.show()
+
+ self.pack_start(vbox1)
+ self.pack_start(vbox2)
+
+ vbox1.show()
+ vbox2.show()
+
+ def get_username(self):
+ return self.user_field.get_text()
+
+ def get_password(self):
+ return self.password_field.get_text()
+
class PrintButton(gtk.Button):
def __init__(self, parent=None):
@@ -93,3 +131,55 @@ class PagePerPageComboBox(gtk.HBox):
def get_page_per_page(self):
return self.combobox.get_active_text()
+
+class PrinterSettingsBlock(gtk.HBox):
+
+ def __init__(self, default_spacing = 5):
+
+ gtk.HBox.__init__(self)
+
+ vbox1 = gtk.VBox(False, default_spacing)
+ vbox2 = gtk.VBox(False, default_spacing)
+
+ self.set_spacing(default_spacing)
+
+ label = gtk.Label("Stampante")
+ vbox1.pack_start(label)
+ label.show()
+
+ self.printer_chooser = PrinterComboBox()
+ vbox2.pack_start( self.printer_chooser )
+ self.printer_chooser.show()
+
+ label = gtk.Label("File")
+ vbox1.pack_start( label )
+ label.show()
+
+ self.select_file_widget = SelectFileWidget()
+ vbox2.pack_start (self.select_file_widget)
+ self.select_file_widget.show()
+
+ label = gtk.Label("Pagine per foglio")
+ vbox1.pack_start(label)
+ label.show()
+
+ self.page_per_page = PagePerPageComboBox()
+ vbox2.pack_start(self.page_per_page)
+ self.page_per_page.show()
+
+ self.pack_start(vbox1)
+ self.pack_start(vbox2)
+
+ vbox1.show()
+ vbox2.show()
+
+ def get_filename(self):
+ return self.select_file_widget.GetFile()
+
+ def get_printer(self):
+ return self.printer_chooser.get_printer()
+
+ def get_page_per_page(self):
+ return self.page_per_page.get_page_per_page()
+
+
diff --git a/DrPrintGui/Input.pyc b/DrPrintGui/Input.pyc
index 88c35e8..07ceccc 100644
Binary files a/DrPrintGui/Input.pyc and b/DrPrintGui/Input.pyc differ
diff --git a/DrPrintGui/MainWin.py b/DrPrintGui/MainWin.py
index 0c1b9e1..7264bb1 100644
--- a/DrPrintGui/MainWin.py
+++ b/DrPrintGui/MainWin.py
@@ -8,7 +8,7 @@ __author__ = 'Leonardo Robol <leo@robol.it>'
import gtk, pygtk
-from Input import UsernameField, PasswordField, PrintButton, SelectFileWidget, PrinterComboBox, PagePerPageComboBox
+from Input import AuthBlock, PrinterSettingsBlock, PrintButton
class MainWin(gtk.Window):
@@ -36,85 +36,42 @@ class MainWin(gtk.Window):
from DrPrintGui"""
# The main LayOut VBox
- layout_box = gtk.Table(rows=9,columns=4)
+ layout_box = gtk.VBox()
+ layout_box.set_spacing( self.default_spacing )
# Qualche istruzinoe preliminare
label = gtk.Label()
label.set_markup("<b>Come usare questo programma:</b>\n\
-1) Inserire nome utente e password - 2) Scegliere il file da stampare e la\
- stampante - 3) Premere il tasto stampa")
+<b>1)</b> Inserire nome utente e password \n<b>2)</b> Scegliere il file da stampare e la\
+ stampante \n<b>3)</b> Premere il tasto stampa")
- layout_box.attach(label, 0, 7, 0, 1)
+ layout_box.pack_start( label )
label.show()
- # The authentication Input (riga 1)
- for j in range(0, 8):
- layout_box.set_row_spacing( j , self.default_spacing )
-
- for j in range(0,2):
- layout_box.set_col_spacing( j , self.default_spacing )
-
- ## Un po' di spazio fra la spiegazione e la sostanza
- layout_box.set_row_spacing(0, 20)
-
- layout_box.set_homogeneous(False)
-
label = gtk.Label()
- label.set_markup("<b>Autenticazione</b>")
- layout_box.attach( label, 0, 2, 1, 2 )
- label.show()
-
- label = gtk.Label("Utente")
- layout_box.attach( label, 0 , 1, 2 , 3)
+ label.set_markup("<b>Autenticazione (sui computer dell'Aula 4)</b>")
+ layout_box.pack_start( label )
label.show()
- self.user_field = UsernameField()
- layout_box.attach( self.user_field, 1, 3, 2 , 3)
- self.user_field.show()
-
- label = gtk.Label("Password")
- layout_box.attach( label, 0, 1, 3, 4)
- label.show()
+ self.auth_block = AuthBlock(self.default_spacing)
+ layout_box.pack_start ( self.auth_block )
+ self.auth_block.show()
- self.password_field = PasswordField()
- layout_box.attach(self.password_field, 1, 3, 3, 4)
- self.password_field.show()
-
-
# The PDF file loading and print settings
label = gtk.Label()
label.set_markup("<b>Configurazione stampante</b>")
- layout_box.attach(label, 0, 2, 4, 5)
+ layout_box.pack_start(label)
label.show()
- label = gtk.Label("Stampante")
- layout_box.attach(label, 0, 1, 5, 6)
- label.show()
-
- self.printer_chooser = PrinterComboBox()
- layout_box.attach( self.printer_chooser, 1, 3, 5, 6)
- self.printer_chooser.show()
-
- label = gtk.Label("File")
- layout_box.attach(label, 0, 1, 7, 8)
- label.show()
-
- self.select_file_widget = SelectFileWidget()
- layout_box.attach( self.select_file_widget, 1, 3, 7, 8)
- self.select_file_widget.show()
+ self.printer_settings_block = PrinterSettingsBlock(self.default_spacing)
+ layout_box.pack_start(self.printer_settings_block)
+ self.printer_settings_block.show()
self.print_button = PrintButton()
- layout_box.attach(self.print_button, 2, 3, 8, 9)
+ layout_box.pack_start(self.print_button)
self.print_button.show()
- label = gtk.Label("Pagine per foglio")
- layout_box.attach(label, 0, 1, 6, 7)
- label.show()
-
- self.page_per_page = PagePerPageComboBox()
- layout_box.attach(self.page_per_page, 1, 3, 6, 7)
- self.page_per_page.show()
-
+
self.add (layout_box)
layout_box.show()
@@ -124,11 +81,11 @@ class MainWin(gtk.Window):
def print_button_clicked_callback(self, widget):
if not self.backend == None:
- printer = self.printer_chooser.get_printer()
- username = self.user_field.get_text()
- password = self.password_field.get_text()
- filename = self.select_file_widget.GetFile()
- page_per_page = self.page_per_page.get_page_per_page()
+ printer = self.printer_settings_block.get_printer()
+ username = self.auth_block.get_username()
+ password = self.auth_block.get_password()
+ filename = self.printer_settings_block.get_filename()
+ page_per_page = self.printer_settings_block.get_page_per_page()
self.backend.send_print(printer = printer,
username = username,
diff --git a/DrPrintGui/MainWin.pyc b/DrPrintGui/MainWin.pyc
index 2f30056..de3f044 100644
Binary files a/DrPrintGui/MainWin.pyc and b/DrPrintGui/MainWin.pyc differ