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 libsaria
|
||||
|
||||
gdk = gtk.gdk
|
||||
gobject.threads_init()
|
||||
|
||||
#gdk = gtk.gdk
|
||||
__vers__ = "Ocarina %s" % libsaria.__vstr__
|
||||
gobject.threads_init()
|
||||
|
||||
def uptime():
|
||||
return now() - __start__
|
||||
|
||||
def startup():
|
||||
libsaria.startup()
|
||||
body.init_page("Library")
|
||||
print "Startup took:", uptime()
|
||||
gtk.main()
|
||||
|
||||
def exit(widget, event):
|
||||
def quit(window, event):
|
||||
gtk.main_quit()
|
||||
libsaria.shutdown()
|
||||
print "Ocarina ran for: %s" % uptime()
|
||||
print "Ocarina ran for:", uptime()
|
||||
|
||||
import window
|
||||
import body
|
||||
|
||||
window.init()
|
||||
body.init(window.window)
|
||||
libsaria.startup()
|
||||
print "Startup took:", uptime()
|
||||
gtk.main()
|
||||
|
||||
import library
|
||||
import playlist
|
||||
import queue
|
||||
playlist.init()
|
||||
queue.init()
|
||||
library.init()
|
||||
startup()
|
||||
|
||||
#import body
|
||||
|
||||
#window.init()
|
||||
#body.init(window.window)
|
||||
|
||||
#import library
|
||||
#import playlist
|
||||
#import queue
|
||||
#playlist.init()
|
||||
#queue.init()
|
||||
#library.init()
|
||||
#startup()
|
||||
|
|
|
@ -1,77 +1,83 @@
|
|||
# Bryan Schumaker (11/24/2010)
|
||||
|
||||
import gtk
|
||||
import ocarina
|
||||
import page
|
||||
Label = gtk.Label
|
||||
prefs = ocarina.libsaria.prefs
|
||||
get_pref = prefs.get_pref
|
||||
set_pref = prefs.set_pref
|
||||
from page import OcarinaPage
|
||||
|
||||
contents = dict()
|
||||
body = gtk.Notebook()
|
||||
body.show()
|
||||
body.set_tab_pos(gtk.POS_LEFT)
|
||||
page_num = body.page_num
|
||||
|
||||
body = None
|
||||
|
||||
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)
|
||||
def add_page(content, page_name):
|
||||
label = gtk.Label(page_name)
|
||||
label.set_angle(90)
|
||||
pg = page.Page(content, add_header, add_footer)
|
||||
contents[name] = pg
|
||||
body.append_page(pg, label)
|
||||
body.set_tab_label_packing(pg, True, True, gtk.PACK_START)
|
||||
page = OcarinaPage(content, label)
|
||||
body.append_page(page, label)
|
||||
body.set_tab_label_packing(page, 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):
|
||||
page = contents.get(name, None)
|
||||
if page == None:
|
||||
return
|
||||
n = body.page_num(page)
|
||||
if n == body.get_current_page():
|
||||
body.set_current_page(n - 1)
|
||||
body.remove_page(n)
|
||||
del contents[name]
|
||||
def remove_page(page):
|
||||
page.invisible()
|
||||
page.rm_content()
|
||||
body.remove_page(page_num(page))
|
||||
|
||||
def current_page():
|
||||
cur_num = body.get_current_page()
|
||||
return body.get_nth_page(cur_num)
|
||||
|
||||
def switch_to_page(page):
|
||||
body.set_current_page(page_num(page))
|
||||
|
||||
def switch_page(notebook, page, pagenum):
|
||||
cur_num = body.get_current_page()
|
||||
child = body.get_nth_page(cur_num)
|
||||
cur_pg = current_page()
|
||||
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()
|
||||
cur_pg.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)
|
||||
#import ocarina
|
||||
#Label = gtk.Label
|
||||
#prefs = ocarina.libsaria.prefs
|
||||
#get_pref = prefs.get_pref
|
||||
#set_pref = prefs.set_pref
|
||||
|
||||
def cur_page_reset():
|
||||
cur_num = body.get_current_page()
|
||||
page = body.get_nth_page(cur_num)
|
||||
page.reset()
|
||||
#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 cur_page_goto():
|
||||
cur_num = body.get_current_page()
|
||||
page = body.get_nth_page(cur_num)
|
||||
page.goto()
|
||||
#def switch_page(notebook, page, pagenum):
|
||||
#cur_num = body.get_current_page()
|
||||
#child = body.get_nth_page(cur_num)
|
||||
#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)
|
||||
|
||||
import gtk
|
||||
import header
|
||||
import footer
|
||||
#import header
|
||||
#import footer
|
||||
SHRINK = gtk.SHRINK
|
||||
GROW = gtk.FILL | gtk.EXPAND
|
||||
|
||||
class Page(gtk.VBox):
|
||||
def __init__(self, content, add_header, add_footer):
|
||||
gtk.VBox.__init__(self)
|
||||
self.content = content
|
||||
self.attrs = content.__dict__
|
||||
self.vis_func = self.attrs.get("visible", None)
|
||||
self.invis_func = self.attrs.get("invisible", None)
|
||||
self.add_header = add_header
|
||||
self.add_footer = add_footer
|
||||
class OcarinaPage(gtk.Table):
|
||||
def __init__(self, content, label):
|
||||
gtk.Table.__init__(self, 3, 1, False)
|
||||
self.content = content
|
||||
self.label = label
|
||||
self.block_shortcuts = False
|
||||
self.attach_center(content)
|
||||
self.show()
|
||||
|
||||
def filter(self, text):
|
||||
self.content.filter(text)
|
||||
def attach_top(self, content):
|
||||
self.attach(content, 0, 1, 0, 1, GROW, SHRINK)
|
||||
|
||||
def reset(self):
|
||||
self.content.reset()
|
||||
def attach_center(self, content):
|
||||
self.attach(content, 0, 1, 1, 2)
|
||||
|
||||
def goto(self):
|
||||
self.content.goto()
|
||||
def attach_bottom(self, content):
|
||||
self.attach(content, 0, 1, 2, 3, GROW, SHRINK)
|
||||
|
||||
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()
|
||||
#self.content = content
|
||||
#self.attrs = content.__dict__
|
||||
#self.vis_func = self.attrs.get("visible", None)
|
||||
#self.invis_func = self.attrs.get("invisible", None)
|
||||
#self.add_header = add_header
|
||||
#self.add_footer = add_footer
|
||||
#self.show()
|
||||
|
||||
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()
|
||||
#def filter(self, text):
|
||||
#self.content.filter(text)
|
||||
|
||||
#def reset(self):
|
||||
#self.content.reset()
|
||||
|
||||
#def goto(self):
|
||||
#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)
|
||||
|
||||
import ocarina
|
||||
from ocarina import body
|
||||
from ocarina import sources
|
||||
import menu
|
||||
import sources
|
||||
import body
|
||||
|
||||
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():
|
||||
body.add_page("Library", lib_page)
|
||||
sources.init_src(library.init_bg, filler)
|
||||
libsaria.event.invite("POSTNEWSOURCE", refresh)
|
||||
#import ocarina
|
||||
#from ocarina import body
|
||||
#from ocarina import sources
|
||||
#import menu
|
||||
|
||||
def filler():
|
||||
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)
|
||||
#lib_page = sources.Source()
|
||||
|
||||
def filter(text):
|
||||
library.filter(text)
|
||||
lib_page.refilter()
|
||||
lib_page.goto()
|
||||
#gtk = ocarina.gtk
|
||||
#sources = ocarina.libsaria.sources
|
||||
#library = sources.library
|
||||
#visible = library.is_visible
|
||||
|
||||
def is_visible(list, iter):
|
||||
return visible(list[iter][0])
|
||||
#libsaria = ocarina.libsaria
|
||||
|
||||
def reset():
|
||||
import playlist
|
||||
playlist.reset()
|
||||
lib_page.clear()
|
||||
library.reset()
|
||||
library.save()
|
||||
#def init():
|
||||
#body.add_page("Library", lib_page)
|
||||
#sources.init_src(library.init_bg, filler)
|
||||
#libsaria.event.invite("POSTNEWSOURCE", refresh)
|
||||
|
||||
def refresh(*args):
|
||||
lib_page.clear()
|
||||
lib_page.fill(library.walk)
|
||||
#def filler():
|
||||
#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 right_click(button, time):
|
||||
menu.make_lib_menu(button, time)
|
||||
#def filter(text):
|
||||
#library.filter(text)
|
||||
#lib_page.refilter()
|
||||
#lib_page.goto()
|
||||
|
||||
def add_selected_to_playlist(menu):
|
||||
import playlist
|
||||
playlist.add_to_playlist(lib_page)
|
||||
#def is_visible(list, iter):
|
||||
#return visible(list[iter][0])
|
||||
|
||||
def add_selected_to_queue(menu):
|
||||
import queue
|
||||
queue.add_to_queue(lib_page)
|
||||
#def reset():
|
||||
#import playlist
|
||||
#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 ocarina
|
||||
import libsaria
|
||||
files = None
|
||||
import body
|
||||
#files = None
|
||||
|
||||
TARGET_TYPE_URI_LIST = 80
|
||||
DND_MASK = gtk.DEST_DEFAULT_MOTION | gtk.DEST_DEFAULT_HIGHLIGHT | gtk.DEST_DEFAULT_DROP
|
||||
DND_LIST = [("text/uri-list", 0, TARGET_TYPE_URI_LIST)]
|
||||
#TARGET_TYPE_URI_LIST = 80
|
||||
#DND_MASK = gtk.DEST_DEFAULT_MOTION | gtk.DEST_DEFAULT_HIGHLIGHT | gtk.DEST_DEFAULT_DROP
|
||||
#DND_LIST = [("text/uri-list", 0, TARGET_TYPE_URI_LIST)]
|
||||
|
||||
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
|
||||
set_title = window.set_title
|
||||
width = libsaria.init_pref("ocarina.window.width", 800)
|
||||
height = libsaria.init_pref("ocarina.window.height", 600)
|
||||
|
||||
window.drag_dest_set(DND_MASK, DND_LIST, gtk.gdk.ACTION_COPY)
|
||||
set_title(ocarina.__vers__)
|
||||
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
|
||||
window.resize(width, height)
|
||||
window.connect("delete-event", ocarina.quit)
|
||||
window.add(body.body)
|
||||
window.show()
|
||||
|
||||
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 set_title(new_title = None):
|
||||
if new_title == None:
|
||||
new_title = ocarina.__vers__
|
||||
window.set_title(new_title)
|
||||
set_title()
|
||||
|
||||
def set_icon(path):
|
||||
if libsaria.path.exists(path):
|
||||
window.set_icon_from_file(path)
|
||||
def set_icon(icon = "images/ocarina.png"):
|
||||
window.set_icon_from_file(icon)
|
||||
set_icon()
|
||||
|
||||
def resized(widget, geom):
|
||||
if libsaria.prefs.get_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:
|
||||
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("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