Skip to content

Commit

Permalink
Screensaver for My Pictures Database pictures
Browse files Browse the repository at this point in the history
  • Loading branch information
smfontes committed Dec 10, 2022
1 parent a35f54e commit d94c172
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 35 deletions.
6 changes: 1 addition & 5 deletions default.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
7 changes: 6 additions & 1 deletion lib/getfilternames.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
Expand Down
43 changes: 24 additions & 19 deletions lib/screensaver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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]
Expand All @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions resources/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
</setting>
<setting help="30103" id="filtername" type="string" label="30003" parent="filter">
<level>0</level>
<default />
<default></default>
<constraints>
<options>
<option>2013 07 30</option><option>Austria</option><option>Blowing Rock</option><option>Foreign</option><option>Linda and Steve</option><option>London</option><option>test all</option></options>
</options>
<allowempty>true</allowempty>
</constraints>
<control type="list" format="string">
<heading>30022</heading>
<heading>30003</heading>
</control>
<dependencies>
<dependency type="visible">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<window>
<zorder>6</zorder>
<controls>
<control type="image">
<posx>0</posx>
Expand All @@ -16,9 +15,6 @@
<animation type="Conditional" condition="String.IsEqual(Window.Property(SlideView.Fade1),1)">
<effect type="fade" start="100" end="0" time="4000"/>
</animation>
<animation type="Conditional" condition="String.IsEqual(Window.Property(SlideView.NoEffectFade1),1)">
<effect type="fade" start="100" end="0" time="0"/>
</animation>
<control type="image" id="1">
<posx>0</posx>
<posy>0</posy>
Expand All @@ -34,9 +30,6 @@
<animation type="Conditional" condition="String.IsEqual(Window.Property(SlideView.Fade2),1)">
<effect type="fade" start="100" end="0" time="4000"/>
</animation>
<animation type="Conditional" condition="String.IsEqual(Window.Property(SlideView.NoEffectFade2),1)">
<effect type="fade" start="100" end="0" time="0"/>
</animation>
<control type="image" id="2">
<posx>0</posx>
<posy>0</posy>
Expand Down

0 comments on commit d94c172

Please sign in to comment.