2010-08-13 23:58:19 -04:00
|
|
|
# Bryan Schumaker (8/13/2010)
|
|
|
|
|
2011-04-17 09:19:19 -04:00
|
|
|
import gtk
|
2010-08-13 23:58:19 -04:00
|
|
|
import ocarina
|
2011-04-17 09:19:19 -04:00
|
|
|
import libsaria
|
2011-04-18 20:29:56 -04:00
|
|
|
import body
|
2011-04-24 08:55:33 -04:00
|
|
|
import shortcuts
|
2011-04-24 19:13:13 -04:00
|
|
|
from libsaria.path import files
|
2010-08-13 23:58:19 -04:00
|
|
|
|
2011-04-24 19:13:13 -04:00
|
|
|
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)]
|
2010-08-15 00:25:24 -04:00
|
|
|
|
2011-04-18 20:29:56 -04:00
|
|
|
width = libsaria.init_pref("ocarina.window.width", 800)
|
|
|
|
height = libsaria.init_pref("ocarina.window.height", 600)
|
2010-08-15 00:25:24 -04:00
|
|
|
|
2011-04-18 20:29:56 -04:00
|
|
|
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
|
|
|
|
window.resize(width, height)
|
|
|
|
window.connect("delete-event", ocarina.quit)
|
2011-04-24 08:55:33 -04:00
|
|
|
window.connect("key-press-event", shortcuts.key_pressed)
|
2011-04-18 20:29:56 -04:00
|
|
|
window.add(body.body)
|
|
|
|
window.show()
|
2010-08-13 23:58:19 -04:00
|
|
|
|
2011-04-24 09:13:13 -04:00
|
|
|
def grab_focus():
|
|
|
|
window.set_focus(None)
|
|
|
|
shortcuts.register_shortcut("Escape", grab_focus, True)
|
|
|
|
|
2011-04-18 20:29:56 -04:00
|
|
|
def set_title(new_title = None):
|
|
|
|
if new_title == None:
|
|
|
|
new_title = ocarina.__vers__
|
|
|
|
window.set_title(new_title)
|
|
|
|
set_title()
|
2010-08-13 23:58:19 -04:00
|
|
|
|
2011-04-18 20:29:56 -04:00
|
|
|
def set_icon(icon = "images/ocarina.png"):
|
|
|
|
window.set_icon_from_file(icon)
|
|
|
|
set_icon()
|
2010-11-23 20:05:37 -05:00
|
|
|
|
2010-08-22 09:20:27 -04:00
|
|
|
def resized(widget, geom):
|
2011-04-17 09:36:11 -04:00
|
|
|
if libsaria.prefs.get_pref("ocarina.window.width") != geom.width:
|
2010-12-16 11:03:09 -05:00
|
|
|
libsaria.prefs.set_pref("ocarina.window.width", geom.width)
|
2011-04-17 09:36:11 -04:00
|
|
|
if libsaria.prefs.get_pref("ocarina.window.height") != geom.height:
|
2010-12-16 11:03:09 -05:00
|
|
|
libsaria.prefs.set_pref("ocarina.window.height", geom.height)
|
2011-04-17 09:36:11 -04:00
|
|
|
window.connect("size-allocate", resized)
|
2011-04-18 20:29:56 -04:00
|
|
|
|
2011-04-24 19:13:13 -04:00
|
|
|
def dnd_receive(widget, context, x, y, selection, type, time):
|
|
|
|
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)
|
|
|
|
window.drag_dest_set(DND_MASK, DND_LIST, gtk.gdk.ACTION_COPY)
|