anytree nodemixin using property or reference - python-3.x

I have an existing tree and I would like to add anytree functionality by adding NodeMixin. The problem is that NodeMixin wants a fixed name 'children' for its sub-elements and I already have a list with a different name.
Another problem (I am using mypy) is that the exiting sub-elements list is not optional - terminal nodes have empty lists and NodeMixin wants 'None' as 'children' of terminal objects.
It will create a lot of changes if I have to rename the object and to deal with the optional nature of the children.
Is it possible to define children as #property or as a reference of the existing sub-elements?

(a) it is possible to use properties for parent and children, (b) it was easy to write custom iterable class for children to account for differences between anytree and my tree iterations.
Update: is_leaf property has to be overridden too - otherwise it will be true for every node.

Related

Android Studio - how to diff two nested objects in debugger?

Let's say I have an object with a lot of nested objects and variables named credential:
After resume program, and re-enter the activity again as different login user:
What's the best way to diff this two objects all in once ? .e.g accountName (String), isNew (boolean) variables, and so on.
I tried "Copy Value" and then "Compare Value with Clipboard" but it only able to compare single text variable. "View Text" is same.
I also tried "Mark Object...", but its object will lose and not permanently store(re-enter class will override the object):
So is there any way to compare two complex and nested object values ?
[UPDATE]
I figure out I can press shift OR Ctrl+A to highlight all and then Ctrl+C to copy, but still it will not included nested object without expand them one by one:
[UPDATE 2]:
I noticed shadow$__klass_ object seems like contains itself and cause endless nested attributes. But it can be solved if I can exclude this object name OR limit the max nested depth ?
You can develop utility method and keep it somewhere in your project which accepts two objects and call it in the eval expression debugger window and see the difference.
You can use some reflection library or develop your own, it could work this way: walk over the object fields by reflection and build the map where the key contains the composite path of fields (f.e. fieldA.fieldANested.number) and the value it has. Then that two maps for the two objects could be compared very easily and you can see the difference in your debugger

How to recreate an element in Threepenny GUI?

If I use the delete function on some Elements, how can I then recreate them (as in make them appear again)?
I have looked around the examples and documentation, but I couldn't find any function that would allow me to do this except maybe mkElement which requires me to pass it a String. However since I'm working with Elements getting the String that would create it would be a bit difficult.
So is there any way to do that?
(Library author here)
Actually the, delete function does more than just remove the element from the DOM tree — it tries to delete any references to it in the JS and Haskell side. Essentially the element is (should be) unuseable after a delete.
If you want to temporarily hide an element, you can
Hide it via the CSS display property.
Rest the children of the parent element, e.g. by element parent # set children [].
Given that delete has the signature delete :: Element -> UI (), it follows that when you call delete, you have an Element in hand. Why can't you just hold onto this Element somewhere? (By which I mean maintain a reference to it in any number of ways.) Then just use (#+) :: UI Element -> [UI Element] -> UI Element to attach it as a child to another element later. If you just want it to reappear where it was before, you'd just attach it as a child to the very element that was its parent to begin with. Is this what you had in mind, or did I misunderstand the question?

System.ComponentModel.BindingList: Add(object) vs. AddNew()

What is the difference between the System.ComponentModel.BindingList methods Add(object) and AddNew()? The MSDN documentation says this:
Add: Adds an object to the end of the Collection<T>.
AddNew: Adds a new item to the collection.
It seems like both methods add an item to the collection, but Add(object) does it in one shot whereas AddNew() is slightly more complicated. My tests with Add(object) seem to be working, but I want to know if I am using the correct method.
So what is the difference between these methods?
AddNew() creates the object for you (that's why it doesn't have a parameter).
It's designed to be used by grids, which don't know how to create a new object to pass to Add().
AddNew() is very handy (it’s the well-known Factory design pattern) when you implement a class derived of BindingList().
It allows your code to initialize new items with values that depend on the list itself - e.g. a foreign key to the parent object if the binding list contains a list of children.

NSTableView content based on a selection of another NSArrayController

The issue
I have a popup button (NSPopUpButton) that is bound to an NSArrayController. This array controller handles parent objects that each have a collection of child objects. I have an NSTableView in which I need to show these children for the selected item in popup. In addition, the list of children needs to be manipulated (add/remove).
I've tried to accomplish this in many ways but always run into some thing that complicates the solution. What is the best way to implement this?
The data is managed here by Core Data and thus, the collections are NSSets. I've tried adding a conversion method in the parent to return a sorted NSArray (in order to bind it with NSArrayController) but this approach prevents the KVO and the array controller is not updated properly.
Thank you in advance.
An example
To clarify, here's a hypothetic example:
Let's say I have a list of countries that is maintained elsewhere. One of these countries is selected in a popup button. Each country has a set of cities. When a country is selected a table view is populated by it's cities.
There is a solution for this without the delegate/datasource setup.
My context is this:
CoreData model with Parents and Children, one Parent has multiple Children via a relationship named children. Both have a attribute name.
The two Entities must be available as classes (each with a .m and a .h). (Xcode will write them for you if you go to File-New-File-CoreData-NSManagedObjectSubclass.) Now the ChildObjects of a ParentObject can be accessed by ParentObject.children
Two NSArrayControllers: ParentArrayController and ChildArrayController.
Two NSTableViews: ParentTable and ChildTable, each with one column for name. (It should not matter whether you use a Popup or a table as long as it's controlled by a NSArrayController.)
The steps to take are as follows:
Connect both NSArrayControllers to the MangagedObjectContext as usual and set them to Mode: Entity Name with their respective Entity (Parent or Child)
Bind both TableViews (their columns) to their NSArrayController as usual.
Now comes the magic: In the ChildArrayControllers binding section under ControllerContent-ContentSet bind to the ParentArrayController with ControllerKey: selection and ModelKeyPath: children.
Done. If you select a ParentObject in the ParentTable the ChildTable shows its children.
To add and remove children to parents you can use the (void)addChildrenObject:(Child *)value; method that Xcode wrote for you in the Parents.m class file.
I didn't find any way to implement this by simply with dragging and dropping. I had to implement a delegate and data source for the table of cities (from the example). The window controller is notified of the selection changes in the popup button and this updates the content on the table view delegate / data source.
I actually feel this is little bit better way to implement the issue (than with bindings and array controllers) since it gives more control over special cases.

Sharepoint : Prevent a feature from activating on a condition

I made a feature that creates a list with some default data (with a list definition and all required XML)
I observed that when the list already exists, the data will be inserted again in the list... So I tried to make a "FeatureReceiver" to prevent the feature from creating the list if it already exists, but the base class of FeatureReceiver is an abstract class, so even if the list doesn't exists, I can't "call" the base function to continue the normal process...
Is there an easy way to do this or will I have to create the list through the FeatureReceiver by calling the XML file?
I would suggest that you create the lists and all the other stuff you have to do (add/remove fields, contenttypes etc) all through code. I usually never create any lists through xml. This might give you some guidance:
http://johanleino.wordpress.com/2009/08/12/howto-add-splist-based-on-a-custom-template/

Resources