Aggiunto un dialogo di Errore (anche se piuttosto grezzo)

Leonardo Robol [2009-09-20 10:33]
Aggiunto un dialogo di Errore (anche se piuttosto grezzo)
quando nome utente e password sono sbagliati
Filename
DrPrintBackend.py
DrPrintGui/Input.py
DrPrintGui/Input.pyc
DrPrintGui/MainWin.py
DrPrintGui/MainWin.pyc
diff --git a/DrPrintBackend.py b/DrPrintBackend.py
index 787c6bb..62a128e 100644
--- a/DrPrintBackend.py
+++ b/DrPrintBackend.py
@@ -1,12 +1,14 @@
 ## Some useful function to help DrPrint to
 # -*- coding: utf-8 -*-

-import paramiko
+import paramiko, gobject
+
+class Backend(gobject.GObject):

-class Backend():
-
     def __init__(self):
-        pass
+        super(Backend, self).__init__()
+
+        gobject.signal_new("auth_failed", Backend, gobject.SIGNAL_RUN_FIRST, None, ())

     def send_print(self, printer, username, password, page_per_page, filename):
         # Get printer name
@@ -16,10 +18,14 @@ class Backend():
         client = paramiko.SSHClient()
         client.set_missing_host_key_policy(paramiko.AutoAddPolicy())

-        client.connect('ssh.dm.unipi.it',
-                       port=22,
-                       username=username,
-                       password=password)
+        try:
+            client.connect('ssh.dm.unipi.it',
+                           port=22,
+                           username=username,
+                           password=password)
+        except paramiko.AuthenticationException, e:
+            self.emit('auth_failed')
+            return

         channel = client.get_transport().open_session()

diff --git a/DrPrintGui/Input.py b/DrPrintGui/Input.py
index 6bda858..fca460c 100644
--- a/DrPrintGui/Input.py
+++ b/DrPrintGui/Input.py
@@ -2,6 +2,18 @@

 import gtk, pygtk, gobject

+class LeftAlignedLabel(gtk.Alignment):
+
+    def __init__(self, markup, left_padding=0):
+
+        gtk.Alignment.__init__(self, 0,0.5,0,0)
+
+        label = gtk.Label()
+        label.set_markup("  "*left_padding + markup)
+
+        self.add(label)
+        label.show()
+
 class UsernameField(gtk.Entry):

     def __init__(self, parent=None):
@@ -22,7 +34,7 @@ class PasswordField(gtk.Entry):

 class AuthBlock(gtk.HBox):

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

         gtk.HBox.__init__(self)

@@ -32,11 +44,11 @@ class AuthBlock(gtk.HBox):
         vbox1 = gtk.VBox()
         vbox2 = gtk.VBox()

-        label = gtk.Label("Utente")
+        label = LeftAlignedLabel("Utente", 2)
         vbox1.pack_start( label )
         label.show()

-        label = gtk.Label("Password")
+        label = LeftAlignedLabel("Password", 2)
         vbox1.pack_start( label )
         label.show()

@@ -134,7 +146,7 @@ class PagePerPageComboBox(gtk.HBox):

 class PrinterSettingsBlock(gtk.HBox):

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

         gtk.HBox.__init__(self)

@@ -143,7 +155,7 @@ class PrinterSettingsBlock(gtk.HBox):

         self.set_spacing(default_spacing)

-        label = gtk.Label("Stampante")
+        label = LeftAlignedLabel("Stampante", 2)
         vbox1.pack_start(label)
         label.show()

@@ -151,7 +163,7 @@ class PrinterSettingsBlock(gtk.HBox):
         vbox2.pack_start( self.printer_chooser )
         self.printer_chooser.show()

-        label = gtk.Label("File")
+        label = LeftAlignedLabel("File", 2)
         vbox1.pack_start( label )
         label.show()

@@ -159,7 +171,7 @@ class PrinterSettingsBlock(gtk.HBox):
         vbox2.pack_start (self.select_file_widget)
         self.select_file_widget.show()

-        label = gtk.Label("Pagine per foglio")
+        label = LeftAlignedLabel("Pagine per foglio", 2)
         vbox1.pack_start(label)
         label.show()

diff --git a/DrPrintGui/Input.pyc b/DrPrintGui/Input.pyc
index 07ceccc..c01e150 100644
Binary files a/DrPrintGui/Input.pyc and b/DrPrintGui/Input.pyc differ
diff --git a/DrPrintGui/MainWin.py b/DrPrintGui/MainWin.py
index 7264bb1..593d99f 100644
--- a/DrPrintGui/MainWin.py
+++ b/DrPrintGui/MainWin.py
@@ -1,15 +1,16 @@
 ## This library is part of DrPrintGui
-##
+#  -*- coding: utf-8 -*-
 ## This file provide the MainWin object,
 ## that is the main window of the DrPrint
 ## application

+
 __author__ = 'Leonardo Robol <leo@robol.it>'

 import gtk, pygtk

-from Input import AuthBlock, PrinterSettingsBlock, PrintButton
-
+from Input import AuthBlock, PrinterSettingsBlock, PrintButton, LeftAlignedLabel
+from Dialogs import ErrorDialog

 class MainWin(gtk.Window):
     """MainWin object for DrPrint"""
@@ -48,18 +49,16 @@ class MainWin(gtk.Window):
         layout_box.pack_start( label )
         label.show()

-        label = gtk.Label()
-        label.set_markup("<b>Autenticazione (sui computer dell'Aula 4)</b>")
+        label = LeftAlignedLabel("<b>Autenticazione (sui computer dell'Aula 4)</b>")
         layout_box.pack_start( label )
         label.show()

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

         # The PDF file loading and print settings
-        label = gtk.Label()
-        label.set_markup("<b>Configurazione stampante</b>")
+        label = LeftAlignedLabel("<b>Configurazione stampante</b>")
         layout_box.pack_start(label)
         label.show()

@@ -78,6 +77,7 @@ class MainWin(gtk.Window):

     def connect_all(self):
         self.print_button.connect('clicked', self.print_button_clicked_callback)
+        self.backend.connect('auth_failed', self.auth_failed_callback)

     def print_button_clicked_callback(self, widget):
         if not self.backend == None:
@@ -95,6 +95,14 @@ class MainWin(gtk.Window):
         else:
             self.debug( "Sembra che non ci sia un backend attaccato\
  a questa interfaccia, quindi non faccio nulla")
+
+    def auth_failed_callback(self, obj):
+        self.debug("Autenticazione fallita")
+        dialog = ErrorDialog("Autenticazione Fallita",
+                             "<b>Autenticazione Fallita</b>\nLo username e la password forniti non sono\n\
+corretti. L'autenticazione su ssh.dm.unipi.it\nnon è andata a buon fine.")
+        dialog.run()
+        dialog.destroy()



diff --git a/DrPrintGui/MainWin.pyc b/DrPrintGui/MainWin.pyc
index de3f044..55cfba8 100644
Binary files a/DrPrintGui/MainWin.pyc and b/DrPrintGui/MainWin.pyc differ
ViewGit