示例#1
0
    def __init__(self, parent, task):
        self._task = task
        Menu.__init__(self, parent)

        # done/todo
        if task.completed:
            self.item_add(None, 'Mark as Todo', None,
                          lambda m,i: self._completed_set(False))
        else:
            self.item_add(None, 'Mark as Done', None,
                          lambda m,i: self._completed_set(True))

        # priority
        it_prio = self.item_add(None, 'Priority')
        for p in ('A', 'B', 'C', 'D', 'E'):
            icon = 'arrow_right' if task.priority == p else None
            self.item_add(it_prio, p, icon, self._priority_cb)

        # completion progress
        it_prog = self.item_add(None, 'Progress')
        for p in range(0, 101, 10):
            if task.progress is not None and p <= task.progress < p + 10:
                icon = 'arrow_right'
            else:
                icon = None
            self.item_add(it_prog, '%d %%' % p, icon, self._progress_cb)

        # delete task
        self.item_separator_add()
        self.item_add(None, 'Delete task', 'delete', self._confirm_delete)

        # show the menu at mouse position
        x, y = self.evas.pointer_canvas_xy_get()
        self.move(x + 2, y)
        self.show()
示例#2
0
    def __init__(self, app, branch):
        self.app = app

        on_head = (branch == app.repo.status.current_branch)
        disable = (on_head or app.repo.status.head_detached)

        Menu.__init__(self, app.win)
        label = '{} {}'.format(branch.name, '(HEAD)' if on_head else '')
        self.item_add(None, label, 'git-branch').disabled = True
        self.item_separator_add()

        self.item_add(None, 'Checkout', None,
                      lambda m,i: self.app.checkout_ref(branch.name)) \
                      .disabled = disable

        self.item_add(None, 'Merge in current branch', 'git-merge',
                      lambda m,i: self.app.action_branch_merge(branch)) \
                      .disabled = disable

        self.item_add(None, 'Compare & Merge', 'git-compare',
                      lambda m,i: self.app.action_compare(target=branch.name)) \
                      .disabled = disable

        self.item_add(None, 'Delete', 'user-trash',
                      lambda m,i: self.app.action_branch_delete(branch)) \
                      .disabled = disable

        # show the menu at mouse position
        x, y = self.evas.pointer_canvas_xy_get()
        self.move(x + 2, y)
        self.show()
示例#3
0
文件: gui.py 项目: simotek/egitu
    def __init__(self, win, parent):
        Menu.__init__(self, win)
        self.win = win

        # main actions
        self.item_add(None, "Refresh", "refresh", self._item_refresh_cb)
        self.item_add(None, "Open", "folder", self._item_open_cb)
        self.item_separator_add()

        # general options
        it_gen = self.item_add(None, "General", "preference")

        it = self.item_add(it_gen, "Use relative dates", None,
                           self._item_check_opts_cb, 'date_relative')
        it.content = Check(self, state=options.date_relative)

        it_gravatar = self.item_add(it_gen, "Gravatar")
        for name in ('mm', 'identicon', 'monsterid', 'wavatar', 'retro'):
            icon = "arrow_right" if name == options.gravatar_default else None
            self.item_add(it_gravatar, name, icon,  self._item_gravatar_cb)
        self.item_separator_add(it_gravatar)
        self.item_add(it_gravatar, 'Clear icons cache', 'delete',
                      lambda m,i: GravatarPict.clear_icon_cache())

        # dag options
        it_dag = self.item_add(None, "Dag", "preference")

        it = self.item_add(it_dag, "Show remote refs", None,
                           self._item_check_opts_cb, 'show_remotes_in_dag')
        it.content = Check(self, state=options.show_remotes_in_dag)

        it = self.item_add(it_dag, "Show commit messagges", None,
                           self._item_check_opts_cb, 'show_message_in_dag')
        it.content = Check(self, state=options.show_message_in_dag)

        # diff options
        it_diff = self.item_add(None, "Diff", "preference")

        it = self.item_add(it_diff, "Wrap long lines", None,
                           self._item_wrap_line_cb)
        it.content = Check(self, state=options.diff_text_wrap)

        it_font = self.item_add(it_diff, "Font face")
        for face in ('Sans', 'Mono'):
            icon = "arrow_right" if face == options.diff_font_face else None
            self.item_add(it_font, face, icon, self._item_font_face_cb)

        it_font = self.item_add(it_diff, "Font size")
        for size in (8, 9, 10, 11, 12, 13, 14):
            icon = "arrow_right" if size == options.diff_font_size else None
            self.item_add(it_font, str(size), icon, self._item_font_size_cb)

        x, y, w, h = parent.geometry
        self.move(x, y + h)
        self.show()
示例#4
0
    def __init__(self, app, tag):
        self.app = app

        Menu.__init__(self, app.win)
        self.item_add(None, tag.name, 'git-tag').disabled = True
        self.item_separator_add()

        self.item_add(None, 'Checkout', None,
                      lambda m,i: self.app.checkout_ref(tag.ref))
        self.item_add(None, 'Delete', 'user-trash',
                      lambda m,i: self.app.action_tag_delete(tag))

        # show the menu at mouse position
        x, y = self.evas.pointer_canvas_xy_get()
        self.move(x + 2, y)
        self.show()
def menu_clicked(obj):
    win = StandardWindow("menu", "Menu test", autodel=True, size=(350, 200))
    if obj is None:
        win.callback_delete_request_add(lambda o: elementary.exit())

    rect = Rectangle(win.evas_get(), color=(0, 0, 0, 0))
    win.resize_object_add(rect)
    rect.size_hint_weight = EVAS_HINT_EXPAND, EVAS_HINT_EXPAND
    rect.show()

    menu = Menu(win)
    item = menu.item_add(None, "first item", "clock")
    item = menu.item_add(None, "second item", "mail-send")
    menu_populate_1(menu, item)

    menu.item_add(item, "sub menu", "refresh")

    rect.event_callback_add(EVAS_CALLBACK_MOUSE_DOWN, menu_show, menu)

    win.show()
示例#6
0
    def __init__(self, app, stash_item):
        self.app = app

        Menu.__init__(self, app.win)
        self.item_add(None, stash_item.desc, 'git-stash').disabled = True
        self.item_separator_add()
        self.item_add(None, 'Show', None,
                      lambda m,i: self.app.action_stash_show_item(stash_item))
        self.item_add(None, 'Apply', None,
                      lambda m,i: self.app.action_stash_apply(stash_item))
        self.item_add(None, 'Pop (apply & delete)', None,
                      lambda m,i: self.app.action_stash_pop(stash_item))
        self.item_add(None, 'Branch & Delete', 'git-branch',
                      lambda m,i: self.app.action_stash_branch(stash_item))
        self.item_add(None, 'Delete', 'user-trash',
                      lambda m,i: self.app.action_stash_drop(stash_item))

        # show the menu at mouse position
        x, y = self.evas.pointer_canvas_xy_get()
        self.move(x + 2, y)
        self.show()
def cb_map_mouse_down(Map, evtinfo):
    (x,y) = evtinfo.position.canvas
    (lon, lat) = Map.canvas_to_region_convert(x, y)
    if evtinfo.button == 3:
        m = Menu(Map)
        mi = m.item_add(None, "Lat: %f" % lat)
        mi.disabled = True
        mi = m.item_add(None, "Lon: %f" % lon)
        mi.disabled = True
        
        mi = m.item_add(None, "Move")
        m.item_add(mi, "Show Sydney", None, cb_menu_show, Map, 151.175274, -33.859126)
        m.item_add(mi, "Show Paris", None, cb_menu_show, Map, 2.342913, 48.853701)
        m.item_add(mi, "Bringin Sydney", None, cb_menu_bringin, Map, 151.175274, -33.859126)
        m.item_add(mi, "Bringin Paris", None, cb_menu_bringin, Map, 2.342913, 48.853701)
        
        mi = m.item_add(None, "Add overlay")
        m.item_add(mi, "Normal", None, cb_menu_overlay_normal, Map, lon, lat)
        m.item_add(mi, "Icon", None, cb_menu_overlay_icon, Map, lon, lat)
        m.item_add(mi, "Custom content", None, cb_menu_overlay_custom, Map, lon, lat)
        m.item_add(mi, "Random color", None, cb_menu_overlay_random_color, Map, lon, lat)
        m.item_add(mi, "Min zoom 4", None, cb_menu_overlay_min_zoom, Map, lon, lat)
        m.item_add(mi, "16 grouped", None, cb_menu_overlay_grouped, Map, lon, lat)
        m.item_add(mi, "Bubble attached", None, cb_menu_overlay_bubble, Map, lon, lat)
        m.item_add(mi, "Line", None, cb_menu_overlay_line, Map, lon, lat)
        m.item_add(mi, "Polygon", None, cb_menu_overlay_poly, Map, lon, lat)
        m.item_add(mi, "Circle", None, cb_menu_overlay_circle, Map, lon, lat)
        m.item_add(mi, "Scale", None, cb_menu_overlay_scale, Map, x, y)

        mi = m.item_add(None, "Overlays")
        m.item_add(mi, "Clear", None, cb_menu_overlays_clear, Map)
        m.item_add(mi, "Show (BROKEN)", None, cb_menu_overlays_show, Map)
        m.item_add(mi, "ungroup (BROKEN)", None, cb_menu_overlays_ungroup, Map)

        mi = m.item_add(None, "Route")
        m.item_add(mi, "Set start point", None, cb_menu_route_start, Map, lon, lat)
        m.item_add(mi, "Set end point", None, cb_menu_route_end, Map, lon, lat)

        m.move(x, y)
        m.show()
示例#8
0
文件: gui.py 项目: DaveMDS/egitu
    def _button_pressed_cb(self, btn):
        # close the menu if it is visible yet
        if self._menu and self._menu.visible:
            self._menu.delete()
            self._menu = None
            return

        # build a new menu
        m = Menu(self.top_widget)
        self._menu = m

        # main actions
        disabled = self.app.repo is None
        m.item_add(None, 'Refresh', 'view-refresh', 
                   self.app.action_reload_repo).disabled = disabled
        m.item_add(None, 'Open...', 'document-open',
                   self.app.action_open)
        m.item_add(None, 'Branches...', 'git-branch', 
                   self.app.action_branches).disabled = disabled
        m.item_add(None, 'Tags...', 'git-tag', 
                   self.app.action_tags).disabled = disabled
        m.item_add(None, 'Compare...', 'git-compare', 
                   self.app.action_compare).disabled = disabled
        m.item_add(None, 'Remotes...', 'git-remote', 
                   self.app.action_remotes).disabled = disabled
        m.item_add(None, 'Stashes...', 'git-stash', 
                   self.app.action_stash_show).disabled = disabled

        # general options
        m.item_separator_add()
        it_gen = m.item_add(None, 'General', 'preference')

        it = m.item_add(it_gen, 'Use relative dates', None,
                        self._item_check_opts_cb, 'date_relative')
        it.content = Check(self, state=options.date_relative)
        
        it = m.item_add(it_gen, 'Review all git commands before execution', None,
                        self._item_check_opts_cb, 'review_git_commands')
        it.content = Check(self, state=options.review_git_commands)

        it_gravatar = m.item_add(it_gen, 'Gravatar')
        for name in ('mm', 'identicon', 'monsterid', 'wavatar', 'retro'):
            icon = 'user-bookmarks' if name == options.gravatar_default else None
            m.item_add(it_gravatar, name, icon,  self._item_gravatar_cb)
        m.item_separator_add(it_gravatar)
        m.item_add(it_gravatar, 'Clear icons cache', 'user-trash',
                   lambda m,i: GravatarPict.clear_icon_cache())

        # dag options
        it_dag = m.item_add(None, 'Dag', 'preference')

        it = m.item_add(it_dag, 'Show remote refs', None,
                        self._item_check_opts_cb, 'show_remotes_in_dag')
        it.content = Check(self, state=options.show_remotes_in_dag)

        it = m.item_add(it_dag, 'Show messages', None,
                        self._item_check_opts_cb, 'show_message_in_dag')
        it.content = Check(self, state=options.show_message_in_dag)

        it = m.item_add(it_dag, 'Show authors', None,
                        self._item_check_opts_cb, 'show_author_in_dag')
        it.content = Check(self, state=options.show_author_in_dag)

        it = m.item_add(it_dag, 'Show stash items', None,
                        self._item_check_opts_cb, 'show_stash_in_dag')
        it.content = Check(self, state=options.show_stash_in_dag)

        it_numb = m.item_add(it_dag, 'Number of commits to load')
        for num in (100, 200, 500, 1000):
            icon = 'user-bookmarks' if num == options.number_of_commits_to_load else None
            m.item_add(it_numb, str(num), icon, self._item_num_commits_cb)

        # diff options
        it_diff = m.item_add(None, 'Diff', 'preference')

        it = m.item_add(it_diff, 'Wrap long lines', None,
                        self._item_wrap_line_cb)
        it.content = Check(self, state=options.diff_text_wrap)

        it_font = m.item_add(it_diff, 'Font face')
        for face in ('Sans', 'Mono'):
            icon = 'user-bookmarks' if face == options.diff_font_face else None
            m.item_add(it_font, face, icon, self._item_font_face_cb)

        it_font = m.item_add(it_diff, 'Font size')
        for size in (8, 9, 10, 11, 12, 13, 14):
            icon = 'user-bookmarks' if size == options.diff_font_size else None
            m.item_add(it_font, str(size), icon, self._item_font_size_cb)

        # quit item
        m.item_separator_add()
        m.item_add(None, 'About', 'help-about', self.app.action_about)
        m.item_add(None, 'Quit', 'application-exit', self.app.action_quit)


        # show the menu
        x, y, w, h = self.geometry
        m.move(x, y + h)
        m.show()
示例#9
0
文件: app.py 项目: JeffHoogland/lekha
    def __init__(self, parent, path, pos=None, zoom=1.0):
        self.doc_path = path
        self._zoom = zoom
        self.doc_pos = pos
        self.pages = []
        self.doc = None
        self.doc_title = os.path.splitext(os.path.basename(path))[0]
        self.visible_pages = []

        super(Document, self).__init__(
            parent, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)

        scr = self.scr = Scroller(
            self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
        scr.callback_scroll_add(self._scrolled)
        self.pack(scr, 0, 0, 4, 5)
        scr.show()

        box = self.page_box = Box(
            scr, size_hint_weight=EXPAND_BOTH, size_hint_align=(0.5, 0.0))
        scr.content = box

        self.on_resize_add(self._resized)

        btn = Button(
            self, text="Toggle outlines", size_hint_align=ALIGN_LEFT)
        btn.callback_clicked_add(lambda x: self.ol_p.toggle())
        self.pack(btn, 0, 5, 1, 1)
        btn.show()

        spn = self.spn = Spinner(
            self, round=1.0,
            size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ)
        spn.special_value_add(1, "First")
        spn.editable = True
        self.pack(spn, 1, 5, 1, 1)
        spn.show()

        btn = Button(
            self, text="show page",
            size_hint_weight=EXPAND_HORIZ, size_hint_align=ALIGN_LEFT)
        btn.callback_clicked_add(self._show_page_cb, spn)
        self.pack(btn, 2, 5, 1, 1)
        btn.show()

        menu = Menu(self.top_widget)
        menu.item_add(
            None, "Zoom In", "zoom-in",
            lambda x, y: self.zoom_in())
        menu.item_add(
            None, "Zoom Out", "zoom-out",
            lambda x, y: self.zoom_out())
        menu.item_add(
            None, "Zoom 1:1", "zoom-original",
            lambda x, y: self.zoom_orig())
        menu.item_add(
            None, "Zoom Fit", "zoom-fit-best",
            lambda x, y: self.zoom_fit())

        def z_clicked(btn):
            x, y = btn.evas.pointer_canvas_xy_get()
            menu.move(x, y)
            menu.show()

        zlbl = self.zlbl = Button(
            self, text="%1.0f %%" % (self.zoom * 100.0),
            size_hint_weight=EXPAND_HORIZ, size_hint_align=ALIGN_RIGHT)
        zlbl.callback_clicked_add(z_clicked)
        self.pack(zlbl, 3, 5, 1, 1)
        zlbl.show()

        n = self.page_notify = Notify(scr, align=(0.02, 0.02))
        b = Box(n, horizontal=True, padding=(6, 0))
        n.content = b

        n = self.load_notify = Notify(scr, align=(0.98, 0.98))
        pb = Progressbar(n, pulse_mode=True, style="wheel")
        n.content = pb
        pb.pulse(True)
        n.show()

        p = self.ol_p = Panel(
            self, orient=ELM_PANEL_ORIENT_LEFT,
            size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH,
            ) #scrollable=True, scrollable_content_size=0.35)
        p.hidden = True
        scr.on_move_add(lambda x: p.move(*x.pos))
        scr.on_resize_add(lambda x: p.resize(x.size[0] * 0.35, x.size[1]))

        ol_gl = self.ol_gl = Genlist(
            p, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH,
            mode=ELM_LIST_COMPRESS, homogeneous=True,
            select_mode=ELM_OBJECT_SELECT_MODE_ALWAYS
            )
        p.content = ol_gl

        ol_gl.callback_contract_request_add(self._gl_contract_req)
        ol_gl.callback_contracted_add(self._gl_contracted)
        ol_gl.callback_expand_request_add(self._gl_expand_req)
        ol_gl.callback_expanded_add(self._gl_expanded)
        ol_gl.show()

        p.show()
        self.show()

        def read_worker():
            t1 = self.t1 = time.clock()
            try:
                self.doc = PyPDF2.PdfFileReader(path)
                self.page_count = self.doc.getNumPages()
            except Exception as e:
                log.exception("Document could not be opened because: %r", e)
                return
            t2 = time.clock()
            log.info("Reading the doc took: %f", t2-t1)

        t = Thread(target=read_worker)
        t.daemon = True
        t.start()

        def worker_check(t):
            if t.is_alive():
                return True
            if self.doc and self.page_count:
                spn.special_value_add(self.page_count, "Last")
                spn.min_max = (1, self.page_count)

                if self.doc.isEncrypted:
                    PasswordPrompt(self)
                    return False

                self.metadata_read()
                self.populate_pages()
                return False

            self.load_notify.content.delete()
            l = Label(
                self.load_notify, style="marker",
                text="Document load error", color=(255, 0, 0, 255))
            self.load_notify.content = l
            l.show()

        timer = Timer(0.2, worker_check, t)
        self.parent.callback_delete_request_add(lambda x: timer.delete())
示例#10
0
    def item_activated_cb(self, gl, item):
        h = item.data
        menu = Menu(self.win)

        menu.item_add(
            None,
            "Resume" if h.is_paused() else "Pause",
            None,
            self.resume_torrent_cb if h.is_paused() else self.pause_torrent_cb,
            h
        )
        q = menu.item_add(None, "Queue", None, None)
        menu.item_add(q, "Up", None, lambda x, y: h.queue_position_up())
        menu.item_add(q, "Down", None, lambda x, y: h.queue_position_down())
        menu.item_add(q, "Top", None, lambda x, y: h.queue_position_top())
        menu.item_add(q, "Bottom", None, lambda x, y: h.queue_position_bottom())
        rem = menu.item_add(None, "Remove torrent", None,
            self.remove_torrent_cb, item, h, False)
        menu.item_add(rem, "and data files", None,
            self.remove_torrent_cb, item, h, True)
        menu.item_add(None, "Force re-check", None,
            self.force_recheck, h)
        menu.item_separator_add(None)
        menu.item_add(None, "Torrent preferences", None,
            self.torrent_preferences_cb, h)

        menu.move(*self.win.evas.pointer_canvas_xy_get())
        menu.show()
示例#11
0
    def item_activated_cb(self, gl, item):
        h = item.data
        menu = Menu(self.win)

        menu.item_add(
            None, "Resume" if h.is_paused() else "Pause", None,
            self.resume_torrent_cb if h.is_paused() else self.pause_torrent_cb,
            h)
        q = menu.item_add(None, "Queue", None, None)
        menu.item_add(q, "Up", None, lambda x, y: h.queue_position_up())
        menu.item_add(q, "Down", None, lambda x, y: h.queue_position_down())
        menu.item_add(q, "Top", None, lambda x, y: h.queue_position_top())
        menu.item_add(q, "Bottom", None,
                      lambda x, y: h.queue_position_bottom())
        rem = menu.item_add(None, "Remove torrent", None,
                            self.remove_torrent_cb, item, h, False)
        menu.item_add(rem, "and data files", None, self.remove_torrent_cb,
                      item, h, True)
        menu.item_add(None, "Force re-check", None, self.force_recheck, h)
        menu.item_separator_add(None)
        menu.item_add(None, "Torrent preferences", None,
                      self.torrent_preferences_cb, h)

        menu.move(*self.win.evas.pointer_canvas_xy_get())
        menu.show()
示例#12
0
    def __init__(self, parent, path, pos=None, zoom=1.0):
        self.doc_path = path
        self._zoom = zoom
        self.doc_pos = pos
        self.pages = []
        self.doc = None
        self.doc_title = os.path.splitext(os.path.basename(path))[0]
        self.visible_pages = []

        super(Document, self).__init__(parent,
                                       size_hint_weight=EXPAND_BOTH,
                                       size_hint_align=FILL_BOTH)

        scr = self.scr = Scroller(self,
                                  size_hint_weight=EXPAND_BOTH,
                                  size_hint_align=FILL_BOTH)
        scr.callback_scroll_add(self._scrolled)
        self.pack(scr, 0, 0, 4, 1)
        scr.show()

        box = self.page_box = Box(scr,
                                  size_hint_weight=EXPAND_BOTH,
                                  size_hint_align=(0.5, 0.0))
        scr.content = box

        self.on_resize_add(self._resized)

        btn = Button(self, text="Toggle outlines", size_hint_align=ALIGN_LEFT)
        btn.callback_clicked_add(lambda x: self.ol_p.toggle())
        self.pack(btn, 0, 1, 1, 1)
        btn.show()

        spn = self.spn = Spinner(self,
                                 round=1.0,
                                 size_hint_weight=EXPAND_HORIZ,
                                 size_hint_align=FILL_HORIZ)
        spn.special_value_add(1, "First")
        spn.editable = True
        self.pack(spn, 1, 1, 1, 1)
        spn.show()

        btn = Button(self,
                     text="show page",
                     size_hint_weight=EXPAND_HORIZ,
                     size_hint_align=ALIGN_LEFT)
        btn.callback_clicked_add(self._show_page_cb, spn)
        self.pack(btn, 2, 1, 1, 1)
        btn.show()

        menu = Menu(self.top_widget)
        menu.item_add(None, "Zoom In", "zoom-in", lambda x, y: self.zoom_in())
        menu.item_add(None, "Zoom Out", "zoom-out",
                      lambda x, y: self.zoom_out())
        menu.item_add(None, "Zoom 1:1", "zoom-original",
                      lambda x, y: self.zoom_orig())
        menu.item_add(None, "Zoom Fit", "zoom-fit-best",
                      lambda x, y: self.zoom_fit())

        def z_clicked(btn):
            x, y = btn.evas.pointer_canvas_xy_get()
            menu.move(x, y)
            menu.show()

        zlbl = self.zlbl = Button(self,
                                  text="%1.0f %%" % (self.zoom * 100.0),
                                  size_hint_weight=EXPAND_HORIZ,
                                  size_hint_align=ALIGN_RIGHT)
        zlbl.callback_clicked_add(z_clicked)
        self.pack(zlbl, 3, 1, 1, 1)
        zlbl.show()

        n = self.page_notify = Notify(scr, align=(0.02, 0.02))
        b = Box(n, horizontal=True, padding=(6, 0))
        n.content = b

        n = self.load_notify = Notify(scr, align=(0.98, 0.98))
        pb = Progressbar(n, pulse_mode=True, style="wheel")
        n.content = pb
        pb.pulse(True)
        n.show()

        p = self.ol_p = Panel(
            self,
            orient=ELM_PANEL_ORIENT_LEFT,
            size_hint_weight=EXPAND_BOTH,
            size_hint_align=FILL_BOTH,
        )  #scrollable=True, scrollable_content_size=0.35)
        p.hidden = True
        scr.on_move_add(lambda x: p.move(*x.pos))
        scr.on_resize_add(lambda x: p.resize(x.size[0] * 0.35, x.size[1]))

        ol_gl = self.ol_gl = Genlist(p,
                                     size_hint_weight=EXPAND_BOTH,
                                     size_hint_align=FILL_BOTH,
                                     mode=ELM_LIST_COMPRESS,
                                     homogeneous=True,
                                     select_mode=ELM_OBJECT_SELECT_MODE_ALWAYS)
        p.content = ol_gl

        ol_gl.callback_contract_request_add(self._gl_contract_req)
        ol_gl.callback_contracted_add(self._gl_contracted)
        ol_gl.callback_expand_request_add(self._gl_expand_req)
        ol_gl.callback_expanded_add(self._gl_expanded)
        ol_gl.show()

        p.show()
        self.show()

        def read_worker():
            t1 = self.t1 = time.clock()
            try:
                self.doc = PyPDF2.PdfFileReader(path)
                self.page_count = self.doc.getNumPages()
            except Exception as e:
                log.exception("Document could not be opened because: %r", e)
                self.doc = None
                self.display_error(e)
                return
            t2 = time.clock()
            log.info("Reading the doc took: %f", t2 - t1)

        t = Thread(target=read_worker)
        t.daemon = True
        t.start()

        def worker_check(t):
            if t.is_alive():
                return True
            elif self.doc and self.page_count:
                spn.special_value_add(self.page_count, "Last")
                spn.min_max = (1, self.page_count)

                if self.doc.isEncrypted:
                    PasswordPrompt(self)
                    return False

                self.metadata_read()
                self.populate_pages()
                return False

        timer = Timer(0.2, worker_check, t)
        self.parent.callback_delete_request_add(lambda x: timer.delete())
示例#13
0
    def _button_pressed_cb(self, btn):
        # close the menu if it is visible yet
        if self._menu and self._menu.visible:
            self._menu.delete()
            self._menu = None
            return

        # build a new menu
        m = Menu(self.top_widget)
        self._menu = m

        # main actions (save, reload, quit)
        it = m.item_add(None, 'Save', 'folder',
                        lambda m,i: self.top_widget.save())
        if need_save() is False:
            it.disabled = True

        m.item_add(None, 'Reload', 'refresh',
                   lambda m,i: self.top_widget.reload())

        m.item_add(None, 'Quit', 'exit',
                   lambda m,i: self.top_widget.safe_quit())

        m.item_add(None, 'Info and help', 'info',
                   lambda m,i: InfoWin(self.top_widget))

        # Todo.txt file...
        m.item_separator_add()
        m.item_add(None, 'Choose Todo.txt file', None,
                   lambda m,i: self._file_change())
        m.item_separator_add()
        
        # group by >
        it_groupby = m.item_add(None, 'Group by')
        icon = 'arrow_right' if options.group_by == 'none' else None
        m.item_add(it_groupby, 'None', icon,
                   lambda m,i: self._groupby_set('none'))
        icon = 'arrow_right' if options.group_by == 'prj' else None
        m.item_add(it_groupby, 'Projects', icon,
                   lambda m,i: self._groupby_set('prj'))
        icon = 'arrow_right' if options.group_by == 'ctx' else None
        m.item_add(it_groupby, 'Contexts', icon,
                   lambda m,i: self._groupby_set('ctx'))

        # sort by >
        it_sortby = m.item_add(None, 'Sort by')
        icon = 'arrow_right' if options.sort_by == 'none' else None
        m.item_add(it_sortby, 'No sort', icon,
                   lambda m,i: self._sortby_set('none'))
        icon = 'arrow_right' if options.sort_by == 'pri' else None
        m.item_add(it_sortby, 'Priority', icon,
                   lambda m,i: self._sortby_set('pri'))

        # layout >
        it_layout = m.item_add(None, 'Layout')
        icon = 'arrow_right' if options.horiz_layout is False else None
        m.item_add(it_layout, 'Vertical', icon,
                   lambda m,i: self._layout_set(False))
        icon = 'arrow_right' if options.horiz_layout is True else None
        m.item_add(it_layout, 'Horizontal', icon,
                   lambda m,i: self._layout_set(True))

        # show the menu
        x, y, w, h = self.geometry
        m.move(x, y + h)
        m.show()