Supporto di qualche parametro a riga di comando.

Leonardo [2010-05-09 15:28]
Supporto di qualche parametro a riga di comando.
Filename
DrPrintGui/Input.py
DrPrintGui/MainWin.py
debian/changelog
drprint
diff --git a/DrPrintGui/Input.py b/DrPrintGui/Input.py
index 5b2b07a..96954b9 100644
--- a/DrPrintGui/Input.py
+++ b/DrPrintGui/Input.py
@@ -32,11 +32,14 @@ class PaddingLeftWidget(gtk.Table):

 class UsernameField(gtk.Entry):

-    def __init__(self, parent=None):
+    def __init__(self, parent=None, user = None):

         gtk.Entry.__init__(self)

-        self.set_text( os.getenv("USER") )
+        if user is None:
+            self.set_text( os.getenv("USER") )
+        else:
+            self.set_text(user)


 class PasswordField(gtk.Entry):
@@ -50,11 +53,11 @@ class PasswordField(gtk.Entry):

 class AuthBlock(gtk.HBox):

-    def __init__(self, default_spacing=5, left_padding=0):
+    def __init__(self, default_spacing=5, left_padding=0, user = None):

         gtk.HBox.__init__(self)

-        self.user_field = UsernameField()
+        self.user_field = UsernameField(user = user)
         self.password_field = PasswordField()

         vbox1 = gtk.VBox()
@@ -107,11 +110,14 @@ class PrintButton(gtk.Button):

 class SelectFileWidget(gtk.HBox):

-    def __init__(self):
+    def __init__(self, filename = None):
         gtk.HBox.__init__(self)
         self.set_spacing (5)

         self.Filename = gtk.Entry()
+        if filename is not None:
+            self.Filename.set_text(filename)
+
         self.Browser = gtk.Button("Sfoglia")

         self.Filename.set_tooltip_text("Se hai bisogno di stampare \
@@ -181,7 +187,7 @@ class PagePerPageComboBox(gtk.HBox):

 class PrinterSettingsBlock(gtk.HBox):

-    def __init__(self, default_spacing = 5, left_padding=0):
+    def __init__(self, default_spacing = 5, left_padding=0, filename = None):

         gtk.HBox.__init__(self)

@@ -202,7 +208,7 @@ class PrinterSettingsBlock(gtk.HBox):
         vbox1.pack_start( label )
         label.show()

-        self.select_file_widget = SelectFileWidget()
+        self.select_file_widget = SelectFileWidget(filename)
         vbox2.pack_start (self.select_file_widget)
         self.select_file_widget.show()

diff --git a/DrPrintGui/MainWin.py b/DrPrintGui/MainWin.py
index 426a8e6..b36173d 100644
--- a/DrPrintGui/MainWin.py
+++ b/DrPrintGui/MainWin.py
@@ -18,9 +18,11 @@ from DrPrintBackend import PrintingError
 class MainWin(gtk.Window):
     """MainWin object for DrPrint"""

-    def __init__(self, backend=None):
+    def __init__(self, backend=None, user = None, filename = None):

         self.backend = backend
+        self.user = user
+        self.filename = filename

         gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)

@@ -77,7 +79,7 @@ class MainWin(gtk.Window):
         layout_box.pack_start( label )
         label.show()

-        self.auth_block = AuthBlock(self.default_spacing, 10)
+        self.auth_block = AuthBlock(self.default_spacing, 10, user = self.user)
         layout_box.pack_start ( self.auth_block )
         self.auth_block.show()

@@ -86,7 +88,8 @@ class MainWin(gtk.Window):
         layout_box.pack_start(label)
         label.show()

-        self.printer_settings_block = PrinterSettingsBlock(self.default_spacing)
+        self.printer_settings_block = PrinterSettingsBlock(self.default_spacing,
+                                                           filename = self.filename)
         layout_box.pack_start(self.printer_settings_block)
         self.printer_settings_block.show()

diff --git a/debian/changelog b/debian/changelog
index 09310d6..0956fba 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+drprint (0.8-4) lucid; urgency=low
+
+  * Supporto di qualche parametro a riga di comando
+
+ -- Leonardo Robol <leonardo@debby>  Sun, 09 May 2010 17:28:28 +0200
+
 drprint (0.8-3) lucid; urgency=low

   * Il pulsante Stampa cambia etichetta durante la stampa
diff --git a/drprint b/drprint
index ce877e4..d59224c 100755
--- a/drprint
+++ b/drprint
@@ -1,11 +1,23 @@
 #!/usr/bin/env python

 import gtk, pygtk
+from optparse import OptionParser
 from DrPrintGui.MainWin import MainWin
 from DrPrintBackend import Backend

 if __name__ == "__main__":

+   ## Analyze comand line options
+   usage = "usage: %prog [options] [file]"
+   parser = OptionParser(usage=usage)
+   parser.add_option("-u", "--user", dest="user",default=None,
+                     help = "set username to use for the ssh connection",
+                     metavar="user")
+
+   (option, args) = parser.parse_args()
+
+   if len(args) > 0:
+      filename = args[0]

    ## Load the Backend that will perform
    ## all the hard work without being seen
@@ -18,7 +30,9 @@ if __name__ == "__main__":
    ## with her .. ( find a good word )
    ## P.S.: We give her a backend, without
    ## it she will be useless.
-   mw = MainWin(backend)
+   mw = MainWin(backend = backend,
+                user = option.user,
+                filename = filename)

    ## Show all :)
    mw.show()
ViewGit