Skip to content

Commit

Permalink
v4.6.16
Browse files Browse the repository at this point in the history
  • Loading branch information
eirannejad committed Feb 25, 2019
2 parents 07283b2 + 593f71a commit ea8a878
Show file tree
Hide file tree
Showing 21 changed files with 280 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Title="MainWindow"
Foreground="#000"
Height="325" Width="690" Margin="0"
SizeToContent="Width"
ShowInTaskbar="False"
BorderThickness="0"
Background="{x:Null}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
<Canvas x:Key="filterIcon">
<Path Canvas.Top="-28" Canvas.Left="-25" Data="F1 M 45.4403,56.9637L 45.4403,55.0463L 52.8201,44.5143L 52.8201,44.4237L 46.13,44.4237L 46.13,41.4774L 57.372,41.4774L 57.372,43.5352L 50.1532,53.9265L 50.1532,54.0174L 57.4869,54.0174L 57.4869,56.9637L 45.4403,56.9637 Z M 34.8333,61.75L 34.8333,42.75L 19,20.5833L 57,20.5833L 41.1667,42.75L 41.1667,58.5833L 34.8333,61.75 Z M 25.903,52.8055L 21.4072,52.8055L 20.289,56.9855L 16.6085,56.9855L 21.4072,41.4556L 26.0661,41.4556L 30.9337,56.9855L 27.1143,56.9855L 25.903,52.8055 Z M 21.9196,50.2801L 25.3905,50.2801L 24.4122,46.9804L 23.9987,45.4806L 23.6201,43.981L 23.5736,43.981L 23.2212,45.4941L 22.8514,47.0194L 21.9196,50.2801 Z " Fill="DimGray"/>
</Canvas>

<Style TargetType="{x:Type Hyperlink}">
<Setter Property="TextBlock.TextDecorations" Value="{x:Null}" />
</Style>
</Window.Resources>
<DockPanel Margin="10" LastChildFill="True">
<Grid DockPanel.Dock="Top" Margin="0,0,0,10" Height="25">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,11 +337,6 @@ def update_ext_info(self, sender, args):
else:
self.hide_element(self.ext_infopanel)

def handle_url_click(self, sender, args):
"""Callback for handling click on package website url
"""
script.open_url(sender.NavigateUri.AbsoluteUri)

def handle_private_repo(self, sender, args):
"""Callback for updating private status of a package
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def open_in_editor(editor_name, selected_cmd, altsrc=False):
NP_SWITCH,
CONFIG_SWITCH,
ALT_FLAG],
search_tip='pyRevit Search')
search_tip='type to search')

logger.debug('matched command: {}'.format(matched_cmdname))
logger.debug('arguments: {}'.format(matched_cmdargs))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,11 @@
print(i.Name)

elif selected_switch == 'Line Styles':
c = revit.doc.Settings.Categories.get_Item(DB.BuiltInCategory.OST_Lines)
subcats = c.SubCategories

for lineStyle in subcats:
print("STYLE NAME: {0} ID: {1}".format(lineStyle.Name.ljust(40),
lineStyle.Id.ToString()))
for lineStyle in revit.query.get_line_styles(doc=revit.doc):
print("STYLE NAME: {} ID: {} ({})".format(
lineStyle.Name.ljust(40),
lineStyle.Id.ToString(),
lineStyle))

elif selected_switch == 'Model / Detail / Sketch Lines':
cat_list = List[DB.BuiltInCategory]([DB.BuiltInCategory.OST_Lines,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@

<Style x:Key="treeItemStyle" TargetType="TreeViewItem">
<Style.Triggers>
<DataTrigger Binding="{Binding used}" Value="False">
<Setter Property="Foreground" Value="DarkGray" />
<DataTrigger Binding="{Binding used}" Value="True">
<Setter Property="FontWeight" Value="Medium" />
</DataTrigger>
<DataTrigger Binding="{Binding locked}" Value="True">
<Setter Property="Background" Value="WhiteSmoke" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Module for managing keynotes using DeffrelDB."""
#pylint: disable=E0401,W0613
import re
import codecs
from collections import namedtuple, defaultdict

Expand Down Expand Up @@ -39,21 +40,26 @@

RKeynoteFilter = namedtuple('RKeynoteFilter', ['name', 'code'])


class RKeynoteFilters(object):
"""Custom filters for filtering keynotes."""

UsedOnly = RKeynoteFilter(name="Used Only", code=":used:")
UnusedOnly = RKeynoteFilter(name="Unused Only", code=":unused:")
LockedOnly = RKeynoteFilter(name="Locked Only", code=":locked:")
UnlockedOnly = RKeynoteFilter(name="Unlocked Only", code=":unlocked:")
UseRegex = RKeynoteFilter(name="Use Regular Expressions (Regex)",
code=":regex:")

@classmethod
def get_available_filters(cls):
"""Get available keynote filters."""
return [cls.UsedOnly,
cls.UnusedOnly,
cls.LockedOnly,
cls.UnlockedOnly,]
cls.UnlockedOnly,
cls.UseRegex
]

@classmethod
def remove_filters(cls, source_string):
Expand Down Expand Up @@ -100,6 +106,10 @@ def children(self):

def filter(self, search_term):
self._filter = search_term.lower()

# use regex for string matching?
use_regex = RKeynoteFilters.UseRegex.code in self._filter

self_pass = False
if RKeynoteFilters.UsedOnly.code in self._filter:
self_pass = self.used
Expand All @@ -117,15 +127,28 @@ def filter(self, search_term):
has_smart_filter = cleaned_sfilter != self._filter

if cleaned_sfilter:
sterm = self.key +' '+ self.text +' '+ self.owner
sterm = self.key + ' ' + self.text + ' ' + self.owner
sterm = sterm.lower()

# here is where matching against the string happens
self_pass_keyword = \
coreutils.fuzzy_search_ratio(sterm.lower(),
cleaned_sfilter) > 80
if has_smart_filter:
self_pass = self_pass_keyword and self_pass
if use_regex:
# check if pattern is valid
try:
self_pass = re.search(
cleaned_sfilter,
sterm,
re.IGNORECASE
)
except Exception:
self_pass = False
else:
self_pass = self_pass_keyword
self_pass_keyword = \
coreutils.fuzzy_search_ratio(sterm, cleaned_sfilter) > 80

if has_smart_filter:
self_pass = self_pass_keyword and self_pass
else:
self_pass = self_pass_keyword

# filter children now
self._filtered_children = \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,9 @@ def __init__(self, xaml_file_name):
"with other projects. Users should NOT be making changes to "
"the existing keynote file during the conversion process.\n"
"Are you sure you want to convert?",
options=["Convert", "Give me more info"])
options=["Convert",
"Select a different keynote file",
"Give me more info"])
if res:
if res == "Convert":
try:
Expand All @@ -370,20 +372,22 @@ def __init__(self, xaml_file_name):
logger.debug('Legacy conversion failed | %s' % convex)
forms.alert("Conversion failed! %s" % convex,
exitscript=True)
elif res == "Select a different keynote file":
self._change_kfile()
elif res == "Give me more info":
script.open_url('https://eirannejad.github.io/pyRevit')
script.exit()
else:
forms.alert("Keynote file is not yet converted.",
exitscript=True)


self._cache = []
self._allcat = kdb.RKeynote(key='', text='-- ALL CATEGORIES --',
parent_key='',
locked=False, owner='',
children=None)

self._needs_update = False
self._config = script.get_config()
self._used_keysdict = self.get_used_keynote_elements()
self.load_config()
Expand Down Expand Up @@ -543,11 +547,15 @@ def load_config(self):
last_category_dict = self._config.get_option('last_category', {})
if last_category_dict and self._kfile in last_category_dict:
self._update_ktree(active_catkey=last_category_dict[self._kfile])
else:
self.selected_category = self._allcat

# load last search term
last_searchterm_dict = self._config.get_option('last_search_term', {})
if last_searchterm_dict and self._kfile in last_searchterm_dict:
self.search_term = last_searchterm_dict[self._kfile]
else:
self.search_term = ""

def _convert_existing(self):
# make a copy of exsing
Expand Down Expand Up @@ -676,10 +684,17 @@ def selected_category_changed(self, sender, args):

def selected_keynote_changed(self, sender, args):
logger.debug('New keynote selected: %s', self.selected_keynote)
if self.selected_keynote and not self.selected_keynote.locked:
self.keynoteEditButtons.IsEnabled = True
if self.selected_keynote \
and not self.selected_keynote.locked:
if self.selected_keynote.parent_key:
self.catEditButtons.IsEnabled = False
self.keynoteEditButtons.IsEnabled = True
else:
self.catEditButtons.IsEnabled = True
self.keynoteEditButtons.IsEnabled = False
else:
self.keynoteEditButtons.IsEnabled = False
self.catEditButtons.IsEnabled = False

def refresh(self, sender, args):
if self._conn:
Expand All @@ -694,33 +709,47 @@ def add_category(self, sender, args):
kdb.EDIT_MODE_ADD_CATEG).show()
if new_cat:
self.selected_category = new_cat.key
# make sure to relaod on close
self._needs_update = True
except System.TimeoutException as toutex:
forms.alert(toutex.Message)
except Exception as ex:
forms.alert(str(ex))

def edit_category(self, sender, args):
selected_category = self.selected_category
selected_keynote = self.selected_keynote
# determine where the category is coming from
# selected category in drop-down
if selected_category:
if selected_category.locked:
target_keynote = selected_category
# or selected category in keynotes list
elif selected_keynote and not selected_keynote.parent_key:
target_keynote = selected_keynote
if target_keynote:
if target_keynote.locked:
forms.alert('Category is locked and is being edited by {}. '
'Wait until their changes are committed. '
'Meanwhile you can use or modify the keynotes '
'under this category.'
.format('\"%s\"' % selected_category.owner
if selected_category.owner
.format('\"%s\"' % target_keynote.owner
if target_keynote.owner
else 'and unknown user'))
else:
try:
EditRecordWindow(self, self._conn,
kdb.EDIT_MODE_EDIT_CATEG,
rkeynote=selected_category).show()
rkeynote=target_keynote).show()
# make sure to relaod on close
self._needs_update = True
except System.TimeoutException as toutex:
forms.alert(toutex.Message)
except Exception as ex:
forms.alert(str(ex))
finally:
self._update_ktree()
if selected_keynote:
self._update_ktree_knotes()

def rekey_category(self, sender, args):
forms.alert("Not yet implemented. Coming soon.")
Expand All @@ -743,6 +772,8 @@ def remove_category(self, sender, args):
yes=True, no=True):
try:
kdb.remove_category(self._conn, selected_category.key)
# make sure to relaod on close
self._needs_update = True
except System.TimeoutException as toutex:
forms.alert(toutex.Message)
except Exception as ex:
Expand Down Expand Up @@ -771,6 +802,8 @@ def add_keynote(self, sender, args):
EditRecordWindow(self, self._conn,
kdb.EDIT_MODE_ADD_KEYNOTE,
pkey=parent_key).show()
# make sure to relaod on close
self._needs_update = True
except System.TimeoutException as toutex:
forms.alert(toutex.Message)
except Exception as ex:
Expand All @@ -785,6 +818,8 @@ def add_sub_keynote(self, sender, args):
EditRecordWindow(self, self._conn,
kdb.EDIT_MODE_ADD_KEYNOTE,
pkey=selected_keynote.key).show()
# make sure to relaod on close
self._needs_update = True
except System.TimeoutException as toutex:
forms.alert(toutex.Message)
except Exception as ex:
Expand All @@ -801,6 +836,8 @@ def duplicate_keynote(self, sender, args):
kdb.EDIT_MODE_ADD_KEYNOTE,
text=self.selected_keynote.text,
pkey=self.selected_keynote.parent_key).show()
# make sure to relaod on close
self._needs_update = True
except System.TimeoutException as toutex:
forms.alert(toutex.Message)
except Exception as ex:
Expand All @@ -826,6 +863,8 @@ def remove_keynote(self, sender, args):
yes=True, no=True):
try:
kdb.remove_keynote(self._conn, selected_keynote.key)
# make sure to relaod on close
self._needs_update = True
except System.TimeoutException as toutex:
forms.alert(toutex.Message)
except Exception as ex:
Expand All @@ -841,6 +880,8 @@ def edit_keynote(self, sender, args):
self._conn,
kdb.EDIT_MODE_EDIT_KEYNOTE,
rkeynote=self.selected_keynote).show()
# make sure to relaod on close
self._needs_update = True
except System.TimeoutException as toutex:
forms.alert(toutex.Message)
except Exception as ex:
Expand All @@ -854,19 +895,31 @@ def rekey_keynote(self, sender, args):
def show_keynote(self, sender, args):
if self.selected_keynote:
self.Close()
for kkey, kids in self.get_used_keynote_elements().items():
if kkey == self.selected_keynote.key:
for kid in kids:
source = viewname = ''
kel = revit.doc.GetElement(kid)
if kel:
source = kel.Parameter[
DB.BuiltInParameter.KEY_SOURCE_PARAM].AsString()
vel = revit.doc.GetElement(kel.OwnerViewId)
if vel:
viewname = revit.query.get_name(vel)
print('{} \"{}\" Keynote @ \"{}\"'
.format(output.linkify(kid), source, viewname))
kids = self.get_used_keynote_elements() \
.get(self.selected_keynote.key, [])
for kid in kids:
source = viewname = ''
kel = revit.doc.GetElement(kid)
ehist = revit.query.get_history(kel)
if kel:
source = kel.Parameter[
DB.BuiltInParameter.KEY_SOURCE_PARAM].AsString()
vel = revit.doc.GetElement(kel.OwnerViewId)
if vel:
viewname = revit.query.get_name(vel)
# prepare report
report = \
'{} \"{}\" Keynote @ \"{}\"'.format(
output.linkify(kid),
source,
viewname
)

if ehist:
report += \
' - Last Edited By \"{}\"'.format(ehist.last_changed_by)

print(report)

def place_keynote(self, sender, args):
self.Close()
Expand Down Expand Up @@ -901,6 +954,8 @@ def show_keynote_history(self, sender, args):

def change_keynote_file(self, sender, args):
self._change_kfile()
# make sure to relaod on close
self._needs_update = True
self.Close()

def show_keynote_file(self, sender, args):
Expand Down Expand Up @@ -948,13 +1003,13 @@ def export_visible_keynotes(self, sender, args):
except System.TimeoutException as toutex:
forms.alert(toutex.Message)


def update_model(self, sender, args):
self.Close()

def window_closing(self, sender, args):
with revit.Transaction('Update Keynotes'):
revit.update.update_linked_keynotes(doc=revit.doc)
if self._needs_update:
with revit.Transaction('Update Keynotes'):
revit.update.update_linked_keynotes(doc=revit.doc)

try:
self.save_config()
Expand Down
Loading

0 comments on commit ea8a878

Please sign in to comment.