Skip to content

Commit

Permalink
Add p tag to default list of tags
Browse files Browse the repository at this point in the history
Also add a more granular default preference assignment so new tags won't break
old json preference files.
  • Loading branch information
dougmassay committed Dec 3, 2016
1 parent 403a933 commit 61c4ff0
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 16 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ First, clone the repo and cd into it:

To create the plugin zip file, run the buildplugin.py script (root of the repository tree) with Python (2 or 3)

$python buildplugin.py
$./buildplugin (so long as buildplugin's executable bit is set, otherwise ... $python ./buildplugin)

This will create the TagMechanic_vX.X.X.zip file that can then be installed into Sigil's plugin manager.

Contributing / Modifying
============
From here on out, a proficiency with developing / creating Sigil plugins is assumed.
Expand All @@ -44,10 +44,10 @@ The core plugin files (this is where most contributors will spend their time) ar
> tk_tooltips.py
> updatecheck.py


Files used for building/maintaining the plugin:

> buildplugin.py -- this is used to build the plugin.
> buildplugin -- this is used to build the plugin.
> checkversion.xml -- used by automatic update checking (not yet implemented).
> setup.cfg -- used for flake8 style and PEP checking. Use it to see if your code complies.
(if my setup.cfg doesn't bark about it, then I don't care about it)
Expand Down
2 changes: 1 addition & 1 deletion buildplugin.py → buildplugin
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,4 @@ def ignore_in_dirs(base, items, ignored_dirs=None):
print ('Plugin successfully created!')

print('Removing temp build directory ...')
removePreviousTmp()
removePreviousTmp()
14 changes: 14 additions & 0 deletions dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ def initUI(self):
self.div_value_entry.pack(side=tkinter_constants.BOTTOM, fill=tkinter_constants.X)
div_frame.pack(side=tkinter_constants.TOP, fill=tkinter_constants.BOTH)

p_frame = tkinter.Frame(body, pady=3)
p_label = tkinter.Label(p_frame, text='Choices to change "p" elements to:')
p_label.pack(side=tkinter_constants.TOP, fill=tkinter_constants.X)
self.p_value = tkinter.StringVar()
self.p_value_entry = tkinter.Entry(p_frame, textvariable=self.p_value)
self.p_value_entry.pack(side=tkinter_constants.BOTTOM, fill=tkinter_constants.X)
p_frame.pack(side=tkinter_constants.TOP, fill=tkinter_constants.BOTH)

i_frame = tkinter.Frame(body, pady=3)
i_label = tkinter.Label(i_frame, text='Choices to change "i" elements to:')
i_label.pack(side=tkinter_constants.TOP, fill=tkinter_constants.X)
Expand Down Expand Up @@ -183,6 +191,8 @@ def populate(self, values):
self.span_value_entry.insert(0, ', '.join(values['span_changes']))
self.div_value_entry.delete(0, tkinter_constants.END)
self.div_value_entry.insert(0, ', '.join(values['div_changes']))
self.p_value_entry.delete(0, tkinter_constants.END)
self.p_value_entry.insert(0, ', '.join(values['p_changes']))
self.i_value_entry.delete(0, tkinter_constants.END)
self.i_value_entry.insert(0, ', '.join(values['i_changes']))
self.em_value_entry.delete(0, tkinter_constants.END)
Expand Down Expand Up @@ -224,6 +234,9 @@ def cmdDo(self):
tmp_list = self.div_value.get().strip(' ').split(',')
self.temp_values['div_changes'] = remove_dupes([x.strip(' ') for x in tmp_list if x])

tmp_list = self.p_value.get().strip(' ').split(',')
self.temp_values['p_changes'] = remove_dupes([x.strip(' ') for x in tmp_list if x])

tmp_list = self.i_value.get().strip(' ').split(',')
self.temp_values['i_changes'] = remove_dupes([x.strip(' ') for x in tmp_list if x])

Expand Down Expand Up @@ -272,5 +285,6 @@ def main():

return 0


if __name__ == "__main__":
sys.exit(main())
2 changes: 1 addition & 1 deletion parsing_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def processml(self):
self.path.append(tname)
elif ttype == 'end':
if tname != self.path[-1]:
print ('improper nesting: ', self.path, tname, type)
print('improper nesting: ', self.path, tname, type)
self.path.pop()

if tname == 'removeme:{0}'.format(tname):
Expand Down
39 changes: 31 additions & 8 deletions plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
combobox_defaults = {
'span_changes' : ['em', 'strong', 'i', 'b', 'small', 'u'],
'div_changes' : ['p', 'blockquote'],
'p_changes' : ['div'],
'i_changes' : ['em', 'span'],
'em_changes' : ['i', 'span'],
'b_changes' : ['strong', 'span'],
Expand All @@ -69,6 +70,14 @@
prefs = {}
BAIL_OUT = False

def check_for_new_prefs(prefs_group, default_values):
''' Make sure that adding new tags doesn't mean that the user has
to delete their preferences json and start all over. Piecemeal defaults
instead of the wholesale approach. '''
for key, value in default_values.items():
if key not in prefs_group:
prefs_group[key] = value

def valid_attributes(tattr):
''' This is not going to catch every, single way a user can screw this up, but
it's going to ensure that they can't enter an attribute string that's going to:
Expand Down Expand Up @@ -146,7 +155,7 @@ def initUI(self):
label.pack(side=tkinter_constants.LEFT, fill=tkinter_constants.Y)
self.tag_combo_value = tkinter.StringVar()
self.tag_combo = tkinter_ttk.Combobox(targetTagFrame, width=22, textvariable=self.tag_combo_value)
self.tag_combo['values'] = ('span', 'div', 'i', 'em', 'b', 'strong', 'u', 'small', 'a', 'section', 'blockquote')
self.tag_combo['values'] = ('span', 'div', 'p', 'i', 'em', 'b', 'strong', 'u', 'small', 'a', 'section', 'blockquote')
self.tag_combo.current(self.gui_prefs['tag'])
self.tag_combo.bind('<<ComboboxSelected>>', self.tag_change_actions)
# CreateToolTip(self.tag_combo, 'Which (x)html element do you wish to work with?')
Expand Down Expand Up @@ -419,6 +428,8 @@ def tag_change_actions(self, event):
self.newtag_combo['values'] = [self.NO_CHANGE_STR] + self.combobox_values['span_changes']
elif self.tag_combo_value.get() == 'div':
self.newtag_combo['values'] = [self.NO_CHANGE_STR] + self.combobox_values['div_changes']
elif self.tag_combo_value.get() == 'p':
self.newtag_combo['values'] = [self.NO_CHANGE_STR] + self.combobox_values['p_changes']
elif self.tag_combo_value.get() == 'i':
self.newtag_combo['values'] = [self.NO_CHANGE_STR] + self.combobox_values['i_changes']
elif self.tag_combo_value.get() == 'em':
Expand Down Expand Up @@ -528,11 +539,22 @@ def run(bk):
global prefs
prefs = bk.getPrefs()

# Or use defaults if json doesn't yet exist
prefs.defaults['gui_selections'] = gui_selections
prefs.defaults['miscellaneous_settings'] = miscellaneous_settings
prefs.defaults['update_settings'] = update_settings
prefs.defaults['combobox_values'] = combobox_defaults
if 'gui_selections' not in prefs: # If the json doesn't exist yet, assign wholesale defaults.
prefs['gui_selections'] = gui_selections
else: # otherwise, use the piecemeal method in case new prefs have been added since json creation.
check_for_new_prefs(prefs['gui_selections'], gui_selections)
if 'miscellaneous_settings' not in prefs:
prefs['miscellaneous_settings']= miscellaneous_settings
else:
check_for_new_prefs(prefs['miscellaneous_settings'], miscellaneous_settings)
if 'update_settings' not in prefs:
prefs['update_settings'] = update_settings
else:
check_for_new_prefs(prefs['update_settings'], update_settings)
if 'combobox_values' not in prefs:
prefs['combobox_values'] = combobox_defaults
else:
check_for_new_prefs(prefs['combobox_values'], combobox_defaults)

root = tkinter.Tk()
root.withdraw()
Expand All @@ -548,13 +570,14 @@ def run(bk):
# Save prefs to back to json
bk.savePrefs(prefs)
if BAIL_OUT:
print ('Changes aborted by user.\n')
print('Changes aborted by user.\n')
return -1
return 0

def main():
print ('I reached main when I should not have\n')
print('I reached main when I should not have\n')
return -1


if __name__ == "__main__":
sys.exit(main())
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<description>Manipulate Spans, Divs and other tags.</description>
<engine>python3.4</engine>
<engine>python2.7</engine>
<version>0.4.1</version>
<version>0.4.2</version>
<oslist>osx,unx,win</oslist>
<autostart>true</autostart>
<autoclose>true</autoclose>
Expand Down
1 change: 1 addition & 0 deletions updatecheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,6 @@ def __init__(self):
print(tuple_version('0.80.3') > tuple_version('0.80.1'))
print(tuple_version('0.80.3') > tuple_version('0.80.30'))


if __name__ == "__main__":
sys.exit(main())

0 comments on commit 61c4ff0

Please sign in to comment.