Began gui rewrite
Cleaning up the code was proving to be more difficult than I initially thought. I have decided to rewrite the gui to make it less intimidating and more easily modified.
This commit is contained in:
parent
e726f166a1
commit
b2db7d3327
|
@ -8,35 +8,33 @@ import gtk
|
||||||
import gobject
|
import gobject
|
||||||
import libsaria
|
import libsaria
|
||||||
|
|
||||||
gdk = gtk.gdk
|
#gdk = gtk.gdk
|
||||||
gobject.threads_init()
|
|
||||||
|
|
||||||
__vers__ = "Ocarina %s" % libsaria.__vstr__
|
__vers__ = "Ocarina %s" % libsaria.__vstr__
|
||||||
|
gobject.threads_init()
|
||||||
|
|
||||||
def uptime():
|
def uptime():
|
||||||
return now() - __start__
|
return now() - __start__
|
||||||
|
|
||||||
def startup():
|
def quit(window, event):
|
||||||
libsaria.startup()
|
|
||||||
body.init_page("Library")
|
|
||||||
print "Startup took:", uptime()
|
|
||||||
gtk.main()
|
|
||||||
|
|
||||||
def exit(widget, event):
|
|
||||||
gtk.main_quit()
|
gtk.main_quit()
|
||||||
libsaria.shutdown()
|
print "Ocarina ran for:", uptime()
|
||||||
print "Ocarina ran for: %s" % uptime()
|
|
||||||
|
|
||||||
import window
|
import window
|
||||||
import body
|
|
||||||
|
|
||||||
window.init()
|
libsaria.startup()
|
||||||
body.init(window.window)
|
print "Startup took:", uptime()
|
||||||
|
gtk.main()
|
||||||
|
|
||||||
import library
|
|
||||||
import playlist
|
#import body
|
||||||
import queue
|
|
||||||
playlist.init()
|
#window.init()
|
||||||
queue.init()
|
#body.init(window.window)
|
||||||
library.init()
|
|
||||||
startup()
|
#import library
|
||||||
|
#import playlist
|
||||||
|
#import queue
|
||||||
|
#playlist.init()
|
||||||
|
#queue.init()
|
||||||
|
#library.init()
|
||||||
|
#startup()
|
||||||
|
|
|
@ -1,77 +1,83 @@
|
||||||
# Bryan Schumaker (11/24/2010)
|
# Bryan Schumaker (11/24/2010)
|
||||||
|
|
||||||
import gtk
|
import gtk
|
||||||
import ocarina
|
from page import OcarinaPage
|
||||||
import page
|
|
||||||
Label = gtk.Label
|
|
||||||
prefs = ocarina.libsaria.prefs
|
|
||||||
get_pref = prefs.get_pref
|
|
||||||
set_pref = prefs.set_pref
|
|
||||||
|
|
||||||
contents = dict()
|
body = gtk.Notebook()
|
||||||
|
body.show()
|
||||||
|
body.set_tab_pos(gtk.POS_LEFT)
|
||||||
|
page_num = body.page_num
|
||||||
|
|
||||||
body = None
|
def add_page(content, page_name):
|
||||||
|
label = gtk.Label(page_name)
|
||||||
def init(window):
|
|
||||||
global body
|
|
||||||
from ocarina.components import entry
|
|
||||||
|
|
||||||
body = gtk.Notebook()
|
|
||||||
body.set_tab_pos(gtk.POS_LEFT)
|
|
||||||
body.show()
|
|
||||||
window.add(body)
|
|
||||||
|
|
||||||
def init_page(page_name):
|
|
||||||
page = prefs.init_pref("ocarina.body.page", page_name)
|
|
||||||
child = contents.get(page, None)
|
|
||||||
if child == None:
|
|
||||||
child = contents.get(page_name)
|
|
||||||
num = body.page_num(child)
|
|
||||||
body.set_current_page(num)
|
|
||||||
child.visible()
|
|
||||||
body.connect("switch-page", switch_page)
|
|
||||||
|
|
||||||
def add_page(name, content, add_header=True, add_footer=True):
|
|
||||||
label = Label(name)
|
|
||||||
label.set_angle(90)
|
label.set_angle(90)
|
||||||
pg = page.Page(content, add_header, add_footer)
|
page = OcarinaPage(content, label)
|
||||||
contents[name] = pg
|
body.append_page(page, label)
|
||||||
body.append_page(pg, label)
|
body.set_tab_label_packing(page, True, True, gtk.PACK_START)
|
||||||
body.set_tab_label_packing(pg, True, True, gtk.PACK_START)
|
n = body.get_n_pages()
|
||||||
|
if n == 1:
|
||||||
|
page.visible()
|
||||||
|
elif n == 2:
|
||||||
|
body.connect("switch-page", switch_page)
|
||||||
|
return page
|
||||||
|
|
||||||
def remove_page(name):
|
def remove_page(page):
|
||||||
page = contents.get(name, None)
|
page.invisible()
|
||||||
if page == None:
|
page.rm_content()
|
||||||
return
|
body.remove_page(page_num(page))
|
||||||
n = body.page_num(page)
|
|
||||||
if n == body.get_current_page():
|
def current_page():
|
||||||
body.set_current_page(n - 1)
|
cur_num = body.get_current_page()
|
||||||
body.remove_page(n)
|
return body.get_nth_page(cur_num)
|
||||||
del contents[name]
|
|
||||||
|
def switch_to_page(page):
|
||||||
|
body.set_current_page(page_num(page))
|
||||||
|
|
||||||
def switch_page(notebook, page, pagenum):
|
def switch_page(notebook, page, pagenum):
|
||||||
cur_num = body.get_current_page()
|
cur_pg = current_page()
|
||||||
child = body.get_nth_page(cur_num)
|
|
||||||
next_pg = body.get_nth_page(pagenum)
|
next_pg = body.get_nth_page(pagenum)
|
||||||
next = None
|
cur_pg.invisible()
|
||||||
for name, item in contents.iteritems():
|
|
||||||
if item == next_pg:
|
|
||||||
next = name
|
|
||||||
set_pref("ocarina.body.page", next)
|
|
||||||
child.invisible()
|
|
||||||
next_pg.visible()
|
next_pg.visible()
|
||||||
|
|
||||||
def cur_page_filter(text):
|
#import ocarina
|
||||||
cur_num = body.get_current_page()
|
#Label = gtk.Label
|
||||||
page = body.get_nth_page(cur_num)
|
#prefs = ocarina.libsaria.prefs
|
||||||
page.filter(text)
|
#get_pref = prefs.get_pref
|
||||||
|
#set_pref = prefs.set_pref
|
||||||
|
|
||||||
def cur_page_reset():
|
#def init_page(page_name):
|
||||||
cur_num = body.get_current_page()
|
#page = prefs.init_pref("ocarina.body.page", page_name)
|
||||||
page = body.get_nth_page(cur_num)
|
#child = contents.get(page, None)
|
||||||
page.reset()
|
#if child == None:
|
||||||
|
#child = contents.get(page_name)
|
||||||
|
#num = body.page_num(child)
|
||||||
|
#body.set_current_page(num)
|
||||||
|
#child.visible()
|
||||||
|
#body.connect("switch-page", switch_page)
|
||||||
|
|
||||||
def cur_page_goto():
|
#def switch_page(notebook, page, pagenum):
|
||||||
cur_num = body.get_current_page()
|
#cur_num = body.get_current_page()
|
||||||
page = body.get_nth_page(cur_num)
|
#child = body.get_nth_page(cur_num)
|
||||||
page.goto()
|
#next_pg = body.get_nth_page(pagenum)
|
||||||
|
#next = None
|
||||||
|
#for name, item in contents.iteritems():
|
||||||
|
#if item == next_pg:
|
||||||
|
#next = name
|
||||||
|
#set_pref("ocarina.body.page", next)
|
||||||
|
#child.invisible()
|
||||||
|
#next_pg.visible()
|
||||||
|
|
||||||
|
#def cur_page_filter(text):
|
||||||
|
#cur_num = body.get_current_page()
|
||||||
|
#page = body.get_nth_page(cur_num)
|
||||||
|
#page.filter(text)
|
||||||
|
|
||||||
|
#def cur_page_reset():
|
||||||
|
#cur_num = body.get_current_page()
|
||||||
|
#page = body.get_nth_page(cur_num)
|
||||||
|
#page.reset()
|
||||||
|
|
||||||
|
#def cur_page_goto():
|
||||||
|
#cur_num = body.get_current_page()
|
||||||
|
#page = body.get_nth_page(cur_num)
|
||||||
|
#page.goto()
|
||||||
|
|
|
@ -1,43 +1,60 @@
|
||||||
# Bryan Schumaker (4 / 17 / 2011)
|
# Bryan Schumaker (4 / 17 / 2011)
|
||||||
|
|
||||||
import gtk
|
import gtk
|
||||||
import header
|
#import header
|
||||||
import footer
|
#import footer
|
||||||
|
SHRINK = gtk.SHRINK
|
||||||
|
GROW = gtk.FILL | gtk.EXPAND
|
||||||
|
|
||||||
class Page(gtk.VBox):
|
class OcarinaPage(gtk.Table):
|
||||||
def __init__(self, content, add_header, add_footer):
|
def __init__(self, content, label):
|
||||||
gtk.VBox.__init__(self)
|
gtk.Table.__init__(self, 3, 1, False)
|
||||||
self.content = content
|
self.content = content
|
||||||
self.attrs = content.__dict__
|
self.label = label
|
||||||
self.vis_func = self.attrs.get("visible", None)
|
self.block_shortcuts = False
|
||||||
self.invis_func = self.attrs.get("invisible", None)
|
self.attach_center(content)
|
||||||
self.add_header = add_header
|
|
||||||
self.add_footer = add_footer
|
|
||||||
self.show()
|
self.show()
|
||||||
|
|
||||||
def filter(self, text):
|
def attach_top(self, content):
|
||||||
self.content.filter(text)
|
self.attach(content, 0, 1, 0, 1, GROW, SHRINK)
|
||||||
|
|
||||||
def reset(self):
|
def attach_center(self, content):
|
||||||
self.content.reset()
|
self.attach(content, 0, 1, 1, 2)
|
||||||
|
|
||||||
def goto(self):
|
def attach_bottom(self, content):
|
||||||
self.content.goto()
|
self.attach(content, 0, 1, 2, 3, GROW, SHRINK)
|
||||||
|
|
||||||
def visible(self):
|
#self.content = content
|
||||||
if self.add_header == True:
|
#self.attrs = content.__dict__
|
||||||
self.pack_start(header.header, False, False)
|
#self.vis_func = self.attrs.get("visible", None)
|
||||||
self.pack_start(self.content, True, True)
|
#self.invis_func = self.attrs.get("invisible", None)
|
||||||
if self.add_footer == True:
|
#self.add_header = add_header
|
||||||
self.pack_start(footer.footer, False, False)
|
#self.add_footer = add_footer
|
||||||
if self.vis_func:
|
#self.show()
|
||||||
self.vis_func()
|
|
||||||
|
|
||||||
def invisible(self):
|
#def filter(self, text):
|
||||||
if self.add_header == True:
|
#self.content.filter(text)
|
||||||
self.remove(header.header)
|
|
||||||
self.remove(self.content)
|
#def reset(self):
|
||||||
if self.add_footer == True:
|
#self.content.reset()
|
||||||
self.remove(footer.footer)
|
|
||||||
if self.invis_func:
|
#def goto(self):
|
||||||
self.invis_func()
|
#self.content.goto()
|
||||||
|
|
||||||
|
#def visible(self):
|
||||||
|
#if self.add_header == True:
|
||||||
|
#self.pack_start(header.header, False, False)
|
||||||
|
#self.pack_start(self.content, True, True)
|
||||||
|
#if self.add_footer == True:
|
||||||
|
#self.pack_start(footer.footer, False, False)
|
||||||
|
#if self.vis_func:
|
||||||
|
#self.vis_func()
|
||||||
|
|
||||||
|
#def invisible(self):
|
||||||
|
#if self.add_header == True:
|
||||||
|
#self.remove(header.header)
|
||||||
|
#self.remove(self.content)
|
||||||
|
#if self.add_footer == True:
|
||||||
|
#self.remove(footer.footer)
|
||||||
|
#if self.invis_func:
|
||||||
|
#self.invis_func()
|
||||||
|
|
|
@ -1,56 +1,64 @@
|
||||||
# Bryan Schumaker (11/26/2010)
|
# Bryan Schumaker (11/26/2010)
|
||||||
|
|
||||||
import ocarina
|
import sources
|
||||||
from ocarina import body
|
import body
|
||||||
from ocarina import sources
|
|
||||||
import menu
|
|
||||||
|
|
||||||
lib_page = sources.Source()
|
lib_page = sources.Source()
|
||||||
|
LIB_PAGE = body.add_page(lib_page, "Library")
|
||||||
|
|
||||||
gtk = ocarina.gtk
|
|
||||||
sources = ocarina.libsaria.sources
|
|
||||||
library = sources.library
|
|
||||||
visible = library.is_visible
|
|
||||||
|
|
||||||
libsaria = ocarina.libsaria
|
|
||||||
|
|
||||||
def init():
|
#import ocarina
|
||||||
body.add_page("Library", lib_page)
|
#from ocarina import body
|
||||||
sources.init_src(library.init_bg, filler)
|
#from ocarina import sources
|
||||||
libsaria.event.invite("POSTNEWSOURCE", refresh)
|
#import menu
|
||||||
|
|
||||||
def filler():
|
#lib_page = sources.Source()
|
||||||
lib_page.init(filter, is_visible, right_click, library.play_id, reset)
|
|
||||||
menu.add_lib_menu_item("Add to queue", add_selected_to_queue)
|
|
||||||
menu.add_lib_menu_item("Add to playlist", add_selected_to_playlist)
|
|
||||||
lib_page.fill(library.walk, True)
|
|
||||||
|
|
||||||
def filter(text):
|
#gtk = ocarina.gtk
|
||||||
library.filter(text)
|
#sources = ocarina.libsaria.sources
|
||||||
lib_page.refilter()
|
#library = sources.library
|
||||||
lib_page.goto()
|
#visible = library.is_visible
|
||||||
|
|
||||||
def is_visible(list, iter):
|
#libsaria = ocarina.libsaria
|
||||||
return visible(list[iter][0])
|
|
||||||
|
|
||||||
def reset():
|
#def init():
|
||||||
import playlist
|
#body.add_page("Library", lib_page)
|
||||||
playlist.reset()
|
#sources.init_src(library.init_bg, filler)
|
||||||
lib_page.clear()
|
#libsaria.event.invite("POSTNEWSOURCE", refresh)
|
||||||
library.reset()
|
|
||||||
library.save()
|
|
||||||
|
|
||||||
def refresh(*args):
|
#def filler():
|
||||||
lib_page.clear()
|
#lib_page.init(filter, is_visible, right_click, library.play_id, reset)
|
||||||
lib_page.fill(library.walk)
|
#menu.add_lib_menu_item("Add to queue", add_selected_to_queue)
|
||||||
|
#menu.add_lib_menu_item("Add to playlist", add_selected_to_playlist)
|
||||||
|
#lib_page.fill(library.walk, True)
|
||||||
|
|
||||||
def right_click(button, time):
|
#def filter(text):
|
||||||
menu.make_lib_menu(button, time)
|
#library.filter(text)
|
||||||
|
#lib_page.refilter()
|
||||||
|
#lib_page.goto()
|
||||||
|
|
||||||
def add_selected_to_playlist(menu):
|
#def is_visible(list, iter):
|
||||||
import playlist
|
#return visible(list[iter][0])
|
||||||
playlist.add_to_playlist(lib_page)
|
|
||||||
|
|
||||||
def add_selected_to_queue(menu):
|
#def reset():
|
||||||
import queue
|
#import playlist
|
||||||
queue.add_to_queue(lib_page)
|
#playlist.reset()
|
||||||
|
#lib_page.clear()
|
||||||
|
#library.reset()
|
||||||
|
#library.save()
|
||||||
|
|
||||||
|
#def refresh(*args):
|
||||||
|
#lib_page.clear()
|
||||||
|
#lib_page.fill(library.walk)
|
||||||
|
|
||||||
|
#def right_click(button, time):
|
||||||
|
#menu.make_lib_menu(button, time)
|
||||||
|
|
||||||
|
#def add_selected_to_playlist(menu):
|
||||||
|
#import playlist
|
||||||
|
#playlist.add_to_playlist(lib_page)
|
||||||
|
|
||||||
|
#def add_selected_to_queue(menu):
|
||||||
|
#import queue
|
||||||
|
#queue.add_to_queue(lib_page)
|
||||||
|
|
|
@ -3,47 +3,57 @@
|
||||||
import gtk
|
import gtk
|
||||||
import ocarina
|
import ocarina
|
||||||
import libsaria
|
import libsaria
|
||||||
files = None
|
import body
|
||||||
|
#files = None
|
||||||
|
|
||||||
TARGET_TYPE_URI_LIST = 80
|
#TARGET_TYPE_URI_LIST = 80
|
||||||
DND_MASK = gtk.DEST_DEFAULT_MOTION | gtk.DEST_DEFAULT_HIGHLIGHT | gtk.DEST_DEFAULT_DROP
|
#DND_MASK = gtk.DEST_DEFAULT_MOTION | gtk.DEST_DEFAULT_HIGHLIGHT | gtk.DEST_DEFAULT_DROP
|
||||||
DND_LIST = [("text/uri-list", 0, TARGET_TYPE_URI_LIST)]
|
#DND_LIST = [("text/uri-list", 0, TARGET_TYPE_URI_LIST)]
|
||||||
|
|
||||||
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
|
width = libsaria.init_pref("ocarina.window.width", 800)
|
||||||
set_title = window.set_title
|
height = libsaria.init_pref("ocarina.window.height", 600)
|
||||||
|
|
||||||
window.drag_dest_set(DND_MASK, DND_LIST, gtk.gdk.ACTION_COPY)
|
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
|
||||||
set_title(ocarina.__vers__)
|
window.resize(width, height)
|
||||||
|
window.connect("delete-event", ocarina.quit)
|
||||||
|
window.add(body.body)
|
||||||
|
window.show()
|
||||||
|
|
||||||
def init():
|
def set_title(new_title = None):
|
||||||
from components import entry
|
if new_title == None:
|
||||||
width = libsaria.init_pref("ocarina.window.width", 800)
|
new_title = ocarina.__vers__
|
||||||
height = libsaria.init_pref("ocarina.window.height", 600)
|
window.set_title(new_title)
|
||||||
window.connect("key-press-event", entry.key_press)
|
set_title()
|
||||||
window.resize(width, height)
|
|
||||||
window.show()
|
|
||||||
|
|
||||||
def set_icon(path):
|
def set_icon(icon = "images/ocarina.png"):
|
||||||
if libsaria.path.exists(path):
|
window.set_icon_from_file(icon)
|
||||||
window.set_icon_from_file(path)
|
set_icon()
|
||||||
|
|
||||||
def resized(widget, geom):
|
def resized(widget, geom):
|
||||||
if libsaria.prefs.get_pref("ocarina.window.width") != geom.width:
|
if libsaria.prefs.get_pref("ocarina.window.width") != geom.width:
|
||||||
libsaria.prefs.set_pref("ocarina.window.width", geom.width)
|
libsaria.prefs.set_pref("ocarina.window.width", geom.width)
|
||||||
if libsaria.prefs.get_pref("ocarina.window.height") != geom.height:
|
if libsaria.prefs.get_pref("ocarina.window.height") != geom.height:
|
||||||
libsaria.prefs.set_pref("ocarina.window.height", geom.height)
|
libsaria.prefs.set_pref("ocarina.window.height", geom.height)
|
||||||
|
|
||||||
def dnd_receive(widget, context, x, y, selection, type, time):
|
|
||||||
global files
|
|
||||||
if files == None:
|
|
||||||
from libsaria.path import files
|
|
||||||
if type == TARGET_TYPE_URI_LIST:
|
|
||||||
uri = selection.data.strip('\r\n\x00')
|
|
||||||
for file in uri.split():
|
|
||||||
file = file[7:]
|
|
||||||
files.universal_open(file)
|
|
||||||
|
|
||||||
window.connect("delete-event", ocarina.exit)
|
|
||||||
window.connect("size-allocate", resized)
|
window.connect("size-allocate", resized)
|
||||||
window.connect("drag-data-received", dnd_receive)
|
|
||||||
set_icon("images/ocarina.png")
|
#window.drag_dest_set(DND_MASK, DND_LIST, gtk.gdk.ACTION_COPY)
|
||||||
|
|
||||||
|
#def init():
|
||||||
|
#from components import entry
|
||||||
|
#width = libsaria.init_pref("ocarina.window.width", 800)
|
||||||
|
#height = libsaria.init_pref("ocarina.window.height", 600)
|
||||||
|
#window.connect("key-press-event", entry.key_press)
|
||||||
|
#window.resize(width, height)
|
||||||
|
#window.show()
|
||||||
|
|
||||||
|
#def dnd_receive(widget, context, x, y, selection, type, time):
|
||||||
|
#global files
|
||||||
|
#if files == None:
|
||||||
|
#from libsaria.path import files
|
||||||
|
#if type == TARGET_TYPE_URI_LIST:
|
||||||
|
#uri = selection.data.strip('\r\n\x00')
|
||||||
|
#for file in uri.split():
|
||||||
|
#file = file[7:]
|
||||||
|
#files.universal_open(file)
|
||||||
|
|
||||||
|
#window.connect("drag-data-received", dnd_receive)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user