def open(self, gtk_app=None): """Open the main window. """ load_accel_map() self.window = (Gtk.ApplicationWindow.new(gtk_app) if gtk_app else Gtk.Window.new(type=Gtk.WindowType.TOPLEVEL)) self.window.set_title(self.title) self.window.set_default_size(*self.size) # set default icons of gaphor windows icon_dir = os.path.abspath( pkg_resources.resource_filename("gaphor.ui", "pixmaps")) icons = (GdkPixbuf.Pixbuf.new_from_file(os.path.join(icon_dir, f)) for f in ICONS) self.window.set_icon_list(list(icons)) self.window.add_accel_group(self.action_manager.get_accel_group()) # Create a full featured window. vbox = Gtk.VBox() self.window.add(vbox) vbox.show() menubar = self.action_manager.get_widget(self.menubar_path) if menubar: vbox.pack_start(menubar, False, True, 0) toolbar = self.action_manager.get_widget(self.toolbar_path) if toolbar: vbox.pack_start(toolbar, False, True, 0) def _factory(name): comp = self.get_ui_component(name) log.debug("open component %s" % str(comp)) return comp.open() layout_file = pkg_resources.resource_filename("gaphor.ui", "layout.xml") self.layout = [] # Gtk.Notebook() with open(layout_file) as f: deserialize(self.layout, vbox, f.read(), _factory) vbox.show() # TODO: add statusbar self.window.present() self.window.connect("delete-event", self._on_window_delete) # We want to store the window size, so it can be reloaded on startup self.window.set_resizable(True) self.window.connect("size-allocate", self._on_window_size_allocate) em = self.event_manager em.subscribe(self._on_file_manager_state_changed) em.subscribe(self._on_undo_manager_state_changed) em.subscribe(self._new_model_content)
def open(self, gtk_app=None): """Open the main window. """ load_accel_map() self.window = (Gtk.ApplicationWindow.new(gtk_app) if gtk_app else Gtk.Window.new(type=Gtk.WindowType.TOPLEVEL)) self.window.set_title(self.title) self.window.set_default_size(*self.size) self.window.add_accel_group(self.action_manager.get_accel_group()) # Create a full featured window. vbox = Gtk.VBox() self.window.add(vbox) vbox.show() menubar = self.action_manager.get_widget( self.action_manager.menubar_path) if menubar: vbox.pack_start(menubar, False, True, 0) toolbar = self.action_manager.get_widget( self.action_manager.toolbar_path) if toolbar: vbox.pack_start(toolbar, False, True, 0) def _factory(name): comp = self.get_ui_component(name) log.debug("open component %s" % str(comp)) return comp.open() self.layout = [] with importlib.resources.open_text("gaphor.ui", "layout.xml") as f: deserialize(self.layout, vbox, f.read(), _factory) vbox.show() self.window.present() self.window.connect("delete-event", self._on_window_delete) # We want to store the window size, so it can be reloaded on startup self.window.set_resizable(True) self.window.connect("size-allocate", self._on_window_size_allocate) em = self.event_manager em.subscribe(self._on_file_manager_state_changed) em.subscribe(self._on_undo_manager_state_changed) em.subscribe(self._new_model_content)
def open(self, gtk_app=None): """Open the main window. """ builder = new_builder() self.window = builder.get_object("main-window") self.window.set_application(gtk_app) hamburger = builder.get_object("hamburger") hamburger.bind_model( create_hamburger_model(self.export_menu.menu, self.tools_menu.menu), None) recent_files = builder.get_object("recent-files") recent_files.bind_model(create_recent_files_model(), None) self.set_title() self.window.set_default_size(*self.size) def _factory(name): comp = self.get_ui_component(name) widget = comp.open() # Okay, this may be hackish. Action groups on component level are also added # to the main window. This ensures that we can call those items from the # (main) menus as well. Also this makes enabling/disabling work. for prefix in widget.list_action_prefixes(): assert prefix not in ("app", "win") self.window.insert_action_group( prefix, widget.get_action_group(prefix)) return widget with importlib.resources.open_text("gaphor.ui", "layout.xml") as f: self.layout = deserialize(self.window, f.read(), _factory) action_group, accel_group = window_action_group( self.component_registry) self.window.insert_action_group("win", action_group) self.window.add_accel_group(accel_group) self.window.show_all() self.window.connect("notify::is-active", self._on_window_active) self.window.connect("delete-event", self._on_window_delete) # We want to store the window size, so it can be reloaded on startup self.window.set_resizable(True) self.window.connect("size-allocate", self._on_window_size_allocate) em = self.event_manager em.subscribe(self._on_file_manager_state_changed) em.subscribe(self._on_undo_manager_state_changed) em.subscribe(self._new_model_content) em.subscribe(self._on_action_enabled)
def open(self, gtk_app=None): """Open the main window. """ self.window = (Gtk.ApplicationWindow.new(gtk_app) if gtk_app else Gtk.Window.new(type=Gtk.WindowType.TOPLEVEL)) def button(label, action_name): b = Gtk.Button.new_with_label(label) b.set_action_name(action_name) b.show() return b header = Gtk.HeaderBar() header.set_show_close_button(True) self.window.set_titlebar(header) header.show() button_box = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 0) button_box.get_style_context().add_class("linked") button_box.pack_start(button(gettext("Open"), "win.file-open"), False, False, 0) button_box.pack_start(create_recent_files_button(), False, False, 0) button_box.show() header.pack_start(button_box) b = Gtk.Button.new_from_icon_name("gaphor-new-diagram-symbolic", Gtk.IconSize.MENU) b.set_action_name("tree-view.create-diagram") b.show() header.pack_start(b) header.pack_end( hamburger_menu( create_hamburger_model(self.export_menu.menu, self.tools_menu.menu))) header.pack_end(button(gettext("Save"), "win.file-save")) b = Gtk.MenuButton.new() image = Gtk.Image.new_from_icon_name("document-edit-symbolic", Gtk.IconSize.MENU) b.add(image) b.set_action_name("win.show-editors") b.show_all() header.pack_end(b) self.set_title() self.window.set_default_size(*self.size) def _factory(name): comp = self.get_ui_component(name) widget = comp.open() # Okay, this may be hackish. Action groups on component level are also added # to the main window. This ensures that we can call those items from the # (main) menus as well. Also this makes enabling/disabling work. for prefix in widget.list_action_prefixes(): assert prefix not in ("app", "win") self.window.insert_action_group( prefix, widget.get_action_group(prefix)) return widget self.layout = [] with importlib.resources.open_text("gaphor.ui", "layout.xml") as f: deserialize(self.layout, self.window, f.read(), _factory) action_group, accel_group = window_action_group( self.component_registry) self.window.insert_action_group("win", action_group) self.window.add_accel_group(accel_group) self.window.present() self.window.connect("delete-event", self._on_window_delete) # We want to store the window size, so it can be reloaded on startup self.window.set_resizable(True) self.window.connect("size-allocate", self._on_window_size_allocate) em = self.event_manager em.subscribe(self._on_file_manager_state_changed) em.subscribe(self._on_undo_manager_state_changed) em.subscribe(self._new_model_content) em.subscribe(self._on_action_enabled)
def open(self, gtk_app=None): """Open the main window. """ load_accel_map() self.window = ( Gtk.ApplicationWindow.new(gtk_app) if gtk_app else Gtk.Window.new(type=Gtk.WindowType.TOPLEVEL) ) self.window.set_title(self.title) self.window.set_default_size(*self.size) # set default icons of gaphor windows icon_dir = os.path.abspath( pkg_resources.resource_filename("gaphor.ui", "pixmaps") ) icons = ( GdkPixbuf.Pixbuf.new_from_file(os.path.join(icon_dir, f)) for f in ICONS ) self.window.set_icon_list(list(icons)) self.window.add_accel_group(self.action_manager.get_accel_group()) # Create a full featured window. vbox = Gtk.VBox() self.window.add(vbox) vbox.show() menubar = self.action_manager.get_widget(self.menubar_path) if menubar: vbox.pack_start(menubar, False, True, 0) toolbar = self.action_manager.get_widget(self.toolbar_path) if toolbar: vbox.pack_start(toolbar, False, True, 0) def _factory(name): comp = self.get_ui_component(name) log.debug("open component %s" % str(comp)) return comp.open() layout_file = pkg_resources.resource_filename("gaphor.ui", "layout.xml") self.layout = [] # Gtk.Notebook() with open(layout_file) as f: deserialize(self.layout, vbox, f.read(), _factory) vbox.show() # TODO: add statusbar self.window.present() self.window.connect("delete-event", self._on_window_delete) # We want to store the window size, so it can be reloaded on startup self.window.set_resizable(True) self.window.connect("size-allocate", self._on_window_size_allocate) cr = self.component_registry cr.register_handler(self._on_file_manager_state_changed) cr.register_handler(self._on_undo_manager_state_changed) cr.register_handler(self._new_model_content)
def open(self): load_accel_map() self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.window.set_title(self.title) self.window.set_size_request(*self.size) self.window.set_resizable(self.resizable) # set default icons of gaphor windows icon_dir = os.path.abspath( pkg_resources.resource_filename('gaphor.ui', 'pixmaps')) icons = (gtk.gdk.pixbuf_new_from_file(os.path.join(icon_dir, f)) for f in ICONS) self.window.set_icon_list(*icons) self.window.add_accel_group(self.ui_manager.get_accel_group()) # Create a full featured window. vbox = gtk.VBox() self.window.add(vbox) vbox.show() menubar = self.ui_manager.get_widget(self.menubar_path) if menubar: vbox.pack_start(menubar, expand=False) toolbar = self.ui_manager.get_widget(self.toolbar_path) if toolbar: vbox.pack_start(toolbar, expand=False) def _factory(name): comp = self.component_registry.get_utility(IUIComponent, name) log.debug('open component %s' % str(comp)) return comp.open() filename = pkg_resources.resource_filename('gaphor.ui', 'layout.xml') self.layout = DockLayout() with open(filename) as f: deserialize(self.layout, vbox, f.read(), _factory) self.layout.connect('item-closed', self._on_item_closed) self.layout.connect('item-selected', self._on_item_selected) vbox.show() # TODO: add statusbar self.window.show() self.window.connect('delete-event', self._on_window_delete) # We want to store the window size, so it can be reloaded on startup self.window.set_property('allow-shrink', True) self.window.connect('size-allocate', self._on_window_size_allocate) self.window.connect('destroy', self._on_window_destroy) #self.window.connect_after('key-press-event', self._on_key_press_event) cr = self.component_registry cr.register_handler(self._on_file_manager_state_changed) cr.register_handler(self._on_undo_manager_state_changed) cr.register_handler(self._new_model_content)