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 queue
|
||||||
from ocarina import menu
|
from ocarina import menu
|
||||||
|
|
||||||
width = libsaria.init_pref("ocarina.window.width", 800)
|
window.init()
|
||||||
height = libsaria.init_pref("ocarina.window.height", 600)
|
|
||||||
|
|
||||||
window.init(width, height)
|
|
||||||
body.init(window)
|
body.init(window)
|
||||||
window.set_title("%s" % ocarina.__vers__)
|
window.set_title("%s" % ocarina.__vers__)
|
||||||
window.set_icon("images/ocarina.png")
|
window.set_icon("images/ocarina.png")
|
||||||
|
|
|
@ -1,62 +1,47 @@
|
||||||
# Bryan Schumaker (8/13/2010)
|
# Bryan Schumaker (8/13/2010)
|
||||||
|
|
||||||
|
import gtk
|
||||||
import ocarina
|
import ocarina
|
||||||
libsaria = ocarina.libsaria
|
import libsaria
|
||||||
gtk = ocarina.gtk
|
|
||||||
files = None
|
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_LIST = [("text/uri-list", 0, TARGET_TYPE_URI_LIST)]
|
||||||
|
|
||||||
window = None
|
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
|
||||||
add = None
|
add = window.add
|
||||||
resize = None
|
resize = window.resize
|
||||||
connect = None
|
connect = window.connect
|
||||||
set_title = None
|
set_title = window.set_title
|
||||||
prefs = None
|
prefs = libsaria.prefs
|
||||||
|
|
||||||
def init(width, height):
|
window.drag_dest_set(DND_MASK, DND_LIST, gtk.gdk.ACTION_COPY)
|
||||||
global window
|
|
||||||
global add
|
|
||||||
global resize
|
|
||||||
global connect
|
|
||||||
global set_title
|
|
||||||
global prefs
|
|
||||||
|
|
||||||
|
def init():
|
||||||
from components import entry
|
from components import entry
|
||||||
|
|
||||||
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
|
width = libsaria.init_pref("ocarina.window.width", 800)
|
||||||
add = window.add
|
height = libsaria.init_pref("ocarina.window.height", 600)
|
||||||
resize = window.resize
|
|
||||||
connect = window.connect
|
|
||||||
set_title = window.set_title
|
|
||||||
prefs = libsaria.prefs
|
|
||||||
|
|
||||||
connect("key-press-event", entry.key_press)
|
connect("key-press-event", entry.key_press)
|
||||||
connect("delete-event", ocarina.exit)
|
connect("delete-event", ocarina.exit)
|
||||||
connect("size-allocate", resized)
|
connect("size-allocate", resized)
|
||||||
connect("drag-data-received", dnd_receive)
|
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)
|
resize(width, height)
|
||||||
window.show()
|
window.show()
|
||||||
|
|
||||||
|
|
||||||
def set_icon(path):
|
def set_icon(path):
|
||||||
global window
|
|
||||||
if libsaria.path.exists(path):
|
if libsaria.path.exists(path):
|
||||||
window.set_icon_from_file(path)
|
window.set_icon_from_file(path)
|
||||||
|
|
||||||
|
|
||||||
def resized(widget, geom):
|
def resized(widget, geom):
|
||||||
if prefs.get_pref("ocarina.window.width") != geom.width:
|
if 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 prefs.get_pref("ocarina.window.height") != geom.height:
|
if 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):
|
def dnd_receive(widget, context, x, y, selection, type, time):
|
||||||
global files
|
global files
|
||||||
if files == None:
|
if files == None:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user