/
win_main.py
2064 lines (1976 loc) · 92 KB
/
win_main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
#
###
# Application: wah!cade
# File: wahcade.py
# Description: Main Window
# Copyright (c) 2005-2010 Andy Balcombe <http://www.anti-particle.com>
###
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
## System Modules
import sys
import glob
import random
import time
import gc
import re
import imp
import shlex
from operator import itemgetter
import subprocess
from subprocess import Popen
## GTK Modules
#gtk
import pygtk
if sys.platform != 'win32':
pygtk.require('2.0')
import gtk
import gobject
gobject.threads_init()
import pango
#dbus
dbus_imported = False
try:
import dbus
dbus_imported = True
except ImportError:
pass
# gStreamer Modules
gst_media_imported = False
try:
import gst_media
gst_media_imported = True
except:
pass
### Project modules
from constants import *
from scrolled_list import ScrollList
from key_consts import mamewah_keys
from wc_common import WahCade
from win_options import WinOptions
from win_message import WinMessage
from win_scrsaver import WinScrSaver
from win_history import WinHistory
from win_cpviewer import WinCPViewer
import filters
from mamewah_ini import MameWahIni
import joystick
#set gettext function
_ = gettext.gettext
class WinMain(WahCade):
"""Wah!Cade Main Window"""
def __init__(self, config_opts):
"""initialise main Wah!Cade window"""
### Set Global Variables
self.init = True
WahCade.__init__(self)
### Defaults
self.gst_media_imported = gst_media_imported
self.pygame_imported = True
self.old_keyb_events = False
self.debug_mode = False
self.tw_api = None
### USER PROFILE
self.userpath = os.path.expanduser(CONFIG_DIR)
if not os.path.exists(CONFIG_DIR):
# copy over ALL config files
self.copy_user_config('all')
# now we've copied stuff, quit and tell the user
self.log_msg("First run, Wah!Cade setting user config profile in: "+ self.userpath,0)
self.log_msg("Restart after configuring (run wahcade-setup or see the README file).",0)
sys.exit(0)
else:
#update current config
self.copy_user_config()
# now we've copied stuff, quit and tell the user
self.log_msg("Wah!Cade updating user config files in: "+ self.userpath)
### SETUP WAHCADE INI FILE
self.wahcade_ini = MameWahIni(os.path.join(CONFIG_DIR, 'wahcade.ini'))
## read in options wahcade.ini,
self.lck_time = self.wahcade_ini.getint('lock_time')
self.keep_aspect = self.wahcade_ini.getint('keep_image_aspect')
self.scrsave_delay = self.wahcade_ini.getint('delay')
self.layout_orientation = self.wahcade_ini.getint('layout_orientation', 0)
self.screentype = self.wahcade_ini.getint('fullscreen', 0)
self.intro_movie = self.wahcade_ini.get('intro_movie_file')
self.showcursor = self.wahcade_ini.getint('show_cursor')
self.display_limiters = self.wahcade_ini.getint('show_list_arrows', 0)
self.wrap_list = self.wahcade_ini.getint('wrap_list')
self.movievol = self.wahcade_ini.getint('movie_volume')
self.music_enabled = self.wahcade_ini.getint('enable_music')
self.music_vol = self.wahcade_ini.getint('music_volume')
self.musicpath = self.wahcade_ini.get('music_path')
self.musicshuffle = self.wahcade_ini.get('shuffle_music', 0)
self.music_movies_mix = self.wahcade_ini.get('music_movie_mix')
self.sound_vol = self.wahcade_ini.getint('sound_volume')
self.sound_enabled = self.wahcade_ini.getint('enable_sounds')
self.delaymovieprev = self.wahcade_ini.getint('delay_before_movie_preview')
self.exit_movie_file = self.wahcade_ini.get('exit_movie_file')
self.layout = self.wahcade_ini.get('layout')
self.splash_use = self.wahcade_ini.getint('splash_use',1)
self.splash_show_text = self.wahcade_ini.getint('splash_show_text',1)
self.splash_border_width = self.wahcade_ini.getint('splash_border_width',10)
### SETUP EMULATOR INI FILE
self.current_emu = self.wahcade_ini.get('current_emulator')
self.emu_ini = MameWahIni(os.path.join(CONFIG_DIR, 'ini/' + self.current_emu + '.ini'))
## read in options emulator.ini,
self.emumovieprevpath = self.emu_ini.get('movie_preview_path')
self.emumovieartworkno = self.emu_ini.getint('movie_artwork_no')
### SETUP CTRLR INI
# Load emulator ctrlr if applicable
try:
self.ctrlr_ini = MameWahIni(os.path.join(CONFIG_DIR, 'ctrlr', self.emu_ini.get('ctrlr')+'.ini'), 'ctrlr')
except:
self.ctrlr_ini = MameWahIni(os.path.join(CONFIG_DIR, 'ctrlr', 'default.ini'), 'ctrlr')
self.use_mouse = self.ctrlr_ini.getint('mouse')
self.joyint = self.ctrlr_ini.getint('joystick')
self.dx_sensitivity = self.ctrlr_ini.getint('mouse_x_sensitivity',100) * 0.01
self.dy_sensitivity = self.ctrlr_ini.getint('mouse_y_sensitivity',100) * 0.01
### Command-line options (parsed after ini is read)
self.check_params(config_opts)
### LOCK FILE
self.lck_filename = os.path.join(CONFIG_DIR, 'emulator.lck')
### remove lock file if it exists
if os.path.exists(self.lck_filename):
self.log_msg('Lock file found: Removing')
os.remove(self.lck_filename)
if not os.path.exists(self.lck_filename):
self.log_msg('Lock File removed successfully')
### Twitter OAuth
self.tw_oath_ckey = self.wahcade_ini.get('consumer_key')
self.tw_oath_csecret = self.wahcade_ini.get('consumer_secret')
self.tw_oath_akey = self.wahcade_ini.get('access_key')
self.tw_oath_asecret = self.wahcade_ini.get('access_secret')
self.tw_ctags = self.wahcade_ini.get('custom_tags')
### WINDOW SETUP
#build the main window
self.winMain = gtk.Window()
self.fixd = gtk.Fixed()
self.imgBackground = gtk.Image()
self.imgMainLogo = gtk.Image()
self.lblGameListIndicator = gtk.Label()
self.lblEmulatorName = gtk.Label()
self.lblGameSelected = gtk.Label()
if self.splash_use == 1:
self.display_splash()
if self.gst_media_imported:
self.drwVideo = gst_media.VideoWidget()
else:
self.drwVideo = gtk.Image()
self.imgArtwork1 = gtk.Image()
self.imgArtwork2 = gtk.Image()
self.imgArtwork3 = gtk.Image()
self.imgArtwork4 = gtk.Image()
self.imgArtwork5 = gtk.Image()
self.imgArtwork6 = gtk.Image()
self.imgArtwork7 = gtk.Image()
self.imgArtwork8 = gtk.Image()
self.imgArtwork9 = gtk.Image()
self.imgArtwork10 = gtk.Image()
self.lblGameDescription = gtk.Label()
self.lblRomName = gtk.Label()
self.lblYearManufacturer = gtk.Label()
self.lblScreenType = gtk.Label()
self.lblControllerType = gtk.Label()
self.lblDriverStatus = gtk.Label()
self.lblCatVer = gtk.Label()
# create scroll list widget
self.sclGames = ScrollList()
# image & label lists
self._layout_items = [
(8, self.imgMainLogo),
(21, self.lblGameListIndicator),
(34, self.lblEmulatorName),
(60, self.lblGameSelected),
(73, self.imgArtwork1),
(86, self.imgArtwork2),
(99, self.imgArtwork3),
(112, self.imgArtwork4),
(125, self.imgArtwork5),
(138, self.imgArtwork6),
(151, self.imgArtwork7),
(164, self.imgArtwork8),
(177, self.imgArtwork9),
(190, self.imgArtwork10),
(47, self.sclGames),
(203, self.lblGameDescription),
(216, self.lblRomName),
(229, self.lblYearManufacturer),
(242, self.lblScreenType),
(255, self.lblControllerType),
(268, self.lblDriverStatus),
(281, self.lblCatVer)]
self._main_images = [
self.imgArtwork1,
self.imgArtwork2,
self.imgArtwork3,
self.imgArtwork4,
self.imgArtwork5,
self.imgArtwork6,
self.imgArtwork7,
self.imgArtwork8,
self.imgArtwork9,
self.imgArtwork10]
self.visible_img_list = []
self.visible_img_paths = []
self._main_labels = [
# self.lblGameListIndicator,
self.lblGameSelected,
self.lblGameDescription,
self.lblRomName,
self.lblYearManufacturer,
self.lblScreenType,
self.lblControllerType,
self.lblDriverStatus,
self.lblCatVer]
# add widgets to main window
self.current_window = 'main'
self.fixd.add(self.imgBackground)
self.imgBackground.show()
self.fixd.show()
self.winMain.add(self.fixd)
for line, widget in self._layout_items:
if widget != self.sclGames:
self.fixd.add(self.make_evb_widget(widget))
else:
self.fixd.add(widget.fixd)
# video widget
self.video_playing = False
self.video_enabled = False
self.video_timer = None
self.video_player = None
self.drwVideo.show()
self.fixd.add(self.drwVideo)
# list
self.sclGames.auto_update = False
self.sclGames.display_limiters = False
# set window properties
self.winMain.set_position(gtk.WIN_POS_NONE)
self.winMain.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_NORMAL)
self.winMain.set_title('Wah!Cade')
# init random engine
random.seed()
# build list
self.lsGames = []
self.lsGames_len = 0
# timers
self.scrsave_time = time.time()
### CREATE OPTIONS WINDOW
self.options = WinOptions(self)
self.options.winOptions.hide()
### create message window
self.message = WinMessage(self)
self.message.winMessage.hide()
### create screen saver window
self.scrsaver = WinScrSaver(self)
self.scrsaver.winScrSaver.hide()
self.scrsave_timer = None
# add options, message & screen saver widgets to _layout_items
self._layout_items += [
(301, self.options.lblHeading),
(314, self.options.sclOptions),
(327, self.options.lblSettingHeading),
(340, self.options.lblSettingValue),
(357, self.message.lblHeading),
(370, self.message.lblMessage),
(383, self.message.lblPrompt),
(396, self.scrsaver.imgArtwork1),
(409, self.scrsaver.imgArtwork2),
(422, self.scrsaver.imgArtwork3),
(435, self.scrsaver.imgArtwork4),
(448, self.scrsaver.imgArtwork5),
(461, self.scrsaver.imgArtwork6),
(474, self.scrsaver.imgArtwork7),
(487, self.scrsaver.imgArtwork8),
(500, self.scrsaver.imgArtwork9),
(513, self.scrsaver.imgArtwork10),
(526, self.scrsaver.lblGameDescription),
(539, self.scrsaver.lblMP3Name)]
### build list of emulators
self.emu_lists = self.buildemulist()
### check that current emu exists...
el = [e[1] for e in self.emu_lists]
if self.current_emu not in el:
#...no, switch to one that does
self.current_emu = el[0]
self.wahcade_ini.set('current_emulator', self.current_emu)
### load list
self.current_list_ini = None
self.emu_ini = None
self.layout_file = ''
self.load_emulator()
self.check_music_settings()
self.winMain.show()
self.drwVideo.set_property('visible', False)
if not self.showcursor:
self.hide_mouse_cursor(self.winMain)
self.screen = self.winMain.get_screen()
self.display = self.screen.get_display()
self.old_mouse = (0, 0)
#fullscreen
if self.screentype == 1:
self.log_msg('Fullscreen mode')
self.winMain.fullscreen()
else:
self.log_msg('Windowed mode')
pass
# show the window to the user
self.winMain.present()
if self.splash_use == 1:
### hide splash
self.splash.destroy()
self.do_events()
self.on_winMain_focus_in()
#### start intro movie
if self.gst_media_imported and os.path.isfile(self.intro_movie):
self.log_msg("Found intro movie file, attempting to play " + self.intro_movie)
#self.scrsaver.play_movie(self.intro_movie,'intro')
else:
self.start_timer('scrsave')
if self.gst_media_imported and self.music_enabled:
self.gstMusic.play()
### INPUT CONFIGURATION
# input defaults
self.pointer_grabbed = False
# get keyboard & mouse events
self.sclGames.connect('update', self.on_sclGames_changed)
self.sclGames.connect('mouse-left-click', self.on_sclGames_changed)
self.sclGames.connect('mouse-right-click', self.on_winMain_key_press)
self.sclGames.connect('mouse-double-click', self.launch_auto_apps_then_game)
self.winMain.connect('destroy', self.on_winMain_destroy)
self.winMain.connect('focus-in-event', self.on_winMain_focus_in)
self.winMain.connect('focus-out-event', self.on_winMain_focus_out)
self.winMain.add_events(
gtk.gdk.POINTER_MOTION_MASK |
gtk.gdk.SCROLL_MASK |
gtk.gdk.BUTTON_RELEASE_MASK |
gtk.gdk.KEY_PRESS_MASK |
gtk.gdk.KEY_RELEASE_MASK)
key_press_events = [
'key-press-event', 'key-release-event', 'button-release-event',
'scroll-event', 'motion-notify-event']
[self.winMain.connect(kpev, self.on_winMain_key_press) for kpev in key_press_events]
#[self.drwVideo.connect(kpev, self.on_winMain_key_press) for kpev in key_press_events]
#key_press_events = ['key-press-event', 'key-release-event']
#[self.drwVideo.connect(kpev, self.on_winMain_key_press) for kpev in key_press_events]
self.main_scroll_keys = [
'UP_1_GAME', 'DOWN_1_GAME',
'UP_1_PAGE', 'DOWN_1_PAGE',
'UP_1_LETTER', 'DOWN_1_LETTER']
self.keypress_count = 0
#### joystick setup
self.joy = None
if (self.joyint == 1) and self.pygame_imported:
self.joy = joystick.joystick(self.debug_mode)
self.joy.use_ini_controls(self.ctrlr_ini)
self.joy.joy_info()
self.start_timer('joystick')
self.on_sclGames_changed()
### __INIT__ Complete
self.init = False
def on_winMain_destroy(self, *args):
"""done, quit the application"""
#stop vid playing if necessary
self.stop_video()
#save ini files
self.wahcade_ini.write()
self.emu_ini.write()
self.current_list_ini.write()
#write fav list
filters.write_fav_list(
os.path.join(CONFIG_DIR, 'files', '%s.fav' % (self.current_emu)),
self.emu_favs_list)
#exit gtk loop
gtk.main_quit()
sys.exit(0)
def exit_wahcade(self, exit_mode='default'):
"""quit"""
exit_movie = os.path.isfile(self.exit_movie_file)
self.stop_video()
if dbus_imported and not exit_mode == 'default':
bus = dbus.SystemBus()
try:
# CONSOLE KIT
ck_obj = bus.get_object('org.freedesktop.ConsoleKit', '/org/freedesktop/ConsoleKit/Manager')
ck = dbus.Interface(ck_obj, 'org.freedesktop.ConsoleKit.Manager')
# UPOWER (for suspend)
up_obj = bus.get_object('org.freedesktop.UPower', '/org/freedesktop/UPower')
up = dbus.Interface(up_obj, 'org.freedesktop.UPower')
except:
# HAL
hal_obj = bus.get_object('org.freedesktop.Hal', '/org/freedesktop/Hal/devices/computer')
hal = dbus.Interface(hal_obj, 'org.freedesktop.Hal.Device.SystemPowerManagement')
if exit_mode == 'default':
if self.gst_media_imported and exit_movie:
#start exit movie
self.log_msg('Exit with movie file, exit mode selected')
#self.scrsaver.play_movie(exit_movie,'exit')
else:
self.log_msg('Default, exit mode selected')
self.on_winMain_destroy()
elif exit_mode == 'reboot':
#reboot
self.log_msg('Reboot, exit mode selected')
try:
if ck:
rv = ck.Restart()
elif hal:
rv = hal.Reboot()
else:
self.log_msg('Could not find suitable system manager for: ' + exit_mode)
except:
self.log_msg('Failed to initiate reboot through console kit/hal')
elif exit_mode == 'shutdown':
#turn off
self.log_msg('Shutdown, exit mode selected')
try:
if ck:
rv = ck.Stop()
elif hal:
rv = hal.Shutdown()
else:
self.log_msg('Could not find suitable system manager for: ' + exit_mode)
except:
self.log_msg('Failed to initiate shutdown through console kit/hal')
elif exit_mode == 'suspend':
#turn off
self.log_msg('Suspend mode selected')
try:
if ck:
rv = up.Suspend()
elif hal:
rv = hal.Suspend()
else:
self.log_msg('Could not find suitable system manager for: ' + exit_mode)
except:
self.log_msg('Failed to initiate suspend through console kit/hal')
if not exit_mode == 'suspend':
self.log_msg('Exiting Wah!Cade, destroying window. Guess we didn\'t choose suspend')
self.on_winMain_destroy()
def on_winMain_focus_in(self, *args):
"""window received focus"""
self.pointer_grabbed = False
if self.sclGames.use_mouse and not self.showcursor:
#need to grab?
mw_keys = ['MOUSE_LEFT', 'MOUSE_RIGHT', 'MOUSE_UP', 'MOUSE_DOWN']
for mw_key in mw_keys:
mw_functions = self.ctrlr_ini.reverse_get(mw_key)
if mw_functions:
#grab pointer
r = gtk.gdk.pointer_grab(
self.winMain.window,
event_mask= gtk.gdk.POINTER_MOTION_MASK |
gtk.gdk.SCROLL_MASK |
gtk.gdk.BUTTON_RELEASE_MASK |
gtk.gdk.KEY_PRESS_MASK |
gtk.gdk.KEY_RELEASE_MASK)#,
#confine_to=self.winMain.window)
if r==gtk.gdk.GRAB_SUCCESS:
self.pointer_grabbed = True
#done
#break
# Remove Lock File workaround
if os.path.exists(self.lck_filename):
self.log_msg('Lock file found: Waiting ' + str(self.lck_time))
self.wait_with_events(self.lck_time)
self.log_msg('Lock time elapsed, removing file')
try:
os.remove(self.lck_filename)
if not os.path.exists(self.lck_filename):
self.log_msg('Lock File removed successfully')
except:
self.log_msg("WARNING: Could not remove lock file, remove manually or restart Wah!Cade")
def on_winMain_focus_out(self, *args):
"""window lost focus"""
self.pointer_grabbed = False
gtk.gdk.pointer_ungrab()
def on_winMain_key_press(self, widget, event, *args):
"""key pressed - translate to mamewah setup"""
if not os.path.exists(self.lck_filename):
current_window = self.current_window
mw_keys = []
mw_key = ''
mw_func = ''
mw_functions = []
joystick_key = None
if len(args) > 1:
if args[0] == "JOYSTICK":
joystick_key = args[1]
if self.debug_mode:
self.log_msg("on_winMain_key_press: joystick:" + str(joystick_key),1)
#reset screen saver time (and turn off if necessary)
self.scrsave_time = time.time()
if self.scrsaver.running:
self.scrsaver.stop_scrsaver()
#print "on_winMain_key_press: callifile_listsng start timer"
self.start_timer('scrsave')
if event.type == gtk.gdk.MOTION_NOTIFY and self.pointer_grabbed:
#mouse moved
x, y = event.get_coords()
dx = x - self.old_mouse[0]
dy = y - self.old_mouse[1]
#print "x,y=", x,y, " ox=,oy=",self.old_mouse[0],self.old_mouse[1], " dx=,dy=",dx,dy
if abs(dx) >= abs(dy):
#x-axis
mm = dx
if mm < -3.0:
mw_keys = ['MOUSE_LEFT']
elif mm > 3.0:
mw_keys = ['MOUSE_RIGHT']
else:
#y-axis
mm = dy
if mm < -3.0:
mw_keys = ['MOUSE_UP']
elif mm > 3.0:
mw_keys = ['MOUSE_DOWN']
self.keypress_count += int(abs(mm) / 10) + 1
#print "mm=",mm, " keyp=",self.keypress_count
if not mw_keys:
self.keypress_count = 0
if widget == self.winMain:
self.sclGames.update()
return
#warp pointer - stops mouse hitting screen edges
winpos = self.winMain.get_position()
self.old_mouse = (200, 200)
self.display.warp_pointer(self.screen, winpos[0] + 200, winpos[1] + 200)
elif event.type == gtk.gdk.BUTTON_RELEASE:
#mouse click
mw_keys = ['MOUSE_BUTTON%s' % (event.button - 1)]
elif event.type == gtk.gdk.SCROLL:
#mouse scroll wheel
if event.direction in [gtk.gdk.SCROLL_UP, gtk.gdk.SCROLL_LEFT]:
mw_keys = ['MOUSE_SCROLLUP']
elif event.direction in [gtk.gdk.SCROLL_DOWN, gtk.gdk.SCROLL_RIGHT]:
mw_keys = ['MOUSE_SCROLLDOWN']
else:
return
elif event.type == gtk.gdk.KEY_PRESS:
if self.debug_mode:
self.log_msg(" key-press",1)
self.keypress_count += 1
if joystick_key:
#joystick action
mw_keys = [joystick_key]
else:
#keyboard pressed, get gtk keyname
keyname = gtk.gdk.keyval_name(event.keyval).lower()
#got something?
if keyname not in mamewah_keys:
return
#get mamewah keyname
mw_keys = mamewah_keys[keyname]
if mw_keys == []:
return
elif event.type == gtk.gdk.KEY_RELEASE:
self.keypress_count = 0
#keyboard released, update labels, images, etc
if widget == self.winMain:
#only update if no further events pending
self.sclGames.update()
if self.old_keyb_events:
if self.debug_mode:
self.log_msg(" key-release",1)
self.sclGames.update()
elif not gtk.gdk.events_pending():
if self.debug_mode:
self.log_msg(" key-release",1)
self.sclGames.update()
if joystick_key:
#don't need "release" joystick actions to be executed
mw_keys = []
if self.debug_mode:
self.log_msg(" joystick: cleared_events",1)
#get mamewah function from key
for mw_key in mw_keys:
mw_functions = self.ctrlr_ini.reverse_get(mw_key)
if mw_functions:
break
for mw_func in mw_functions:
#which function?
if current_window == 'main':
#main form
if mw_func == 'UP_1_GAME':
self.play_clip('UP_1_GAME')
self.sclGames.scroll((int(self.keypress_count / 20) * -1) - 1)
elif mw_func == 'DOWN_1_GAME':
self.play_clip('DOWN_1_GAME')
self.sclGames.scroll(int(self.keypress_count / 20) + 1)
elif mw_func == 'UP_1_PAGE':
self.play_clip('UP_1_PAGE')
self.sclGames.scroll(-self.sclGames.num_rows)
elif mw_func == 'DOWN_1_PAGE':
self.play_clip('DOWN_1_PAGE')
self.sclGames.scroll(+self.sclGames.num_rows)
elif mw_func == 'UP_1_LETTER':
self.play_clip('UP_1_LETTER')
if self.lsGames_len == 0:
break
cl = self.lsGames[self.sclGames.get_selected()][0][0]
games = [r[0] for r in self.lsGames]
games = games[:self.sclGames.get_selected()]
games.reverse()
i = 0
for row in games:
i += 1
if row[0] != cl:
self.sclGames.scroll(-i)
break
if i >= len(games):
self.sclGames.scroll(-i)
elif mw_func == 'DOWN_1_LETTER':
self.play_clip('DOWN_1_LETTER')
if self.lsGames_len == 0:
break
cl = self.lsGames[self.sclGames.get_selected()][0][0]
games = [r[0] for r in self.lsGames]
games = games[self.sclGames.get_selected():]
i = -1
for row in games:
i += 1
if row[0] != cl:
self.sclGames.scroll(+i)
break
elif mw_func == 'RANDOM_GAME':
self.play_clip('RANDOM_GAME')
self.sclGames.set_selected(self.get_random_game_idx())
elif mw_func == 'FIND_GAME':
self.play_clip('FIND_GAME')
self.options.set_menu('find')
self.show_window('options')
elif mw_func == 'ADD_GAME_TO_LIST':
self.play_clip('ADD_GAME_TO_LIST')
self.options.set_menu('add_to_list')
self.show_window('options')
elif mw_func == 'REMOVE_GAME_FROM_LIST':
self.play_clip('REMOVE_GAME_FROM_LIST')
self.remove_current_game()
elif mw_func == 'LAUNCH_GAME':
self.play_clip('LAUNCH_GAME')
self.launch_auto_apps_then_game()
elif mw_func == 'LAUNCH_GAME_WITH_OPTIONS1':
self.play_clip('LAUNCH_GAME_WITH_OPTIONS1')
self.launch_auto_apps_then_game(
self.emu_ini.get('alt_commandline_format_1'))
elif mw_func == 'LAUNCH_GAME_WITH_OPTIONS2':
self.play_clip('LAUNCH_GAME_WITH_OPTIONS2')
self.launch_auto_apps_then_game(
self.emu_ini.get('alt_commandline_format_2'))
elif mw_func == 'MENU_SHOW':
self.play_clip('MENU_SHOW')
self.options.set_menu('main')
self.show_window('options')
elif mw_func == 'SELECT_EMULATOR':
self.play_clip('SELECT_EMULATOR')
self.options.set_menu('emu_list')
self.show_window('options')
elif mw_func == 'NEXT_EMULATOR':
self.play_clip('NEXT_EMULATOR')
emu_list = [e[1] for e in self.emu_lists]
emu_idx = emu_list.index(self.current_emu)
if emu_idx < len(emu_list) - 1:
emu_idx += 1
else:
emu_idx = 0
self.load_emulator(emu_list[emu_idx])
elif mw_func == 'PREVIOUS_EMULATOR':
self.play_clip('PREVIOUS_EMULATOR')
emu_list = [e[1] for e in self.emu_lists]
emu_idx = emu_list.index(self.current_emu)
if emu_idx > 0:
emu_idx -= 1
else:
emu_idx = len(emu_list) - 1
self.load_emulator(emu_list[emu_idx])
elif mw_func == 'SELECT_GAMELIST':
self.play_clip('SELECT_GAMELIST')
self.options.set_menu('game_list')
self.show_window('options')
elif mw_func == 'NEXT_GAMELIST':
self.play_clip('NEXT_GAMELIST')
self.current_list_idx = self.get_next_list_in_cycle(+1)
self.load_list()
elif mw_func == 'PREVIOUS_GAMELIST':
self.play_clip('PREVIOUS_GAMELIST')
self.current_list_idx = self.get_next_list_in_cycle(-1)
self.load_list()
elif mw_func == 'ROTATE_SCREEN_TOGGLE':
self.play_clip('ROTATE_SCREEN_TOGGLE')
self.load_layouts('toggle')
elif mw_func == 'ROTATE_SCREEN_0':
self.play_clip('ROTATE_SCREEN_0')
self.load_layouts(0)
elif mw_func == 'ROTATE_SCREEN_90':
self.play_clip('ROTATE_SCREEN_90')
self.load_layouts(90)
elif mw_func == 'ROTATE_SCREEN_180':
self.play_clip('ROTATE_SCREEN_180')
self.load_layouts(180)
elif mw_func == 'ROTATE_SCREEN_270':
self.play_clip('ROTATE_SCREEN_270')
self.load_layouts(270)
elif mw_func == 'NEXT_TRACK':
self.play_clip('NEXT_TRACK')
if self.music_enabled:
self.gstMusic.next_track()
elif mw_func == 'PREVIOUS_TRACK':
self.play_clip('PREVIOUS_TRACK')
if self.music_enabled:
self.gstMusic.previous_track()
elif mw_func == 'LAUNCH_APP_1':
self.play_clip('LAUNCH_APP_1')
self.external_app_queue = []
self.launch_external_application(1)
elif mw_func == 'LAUNCH_APP_2':
self.play_clip('LAUNCH_APP_2')
self.external_app_queue = []
self.launch_external_application(2)
elif mw_func == 'LAUNCH_APP_3':
self.play_clip('LAUNCH_APP_3')
self.external_app_queue = []
self.launch_external_application(3)
elif mw_func == 'EXIT_TO_WINDOWS':
self.play_clip('EXIT_TO_WINDOWS')
self.exit_wahcade()
elif mw_func == 'EXIT_WITH_CHOICE':
self.play_clip('EXIT_WITH_CHOICE')
self.options.set_menu('exit')
self.show_window('options')
elif current_window == 'options':
#options form
if mw_func == 'OP_UP_1_OPTION':
self.play_clip('OP_UP_1_OPTION')
self.options.sclOptions.scroll(-1)
elif mw_func == 'OP_DOWN_1_OPTION':
self.play_clip('OP_DOWN_1_OPTION')
self.options.sclOptions.scroll(+1)
elif mw_func == 'OP_UP_1_OPTION_PAGE':
self.play_clip('OP_UP_1_OPTION_PAGE')
self.options.sclOptions.scroll(-self.options.sclOptions.num_rows)
elif mw_func == 'OP_DOWN_1_OPTION_PAGE':
self.play_clip('OP_DOWN_1_OPTION_PAGE')
self.options.sclOptions.scroll(+self.options.sclOptions.num_rows)
elif mw_func == 'OP_MENU_SELECT':
self.play_clip('OP_MENU_SELECT')
self.options.menu_selected()
elif mw_func == 'OP_MENU_HIDE':
self.play_clip('OP_MENU_HIDE')
self.hide_window('options')
elif mw_func == 'OP_MENU_BACK':
self.play_clip('OP_MENU_BACK')
if self.options.current_menu == 'main':
self.hide_window('options')
elif self.options.current_menu in ['emu_list', 'game_list', 'list_options', 'music', 'exit']:
self.options.set_menu('main')
elif self.options.current_menu == 'add_to_list':
self.options.set_menu('list_options')
elif self.options.current_menu == 'generate_ftr':
if self.current_filter_changed:
#generate new filter
self.options.set_menu('generate_new_list')
else:
self.options.set_menu('list_options')
elif self.options.current_menu.startswith('ftr:'):
self.options.set_menu('generate_ftr')
elif self.options.current_menu == 'find':
self.options.find_game('back')
elif self.options.current_menu == 'music_dir':
self.options.set_menu('music')
elif current_window == 'scrsaver':
#screensaver
if mw_func == 'SS_FIND_N_SELECT_GAME':
self.sclGames.set_selected(self.scrsaver.game_idx)
#stop into / exit movie playing if any key is pressed
if self.scrsaver.movie_type in ('intro', 'exit'):
self.scrsaver.video_player.stop()
#history viewer
elif current_window == 'history':
if mw_func == 'UP_1_GAME':
self.play_clip('UP_1_GAME')
self.histview.sclHistory.scroll((int(self.keypress_count / 20) * -1) - 1)
elif mw_func == 'DOWN_1_GAME':
self.play_clip('DOWN_1_GAME')
self.histview.sclHistory.scroll(int(self.keypress_count / 20) + 1)
elif mw_func in ['UP_1_PAGE', 'UP_1_LETTER']:
self.play_clip('UP_1_PAGE')
self.histview.sclHistory.scroll(-self.histview.sclHistory.num_rows)
elif mw_func in ['DOWN_1_PAGE', 'DOWN_1_LETTER']:
self.play_clip('DOWN_1_PAGE')
self.histview.sclHistory.scroll(+self.histview.sclHistory.num_rows)
elif mw_func in [
'EXIT_TO_WINDOWS',
'LAUNCH_APP_%s' % self.histview.app_number,
'LAUNCH_GAME']:
self.hide_window('history')
self.auto_launch_external_app()
#control panel viewer
elif current_window == 'cpviewer':
if mw_func in [
'EXIT_TO_WINDOWS',
'LAUNCH_APP_%s' % self.cpviewer.app_number,
'LAUNCH_GAME']:
self.hide_window('cpviewer')
self.auto_launch_external_app()
#message window
elif current_window == 'message':
if self.message.wait_for_key:
self.message.hide()
#force games list update if using mouse scroll wheel
if 'MOUSE_SCROLLUP' in mw_keys or 'MOUSE_SCROLLDOWN' in mw_keys:
if widget == self.winMain:
self.play_clip('UP_1_GAME')
self.sclGames.update()
def on_sclGames_changed(self, *args):
"""game selected"""
#print "on_sclGames_changed: sel=", self.sclGames.get_selected()
self.game_ini_file = None
self.stop_video()
if self.sclGames.get_selected() > self.lsGames_len - 1:
#blank labels & images
for img in self.visible_img_list:
img.set_from_file(None)
for lbl in self._main_labels:
lbl.set_text('')
return
#set current game in ini file
self.current_list_ini.set('current_game', self.sclGames.get_selected())
#get info
game_info = filters.get_game_dict(self.lsGames[self.sclGames.get_selected()])
#check for game ini file
game_ini_file = os.path.join(CONFIG_DIR, 'ini', '%s' % self.current_emu, '%s' % game_info['rom_name'] + '.ini' )
if os.path.isfile(game_ini_file):
self.log_msg(game_info['rom_name'] + " has custom ini file")
self.game_ini_file = MameWahIni(game_ini_file)
#set layout text items
self.lblGameDescription.set_text(game_info['game_name'])
self.lblGameSelected.set_text(_('Game %s of %s selected') % (
self.sclGames.get_selected() + 1,
self.lsGames_len))
if game_info['clone_of'] != '':
rom_name_desc = _('%s (Clone of %s)') % (game_info['rom_name'], game_info['clone_of'])
else:
rom_name_desc = game_info['rom_name']
self.lblRomName.set_text(rom_name_desc)
self.lblYearManufacturer.set_text('%s %s' % (game_info['year'], game_info['manufacturer']))
self.lblScreenType.set_text('%s %s' % (game_info['screen_type'], game_info['display_type']))
self.lblControllerType.set_text(game_info['controller_type'])
self.lblDriverStatus.set_text('%s, %s, %s' % (
game_info['driver_status'],
game_info['colour_status'],
game_info['sound_status']))
self.lblCatVer.set_text(game_info['category'])
#start video timer
if self.scrsaver.movie_type not in ('intro', 'exit'):
self.start_timer('video')
#set layout images
for i, img in enumerate(self.visible_img_list):
img_filename = self.get_artwork_image(
self.visible_img_paths[i],
self.layout_path,
game_info,
self.current_emu,
(i + 1))
self.display_scaled_image(img, img_filename, self.keep_aspect, img.get_data('text-rotation'))
def on_scrsave_timer(self):
if self.lsGames_len == 0:
print _("Error: Empty Gamelist: [%s]") % (self.current_emu)
return False
"""timer event - check to see if we need to start video or screen saver"""
#need to start screen saver?
if int(time.time() - self.scrsave_time) >= self.scrsave_delay:
#yes, stop any vids playing
self.stop_video()
if self.emu_ini.get('saver_type') in ['blank_screen', 'slideshow', 'movie', 'launch_scr']:
#start screen saver
self.scrsaver.start_scrsaver(self.emu_ini.get('saver_type'))
else:
print _("Error: wrong screen saver type: [%s]") % (self.emu_ini.get('saver_type'))
return False
#done
return True
def on_video_timer(self):
"""timer event - start video playing"""
#start video playing?
if self.video_enabled and self.current_window == 'main':
#stop existing vid playing
self.stop_video()
#something in the list?
if self.lsGames_len == 0:
return False
#get info
vid_filename = self.get_video_file(
self.emu_ini.get('movie_preview_path'),
filters.get_game_dict(self.lsGames[self.sclGames.get_selected()]))
#print "vid_filename=",vid_filename
if os.path.isfile(vid_filename):
#resize video widget
self.video_playing = True
img_w, img_h = self.video_artwork_widget.get_size_request()
xpos = (img_w - self.video_width) / 2
ypos = (img_h - self.video_height) / 2
self.fixd.move(
self.drwVideo,
self.fixd.child_get_property(self.video_artwork_widget.get_parent(), 'x') + xpos,
self.fixd.child_get_property(self.video_artwork_widget.get_parent(), 'y') + ypos,
)
self.drwVideo.set_size_request(self.video_width, self.video_height)
self.drwVideo.set_property('visible', True)
self.video_artwork_widget.set_property('visible', False)
#set volume
if self.music_movies_mix == 'mute_movies':
vol = 0
else:
vol = self.wahcade_ini.getint('movie_volume')
self.video_player.set_volume(vol)
#start video
self.video_player.play(vid_filename)
#done
return False
def stop_video(self):
"""stop and playing video and timer"""
if self.video_timer:
gobject.source_remove(self.video_timer)
self.video_timer = None
if self.video_playing:
self.video_playing = False