viewgit/index.php:465 Only variables should be passed by reference [2048]

viewgit/index.php:466 Non-static method GeSHi::get_language_name_from_extension() should not be called statically [2048]

  1. # -*- coding: utf-8 -*-
  2. ## This library is part of DrPrintGui
  3. ## This file provide the MainWin object,
  4. ## that is the main window of the DrPrint
  5. ## application
  6.  
  7.  
  8. __author__ = 'Leonardo Robol <leo@robol.it>'
  9.  
  10. import gtk, pygtk
  11. import os
  12. import sys
  13.  
  14. from Input import AuthBlock, PrinterSettingsBlock, PrintButton, LeftAlignedLabel, \
  15. PageRangeBlock, OrientationSelect, SidesSelect, QueueButton
  16. from Dialogs import ErrorDialog, MessageDialog, InfoDialog, QueueDialog, ProgressDialog
  17. from DrPrintBackend import PrintingError
  18.  
  19. class MainWin(gtk.Window):
  20. """MainWin object for DrPrint"""
  21.  
  22. def __init__(self, backend=None, user = None, filename = None):
  23.  
  24. self.backend = backend
  25. self.user = user
  26. self.filename = filename
  27.  
  28. gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
  29. self.set_title("DrPrint")
  30.  
  31. self.set_title = "DrPrint 1.0-rc1"
  32. self.set_border_width(10)
  33.  
  34. self.default_spacing = 5
  35.  
  36. self.connect('destroy' , gtk.main_quit)
  37.  
  38. self.build()
  39.  
  40. self.connect_all()
  41.  
  42. def build(self):
  43. """This function builds up the interface using pieces
  44. from DrPrintGui"""
  45.  
  46. # The main Layout VBox
  47. layout_box = gtk.VBox()
  48. layout_box.set_spacing( self.default_spacing )
  49.  
  50. # Inseriamo l'immagine di Dr Print
  51. image_file = "/usr/share/drprint/drprint_gui.png"
  52. try:
  53. os.stat(image_file)
  54. except OSError:
  55. image_file = "/usr/local/share/drprint/drprint_gui.png"
  56. try:
  57. os.stat(image_file)
  58. except OSError:
  59. image_file = "drprint_gui.png"
  60. drprint_img = gtk.image_new_from_file(image_file)
  61.  
  62. # Qualche istruzinoe preliminare
  63. label = gtk.Label()
  64. label.set_markup("<b>Come usare questo programma:</b>\n\
  65. <b>1)</b> Inserire nome utente e password \n<b>2)</b> Scegliere il file da stampare e la\
  66. stampante \n<b>3)</b> Premere il tasto stampa")
  67.  
  68. hbox = gtk.HBox();
  69. hbox.show()
  70. hbox.set_spacing(self.default_spacing)
  71.  
  72. hbox.pack_start(drprint_img)
  73. drprint_img.show()
  74.  
  75. hbox.pack_start( label )
  76. label.show()
  77.  
  78. layout_box.pack_start(hbox, 20)
  79.  
  80.  
  81. label = LeftAlignedLabel("<b>Autenticazione (sui computer dell'Aula 4)</b>")
  82. layout_box.pack_start(label)
  83. label.show()
  84.  
  85. hosts = ['ssh.dm.unipi.it', 'ssh1.dm.unipi.it', 'ssh2.dm.unipi.it']
  86. self.auth_block = AuthBlock(self.default_spacing, 10, user = self.user,
  87. default_hosts = hosts)
  88. layout_box.pack_start(self.auth_block)
  89. self.auth_block.show()
  90.  
  91. # The PDF file loading and print settings
  92. label = LeftAlignedLabel("<b>Configurazione stampante</b>")
  93. layout_box.pack_start(label)
  94. label.show()
  95.  
  96. # Piano terra e secondo piano
  97. printers = ['cdcpt@printserver', 'cdcpp@printserver']
  98.  
  99. # Le stampanti numerate
  100. printers.extend(map(lambda x : "cdc"+str(x), range(1,12)))
  101.  
  102. # Togliamo la cdc2 che sembra non esistere
  103. printers.remove("cdc2")
  104.  
  105. self.printer_settings_block = PrinterSettingsBlock(self.default_spacing,
  106. filename = self.filename,
  107. printers = printers)
  108. layout_box.pack_start(self.printer_settings_block)
  109. self.printer_settings_block.show()
  110.  
  111. self.orientation_select = OrientationSelect()
  112. layout_box.pack_start(self.orientation_select)
  113. self.orientation_select.show()
  114.  
  115. label = LeftAlignedLabel("<b>Configurazione Avanzata</b>")
  116. layout_box.pack_start(label)
  117. label.show()
  118.  
  119. self.page_range_block = PageRangeBlock()
  120. layout_box.pack_start(self.page_range_block)
  121. self.page_range_block.show()
  122.  
  123. label = LeftAlignedLabel( "<b>Fronte retro</b>" )
  124. layout_box.pack_start(label)
  125. label.show()
  126.  
  127. self.sides_select = SidesSelect()
  128. layout_box.pack_start(self.sides_select)
  129. self.sides_select.show()
  130.  
  131. # Bottoni finali, omogenei :)
  132. hbox = gtk.HBox(True)
  133.  
  134. self.queue_button = QueueButton()
  135. hbox.pack_start(self.queue_button)
  136. self.queue_button.show()
  137.  
  138. self.print_button = PrintButton()
  139. hbox.pack_start(self.print_button)
  140. self.print_button.show()
  141.  
  142. layout_box.pack_start(hbox)
  143. hbox.show ()
  144.  
  145.  
  146. self.add (layout_box)
  147. layout_box.show()
  148.  
  149.  
  150. def connect_all(self):
  151. self.queue_button.connect('clicked', self.queue_button_clicked_callback)
  152. self.print_button.connect('clicked', self.print_button_clicked_callback)
  153.  
  154. def queue_button_clicked_callback(self, widget):
  155. self.queue_button.set_state("running")
  156. printer = self.printer_settings_block.get_printer()
  157. username = self.auth_block.get_username()
  158. password = self.auth_block.get_password()
  159. remote_host = self.auth_block.get_remote_host()
  160. try:
  161. jobs = self.backend.get_queue(printer, remote_host, username, password)
  162. except RuntimeError, e:
  163. dialog = ErrorDialog("<b>Errore di connessione</b>",
  164. "Il seguente errore si è verificato durante il recupero della coda: %s" % e)
  165. resp = dialog.run()
  166. dialog.destroy()
  167. jobs = None
  168.  
  169. # Se siamo riusciti a scucire qualche informazione la mostriamo,
  170. # altrimenti no.
  171. self.queue_button.set_state("idle")
  172. if jobs is not None:
  173. qd = QueueDialog(jobs, printer)
  174. resp = qd.run()
  175. qd.destroy()
  176.  
  177.  
  178.  
  179. def print_button_clicked_callback(self, widget):
  180. if not self.backend == None:
  181.  
  182. # Comunichiamo all'utente che qualcosa sta succedendo
  183. self.print_button.set_state ("printing")
  184.  
  185. printer = self.printer_settings_block.get_printer()
  186. username = self.auth_block.get_username()
  187. password = self.auth_block.get_password()
  188. filename = self.printer_settings_block.get_filename()
  189. page_per_page = self.printer_settings_block.get_page_per_page()
  190. page_range = self.page_range_block.get_page_range()
  191. copies = self.printer_settings_block.get_copies()
  192. orientation = self.orientation_select.get_orientation()
  193. sides = self.sides_select.get_sides_select()
  194. remote_host = self.auth_block.get_remote_host ()
  195.  
  196. resp = gtk.RESPONSE_OK
  197.  
  198. # Proviamo a salvare l'utente utilizzato. Se non ci si riesce
  199. # non ci lamentiamo troppo.
  200. try:
  201. with open(os.path.expanduser("~/.drprint"), "w") as handle:
  202. handle.write(username)
  203. except OSError:
  204. pass
  205.  
  206. if not (filename.lower().endswith("pdf") |
  207. filename.lower().endswith("ps") |
  208. filename.lower().endswith("txt")):
  209. dialog = MessageDialog("Attenzione!",
  210. "Il file che hai scelto di stampare\n\
  211. non sembra essere un file <b>PS</b>,\n\
  212. un file <b>PDF</b> o un file di testo, e quindi \n\
  213. probabilmente il programma non stamperà\n\
  214. quello che vuoi.\n\
  215. Se vuoi continuare premi OK")
  216. resp = dialog.run()
  217. dialog.destroy()
  218.  
  219.  
  220. if resp == gtk.RESPONSE_OK:
  221. try:
  222. progress_dialog = ProgressDialog(filename)
  223. self.backend.connect('transfer-started', lambda widget : progress_dialog.show())
  224. self.backend.connect('transfer-progress',
  225. lambda widget, a, b : progress_dialog.set_fraction(a * 1.0 / b))
  226. self.backend.connect('transfer-finished', lambda widget : progress_dialog.hide())
  227. progress_dialog.connect('transfer-cancelled', self.backend.cancel_transfer)
  228. result = self.backend.send_print(printer = printer,
  229. username = username,
  230. password = password,
  231. filename = filename,
  232. page_per_page = page_per_page,
  233. page_range = page_range,
  234. copies = copies,
  235. orientation=orientation,
  236. sides = sides,
  237. remote_host = remote_host)
  238. except PrintingError, e:
  239. # Comunichiamo il fallimento
  240. dialog = ErrorDialog("<b>Errore di stampa</b>",
  241. "Il seguente errore si è verificato durante la stampa: %s." % e)
  242. dialog.run()
  243. dialog.destroy()
  244. else:
  245. if not result:
  246. dialog = InfoDialog("Stampa effettuata",
  247. "Il file %s è stato stampato correttamente sulla stampante <b>%s</b>."
  248. % (filename, printer))
  249. dialog.run()
  250. dialog.destroy()
  251.  
  252. self.print_button.set_state("idle")
  253. else:
  254. self.debug( "Sembra che non ci sia un backend attaccato\
  255. a questa interfaccia, quindi non faccio nulla")
  256.  
  257.  
  258.  
  259.  
  260. def debug(self, text):
  261. print text
  262.  
  263.  
  264.