mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
DRYer
This commit is contained in:
parent
ab332d0b99
commit
0fe268343b
@ -6,6 +6,7 @@ from dom import ensure_id
|
|||||||
from elementmaker import E
|
from elementmaker import E
|
||||||
from session import get_interface_data
|
from session import get_interface_data
|
||||||
from gettext import gettext as _
|
from gettext import gettext as _
|
||||||
|
from utils import conditional_timeout
|
||||||
|
|
||||||
from book_list.globals import get_db
|
from book_list.globals import get_db
|
||||||
from book_list.top_bar import create_top_bar
|
from book_list.top_bar import create_top_bar
|
||||||
@ -13,12 +14,10 @@ from book_list.ui import set_default_panel_handler, show_panel
|
|||||||
|
|
||||||
|
|
||||||
def show_recent():
|
def show_recent():
|
||||||
|
container = this
|
||||||
db = get_db()
|
db = get_db()
|
||||||
if not db.initialized:
|
if not db.initialized:
|
||||||
window.setTimeout(show_recent.bind(this), 5)
|
conditional_timeout(container.id, 5, show_recent)
|
||||||
return
|
|
||||||
container = document.getElementById(this)
|
|
||||||
if not container:
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
@ -31,7 +30,7 @@ def init(container_id):
|
|||||||
recent = E.div(style='display:none')
|
recent = E.div(style='display:none')
|
||||||
recent_container_id = ensure_id(recent)
|
recent_container_id = ensure_id(recent)
|
||||||
container.appendChild(recent)
|
container.appendChild(recent)
|
||||||
window.setTimeout(show_recent.bind(recent_container_id), 5)
|
conditional_timeout(recent_container_id, 5, show_recent)
|
||||||
|
|
||||||
# Choose library
|
# Choose library
|
||||||
cl = E.div(
|
cl = E.div(
|
||||||
|
@ -162,6 +162,13 @@ def uniq(vals):
|
|||||||
ans.push(x)
|
ans.push(x)
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
|
def conditional_timeout(elem_id, timeout, func):
|
||||||
|
def ct_impl():
|
||||||
|
elem = document.getElementById(elem_id)
|
||||||
|
if elem:
|
||||||
|
func.call(elem)
|
||||||
|
window.setTimeout(ct_impl, timeout)
|
||||||
|
|
||||||
if __name__ is '__main__':
|
if __name__ is '__main__':
|
||||||
from pythonize import strings
|
from pythonize import strings
|
||||||
strings()
|
strings()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user