Update InterfaceController with different data - watchkit

Hi I am new to WatchKit development. I want to know that can I update a single interface controller with multiple data for button clicks

You could have many different objects in your InterfaceController, such as labels, image views, etc.
Updating WKInterfaceLabels
You should call the setText() method on the corresponding label.
For example, you have a button and a label, and you want to print "Hello" on the label when the button is clicked. In this case, you should connect an action to the button in your interface (by control-dragging button to the code), and then add the following code in the method created:
Swift
label1.setText("Hello")
Objective-C
[label1 setText:#"Hello"];
Updating WKInterfaceImages
You should call setImage() or setImageNamed() methods on the corresponding image view.
First, the image should be located in the Asset Catalog of your WatchKit App Target, must be bundled or available as an UIImage. Then you could use these codes:
Case #1: Available as file in bundle or Asset Catalog
Swift
image1.setImageNamed("imageName")
Objective-C
[image1 setImageNamed:#"imageName"];
Case #2: Available as an UIImage
Swift
image1.setImage(image)
Objective-C
[image1 setImage:image];
If you want to have animated photos, try this link.
Conclusion
To update WKInterfaceLabels, you should call the setText() method on the corresponding label.
To update WKInterfaceImages, you should call setImage() or setImageNamed() methods on the corresponding image view.
Resources
WKInterfaceImage Class Reference
WKInterfaceLabel Class Reference

Related

how to implement source filter property page?

I have followed the instructions at http://msdn.microsoft.com/en-us/library/windows/desktop/dd375010%28v=vs.85%29.aspx to create a property page for my CSourceStream based stream.
When testing with amcap I can see that amcap now shows the menu item to show the capture pin properties (ISpecifyPropertyPages::GetPages is queried). The problem is that when amcap calls OleCreatePropertyFrame it returns with E_FAIL and I am not sure why, it does not seem to even get to the stage of quering my dll for the factory method to instantiate the CBasePropertyPage based property class.
The problem was my DllRegisterServer only registered my filter.
I can use AMovieDllRegisterServer2 to register all components in g_Templates but that function does not register source filters properly so for the moment I am just calling AMovieDllRegisterServer2 and then re-registering my filter with source filter specific code.

adding a button in tryton view form

hi i have been searching and i cant find any tutorial about how to add a button in my view_form part of a custom module.
i wanted to add a button and make it call a method i made every time it is clicked.
in xml view form :
<label name="fieldstring"/>
<field name="fieldstring"/>
<button name="dosomething"/>
code:
def dosomething(cls,records):
#treatement
is there any example module that is using a button associated to a treatment??
In order to add a button to a view you have to make 3 steps:
Add the button to the _buttons dictionary of ModelView class. Normally this is done in the setup method of your class. Here you can define the icon and the states (when the button is invisible for example). If nothing needed you can define it with an empty dictionary.
For example:
#classmethod
def __setup__(cls):
super(Class, cls).__setup__()
cls._buttons.update({
'mybutton': {},
})
More complex examples can be found on tryton modules, for example:
http://hg.tryton.org/modules/account_invoice/file/84a41902ff5d/invoice.py#l224
Declare your method and decorate it with ModelView.button (in order to check access right to this button). For example:
#classmethod
#ModelView.button
def mybutton(cls, records)
#DO whatever you want with records
NOTE that the name method must be the one that you use as key of the _buttons dictionary in step1.
And finally add it to the view. You can find all the attributes that can be used on:
http://doc.tryton.org/3.2/trytond/doc/topics/views/index.html?highlight=button#button
Note that the string and name attributes are mandatory.
Also the name must be the name of the method to call, defined in step 2.
You can find some examples in:
http://hg.tryton.org/modules/account_invoice/file/84a41902ff5d/view/invoice_form.xml#l51

Set highlighted record on a list page through code on called object

On the CustListPage I have added functionality on the ribbon which opens a popup/dialog form from where you can see related Customers.
How do I, on selection of one of the related customers on my dialog, jump to that customer on the listpage?
What I’ve tried so far:
I’ve added a method (lets call it setActiveRecord) on the CustTableListPageInteraction class that should set the activeRecord on the listpage to the record I’m passing to this method. I’m passing the CustTableListPageInteraction class to the dialog form, using a parm method. Now on my dialog form I can see that I receive the CustTableListPageInteraction class. However, I’m unable to execute my method setActiveRecord on the CustTableListPageInteraction, because I get a “object not initialized”.
What is the best route to follow to update a ListPage from a called object? Because the listpage is driven by the class, I find it very difficult to pass parameters back.

Making sure my extended lists always show "current" data?

When you create a Data Extender for a CME list – for instance to add a column for the Schema as in this example – it all works fine and dandy whenever you do actions that force a List reload.
However, some actions don’t force a list reload (like editing a component in a folder, then saving & closing) and it looks like Anguilla is loading the data for the item that changed using a different mechanism that loads only the data for the item in question (which makes sense).
If I would want my extended list view to behave properly and also load my additional attributes whenever a given item changes (instead of only when the list view is reloaded) what else do I need to do?
I found how Anguilla takes care of this. When you implement a Data Extender, you are extending the information regarding the items displayed in the list, which basically means that you are extending the Data (Model) behind the item in question.
Each Item in Tridion has its own class in the Anguilla Framework, for example a Component has its own Tridion.ContentManager.Component javascript "class".
Having said this, and going back to the example that shows the schema name of the component, we are not actually extending the model, since that information is already available in the component. However, we need to overwrite the methods exposed on each used for displaying information in the lists the item is in, in this case a Component.
So, when we deal with a Data Extender, if we want a full implementation of this functionality, we not only need to define the data extender:
<ext:dataextender
name="IntelligentDataExtender"
type="Com.Tridion.PS.Extensions.IntelligentDataExtender,PS.GUI.Extensions">
<ext:description>Shows extra info</ext:description>
</ext:dataextender>
But also we need to define what's the column we are adding:
<ext:lists>
<ext:add>
<ext:extension name="IntelligentColumnExtender"
assignid="IntelligentDataColumnExtender">
<ext:listDefinition>
<ext:selectornamespaces/>
<ext:columns>
<column
xmlns="http://www.sdltridion.com/2009/GUI/extensions/List"
id="IntelligentData"
type="data"
title="Additional Info"
selector="#ExtendedInfo"
translate="String"/>
</ext:columns>
</ext:listDefinition>
<ext:apply>
<ext:view name="DashboardView" />
</ext:apply>
</ext:extension>
</ext:add>
</ext:lists>
Once we have this, the GUI will display the column we just added: "Additional Info"
Well, now we need to achieve the list refreshing when the item is edited/checked-out and in, etc...
For that, we need to extend the model and implement a few methods in the Object we are extending. In this example I am extending the Page object, so whenever a page is edited, the row in the list we want to update gets refreshed, together with the rest of the cells in the table.
To extend the model we need to define what types are we extending, in this example I am going to use the "Page" class as an example. First of all you need to define the model extension in the config file of your Editor:
<cfg:group name="Com.Tridion.PS.Extensions.UI.Model"
merger="Tridion.Web.UI.Core.Configuration.Resources.DomainModelProcessor"
merge="always">
<cfg:domainmodel name="Com.Tridion.PS.Extensions.UI.Model">
<cfg:fileset>
<cfg:file type="script">/Scripts/PSPage.js</cfg:file>
</cfg:fileset>
<cfg:services />
</cfg:domainmodel>
</cfg:group>
and
<ext:modelextensions>
<cfg:itemtypes>
<cfg:itemtype id="tcm:64" implementation="Com.Tridion.PS.Extensions.UI.PSPage" />
</cfg:itemtypes>
</ext:modelextensions>
As you can see I am extending the Page by using the "Com.Tridion.PS.Extensions.UI.PSPage" class that is defined in the Javascript file "/Scripts/PSPage.js".
The only method that handles the row refreshing is the following:
Com.Tridion.PS.Extensions.UI.PSPage.prototype.getListItemXmlAttributes
= function PSPage$getListItemXmlAttributes(customAttributes) {
var attribs = {};
var p = this.properties;
if (customAttributes) {
for (var attr in customAttributes) {
attribs[attr] = customAttributes[attr];
}
}
//This adds my custom column back when the item is updated
attribs["ExtendedInfo"] = p.extendedInfo;
return this.callBase(
"Tridion.ContentManager.Page",
"getListItemXmlAttributes",
[attribs])
};
As you can see I am implementing the "ExtendedInfo" attribute which is the one displayed in my additional column.
There's more than just adding a Data Extender when dealing with adding a column to our lists. I will write a post in my blog here to provide with a fully working example.
I hope it makes sense.
Well, Jaime correctly described how CME updates changed items in Lists. But I want to add some additional information on how List controls, domain model List and Items are interact with each other. This might help you building your own extension with similar functionality.
Most of the domain model List items inherit from Tridion.ContentManager.ListTcmItems class. On the moment when any List item, based on mentioned class, is loaded it will be registered in Lists Registry (and un-registered when the List is unloaded). This will allow Model to use registered Lists as source of static data for Items and to update changed Items data in these Lists.
Update Item static data
For example, we have loaded ListCategories and there is only one Category in the List:
var pub = $models.getItem("tcm:0-1-1");
var list = pub.getListCategories();
list.load();
// After list is loaded
list.getXml();
That getXml() returns an XML like (simplified):
<tcm:ListCategories>
<tcm:Item ID="tcm:1-4-512" Type="512" Title="Keys" />
</tcm:ListCategories>
After that, if you try to get some static data for Category "Keys" it will be already set:
var category = $models.getItem("tcm:1-4-512");
category.isLoaded(); // return false
category.isStaticLoaded(); // return false
category.getTitle(); // return undefined
category.getStaticTitle(); // return "Keys"!
That is possible because $models.getItem call will do two things: it will return an existing (or create a new) domain model object and call $models.updateItemData method with it. This method call will go through all registered Lists in the Lists Registry and for all Lists whose TimeStamp bigger than Item's Last Update TimeStamp will call list.updateItemData with the model object.
The updateItemData method will check if the passed Item is in the list and if it is, then the Item will be updated with the static data that is available from the List.
Updating data of changed Items in the List
When a domain model Item is modified (updated, removed, created new) one of these methods is called:
$models.itemUpdated
$models.itemRemoved
These methods will go through the Lists in Lists Registry and call list.itemUpdated (or list.itemRemoved). These methods will check is passed Item is contained in their List and if so they will update the List xml from the Item data.
For that purpose there is a getListItemXmlNode method in the Tridion.ContentManager.Item class. This method will build List xml node based on the array of attributes, provided by getListItemXmlAttributes method on the Item. That's what Jaime mentioned in his answer.
If the List xml was updated, one of these events will be fired on List object:
itemadd
itemupdate
itemremove
Listening to these events on a List object in your view will allow you to timely update your List Control.
So if you want this mechanism to work with your extension, stick to these rules:
If you are creating new domain model List object - it should inherit Tridion.ContentManager.ListTcmItems class or it should implement the getId(), itemUpdated(item), itemsUpdated(item), itemRemoved(item) and updateItemData(item) methods
If you want to see changes in List control - attach handlers to corresponding events on the domain model List object and update your List control
If you are creating new domain model Item - it should inherit Tridion.ContentManager.Item class and you should improve getListItemXmlAttributes method to return correct array of attributes for the List
The CME will indeed update the items in the list dynamically after the save occurs, without going to the server.
To do so, it calls a method named "getListItemXml" which returns the update XML element for the list. It will then update or add this element, which will update or add the item in the list view.
getListItemXml is a method of the different Model objects.
So how do you take advantage of this? I'm not sure.
Perhaps you could overwrite the method (or maybe getListItemXmlAttributes is best) with your own to add the additional data?
There is also an "itemupdate" event fired whenever an item is updated in the list.
You can hook into that by doing something like this:
var myEventHandler = function(event)
{
$log.message("Item updated. TridionEvent object passed: " + event);
}
var view = $display.getView();
var list = view.getListObject("uri-of-Folder");
list.addEventListener("itemupdate", myEventHandler);
I suppose you could use that to update the list entry for the item after the fact.
Be sure to call removeEventHandler at some point too.
None of this is optimal, obviously.
But I don't know of any extension point that would solve this particular problem.
I think I would (attempt to) implement this by monitoring the items in a folder periodically and updating that list after this polling mechanism had detected a change in that folder.
For example, I would write some javascript timeout or interval that runs in the background and checks the items in the current folder. If it detects a change, it triggers the update of the list.
Alternatively, you could also try to intercept the action that changed your list (e.g. the creation of a new item), maybe by means of an event system, and as such update your list. I don't think this is much different than the first approach, as I think it still implies some level of polling from the GUI side.

Type Coercion error when casting an object loaded in a different application domain

My application currently contains a number of Widgets that are managed by a Widget Manager. When the user clicks on a widget (e.g. a Helper widget), the Widget Manager loads the widget into a separate sibling application domain with the following line of code:
wgtInfo.load(null, null, null, moduleFactory); //wgtInfo = IModuleInfo
However, I am unable to use the widget's variables and functions later on. I attempt to find the Helper widget from the Widget Manager's list of widgets, and I do successfully. But when I try to caste the Helper Widget from type IBaseWidget (the interface all widgets share) to type HelperWidget, I receive the following error:
TypeError: Error #1034: Type Coercion failed.....
This is because the application domain of the class trying to use the Helper widget is different from the application domain of the Helper Widget. I tried to fix this by loading all widgets into the same application domain as the loader:
wgtInfo.load(ApplicationDomain.currentDomain, null, null, moduleFactory);
I now get the following error whenever I attempt to load the Helper widget:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
How can I load my Helper widget into a common application domain that is accessible by the other widgets?
I believe your problem comes from the class not being included in the swf. This is because Flash doesn't compile in classes in a swf if they aren't used to reduce filesize. To prevent this, you only need to create a variable with the helper class you need in that class, like this:
private var helper:HelperWidget;
See if that helps.
I'm gonna repost my 'comment' as a real answer. I'm guessing that the error is not based on the ApplicationDomain but based on which classes you are being compiled into your Module. When Flex compiles the SWF it automatically optimizes unused classes out of the SWF. You can force them back into the SWF in one of two ways:
Use the compiler argument include-libraries to force the Flex compiler to add the class to your SWF.
Add a fake variable in in your application so that the Flex compiler thinks it is used and adds it to the final SWF. Something like this.
private var myFakeObject : HelperWidth;
After trying a number of solutions unsuccessfully (including the other responses on this page), I resorted to another, event-driven, solution.
I ended up dispatching a custom event to notify my other widgets when the Helper widget had completed loading:
(HelperWidget.mxml)
ViewerContainer.addEventListener(AppEvent.WIDGET_OPEN_TAB, widgetOpenTabHandler); //listen for other widgets to open a tab within the Helper Widget
ViewerContainer.dispatchEvent(new AppEvent(AppEvent.WIDGET_READY_OPEN_TAB)); //notify other widgets that loading is complete
My other widgets listen for this event to fire, and upon completion, dispatch another event (AppEvent.WIDGET_OPEN_TAB) to perform a function within the Helper widget.

Resources