Clean up window creation
I do as much as I can outside of the init() function to make the code more readable. Doing everything in init() can make things more complicated and annoying.
This commit is contained in:
parent
5e051b523d
commit
ef78427954
|
@ -10,10 +10,7 @@ from ocarina import playlist
|
|||
from ocarina import queue
|
||||
from ocarina import menu
|
||||
|
||||
width = libsaria.init_pref("ocarina.window.width", 800)
|
||||
height = libsaria.init_pref("ocarina.window.height", 600)
|
||||
|
||||
window.init(width, height)
|
||||
window.init()
|
||||
body.init(window)
|
||||
window.set_title("%s" % ocarina.__vers__)
|
||||
window.set_icon("images/ocarina.png")
|
||||
|
|
|
@ -1,62 +1,47 @@
|
|||
# Bryan Schumaker (8/13/2010)
|
||||
|
||||
import gtk
|
||||
import ocarina
|
||||
libsaria = ocarina.libsaria
|
||||
gtk = ocarina.gtk
|
||||
import libsaria
|
||||
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)]
|
||||
|
||||
window = None
|
||||
add = None
|
||||
resize = None
|
||||
connect = None
|
||||
set_title = None
|
||||
prefs = None
|
||||
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
|
||||
add = window.add
|
||||
resize = window.resize
|
||||
connect = window.connect
|
||||
set_title = window.set_title
|
||||
prefs = libsaria.prefs
|
||||
|
||||
def init(width, height):
|
||||
global window
|
||||
global add
|
||||
global resize
|
||||
global connect
|
||||
global set_title
|
||||
global prefs
|
||||
window.drag_dest_set(DND_MASK, DND_LIST, gtk.gdk.ACTION_COPY)
|
||||
|
||||
def init():
|
||||
from components import entry
|
||||
|
||||
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
|
||||
add = window.add
|
||||
resize = window.resize
|
||||
connect = window.connect
|
||||
set_title = window.set_title
|
||||
prefs = libsaria.prefs
|
||||
width = libsaria.init_pref("ocarina.window.width", 800)
|
||||
height = libsaria.init_pref("ocarina.window.height", 600)
|
||||
|
||||
connect("key-press-event", entry.key_press)
|
||||
connect("delete-event", ocarina.exit)
|
||||
connect("size-allocate", resized)
|
||||
connect("drag-data-received", dnd_receive)
|
||||
|
||||
mask = gtk.DEST_DEFAULT_MOTION | gtk.DEST_DEFAULT_HIGHLIGHT | gtk.DEST_DEFAULT_DROP
|
||||
dnd_list = [("text/uri-list", 0, TARGET_TYPE_URI_LIST)]
|
||||
window.drag_dest_set(mask, dnd_list, gtk.gdk.ACTION_COPY)
|
||||
|
||||
resize(width, height)
|
||||
window.show()
|
||||
|
||||
|
||||
def set_icon(path):
|
||||
global window
|
||||
if libsaria.path.exists(path):
|
||||
window.set_icon_from_file(path)
|
||||
|
||||
|
||||
def resized(widget, geom):
|
||||
if prefs.get_pref("ocarina.window.width") != geom.width:
|
||||
libsaria.prefs.set_pref("ocarina.window.width", geom.width)
|
||||
if 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:
|
||||
|
|
Loading…
Reference in New Issue
Block a user