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:
parent
1139ba09c3
commit
8674fd8f17
|
@ -18,7 +18,7 @@ get_window = None
|
|||
|
||||
|
||||
# Global variables for some objects
|
||||
main_window = None
|
||||
#main_window = None
|
||||
#main_tabs = None
|
||||
|
||||
def startup():
|
||||
|
@ -56,17 +56,16 @@ def remove_tab(text):
|
|||
def get_window_once(size):
|
||||
global window
|
||||
global get_window
|
||||
global main_window
|
||||
import window
|
||||
main_window = window.Window(size)
|
||||
main_window.add(get_tabs())
|
||||
window.init(size)
|
||||
window.add(get_tabs())
|
||||
get_window = get_window_rest
|
||||
return main_window
|
||||
return window.window
|
||||
def get_window_rest(size=None):
|
||||
global main_window
|
||||
global window
|
||||
if size != None:
|
||||
main_window.resize(size[0], size[1])
|
||||
return main_window
|
||||
window.resize(size[0], size[1])
|
||||
return window.window
|
||||
get_window = get_window_once
|
||||
|
||||
def set_window_title(text):
|
||||
|
|
|
@ -7,34 +7,46 @@ data = None
|
|||
|
||||
TARGET_TYPE_URI_LIST = 80
|
||||
|
||||
|
||||
class Window(gtk.Window):
|
||||
def __init__(self, size):
|
||||
gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
|
||||
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()
|
||||
window = None
|
||||
add = None
|
||||
resize = None
|
||||
connect = None
|
||||
|
||||
|
||||
def resized(self, widget, geom):
|
||||
libsaria.prefs["window_size"] = (geom.width, geom.height)
|
||||
def init(size):
|
||||
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):
|
||||
global data
|
||||
if data == None:
|
||||
from libsaria import data
|
||||
if type == TARGET_TYPE_URI_LIST:
|
||||
uri = selection.data.strip('\r\n\x00')
|
||||
import os
|
||||
for file in uri.split():
|
||||
file = file[7:]
|
||||
data.universal_open(file)
|
||||
def resized(widget, geom):
|
||||
libsaria.prefs["window_size"] = (geom.width, geom.height)
|
||||
|
||||
|
||||
def dnd_receive(widget, context, x, y, selection, type, time):
|
||||
global data
|
||||
if data == None:
|
||||
from libsaria import data
|
||||
if type == TARGET_TYPE_URI_LIST:
|
||||
uri = selection.data.strip('\r\n\x00')
|
||||
import os
|
||||
for file in uri.split():
|
||||
file = file[7:]
|
||||
data.universal_open(file)
|
||||
|
|
Loading…
Reference in New Issue