From d94c17248a9fade1b4798e370630cbde184eda3a Mon Sep 17 00:00:00 2001 From: smfontes Date: Sat, 10 Dec 2022 07:35:25 -0500 Subject: [PATCH] Screensaver for My Pictures Database pictures --- default.py | 6 +-- lib/getfilternames.py | 7 ++- lib/screensaver.py | 43 +++++++++++-------- resources/settings.xml | 6 +-- .../1080i/screensaver.mypicsdb2.slideshow.xml | 7 --- 5 files changed, 34 insertions(+), 35 deletions(-) diff --git a/default.py b/default.py index 6ac5b80..a78fc5a 100644 --- a/default.py +++ b/default.py @@ -2,13 +2,9 @@ from lib import screensaver -ADDON = xbmcaddon.Addon() -CWD = ADDON.getAddonInfo('path') -ADDONVERSION = ADDON.getAddonInfo('version') +CWD = xbmcaddon.Addon().getAddonInfo('path') if __name__ == '__main__': - screensaver.log('script version %s started' % ADDONVERSION) screensaver_window = screensaver.Screensaver('screensaver.mypicsdb2.slideshow.xml', CWD, 'default') screensaver_window.doModal() del screensaver_window -screensaver.log('script stopped') diff --git a/lib/getfilternames.py b/lib/getfilternames.py index bd9d7ad..c4a1e38 100644 --- a/lib/getfilternames.py +++ b/lib/getfilternames.py @@ -29,7 +29,6 @@ query = """Select strFilterName FROM FilterWizard""" filter_names_list = MPDB.cur.request(query) filter_names = [name[0] for name in filter_names_list] -filter_names.pop(0) # Remove 'Last Filter Used' filter name # Find where to insert the filter names in the settings.xml file settings_file = os.path.join(xbmcaddon.Addon().getAddonInfo('path'), 'resources', "settings.xml") @@ -44,6 +43,12 @@ for filter_name in filter_names: option=ET.SubElement(options,'option') option.text=filter_name + +# Add first filter name as default value if there are any filters +if len(filter_names) > 0: + default = tree.find(".//*setting[@id='filtername']/default") + default.text=filter_names[0] + tree.write(settings_file) # Notify that you must exit from settings and return to see any new filter names diff --git a/lib/screensaver.py b/lib/screensaver.py index 7e4db9d..f11971c 100644 --- a/lib/screensaver.py +++ b/lib/screensaver.py @@ -43,7 +43,21 @@ def log(msg, level=xbmc.LOGINFO): xbmc.log(str("[%s] line %5d in %s >> %s"%(ADDON.getAddonInfo('name'), int(lineno), filename, msg.__str__())), level) # Formats that can be displayed in a slideshow -PICTURE_FORMATS = ('bmp', 'jpeg', 'jpg', 'gif', 'png', 'tiff', 'mng', 'ico', 'pcx', 'tga') +PICTURE_FORMATS = ('jpg', 'jpeg', 'tiff', 'gif', 'png', 'bmp', 'mng', 'ico', 'pcx', 'tga') +SINGLE_PICTURE_QUERY = """ SELECT strPath, strFilename FROM Files """ +SINGLE_PICTURE_QUERY += """ WHERE strFilename LIKE '%s' """ +SINGLE_PICTURE_QUERY += """ OR strFilename LIKE '%s' """ +SINGLE_PICTURE_QUERY += """ OR strFilename LIKE '%s' """ +SINGLE_PICTURE_QUERY += """ OR strFilename LIKE '%s' """ +SINGLE_PICTURE_QUERY += """ OR strFilename LIKE '%s' """ +SINGLE_PICTURE_QUERY += """ OR strFilename LIKE '%s' """ +SINGLE_PICTURE_QUERY += """ OR strFilename LIKE '%s' """ +SINGLE_PICTURE_QUERY += """ OR strFilename LIKE '%s' """ +SINGLE_PICTURE_QUERY += """ OR strFilename LIKE '%s' """ +SINGLE_PICTURE_QUERY += """ OR strFilename LIKE '%s' """ +SINGLE_PICTURE_QUERY += """ ORDER BY RANDOM() LIMIT 1 """ +SINGLE_PICTURE_QUERY = SINGLE_PICTURE_QUERY % PICTURE_FORMATS +SINGLE_PICTURE_QUERY = SINGLE_PICTURE_QUERY.replace("LIKE '", "LIKE '%") # Get the Database from the My Pictures Database addon MPDB = MypicsDB.MyPictureDB() @@ -119,11 +133,8 @@ def _start_show(self): # loop until onScreensaverDeactivated is called while (not self.Monitor.abortRequested()) and (not self.stop): # Get the next picture - (folder, file) = self._get_item() - img_name = os.path.join(folder, file) + img_name = self._get_item() current_image_control.setImage(img_name, False) - # give xbmc some time to load the image - xbmc.sleep(1000) self._set_prop('Fade%d' % order[0], '0') self._set_prop('Fade%d' % order[1], '1') # define next image @@ -143,11 +154,8 @@ def _start_show(self): if self.stop or self.Monitor.abortRequested(): break - def exec_query(self,query): - return MPDB.cur.request(query) - def _get_item(self, update=False): - if self.slideshow_filter and self.slideshow_filtername != "": + if self.slideshow_filter: # Using a filter # Use the next picture that matched the filter result = self.filtered_results[self.filtered_results_index] @@ -159,18 +167,15 @@ def _get_item(self, update=False): self.filtered_results_index = 0 else: # Not using a filter - displayable = False - while not displayable: - query = """ SELECT strPath, strFilename FROM Files ORDER BY RANDOM() LIMIT 1""" - result_list = self.exec_query(query) - log(result_list) - result = result_list[0] - # Make sure only diplayable pictures are used - if result[1].lower().endswith(PICTURE_FORMATS): - displayable = True - return result + result_list = self.exec_query(SINGLE_PICTURE_QUERY) + result = result_list[0] + (folder, file) = result + return os.path.join(folder, file) # Utility functions + def exec_query(self,query): + return MPDB.cur.request(query) + def _set_prop(self, name, value): self.winid.setProperty('SlideView.%s' % name, value) diff --git a/resources/settings.xml b/resources/settings.xml index dd7fe58..360f1a6 100644 --- a/resources/settings.xml +++ b/resources/settings.xml @@ -22,14 +22,14 @@ 0 - + - + true - 30022 + 30003 diff --git a/resources/skins/default/1080i/screensaver.mypicsdb2.slideshow.xml b/resources/skins/default/1080i/screensaver.mypicsdb2.slideshow.xml index ec2c3bd..f6747ba 100644 --- a/resources/skins/default/1080i/screensaver.mypicsdb2.slideshow.xml +++ b/resources/skins/default/1080i/screensaver.mypicsdb2.slideshow.xml @@ -1,6 +1,5 @@ - 6 0 @@ -16,9 +15,6 @@ - - - 0 0 @@ -34,9 +30,6 @@ - - - 0 0