def __init__(self, doc, number): """ :param doc: the PDF document :type doc: :class:`Poppler.Document` :param number: number of the page to fetch in the document :type number: integer """ self.page = doc.get_page(number) self.page_nb = number # Read page size self.pw, self.ph = self.page.get_size() if util.poppler_links_available(): # Read links on the page link_mapping = self.page.get_link_mapping() self.links = [] for link in link_mapping: if type(link.action) is Poppler.ActionGotoDest: dest = link.action.dest page_num = dest.page_num if dest.type == Poppler.DEST_NAMED: page_num = doc.find_dest(dest.named_dest).page_num # Page numbering starts at 0 page_num -= 1 my_link = Link(link.area.x1, link.area.y1, link.area.x2, link.area.y2, page_num) self.links.append(my_link)
def __init__(self, doc): """ :param doc: the current document :type doc: :class:`pympress.document.Document` """ black = Gdk.Color(0, 0, 0) # Common to both windows icon_list = util.load_icons() # Use notes mode by default if the document has notes self.notes_mode = doc.has_notes() # Content window self.c_win.set_title("pympress content") self.c_win.set_default_size(1024, 728) self.c_win.modify_bg(Gtk.StateFlags.NORMAL, black) self.c_win.connect("delete-event", Gtk.main_quit) self.c_win.set_icon_list(icon_list) self.c_frame.modify_bg(Gtk.StateFlags.NORMAL, black) self.c_da.modify_bg(Gtk.StateFlags.NORMAL, black) self.c_da.connect("draw", self.on_expose) self.c_da.set_name("c_da") self.c_frame.add(self.c_da) self.c_win.add(self.c_frame) self.c_win.add_events(Gdk.EventMask.KEY_PRESS_MASK | Gdk.EventMask.SCROLL_MASK) self.c_win.connect("key-press-event", self.on_navigation) self.c_win.connect("scroll-event", self.on_navigation) # Presenter window p_win = Gtk.Window(Gtk.WindowType.TOPLEVEL) p_win.set_title("pympress presenter") p_win.set_default_size(1024, 728) p_win.set_position(Gtk.WindowPosition.CENTER) p_win.connect("delete-event", Gtk.main_quit) p_win.set_icon_list(icon_list) # Put Menu and Table in VBox bigvbox = Gtk.VBox(False, 2) p_win.add(bigvbox) # UI Manager for menu ui_manager = Gtk.UIManager() # UI description ui_desc = ''' <menubar name="MenuBar"> <menu action="File"> <menuitem action="Quit"/> </menu> <menu action="Presentation"> <menuitem action="Pause timer"/> <menuitem action="Reset timer"/> <menuitem action="Fullscreen"/> <menuitem action="Notes mode"/> </menu> <menu action="Help"> <menuitem action="About"/> </menu> </menubar>''' ui_manager.add_ui_from_string(ui_desc) # Accelerator group accel_group = ui_manager.get_accel_group() p_win.add_accel_group(accel_group) # Action group action_group = Gtk.ActionGroup("MenuBar") # Name, stock id, label, accelerator, tooltip, action [, is_active] action_group.add_actions([ ("File", None, "_File"), ("Presentation", None, "_Presentation"), ("Help", None, "_Help"), ("Quit", Gtk.STOCK_QUIT, "_Quit", "q", None, Gtk.main_quit), ("Reset timer", None, "_Reset timer", "r", None, self.reset_timer), ("About", None, "_About", None, None, self.menu_about), ]) action_group.add_toggle_actions([ ("Pause timer", None, "_Pause timer", "p", None, self.switch_pause, True), ("Fullscreen", None, "_Fullscreen", "f", None, self.switch_fullscreen, False), ("Notes mode", None, "_Note mode", "n", None, self.switch_mode, self.notes_mode), ]) ui_manager.insert_action_group(action_group) # Add menu bar to the window menubar = ui_manager.get_widget('/MenuBar') h = ui_manager.get_widget('/MenuBar/Help') h.set_right_justified(True) bigvbox.pack_start(menubar, False, False, 0) # A little space around everything in the window align = Gtk.Alignment() align.set(0.5, 0.5, 1, 1) align.set_padding(20, 20, 20, 20) # Table table = Gtk.Table(2, 10, False) table.set_col_spacings(25) table.set_row_spacings(25) align.add(table) bigvbox.pack_end(align, False, False, 0) # "Current slide" frame frame = Gtk.Frame() frame.set_label("Current slide") table.attach(frame, 0, 6, 0, 1) align = Gtk.Alignment() align.set(0.5, 0.5, 1, 1) align.set_padding(0, 0, 12, 0) frame.add(align) vbox = Gtk.VBox() align.add(vbox) vbox.pack_start(self.p_frame_cur, False, False, 0) self.eb_cur.set_visible_window(False) self.eb_cur.connect("event", self.on_label_event) vbox.pack_start(self.eb_cur, False, False, 10) self.p_da_cur.modify_bg(Gtk.StateFlags.NORMAL, black) self.p_da_cur.connect("draw", self.on_expose) self.p_da_cur.set_name("p_da_cur") self.p_da_cur.set_size_request(0, 400) #FIXME: size of preview is fixed self.p_frame_cur.add(self.p_da_cur) # "Current slide" label and entry self.label_cur.set_justify(Gtk.Justification.CENTER) self.label_cur.set_use_markup(True) self.eb_cur.add(self.label_cur) self.entry_cur.set_alignment(0.5) self.entry_cur.modify_font(Pango.FontDescription('36')) # "Next slide" frame frame = Gtk.Frame() frame.set_label("Next slide") table.attach(frame, 6, 10, 0, 1) align = Gtk.Alignment() align.set(0.5, 0.5, 1, 1) align.set_padding(0, 0, 12, 0) frame.add(align) vbox = Gtk.VBox() align.add(vbox) self.label_next.set_justify(Gtk.Justification.CENTER) self.label_next.set_use_markup(True) vbox.pack_end(self.label_next, False, False, 10) vbox.pack_end(self.p_frame_next, False, False, 0) self.p_da_next.modify_bg(Gtk.StateFlags.NORMAL, black) self.p_da_next.connect("draw", self.on_expose) self.p_da_next.set_name("p_da_next") self.p_da_next.set_size_request(0, 290) #FIXME: size of preview is fixed self.p_frame_next.add(self.p_da_next) # "Time elapsed" frame frame = Gtk.Frame() frame.set_label("Time elapsed") table.attach(frame, 0, 5, 1, 2, yoptions=Gtk.AttachOptions.FILL) align = Gtk.Alignment() align.set(0.5, 0.5, 1, 1) align.set_padding(10, 10, 12, 0) frame.add(align) self.label_time.set_justify(Gtk.Justification.CENTER) self.label_time.set_use_markup(True) align.add(self.label_time) # "Clock" frame frame = Gtk.Frame() frame.set_label("Clock") table.attach(frame, 5, 10, 1, 2, yoptions=Gtk.AttachOptions.FILL) align = Gtk.Alignment() align.set(0.5, 0.5, 1, 1) align.set_padding(10, 10, 12, 0) frame.add(align) self.label_clock.set_justify(Gtk.Justification.CENTER) self.label_clock.set_use_markup(True) align.add(self.label_clock) p_win.connect("destroy", Gtk.main_quit) p_win.show_all() # Add events p_win.add_events(Gdk.EventMask.KEY_PRESS_MASK | Gdk.EventMask.SCROLL_MASK) p_win.connect("key-press-event", self.on_navigation) p_win.connect("scroll-event", self.on_navigation) # Hyperlinks if available if util.poppler_links_available(): self.c_da.add_events(Gdk.EventMask.BUTTON_PRESS_MASK | Gdk.EventMask.POINTER_MOTION_MASK) self.c_da.connect("button-press-event", self.on_link) self.c_da.connect("motion-notify-event", self.on_link) self.p_da_cur.add_events(Gdk.EventMask.BUTTON_PRESS_MASK | Gdk.EventMask.POINTER_MOTION_MASK) self.p_da_cur.connect("button-press-event", self.on_link) self.p_da_cur.connect("motion-notify-event", self.on_link) self.p_da_next.add_events(Gdk.EventMask.BUTTON_PRESS_MASK | Gdk.EventMask.POINTER_MOTION_MASK) self.p_da_next.connect("button-press-event", self.on_link) self.p_da_next.connect("motion-notify-event", self.on_link) # Setup timer GLib.timeout_add(250, self.update_time) # Document self.doc = doc # Show all windows self.c_win.show_all() p_win.show_all()