@@ -323,35 +323,37 @@ class DownloadState(object):
323323
324324def load_serialized_images ():
325325 global box_logo_pixbuf , window_icon
326- import gtk
326+ import gi
327+ gi .require_version ('GdkPixbuf' , '2.0' )
328+ from gi .repository import GdkPixbuf
327329 box_logo_pixbuf = @IMAGEDATA64 @
328330 window_icon = @IMAGEDATA16 @
329331
330332GUI_AVAILABLE = os .environ .get ("DISPLAY" , '' )
331333
332334if GUI_AVAILABLE :
333335 def download ():
334- import pygtk
335- pygtk .require ("2.0" )
336- import gtk
337- import gobject
338- import pango
336+ import gi
337+ gi .require_version ('Gdk' , '3.0' )
338+ gi .require_version ('Gtk' , '3.0' )
339+ from gi .repository import GObject
340+ from gi .repository import Gdk
341+ from gi .repository import Gtk
342+ from gi .repository import Pango
339343 import webbrowser
340344
341- gtk .gdk .threads_init ()
342-
343345 load_serialized_images ()
344346
345347 global FatalVisibleError
346348 def FatalVisibleError (s ):
347- error = gtk .MessageDialog (parent = None ,
348- flags = gtk . DIALOG_MODAL ,
349- type = gtk . MESSAGE_ERROR ,
350- buttons = gtk . BUTTONS_OK ,
349+ error = Gtk .MessageDialog (parent = None ,
350+ flags = Gtk . DialogFlags . MODAL ,
351+ type = Gtk . MessageType . ERROR ,
352+ buttons = Gtk . ButtonsType . OK ,
351353 message_format = s )
352354 error .set_title ("Error" )
353355 error .run ()
354- gtk .main_quit ()
356+ Gtk .main_quit ()
355357 sys .exit (- 1 )
356358
357359 class GeneratorTask (object ):
@@ -369,17 +371,17 @@ if GUI_AVAILABLE:
369371 ret = ()
370372 if not isinstance (ret , tuple ):
371373 ret = (ret ,)
372- gobject .idle_add (self .loop_callback , * ret )
374+ GObject .idle_add (self .loop_callback , * ret )
373375
374376 if self ._stopped :
375377 thread .exit ()
376378 except Exception , ex :
377379 print ex
378380 if self .on_exception is not None :
379- gobject .idle_add (self .on_exception , ex )
381+ GObject .idle_add (self .on_exception , ex )
380382 else :
381383 if self .on_done is not None :
382- gobject .idle_add (self .on_done )
384+ GObject .idle_add (self .on_done )
383385
384386 def start (self , * args , ** kwargs ):
385387 t = threading .Thread (target = self ._run , args = args , kwargs = kwargs )
@@ -389,7 +391,7 @@ if GUI_AVAILABLE:
389391 def stop (self ):
390392 self ._stopped = True
391393
392- class DownloadDialog (gtk .Dialog ):
394+ class DownloadDialog (Gtk .Dialog ):
393395 def handle_delete_event (self , wid , ev , data = None ):
394396 self .handle_cancel (wid )
395397
@@ -401,7 +403,7 @@ if GUI_AVAILABLE:
401403 self .task .stop ()
402404 if self .download :
403405 self .download .cancel ()
404- gtk .main_quit ()
406+ Gtk .main_quit ()
405407 self .user_cancelled = True
406408
407409 def handle_ok (self , button ):
@@ -443,7 +445,7 @@ if GUI_AVAILABLE:
443445 self .update_progress (UNPACKING , 1.0 )
444446 if not self .download .is_dropbox_valid ():
445447 FatalVisibleError (ERROR_INVALID_DROPBOX )
446- gtk .main_quit ()
448+ Gtk .main_quit ()
447449
448450 def error (ex ):
449451 if isinstance (ex , SignatureVerifyError ):
@@ -467,15 +469,15 @@ if GUI_AVAILABLE:
467469 def label_motion (self , widget , event ):
468470 offx , offy = self .label .get_layout_offsets ()
469471 layout = self .label .get_layout ()
470- index = layout .xy_to_index (int ((offx + event .x )* pango .SCALE ),
471- int ((offy + event .y )* pango .SCALE ))[0 ]
472+ index = layout .xy_to_index (int ((offx + event .x )* Pango .SCALE ),
473+ int ((offy + event .y )* Pango .SCALE ))[1 ]
472474 link_index = layout .get_text ().find (LINK )
473475 if index >= link_index and index < link_index + len (LINK ):
474476 self .hovering = True
475- self .label_box .window .set_cursor (gtk . gdk . Cursor (gtk . gdk .HAND2 ))
477+ self .label_box .get_window () .set_cursor (Gdk . Cursor (Gdk . CursorType .HAND2 ))
476478 else :
477479 self .hovering = False
478- self .label_box .window .set_cursor (gtk . gdk . Cursor (gtk . gdk .ARROW ))
480+ self .label_box .get_window () .set_cursor (Gdk . Cursor (Gdk . CursorType .ARROW ))
479481
480482
481483 def __init__ (self ):
@@ -488,49 +490,51 @@ if GUI_AVAILABLE:
488490 self .user_cancelled = False
489491 self .task = None
490492
491- self .ok = ok = gtk .Button (stock = gtk .STOCK_OK )
493+ self .ok = ok = Gtk .Button (stock = Gtk .STOCK_OK )
492494 ok .connect ('clicked' , self .handle_ok )
493495 self .action_area .add (ok )
494496 ok .show ()
495497
496- cancel = gtk .Button (stock = gtk .STOCK_CANCEL )
498+ cancel = Gtk .Button (stock = Gtk .STOCK_CANCEL )
497499 cancel .connect ('clicked' , self .handle_cancel )
498500 self .action_area .add (cancel )
499501 cancel .show ()
500502
501503 self .connect ('delete_event' , self .handle_delete_event )
502504
503- self .box_logo = gtk . image_new_from_pixbuf (box_logo_pixbuf )
505+ self .box_logo = Gtk . Image . new_from_pixbuf (box_logo_pixbuf )
504506 self .box_logo .show ()
505507
506508 self .set_icon (window_icon )
507509
508- self .progress = gtk .ProgressBar ()
510+ self .progress = Gtk .ProgressBar ()
509511 self .progress .set_property ('width-request' , 300 )
512+ self .progress .set_property ('show-text' , True )
510513
511- self .label = gtk .Label ()
514+ self .label = Gtk .Label ()
512515 GPG_WARNING_MSG = (u"\n \n " + GPG_WARNING ) if not gpg and not gpgme else u""
513516 self .label .set_markup ('%s <span foreground="#000099" underline="single" weight="bold">%s</span>\n \n %s%s' % (INFO , LINK , WARNING , GPG_WARNING_MSG ))
514517 self .label .set_line_wrap (True )
518+ self .label .set_max_width_chars (42 )
515519 self .label .set_property ('width-request' , 300 )
516520 self .label .show ()
517521
518- self .label_box = gtk .EventBox ()
522+ self .label_box = Gtk .EventBox ()
519523 self .label_box .add (self .label )
520524 self .label_box .connect ("button-release-event" , self .mouse_up )
521525 self .label_box .connect ("button-press-event" , self .mouse_down )
522526 self .label_box .connect ("motion-notify-event" , self .label_motion )
523527
524528 self .label_box .show ()
525529 def on_realize (widget ):
526- self .label_box .add_events (gtk . gdk .POINTER_MOTION_MASK )
530+ self .label_box .add_events (Gdk . EventMask .POINTER_MOTION_MASK )
527531 self .label_box .connect ("realize" , on_realize )
528532
529- self .hbox = gtk .HBox (spacing = 10 )
533+ self .hbox = Gtk .HBox (spacing = 10 )
530534 self .hbox .set_property ('border-width' ,10 )
531- self .hbox .pack_start (self .box_logo , False , False )
532- self .hbox .pack_start (self .label_box , False , False )
533- self .hbox .pack_start (self .progress , False , False )
535+ self .hbox .pack_start (self .box_logo , False , False , 0 )
536+ self .hbox .pack_start (self .label_box , False , False , 0 )
537+ self .hbox .pack_start (self .progress , False , False , 0 )
534538 self .hbox .show ()
535539
536540 self .vbox .add (self .hbox )
@@ -539,17 +543,17 @@ if GUI_AVAILABLE:
539543
540544 try :
541545 if can_reroll_autostart ():
542- dont_show_again = gtk .CheckButton ("_Don't show this again" )
546+ dont_show_again = Gtk .CheckButton . new_with_mnemonic ("_Don't show this again" )
543547 dont_show_again .connect ('toggled' , self .handle_dont_show_toggle )
544548 dont_show_again .show ()
545549
546- self .dont_show_again_align = gtk .Alignment (xalign = 1.0 , yalign = 0.0 , xscale = 0.0 , yscale = 0.0 )
550+ self .dont_show_again_align = Gtk .Alignment (xalign = 1.0 , yalign = 0.0 , xscale = 0.0 , yscale = 0.0 )
547551 self .dont_show_again_align .add (dont_show_again )
548552 self .dont_show_again_align .show ()
549553
550- hbox = gtk .HBox ()
554+ hbox = Gtk .HBox ()
551555 hbox .set_property ('border-width' , 10 )
552- hbox .pack_start (self .dont_show_again_align , True , True )
556+ hbox .pack_start (self .dont_show_again_align , True , True , 0 )
553557 hbox .show ()
554558
555559 self .vbox .add (hbox )
@@ -562,7 +566,7 @@ if GUI_AVAILABLE:
562566
563567 dialog = DownloadDialog ()
564568 dialog .show ()
565- gtk .main ()
569+ Gtk .main ()
566570 if dialog .user_cancelled :
567571 raise Exception ("user cancelled download!!!" )
568572else :
0 commit comments