1 from sugar
.activity
import activity
9 class WineActivity(activity
.Activity
):
10 def __init__(self
, handle
):
11 activity
.Activity
.__init
__(self
, handle
)
13 self
.bundle_path
= activity
.get_bundle_path()
16 activity_root
= activity
.get_activity_root()
17 wine_prefix
= os
.path
.join(activity_root
, 'data', 'wine')
18 except AttributeError:
20 activity_root
= os
.environ
['SUGAR_ACTIVITY_ROOT']
21 wine_prefix
= os
.path
.join(activity_root
, 'data', 'wine')
24 wine_prefix
= os
.path
.expanduser('~/.wine')
27 self
.desktop_parent
= gtk
.EventBox()
28 self
.desktop_parent
.show()
29 self
.set_canvas(self
.desktop_parent
)
30 except AttributeError:
31 # remove any children of the window that Sugar may have added
32 for widget
in self
.get_children():
35 self
.desktop_parent
= self
37 os
.environ
['LD_LIBRARY_PATH'] = "%s:%s" % (os
.path
.join(self
.bundle_path
, 'lib'), os
.environ
.get('LD_LIBRARY_PATH', ''))
38 os
.environ
['PATH'] = "%s:%s" % (os
.path
.join(self
.bundle_path
, 'bin'), os
.environ
.get('PATH', ''))
39 os
.environ
['WINEPREFIX'] = wine_prefix
40 os
.environ
['WINELOADER'] = os
.path
.join(self
.bundle_path
, 'bin/wine')
41 os
.environ
['WINESERVER'] = os
.path
.join(self
.bundle_path
, 'bin/wineserver')
42 os
.environ
['WINEDLLPATH'] = os
.path
.join(self
.bundle_path
, 'lib/wine')
44 firstrun
= not os
.path
.exists(wine_prefix
)
46 self
.setup_prefix(firstrun
)
48 self
.desktop_parent
.connect('map', self
.on_parent_map
)
50 self
.set_title("Wine")
52 def on_parent_map(self
, widget
):
53 os
.environ
['WINE_DESKTOP_PARENT'] = str(self
.desktop_parent
.window
.xid
)
57 allocation
= self
.desktop_parent
.get_allocation()
59 width
= gtk
.gdk
.screen_width()
60 height
= gtk
.gdk
.screen_height()
62 self
.wine_pid
, stdin
, stdout
, stderr
= gobject
.spawn_async(
63 ('wine', 'explorer', '/desktop=Sugar,%sx%s' % (width
, height
)),
64 flags
=gobject
.SPAWN_SEARCH_PATH|gobject
.SPAWN_DO_NOT_REAP_CHILD
)
65 gobject
.child_watch_add(self
.wine_pid
, self
.on_wine_quit
, None)
67 def start_wine(self
, *args
):
69 ['wine', 'explorer', '/desktop=Sugar'] + [str(x
) for x
in args
],
70 flags
=gobject
.SPAWN_SEARCH_PATH
)
72 def get_unix_path(self
, windowspath
):
73 pid
, stdin
, stdout
, stderr
= gobject
.spawn_async(
74 ('winepath', '--unix', windowspath
),
75 flags
=gobject
.SPAWN_SEARCH_PATH
,
79 s
= os
.read(stdout
, 4096)
82 s
= os
.read(stdout
, 4096)
84 result
= ''.join(result
).rstrip('\n')
88 def setup_prefix(self
, firstrun
):
89 os
.system('wineboot --init')
92 #set up desktop background
93 winini
= self
.get_unix_path(r
'c:\windows\win.ini')
96 f
.write("\r\n\r\n[desktop]\r\nWallPaper=c:\\windows\\landscape.bmp")
100 landscapebmp
= self
.get_unix_path(r
'c:\windows\landscape.bmp')
101 shutil
.copyfile(os
.path
.join(self
.bundle_path
, 'background', 'landscape.bmp'), landscapebmp
)
103 def on_wine_quit(self
, pid
, condition
, data
):
106 def read_file(self
, file_path
):
107 #the file is read-only and will be deleted so make a copy
108 tempdir
= tempfile
.mkdtemp('', '', self
.get_unix_path(r
'c:\windows\temp'))
109 head
, tail
= os
.path
.split(file_path
)
110 exefile
= os
.path
.join(tempdir
, tail
)
111 shutil
.copyfile(file_path
, exefile
)
112 self
.start_wine('start', '/unix', exefile
)