Example #1
0
 def __init__(self):
     print (time.time()-start_time, "start init application")
     Gtk.Application.__init__(self, application_id = self.application_id, flags = Gio.ApplicationFlags.FLAGS_NONE)
     GLib.threads_init()
     Gdk.threads_init()
     
     self.datadir = os.path.dirname(os.path.dirname(os.path.realpath(sys.argv[0])))
     
     self.savedatadir = Environement.save_data_path()
     
     self.systems = Badnik.SystemCollection.full ()
     
     self.gamesdb = Badnik.Library(db_name = "games", db_dir = self.savedatadir, systems = self.systems)
     #self.gamesdb.app = self
     self.gamesdb.path = os.path.join(self.savedatadir, "games.db")
     
     self.focused_game = None
     
     self.connect("activate", self.on_activate)
     
     self.register(None)
     
     self.settings = Gio.Settings.new(self.application_id)
     
     self.builder = Gtk.Builder()
     self.builder.add_from_file(Environement.get_resource("AppMenu.ui"))
     self.builder.connect_signals(self)
     
     self.menumodel = self.builder.get_object("AppMenu")
     self.set_app_menu(self.menumodel)
     
     self._action_entries = [ { 'name': 'quit', 'callback': self.on_quit, 'accel': '<Primary>q' },
                              { 'name': 'about', 'callback': self.on_about },
                              { 'name': 'help', 'callback': self.on_help, 'accel': 'F1' },
                              #{ 'name': 'fullscreen', 'callback': self.on_fullscreen, 'accel': 'F11' },
                              #{ 'name': 'view-as', 'callback': self.on_view_as, 'create_hook': self._view_as_create_hook,
                              #  'parameter_type': 's', 'state': self.settings.get_value('view-as') },
                              { 'name': 'add-games', 'callback': self.on_add_games },
                              #{ 'name': 'download-metadata', 'callback': self.on_download_metadata, 'accel': '<Primary>m' }
                            ]
     self._add_actions()
     
     settings = Gtk.Settings.get_default()
     settings.set_property("gtk-application-prefer-dark-theme", True)
     settings.set_property("gtk-shell-shows-app-menu", True)
     print (time.time()-start_time, "end init application")
     
     self.running_games = {}
     
     self.systems.connect("game_found", self.on_game_found)
     self.gamesdb.connect("game_added", self.on_game_added)
Example #2
0
    def __init__(self):
        super(Gtk.EventBox, self).__init__()
        
        self.ui = Gtk.Builder()
        self.ui.add_from_file(Environement.get_resource('GameView.ui'))
        
        # Set the star rank
        self.rank_adjustment = Gtk.Adjustment()
        self.rank_adjustment.set_upper(100)
        
        self.rank = StarRank()
        self.rank.set_adjustment(self.rank_adjustment)
        
        self.ui.get_object('rankBox').add(self.rank)
        
        # Set the screenshot flow
        self.screenshots = PictureFlow()
        self.screenshots.set_size_request(-1, 256)
        
        self.ui.get_object('screenshotsBox').add(self.screenshots)
        
        # Add the UI
        self.add(self.ui.get_object('GameView'))
        self.show_all()

        self.game = None
        self.playinfo = None
Example #3
0
def run_playground(rows=14, cols=12, terminal=None, obstacles=None):
    agent = Agent(x=None, y=None, bound_x=cols - 1, bound_y=rows - 1)
    env = Environement(agent,
                       init_state=(0, 0),
                       terminal_state=f'{terminal[0]}|{terminal[1]}',
                       step_reward=-1,
                       final_reward=100,
                       field_row=rows,
                       field_cols=cols,
                       obstacles=obstacles)
    pg = Playground(episodes=1000,
                    limit=50,
                    epsilon=0.3,
                    gamma=0.3,
                    lr=0.1,
                    env=env)
    pg.play()

    states = pg.create_episode()
    return states, pg
Example #4
0
	def get_pixbuf (self, size, framed, flags):
		cover = self.gameinfo.get_property("cover")
		cache = CoverDrawer()
		
		# Try to load/download the cover
		if cover:
			cached = CachedResource(Environement.save_cover_path())
			lcover = cached.get_resource(cover.get_front())
			
			try:
				pixbuf = GdkPixbuf.Pixbuf.new_from_file(lcover)
			except:
				pixbuf = None
			
			if pixbuf:
				if framed:
					return cache.get_framed_icon(pixbuf, size, size)
				else:
					return cache._get_icon(pixbuf, size, size)
		
		icon_theme = Gtk.IconTheme.get_default()
		
		#Try to load and return the icon.
		if self.gameinfo.get_property("icon"):
			icon_info = icon_theme.lookup_icon(self.gameinfo.get_property("icon").split(".")[0], size, flags)
			if icon_info:
				try:
					filename = icon_info.get_filename()
					pixbuf = GdkPixbuf.Pixbuf.new_from_file(filename)
				except:
					pixbuf = None
				
				if pixbuf:
					if framed:
						return cache.get_framed_icon(pixbuf, size, size)
					else:
						return cache._get_icon(pixbuf, size, size)
		
		return cache.make_default_icon(size, size)
Example #5
0
 def _update(self):
     info = self.game.get_info('*')
     
     # Set the cover
     cover_url = info.get_property('cover')
     cover_url = cover_url.get_front() if cover_url else None
     icon_name = info.get_property('icon')
     cover = self.coverdrawer.get_icon(cover_url, icon_name, self.cover_size, self.framed)
     self.ui.get_object('cover').set_from_pixbuf(cover)
     
     # Set the title
     title = info.get_property("title")
     title = title if title else "Unknown title"
     self.ui.get_object('title_label').set_markup(title)
     
     # Set the developers
     developers = info.get_developers ()
     developers = ", ".join(developers) if developers and len(developers) > 0 else "Unknown developers"
     self.ui.get_object('developers_label').set_markup(developers)
     
     # Set the release date
     date = info.get_property("release_date")
     if date and date.get_year ():
         year = str (date.get_year ())
         month = str (int (date.get_month ()))
         day = str (date.get_day ())
         
         self.ui.get_object('released_label_info').set_markup('/'.join ((day, month, year)))
     else:
         self.ui.get_object('released_label_info').set_markup('----')
     
     # Set the genres
     genres = info.get_genres()
     if genres and len(genres) > 0:
         self.ui.get_object('genres_label_info').set_markup(', '.join(genres))
     else:
         self.ui.get_object('genres_label_info').set_markup('----')
     
     # Set the play informations
     duration = self.playinfo.get_usage_duration ()
     last_play = self.playinfo.get_last_usage ()
     if duration > 0:
         self.ui.get_object('play_duration_label_info').set_markup(duration_to_string(duration))
         self.ui.get_object('last_play_label_info').set_markup(time_to_string(last_play))
     else:
         self.ui.get_object('play_duration_label_info').set_markup('--:--')
         self.ui.get_object('last_play_label_info').set_markup('--:--')
     
     # Set the screenshots
     screenshots = info.get_screenshots()
     for s in screenshots:
         cached = CachedResource(Environement.save_screenshots_path())
         s = cached.get_resource(s)
         self.screenshots.add_from_file(s)
     
     # Set the local players number
     players = info.get_property("local_players")
     if players:
         min = players.get_lower_endpoint ()
         max = players.get_upper_endpoint ()
         players = str(min) if min == max else str(min) + '-' + str(max)
         
         self.ui.get_object('local_players_info').set_markup(players)
     else:
         self.ui.get_object('local_players_info').set_markup('-')
     
     # Set the online players number
     online = info.get_property("online_players")
     if online:
         min = online.get_lower_endpoint ()
         max = online.get_upper_endpoint ()
         online = str(min) if min == max else str(min) + '-' + str(max)
         
         self.ui.get_object('online_players_info').set_markup(online)
     else:
         self.ui.get_object('online_players_info').set_markup('-')
     
     # Set the description
     description = info.get_property("description")
     if description:
         self.ui.get_object('description_label_info').set_markup(description)
     else:
         self.ui.get_object('description_label_info').set_markup('----')