Declassify Window()

We should only ever have one instance of the main window, so there is no
reason for it to be a class.  I have turned it into a set of functions
that do the same thing.
This commit is contained in:
Bryan Schumaker 2010-08-22 09:20:27 -04:00
parent 1139ba09c3
commit 8674fd8f17
2 changed files with 46 additions and 35 deletions

View File

@ -18,7 +18,7 @@ get_window = None
# Global variables for some objects # Global variables for some objects
main_window = None #main_window = None
#main_tabs = None #main_tabs = None
def startup(): def startup():
@ -56,17 +56,16 @@ def remove_tab(text):
def get_window_once(size): def get_window_once(size):
global window global window
global get_window global get_window
global main_window
import window import window
main_window = window.Window(size) window.init(size)
main_window.add(get_tabs()) window.add(get_tabs())
get_window = get_window_rest get_window = get_window_rest
return main_window return window.window
def get_window_rest(size=None): def get_window_rest(size=None):
global main_window global window
if size != None: if size != None:
main_window.resize(size[0], size[1]) window.resize(size[0], size[1])
return main_window return window.window
get_window = get_window_once get_window = get_window_once
def set_window_title(text): def set_window_title(text):

View File

@ -7,34 +7,46 @@ data = None
TARGET_TYPE_URI_LIST = 80 TARGET_TYPE_URI_LIST = 80
window = None
class Window(gtk.Window): add = None
def __init__(self, size): resize = None
gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL) connect = None
connect = self.connect
connect("delete-event", ocarina.exit)
connect("size-allocate", self.resized)
connect("drag-data-received", self.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)]
self.drag_dest_set(mask, dnd_list, gtk.gdk.ACTION_COPY)
self.resize(size[0], size[1])
self.show()
def resized(self, widget, geom): def init(size):
libsaria.prefs["window_size"] = (geom.width, geom.height) global window
global add
global resize
global connect
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
add = window.add
resize = window.resize
connect = window.connect
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)
window.resize(size[0], size[1])
window.show()
def dnd_receive(self, widget, context, x, y, selection, type, time): def resized(widget, geom):
global data libsaria.prefs["window_size"] = (geom.width, geom.height)
if data == None:
from libsaria import data
if type == TARGET_TYPE_URI_LIST: def dnd_receive(widget, context, x, y, selection, type, time):
uri = selection.data.strip('\r\n\x00') global data
import os if data == None:
for file in uri.split(): from libsaria import data
file = file[7:] if type == TARGET_TYPE_URI_LIST:
data.universal_open(file) uri = selection.data.strip('\r\n\x00')
import os
for file in uri.split():
file = file[7:]
data.universal_open(file)