def main(*args, **kwargs): '''Client code main loop.''' # Import statements are inside the function so that they aren't imported # every time something from the client is imported # cluttergtk must be imported before the first import of clutter so it # must be imported even though pylint complains about it not being used. import cluttergtk import clutter import gobject import gtk from entertainerlib.client.translation_setup import TranslationSetup TranslationSetup() from entertainerlib.backend.backend_server import BackendServer from entertainerlib.configuration import Configuration from entertainerlib.client.client import Client gobject.threads_init() gtk.gdk.threads_init() clutter.threads_init() config = Configuration() if config.start_auto_server: print "Entertainer backend starting..." BackendServer() client_client = Client() client_client.start()
def __init__(self): self.config = Configuration() if not os.path.exists(self.config.MUSIC_DB): raise Exception("Music database doesn't exist!") self.db_connection = sqlite.connect(self.config.MUSIC_DB) self.cursor = self.db_connection.cursor()
def setUp(self): '''Set up the basic file I/O requirements.''' self.test_dir = self.get_temp_file() os.mkdir(self.test_dir) self.test_cfg_dir = self.get_temp_file() self.config = Configuration(self.test_cfg_dir) self.data_dir = os.path.dirname(__file__) + '/data'
def __init__(self, artist, title, length, year, album_art_url, tracks): self.config = Configuration() self.artist = artist self.title = title self.length = length self.year = year self.album_art_url = album_art_url self.tracks = tracks
def __init__(self, title): self.config = Configuration() self.number_of_episodes = 0 # Season list of numbers. For example [1,2,3,5] in case that user # doesn't have episodes from season 4. self.seasons = [] self.title = title
def __init__(self): self.config = Configuration() if not os.path.exists(self.config.VIDEO_DB): raise Exception("Video database doesn't exist!") self.connection = sqlite.connect(self.config.VIDEO_DB) self.cursor = self.connection.cursor()
def server_main(*args, **kwargs): '''Entertainer Server main function.''' startLogging(sys.stdout) config = Configuration() server = server_registry.get(config.network_options['type']) server = server() reactor.listenTCP(config.network_options['port'], server) reactor.run()
def __init__(self): # XXX: laymansterms - VideoItem should really have a few mandatory # parameters. title, filename, maybe more. Playable.__init__(self) self.config = Configuration() self._title = "" self.filename = "" self.art_hash = ""
def __init__(self, remove_from_stage_callback): '''Initialize the factory The remove_from_stage_callback is a callback that all transition objects require to remove a "from_screen" from the stage without having direct access to the stage. ''' self.remove_from_stage_callback = remove_from_stage_callback self.config = Configuration()
def __init__(self): """Create a new music database object.""" self.logger = Logger().getLogger( 'backend.components.mediacache.MusicCache') self.config = Configuration() if not os.path.exists(self.config.MUSIC_DB): self.__createMusicCacheDatabase() self.__db_conn = sqlite.connect(self.config.MUSIC_DB) self.__db_cursor = self.__db_conn.cursor()
def __init__(self): """ Create a new MediaCacheManager object """ MessageHandler.__init__(self) self.logger = Logger().getLogger( 'backend.components.mediacache.MediaCacheManager') self.config = Configuration() self.video_folders = self.config.media_folders self._index_videos(self.video_folders) self.music_folders = self.config.media_folders self._index_music(self.music_folders) self.image_folders = self.config.media_folders self._index_images(self.image_folders)
def __init__(self): """ Create a new ImageCache. Creates a new database if not already exists and opens a connection to it. """ self.logger = Logger().getLogger( 'backend.components.mediacache.ImageCache') self.config = Configuration() if not os.path.exists(self.config.IMAGE_DB): self._createImageCacheDatabase() self.db_conn = sqlite.connect(self.config.IMAGE_DB) self.db_cursor = self.db_conn.cursor()
def __init__(self): config = Configuration() music_library = MusicLibrary() image_library = ImageLibrary() video_library = VideoLibrary() self.ui = UserInterface(image_library, music_library, video_library, self.quit_client) if config.tray_icon_enabled: SystemTrayIcon(self.quit_client, self.toggle_interface_visibility) startLogging(sys.stdout) client = EntertainerLocalClientProtocol ClientCreator(reactor, client)
def __init__(self, x, y, width, height, direction): Base.__init__(self) clutter.Group.__init__(self) self.config = Configuration() # Size self.width = self.get_abs_x(width) self.height = self.get_abs_y(height) self.direction = direction self.delimiter = " | " self.current = 1 self.maximum = 1 self.theme = self.config.theme self.fg = self.theme.get_color("arrow_foreground") self.bg = self.theme.get_color("arrow_background") if direction == ListIndicator.VERTICAL: text_x_pos = width / 3 else: text_x_pos = width / 2 self.text = Label( height * 0.8, "text", text_x_pos, height / 2, str(self.maximum) + self.delimiter + str(self.maximum)) self.text.set_anchor_point_from_gravity(clutter.GRAVITY_CENTER) self.add(self.text) # Create arrows and calculate positions on screen if direction == ListIndicator.VERTICAL: self.arrow1 = ArrowTexture(5 * width / 7, height / 2, height / 2, self.fg, self.bg, ArrowTexture.UP) self.arrow2 = ArrowTexture(6 * width / 7, height / 2, height / 2, self.fg, self.bg, ArrowTexture.DOWN) elif direction == ListIndicator.HORIZONTAL: self.arrow1 = ArrowTexture(height / 2, height / 2, height / 2, self.fg, self.bg, ArrowTexture.LEFT) self.arrow2 = ArrowTexture(6 * width / 7, height / 2, height / 2, self.fg, self.bg, ArrowTexture.RIGHT) self.add(self.arrow1) self.add(self.arrow2) self.set_position(self.get_abs_x(x), self.get_abs_y(y))
def __init__(self, filename, album_path, title, description, date, time, width, height,filesize, thumb_hash): """Initialize image""" self.config = Configuration() # Filename of the image (full absolute path) self.__filename = filename # Album path of the album that contains this image self.__album_path = album_path self.__title = title # Title of the image self.__description = description # Description/Comment of the image self.__date = date # Taken date of image self.__time = time # Taken time of the image self.__width = width # Width in pixels self.__height = height # Height in pixels self.__filesize = filesize # Image filesize in bytes self.__thumb_hash = thumb_hash # Image thumbnail hash value
def __init__(self): '''Create a new Entertainer logger object This logger creates the necessary customization for Entertainer logging and should be followed by a getLogger call. Example call: self.logger = Logger().getLogger('my.source.class') ''' self.config = Configuration() logging.basicConfig( level=logging.DEBUG, format='%(asctime)s %(name)s %(levelname)s %(message)s', filename=self.config.LOG, filemode='a')
def __init__(self, filename): """ Initialize metadata search thread. @param filename: Filename as string (find metadata for this file) """ threading.Thread.__init__(self) self.setName("Video metadata search thread") self.logger = Logger().getLogger( 'backend.components.mediacache.VideoMetadataSearch') self.config = Configuration() self.filename = filename self.title, self.season, self.episode = self._parse_filename(filename) try: self.IMDb = imdb.IMDb() except imdb.IMDbError: raise IOError("Couldn't connect to IMDB server!")
def __init__(self, path): """Initialize album""" self.config = Configuration() connection = sqlite.connect(self.config.IMAGE_DB) cursor = connection.cursor() cursor.execute( "SELECT path, title, description, hash FROM album WHERE path='%s'" % path) result = cursor.fetchall() self.__path = result[0][0] # Path of the album self.__title = result[0][1] # Title of the album self.__description = result[0][2] # Description text for the album self.__thumbnail = None # Thumbnail URL of the album if len(result[0][3]) > 0: self.__thumbnail = os.path.join(self.config.IMAGE_THUMB_DIR, result[0][3] + ".jpg") connection.close()
def __init__(self, message_type_dictionary=None, message_handler=None, client_name="Unknown client"): """ Create a new MessageBusProxy object @param message_type_dictionary: Dictionary that contains message types @param message_handler: MessageHandler object @param client_name: Name of the client (as string) """ threading.Thread.__init__(self) if message_type_dictionary is None: self.message_type_dictionary = {} else: self.message_type_dictionary = message_type_dictionary self.message_handler = message_handler self.client_name = client_name self.socket_to_server = socket.socket( socket.AF_INET, socket.SOCK_STREAM ) self.socket_as_file = self.socket_to_server.makefile() self.config = Configuration()
def __init__(self): gobject.threads_init() self.config = Configuration() self.logger = Logger().getLogger('backend.BackendServer') self.message_bus = MessageBus() self._port = self.config.port # Connection server - Thread that listens incoming socket connections self.connection_server = None self.scheduler = None self.media_manager = None # The order of the initialize method calls is significant! Don't change # the order unless you know what you are doing! self.initialize_configuration() self.initialize_media_cache_manager() self.initialize_connection_server() self.initialize_scheduler()
def __init__(self, quit_callback, toggle_interface_visibility_callback): '''Create the system tray icon and pop-up menu for it.''' self.quit_callback = quit_callback self.toggle_interface_visibility_callback = \ toggle_interface_visibility_callback self.config = Configuration() # Path to the tray icon when using a branch self.tray_icon_url = os.path.join(self.FILE_DIR, "..", "..", "icons", "hicolor", "24x24", "apps", "entertainer.png") self.icon_widget = gtk.StatusIcon() self.icon_widget.set_tooltip(_("Entertainer Server")) # Load UI with gtk.Builder uifile = os.path.join(self.UI_DIR, 'system_tray_icon_menu.ui') self.menu_widgets = gtk.Builder() self.menu_widgets.set_translation_domain('entertainer') self.menu_widgets.add_from_file(uifile) # Bind menu signals callback_dic = { "on_menuitem_client_activate": self.on_menuitem_client_activate, "on_menuitem_manager_activate": self.on_menuitem_manager_activate, "on_menuitem_log_viewer_activate": self.on_menuitem_log_viewer_activate, "on_menuitem_quit_activate": self.on_menuitem_quit_activate } self.menu_widgets.connect_signals(callback_dic) self.popup = self.menu_widgets.get_object("SystemTrayIconMenu") # Check if running from a branch to set the tray icon if (os.path.exists(self.tray_icon_url)): self.icon_widget.set_from_file(self.tray_icon_url) else: # Must be running from a package, therefore available by icon name self.icon_widget.set_from_icon_name("entertainer") self.icon_widget.connect('activate', self.systray_icon_activated) self.icon_widget.connect('popup-menu', self.open_popup_menu)
def __init__(self, filename, thumb_type): self.config = Configuration() thumb_dir = os.path.join(self.config.THUMB_DIR, thumb_type) self.filename = filename filehash = hashlib.md5() filehash.update(self.filename) self.filename_hash = filehash.hexdigest() if not os.path.exists(self.filename): raise ThumbnailerException( 'File to thumbnail does not exist : %s' % self.filename) if os.path.exists(thumb_dir): if os.path.isfile(filename): self._thumb_file = os.path.join(thumb_dir, self.filename_hash + '.jpg') else: raise ThumbnailerException( 'Thumbnailer filename is a folder : %s' % self.filename) else: raise ThumbnailerException('Unknown thumbnail type : %s' % (thumb_type))
def __init__(self): self.configuration = Configuration() self._store = Store(self.configuration.MEDIA_DB)
def __init__(self, remove_from_stage_callback): self.config = Configuration() self.screens = [] self.remove_from_stage_callback = remove_from_stage_callback
def __init__(self, remove_from_stage_callback): Transition.__init__(self, remove_from_stage_callback) self.config = Configuration() self.out_behaviour = None self.in_behaviour = None
def testBorg(self): '''Test that configuration objects share state''' self.second_config = Configuration() self.assertTrue( self.second_config.__dict__ is self.configuration.__dict__)
def __init__(self, image_library, music_library, video_library, quit_client_callback): self.quit_client_callback = quit_client_callback self.config = Configuration() # Store the dimensions in case users want to return to window mode self.old_width = self.config.stage_width self.old_height = self.config.stage_height self.logger = Logger().getLogger('client.gui.UserInterface') self.window = gtk.Window() self.window.connect('destroy', self.destroy_callback) self.window.set_title('Entertainer') # Set the window icon icon_theme = gtk.icon_theme_get_default() try: icon = icon_theme.load_icon('entertainer', 48, 0) self.window.set_icon(icon) except gobject.GError: # Must not be installed from a package, get icon from the branch file_dir = os.path.dirname(__file__) icon_path = os.path.join(file_dir, '..', '..', 'icons', 'hicolor', '48x48', 'apps', 'entertainer.png') icon = gtk.gdk.pixbuf_new_from_file(icon_path) self.window.set_icon(icon) # cluttergtk.Embed contains the stage that is the canvas for the GUI embed = cluttergtk.Embed() # Enforce a minimum size to prevent weird widget bugs embed.set_size_request( self.config.stage_width, self.config.stage_height) self.window.add(embed) # The embed widget must be realized before you can get the stage. embed.realize() self.stage = embed.get_stage() self._hide_cursor_timeout_key = None self.stage.connect('key-press-event', self.handle_keyboard_event) self.stage.connect('motion-event', self._handle_motion_event) self.stage.set_color(self.config.theme.get_color("background")) self.stage.set_size(self.config.stage_width, self.config.stage_height) self.stage.set_title("Entertainer") if self.config.start_in_fullscreen: self._fullscreen() self.is_fullscreen = True else: self.is_fullscreen = False # Initialize Screen history (allows user to navigate "back") self.history = ScreenHistory(self._remove_from_stage) self.player = MediaPlayer(self.stage, self.config.stage_width, self.config.stage_height) self.player.connect('volume-changed', self._on_volume_changed) # Initialize menu overlay texture self.is_overlay = False self.menu_overlay = MenuOverlay(self.config.theme) self.menu_overlay.set_opacity(0) self.menu_overlay.set_size( self.config.stage_width, self.config.stage_height) self.stage.add(self.menu_overlay) self.volume_indicator = VolumeIndicator() self.stage.add(self.volume_indicator) self.volume_indicator.connect('hiding', self._on_volume_indicator_hiding) self.fade_screen_timeline = clutter.Timeline(200) alpha = clutter.Alpha(self.fade_screen_timeline, clutter.EASE_IN_OUT_SINE) self.fade_screen_behaviour = clutter.BehaviourOpacity(255, 0, alpha) # Transition object. Handles effects between screen changes. transition_factory = TransitionFactory(self._remove_from_stage) self.transition = transition_factory.generate_transition() # Screen factory to create new screens self.screen_factory = ScreenFactory( image_library, music_library, video_library, self.player, self.move_to_new_screen, self.move_to_previous_screen) def default_key_to_user_event(): '''Return the default user event provided by an unmapped keyboard event.''' return UserEvent.DEFAULT_EVENT # Dictionary for keyboard event handling self.key_to_user_event = defaultdict(default_key_to_user_event, { clutter.keysyms.Return : UserEvent.NAVIGATE_SELECT, clutter.keysyms.Up : UserEvent.NAVIGATE_UP, clutter.keysyms.Down : UserEvent.NAVIGATE_DOWN, clutter.keysyms.Left : UserEvent.NAVIGATE_LEFT, clutter.keysyms.Right : UserEvent.NAVIGATE_RIGHT, clutter.keysyms.BackSpace : UserEvent.NAVIGATE_BACK, clutter.keysyms.h : UserEvent.NAVIGATE_HOME, clutter.keysyms.w : UserEvent.NAVIGATE_FIRST_PAGE, clutter.keysyms.e : UserEvent.NAVIGATE_PREVIOUS_PAGE, clutter.keysyms.r : UserEvent.NAVIGATE_NEXT_PAGE, clutter.keysyms.t : UserEvent.NAVIGATE_LAST_PAGE, clutter.keysyms.f : UserEvent.TOGGLE_FULLSCREEN, clutter.keysyms.p : UserEvent.PLAYER_PLAY_PAUSE, clutter.keysyms.s : UserEvent.PLAYER_STOP, clutter.keysyms._1 : UserEvent.USE_ASPECT_RATIO_1, clutter.keysyms._2 : UserEvent.USE_ASPECT_RATIO_2, clutter.keysyms._3 : UserEvent.USE_ASPECT_RATIO_3, clutter.keysyms._4 : UserEvent.USE_ASPECT_RATIO_4, clutter.keysyms.x : UserEvent.PLAYER_SKIP_BACKWARD, clutter.keysyms.c : UserEvent.PLAYER_SKIP_FORWARD, clutter.keysyms.z : UserEvent.PLAYER_PREVIOUS, clutter.keysyms.v : UserEvent.PLAYER_NEXT, clutter.keysyms.m : UserEvent.PLAYER_VOLUME_UP, clutter.keysyms.l : UserEvent.PLAYER_VOLUME_DOWN, clutter.keysyms.q : UserEvent.QUIT, clutter.keysyms.Escape : UserEvent.QUIT }) self.event_handlers = { UserEvent.DEFAULT_EVENT : self._handle_default, UserEvent.NAVIGATE_SELECT : self._handle_default, UserEvent.NAVIGATE_UP : self._handle_default, UserEvent.NAVIGATE_DOWN : self._handle_default, UserEvent.NAVIGATE_LEFT : self._handle_default, UserEvent.NAVIGATE_RIGHT : self._handle_default, UserEvent.NAVIGATE_BACK : self._handle_navigate_back, UserEvent.NAVIGATE_HOME : self._handle_navigate_home, UserEvent.NAVIGATE_FIRST_PAGE : self._handle_default, UserEvent.NAVIGATE_PREVIOUS_PAGE : self._handle_default, UserEvent.NAVIGATE_NEXT_PAGE : self._handle_default, UserEvent.NAVIGATE_LAST_PAGE : self._handle_default, UserEvent.TOGGLE_FULLSCREEN : self._handle_toggle_fullscreen, UserEvent.PLAYER_PLAY_PAUSE : self._handle_player_play_pause, UserEvent.PLAYER_STOP : self._handle_player_stop, UserEvent.USE_ASPECT_RATIO_1 : self._handle_aspect_ratio, UserEvent.USE_ASPECT_RATIO_2 : self._handle_aspect_ratio, UserEvent.USE_ASPECT_RATIO_3 : self._handle_aspect_ratio, UserEvent.USE_ASPECT_RATIO_4 : self._handle_aspect_ratio, UserEvent.PLAYER_SKIP_BACKWARD : self._handle_player_skip_backward, UserEvent.PLAYER_SKIP_FORWARD : self._handle_player_skip_forward, UserEvent.PLAYER_PREVIOUS : self._handle_player_previous, UserEvent.PLAYER_NEXT : self._handle_player_next, UserEvent.PLAYER_VOLUME_UP : self._handle_player_volume_up, UserEvent.PLAYER_VOLUME_DOWN : self._handle_player_volume_down, UserEvent.QUIT : self._handle_quit_client } self.logger.debug("Frontend GUI initialized succesfully")
def __init__(self): self.configuration = Configuration() self.logger = Logger().getLogger( 'entertainerlib.indexer.indexing.Indexer')
def __init__(self, location=""): self.location = location self.forecasts = [] self.theme = Configuration().theme self.locale = self._get_locale() self.refresh()
def setUp(self): '''Set up the test''' EntertainerTest.setUp(self) self.configuration = Configuration()