-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
first working implementation of the newsfeed system
- Loading branch information
1 parent
11ea35f
commit c51f90e
Showing
10 changed files
with
211 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,37 @@ | ||
import bpy | ||
import os | ||
|
||
from .addon_prefs import get_addon_preferences | ||
from .global_variables import newsfeed_file, newsfeed_url | ||
from .internet_functions import download_file | ||
from .json_functions import read_json, load_json_in_collection | ||
from .print_functions import print_and_report | ||
|
||
|
||
# reload newsfeed | ||
def reload_newsfeed(manifest_dataset): | ||
# download newsfeed file if needed | ||
def download_newsfeed(manifest_dataset): | ||
newsfeed_path = os.path.join(get_addon_preferences().download_folder, newsfeed_file) | ||
|
||
if not os.path.isfile(newsfeed_path): | ||
download_file(newsfeed_url, newsfeed_path) | ||
print_and_report(None, "Downloading Newsfeed", "INFO") #debug | ||
return True | ||
|
||
elif manifest_dataset["newsfeed_hash"] != read_json(newsfeed_path)["newsfeed_hash"]: | ||
download_file(newsfeed_url, newsfeed_path) | ||
print_and_report(None, "Downloading Newsfeed", "INFO") #debug | ||
return True | ||
|
||
return False | ||
|
||
|
||
# reload newsfeed datas | ||
def reload_newsfeed(): | ||
|
||
print_and_report(None, "Loading Newsfeed", "INFO") #debug | ||
|
||
newsfeed_path = os.path.join(get_addon_preferences().download_folder, newsfeed_file) | ||
|
||
properties_coll = bpy.data.window_managers[0].an_templates_properties | ||
|
||
return | ||
load_json_in_collection(read_json(newsfeed_path), properties_coll.news, 'news') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import bpy | ||
|
||
|
||
class ANTEMPLATES_OT_newsfeed_actions(bpy.types.Operator): | ||
bl_idname = "antemplates.newsfeed_actions" | ||
bl_label = "Newsfeed Actions" | ||
bl_description = "Go to Previous/Next News" | ||
bl_options = {'REGISTER', 'INTERNAL'} | ||
|
||
action: bpy.props.EnumProperty( | ||
items=( | ||
('PREV', "Previous", ""), | ||
('NEXT', "Next", ""), | ||
) | ||
) | ||
|
||
|
||
@classmethod | ||
def poll(cls, context): | ||
return len(context.window_manager.an_templates_properties.news) not in {0,1} | ||
|
||
|
||
def invoke(self, context, event): | ||
|
||
properties_coll = context.window_manager.an_templates_properties | ||
|
||
idx = properties_coll.active_news | ||
total = len(properties_coll.news) | ||
|
||
if self.action == 'PREV': | ||
if idx - 1 in range(0, total): | ||
context.window_manager.an_templates_properties.active_news -= 1 | ||
else: | ||
context.window_manager.an_templates_properties.active_news = total - 1 | ||
else: | ||
if idx + 1 in range(0, total): | ||
context.window_manager.an_templates_properties.active_news += 1 | ||
else: | ||
context.window_manager.an_templates_properties.active_news = 0 | ||
|
||
return {"FINISHED"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import bpy | ||
|
||
from .print_functions import print_and_report | ||
|
||
|
||
class ANTEMPLATES_OT_search_select_nodetree(bpy.types.Operator): | ||
bl_idname = "antemplates.search_select_nodetree" | ||
bl_label = "Select Nodetree" | ||
bl_description = "Select Nodetree in Templates Panel" | ||
bl_options = {'REGISTER', 'INTERNAL'} | ||
|
||
name : bpy.props.StringProperty(default="") | ||
|
||
|
||
@classmethod | ||
def poll(cls, context): | ||
return True | ||
|
||
|
||
def execute(self, context): | ||
|
||
winman = context.window_manager | ||
|
||
properties_coll = winman.an_templates_properties | ||
nodetree_coll = winman.an_templates_nodetrees | ||
|
||
try: | ||
nodetree_coll[self.name] | ||
except KeyError: | ||
print_and_report(self, "Unable to Find Nodetree : " + self.from_name, "WARNING") #debug | ||
return {'FINISHED'} | ||
|
||
properties_coll.nodetree_search = self.name | ||
|
||
idx = 0 | ||
for n in nodetree_coll: | ||
|
||
if n.name == self.name: | ||
properties_coll.nodetrees_index = idx | ||
break | ||
|
||
idx += 1 | ||
|
||
print_and_report(self, "Nodetree Selected in Templates Panel", "INFO") #debug | ||
|
||
return {"FINISHED"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# split string on spaces | ||
def split_string_on_spaces(string, char_limit): | ||
|
||
lines = [] | ||
|
||
words = string.split() | ||
|
||
print(words) | ||
|
||
line = "" | ||
for w in words: | ||
if len(line) < char_limit: | ||
line += w + " " | ||
else: | ||
line = line[:-1] | ||
lines.append(line) | ||
line = w + " " | ||
|
||
if line not in lines: | ||
lines.append(line) | ||
|
||
return lines |