-
Notifications
You must be signed in to change notification settings - Fork 3
Implementation
- 2.2 Get resolution of all monitors, i.e. implement multi-monitor support, remember the collage plugins
Plugins are handled by the PluginManager
class implemented in /plugin/__init__.py
. When PluginManager
is instantiated it searches the /plugin/
folder for
subclasses of each of the plugin parent classes, i.e. the plugin types; and stores them in the plugins
dictionary, the dictionary keys are the names of plugin parent classes.
An instance of PluginManager
is stored in /plugin/__init__.py
as plugin_manager
.
The methods below that are not marked Requires implementation are implemented in the plugin parent class.
Creates a wallpaper collage, popping one or more instances of pygame.Surface
from the Wallpaper
class and returning a new instance of pygame.Surface
, the new wallpaper.
-
self.wallpaper_source
: TheWallpaper
instance currently in use -
self.config
: The configuration dictionary. -
self.logger
: The logger currently in use.
-
__init__(self)
- Instantiated by
PluginManager
class. Instance variables set after it's been initialized. - Requires implementation, Ex.
- Instantiated by
def __init__(self, wallpaper_queue, config):
super(CollagePluginName, self).__init__(wallpaper_queue, config)
-
generate(self, size)
- Generated a new wallpaper.
-
size
: tuple of length 2, dimensions of the generated wallpaper. - Requires implementation, Ex. from
SimpleResize
plugin.
wallpapers = self._get_wallpapers()
self.logger.debug('Generating...')
collage = pygame.Surface(size)
wp_offset, wp = self._resize_wallpaper(wallpapers[0], size)
for x1, x2 in enumerate(range(size[0]), wp_offset[0]):
for y1, y2 in enumerate(range(size[1]), wp_offset[1]):
collage.set_at((x2, y2), wp.get_at((x1, y1)))
self.logger.debug('Generation complete')
return collage
-
_resize_wallpaper(self, wallpaper, size)
- Resized a
pygame.Surface
to the desired size. This method returns an offset tuple, (x value, y value), and the resized wallpaper. Cropping is done after resize to speed up the resizing proccess. -
wallpaper
:pygame.Surface
which needs to be resized. -
size
: the new size the wallpaper should take.
- Resized a
Adds arguments to the command line and options to the configuration file. This is the only plugin whose parent class doesn't inherit the Plugin
class and so has no self.config
dictionary.
-
self.default
: Default value of the opion. ANone
value means it's required. -
self.option
: The name of the option, used in config file and as the long form command line option. -
self.cmd_short
: Used as the short form command line option. -
self.cmd_argument
: The name of the argument in the command line. ANone
value (default) means there is no argument. -
self.description
: The description written in the command line when -h or --help is used. -
self.conf_description
: The description written in the sample configuration. -
self.conf_default
: The default value in written in the sample configuration.
-
__init__(self)
- Requires implementation, Ex. from
ResolutionOption
plugin.
- Requires implementation, Ex. from
def __init__(self):
super(ResolutionOption, self).__init__()
self.default = self.parse("0x0")
self.option = 'resolution'
self.cmd_short = 'r'
self.cmd_argument = 'RES'
self.description = 'Forces resolution of generated wallpaper'
self.conf_description = ['# forces resolution of generated wallpaper\n',
'# i.e. desktop resolution is not queried, useful if\n',
'# get_resolution plugins fail\n',
'# e.x. setting:\n',
'# resolution=1680x1050\n']
-
parse(self, value)
- Returns an appropriate object instead of the string value.
- ex.
'4'
is turned intoint(4)
.
- ex.
- Returns
value
if parse is not implemented. -
value
: the value to be parsed. - Requires implementation, Ex. from
ResolutionOption
plugin.
- Returns an appropriate object instead of the string value.
def parse(self, value):
res = value.split('x')
if type(res) == str:
res = value.split('X')
return tuple([int(i) for i in res])
Gets the resolution of all monitors, returns a tuple of monitor resolution tuples.
-
self.config
: The configuration dictionary. -
self.logger
: The logger currently in use.
-
__init__(self)
- Instantiated by
PluginManager
class. Instance variables set after it's been initialized. - Requires implementation, Ex.
- Instantiated by
def __init__(self):
super(GetResolutionPluginName, self).__init__()
-
platform_check(self)
- Checks if this plugin is viable on the current platform.
- Requires implementation
-
get(self)
- Gets the resolution, returns a tuple of size 2 with the dimensions of the monitor resolution.
- Requires implementation
Sets the image found in config['wallpaper']
path as the current desktop wallpaper.
-
self.config
: The configuration dictionary. -
self.logger
: The logger currently in use.
-
__init__(self)
- Instantiated by
PluginManager
class. Instance variables set after it's been initialized. - Requires implementation, Ex.
- Instantiated by
def __init__(self):
super(SetWallpaperPluginName, self).__init__()
-
platform_check(self)
- Checks if this plugin is viable on the current platform.
- Requires implementation
-
set(self)
- Sets the wallpaper.
- Requires implementation
Searches for new wallpapers, sources could be file system, flickr, instagram, reddit, etc. The wallpaper class in the app handles calls to these plugins. Images found are kept in a list. Images need to be saved in the file system to be able to create pygame image instances.
-
self.wallpapers
: The list of wallpapers available. -
self.config
: The configuration dictionary. -
self.logger
: The logger currently in use.
-
pop(self, count=1)
- Called by the
Wallpaper
class when it'spop
method is called. - Returns a list of
pygame.Surface
instances. - Requires implementation
- Called by the
-
_images_from_path(self, path)
- Returns a
pygame.Surface
instance of the image in path.
- Returns a
-
count(self)
- Returns a count of wallpapers available from this plugin.
Creates a user interface for the application
-
self.app
: The application instance, set in the Application's__init__
function. -
self.config
: The configuration dictionary. -
self.logger
: The logger currently in use.
-
__init__(self)
- Initializes the ui plugin, the ui itself should be initalized when
start_app
is called. - base class sets the neccessary instance variables.
- Initializes the ui plugin, the ui itself should be initalized when
-
start_app(self)
- This method starts both the application loop thread and the main thread (the UI thread).
-
exit_app(self)
- Stops the necessary threads to stop the application running.
-
start_generating(self)
- Tries to start generating a new collage as soon as possible.
Plugin events, these hooks are called when certain events happen in the application.
-
app_initialized(self)
- Called after app has been initialized.
- UI can be initialized now.
-
app_started(self)
- Called when main loop is first called.
-
app_quitting(self)
- Called when the main loop is stopped completely.
-
generate_finished(self)
- Called when generation of collage is complete.
-
generate_started(self)
- Called when generation of a collage is starting.
-
wallpaper_search_finished(self)
- Called after wallpaper search plugin(s) has finished searching.
-
wallpaper_search_started(self)
- Called when wallpaper search plugin(s) is started.