現在 Comipoli の GTK4 化の準備をしているんだが。
まずメニュー。
GTK3 は GtkModelButton を GtkBox に入れソレを GtkPopoverMenu に。
だったけど GTK4 は GtkModelButton が廃止されている。
なので GTK4 は GMenuItem を GtkPopoverMenu に入れろとあるんだが。
GMenuItem をコードで作る方法はどこにも書いていない。
しかたがないので XML で作る。
それから、GtkButton の image プロパティが廃止されていた。
代わりに icon-name が追加、つまり GtkImage を時前で用意しなくてもいい。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | #!/usr/bin/env python3 from gi.repository import Gtk menu_model = ''' <?xml version="1.0" encoding="UTF-8"?> <interface> <menu id='comipoli-menu'> <section> <item> <attribute name='label' translatable='yes'>_Open</attribute> <attribute name='action'>app.new_file_action</attribute> </item> <item> <attribute name='label' translatable='yes'>_New Window</attribute> <attribute name='action'>app.new_window_action</attribute> </item> <item> <attribute name='label' translatable='yes'>_Preference</attribute> <attribute name='action'>app.preference_action</attribute> </item> <item> <attribute name='label' translatable='yes'>_Keyboard Shortcut</attribute> <attribute name='action'>app.shortcut_action</attribute> </item> <item> <attribute name='label' translatable='yes'>_About</attribute> <attribute name='action'>app.about_action</attribute> </item> <item> <attribute name='label' translatable='yes'>_Quit</attribute> <attribute name='action'>app.quit_action</attribute> </item> </section> </menu> </interface> ''' class ComipoliMenuButton(Gtk.MenuButton): def __init__( self ): ''' GTK3 # MenuIten menu_open = Gtk.ModelButton(active=True, action_name='app.new_file_action', text='_Open', use_markup=True) menu_new = Gtk.ModelButton(active=True, action_name='app.new_window_action', text='_New Window', use_markup=True) menu_pref = Gtk.ModelButton(active=True, action_name='app.preference_action', text='_Preference', use_markup=True) menu_kbd = Gtk.ModelButton(active=True, action_name='app.shortcut_action', text='_Keyboard Shortcut', use_markup=True) menu_about = Gtk.ModelButton(active=True, action_name='app.about_action', text='_About', use_markup=True) menu_quit = Gtk.ModelButton(active=True, action_name='app.quit_action', text='_Quit', use_markup=True) # Box vbox = Gtk.Box(visible=True, margin=10, orientation=Gtk.Orientation.VERTICAL) vbox.pack_start(menu_open, False, False, 0) vbox.pack_start(Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL), False, False, 0) vbox.pack_start(menu_new, False, False, 0) vbox.pack_start(menu_pref, False, False, 0) vbox.pack_start(menu_kbd, False, False, 0) vbox.pack_start(menu_about, False, False, 0) vbox.pack_start(Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL), False, False, 0) vbox.pack_start(menu_quit, False, False, 0) # PopoverMenu self.popover = Gtk.PopoverMenu() self.popover.add(vbox) ''' builder = Gtk.Builder.new_from_string(menu_model, len (menu_model)) model = builder.get_object( 'comipoli-menu' ) self .popover = Gtk.PopoverMenu.new_from_model(model) ''' GTK3 #image = Gtk.Image(icon_name='open-menu-symbolic') #Gtk.MenuButton.__init__(self, can_focus=False, focus_on_click=False, image=image, visible=True, popover=self.popover) ''' Gtk.MenuButton.__init__( self , can_focus = False , focus_on_click = False , icon_name = 'open-menu-symbolic' , visible = True , popover = self .popover) def do_toggled( self ): if self .props.active: self .popover.show_all() else : self .popover.hide() |
丸ごと作り替えだった。
そうそう、GtkShortcutsWindow の pack_start が廃止。
かつ GtkBox のサブクラスに、なので append で配置する。
orientation=Gtk.Orientation.HORIZONTAL 指定を忘れずに。
最初縦に配置されてしばらく悩んでしまった。
そんなことより。
GtkShortcutsWindow を表示すると上記エラーを吐く。
もちろんサーチバーは出ない、これバグだよな。
Fedora 36 では修正されているのかな?
まだ色々とあるけど解決していないのでまた今度。