@@ -323,35 +323,37 @@ class DownloadState(object):
323
323
324
324
def load_serialized_images ():
325
325
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
327
329
box_logo_pixbuf = @IMAGEDATA64 @
328
330
window_icon = @IMAGEDATA16 @
329
331
330
332
GUI_AVAILABLE = os .environ .get ("DISPLAY" , '' )
331
333
332
334
if GUI_AVAILABLE :
333
335
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
339
343
import webbrowser
340
344
341
- gtk .gdk .threads_init ()
342
-
343
345
load_serialized_images ()
344
346
345
347
global FatalVisibleError
346
348
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 ,
351
353
message_format = s )
352
354
error .set_title ("Error" )
353
355
error .run ()
354
- gtk .main_quit ()
356
+ Gtk .main_quit ()
355
357
sys .exit (- 1 )
356
358
357
359
class GeneratorTask (object ):
@@ -369,17 +371,17 @@ if GUI_AVAILABLE:
369
371
ret = ()
370
372
if not isinstance (ret , tuple ):
371
373
ret = (ret ,)
372
- gobject .idle_add (self .loop_callback , * ret )
374
+ GObject .idle_add (self .loop_callback , * ret )
373
375
374
376
if self ._stopped :
375
377
thread .exit ()
376
378
except Exception , ex :
377
379
print ex
378
380
if self .on_exception is not None :
379
- gobject .idle_add (self .on_exception , ex )
381
+ GObject .idle_add (self .on_exception , ex )
380
382
else :
381
383
if self .on_done is not None :
382
- gobject .idle_add (self .on_done )
384
+ GObject .idle_add (self .on_done )
383
385
384
386
def start (self , * args , ** kwargs ):
385
387
t = threading .Thread (target = self ._run , args = args , kwargs = kwargs )
@@ -389,7 +391,7 @@ if GUI_AVAILABLE:
389
391
def stop (self ):
390
392
self ._stopped = True
391
393
392
- class DownloadDialog (gtk .Dialog ):
394
+ class DownloadDialog (Gtk .Dialog ):
393
395
def handle_delete_event (self , wid , ev , data = None ):
394
396
self .handle_cancel (wid )
395
397
@@ -401,7 +403,7 @@ if GUI_AVAILABLE:
401
403
self .task .stop ()
402
404
if self .download :
403
405
self .download .cancel ()
404
- gtk .main_quit ()
406
+ Gtk .main_quit ()
405
407
self .user_cancelled = True
406
408
407
409
def handle_ok (self , button ):
@@ -443,7 +445,7 @@ if GUI_AVAILABLE:
443
445
self .update_progress (UNPACKING , 1.0 )
444
446
if not self .download .is_dropbox_valid ():
445
447
FatalVisibleError (ERROR_INVALID_DROPBOX )
446
- gtk .main_quit ()
448
+ Gtk .main_quit ()
447
449
448
450
def error (ex ):
449
451
if isinstance (ex , SignatureVerifyError ):
@@ -467,15 +469,15 @@ if GUI_AVAILABLE:
467
469
def label_motion (self , widget , event ):
468
470
offx , offy = self .label .get_layout_offsets ()
469
471
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 ]
472
474
link_index = layout .get_text ().find (LINK )
473
475
if index >= link_index and index < link_index + len (LINK ):
474
476
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 ))
476
478
else :
477
479
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 ))
479
481
480
482
481
483
def __init__ (self ):
@@ -488,49 +490,51 @@ if GUI_AVAILABLE:
488
490
self .user_cancelled = False
489
491
self .task = None
490
492
491
- self .ok = ok = gtk .Button (stock = gtk .STOCK_OK )
493
+ self .ok = ok = Gtk .Button (stock = Gtk .STOCK_OK )
492
494
ok .connect ('clicked' , self .handle_ok )
493
495
self .action_area .add (ok )
494
496
ok .show ()
495
497
496
- cancel = gtk .Button (stock = gtk .STOCK_CANCEL )
498
+ cancel = Gtk .Button (stock = Gtk .STOCK_CANCEL )
497
499
cancel .connect ('clicked' , self .handle_cancel )
498
500
self .action_area .add (cancel )
499
501
cancel .show ()
500
502
501
503
self .connect ('delete_event' , self .handle_delete_event )
502
504
503
- self .box_logo = gtk . image_new_from_pixbuf (box_logo_pixbuf )
505
+ self .box_logo = Gtk . Image . new_from_pixbuf (box_logo_pixbuf )
504
506
self .box_logo .show ()
505
507
506
508
self .set_icon (window_icon )
507
509
508
- self .progress = gtk .ProgressBar ()
510
+ self .progress = Gtk .ProgressBar ()
509
511
self .progress .set_property ('width-request' , 300 )
512
+ self .progress .set_property ('show-text' , True )
510
513
511
- self .label = gtk .Label ()
514
+ self .label = Gtk .Label ()
512
515
GPG_WARNING_MSG = (u"\n \n " + GPG_WARNING ) if not gpg and not gpgme else u""
513
516
self .label .set_markup ('%s <span foreground="#000099" underline="single" weight="bold">%s</span>\n \n %s%s' % (INFO , LINK , WARNING , GPG_WARNING_MSG ))
514
517
self .label .set_line_wrap (True )
518
+ self .label .set_max_width_chars (42 )
515
519
self .label .set_property ('width-request' , 300 )
516
520
self .label .show ()
517
521
518
- self .label_box = gtk .EventBox ()
522
+ self .label_box = Gtk .EventBox ()
519
523
self .label_box .add (self .label )
520
524
self .label_box .connect ("button-release-event" , self .mouse_up )
521
525
self .label_box .connect ("button-press-event" , self .mouse_down )
522
526
self .label_box .connect ("motion-notify-event" , self .label_motion )
523
527
524
528
self .label_box .show ()
525
529
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 )
527
531
self .label_box .connect ("realize" , on_realize )
528
532
529
- self .hbox = gtk .HBox (spacing = 10 )
533
+ self .hbox = Gtk .HBox (spacing = 10 )
530
534
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 )
534
538
self .hbox .show ()
535
539
536
540
self .vbox .add (self .hbox )
@@ -539,17 +543,17 @@ if GUI_AVAILABLE:
539
543
540
544
try :
541
545
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" )
543
547
dont_show_again .connect ('toggled' , self .handle_dont_show_toggle )
544
548
dont_show_again .show ()
545
549
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 )
547
551
self .dont_show_again_align .add (dont_show_again )
548
552
self .dont_show_again_align .show ()
549
553
550
- hbox = gtk .HBox ()
554
+ hbox = Gtk .HBox ()
551
555
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 )
553
557
hbox .show ()
554
558
555
559
self .vbox .add (hbox )
@@ -562,7 +566,7 @@ if GUI_AVAILABLE:
562
566
563
567
dialog = DownloadDialog ()
564
568
dialog .show ()
565
- gtk .main ()
569
+ Gtk .main ()
566
570
if dialog .user_cancelled :
567
571
raise Exception ("user cancelled download!!!" )
568
572
else :
0 commit comments