[tutorial] How-To-Make-A-CHT-Widget

Are you interested in making or editing a CHT widget?

  • YES

    Votes: 82 95.3%
  • NO

    Votes: 4 4.7%

  • Total voters
    86
Search This thread

palokm

Senior Member
Apr 7, 2009
564
170
Bratislava
I do not know whether to understand

but what you create can also be used differently, but I would adjust it to 512x256
use this as a background for hours every day

I tried it with, but it is bad size 512x128

it works, just wants to adjust
 

Attachments

  • Screen03.jpg
    Screen03.jpg
    33.6 KB · Views: 16
Last edited:

Dunc001

Inactive Recognized Developer
Apr 6, 2010
2,705
1,462
Hiding out south of the border...
For the next day function I made then a little lua snippet (attached)....

...With this value it should be possible to determine the sequence of the weekdays and also the highlighting of the actual day.

Hey Rat, long time my friend - hope you are well :cool: Wasn't that the code snippet you sent me which I could only figure out how to use if the current day was always in position 1 rather than the weekdays staying static and the current day moving (ie for Wednesday it would display WEDTHUFRISATSUNMONTUE and so on). Or did you have an idea for how to then match the current day with a string and then highlight the correct day string according to what 'today' is?
 

RoryB

Inactive Recognized Developer
Sep 4, 2008
2,921
766
Lexington
So to kill a process I could use
Shell_NavigateTo("\\windows\\dfTaskMgr.exe", "/kill processname.exe")

And a loop to check for file I could use

Code:
Filetimer = timer(0.5)
Filetmer:Stop()
Filetimer.OnElapsed:connect(function()
    if MusicHelper_FileExist("\\windows\\StartUP\\file name.lnk") then
      MusiceHelper_FileDelete("\\windows\\StartUP\\file name.lnk")
      if Filetimer then
        Filetimer:Stop()
        Filetimer = nil
      end
    else
      Filetimer:Start()
    end
end)
 
  • Like
Reactions: poyensa

poyensa

Retired Forum Mod / Retired Recognized Developer
Apr 27, 2010
3,160
2,568
mi patria en mis zapatos
I do not know whether to understand

but what you create can also be used differently, but I would adjust it to 512x256
use this as a background for hours every day

I tried it with, but it is bad size 512x128

it works, just wants to adjust

I think i understand now. You are using as background of other widgets. It should be better to use Poy6BG v2 for that. Have a look to my sign.

Poy6BG v2 should accept png backgrounds but has to be some errors, at least its not worki.g well niw ... i will look deeper.
 

palokm

Senior Member
Apr 7, 2009
564
170
Bratislava
Yes I understand.
Only in this way would be the desktop clock changed automatically at 00:00

Poy6BG v2 ... uses this as a dark background for the widget
......................................................................................

is a big problem converted to 512x256?

I tried to test
 

poyensa

Retired Forum Mod / Retired Recognized Developer
Apr 27, 2010
3,160
2,568
mi patria en mis zapatos
Yes I understand.
Only in this way would be the desktop clock changed automatically at 00:00

Poy6BG v2 ... uses this as a dark background for the widget
......................................................................................

is a big problem converted to 512x256?

I tried to test

Try CHTwPoy6BG_v3.cab, now able to use any PNG as background, any size.
 
  • Like
Reactions: ezzie

rat_2665

Retired Recognized Developer
Jan 29, 2010
613
200
Hey Rat, long time my friend - hope you are well :cool: Wasn't that the code snippet you sent me which I could only figure out how to use if the current day was always in position 1 rather than the weekdays staying static and the current day moving (ie for Wednesday it would display WEDTHUFRISATSUNMONTUE and so on). Or did you have an idea for how to then match the current day with a string and then highlight the correct day string according to what 'today' is?

Yeah I'm well, but a little busy ;). So just an idea:
1. Create a sequence with the next day function (yes, it was the code snippet I sent you). First day is the actual day, f. e. WEDTHUFRISATSUNMONTUE.
2. Determine the numerical value x for the actual week day (here 3).
3. Change all positions x (here three) steps to the right. Of course for the last x positions greater 7 you have to start at the beginning. So you get for all x a static sequence like SUNMONTUEWEDTHUFRISAT.
4. Now highlight the x+1 Position. That's the actual day.
 
  • Like
Reactions: poyensa

RoryB

Inactive Recognized Developer
Sep 4, 2008
2,921
766
Lexington
Help please

This does not work for me. I never get the registry change even though the file is deleted earlier.


Code:
Filetimer = timer(0.5)
Filetmer:Stop()
Filetimer.OnElapsed:connect(function()
	if MusicHelper_FileExists("\\windows\\StartUp\\Voice Command.lnk") then
		Filetimer:Start()
	else
		_application.Store:SetIntValue(Lifetime_Permanent, "CHT.VoiceCommand.Active", 0)
		if Filetimer then
			Filetimer:Stop()
			Filetimer = nil
		end
	end
 

RoryB

Inactive Recognized Developer
Sep 4, 2008
2,921
766
Lexington
Figured it out from lockscreen lua. You need a timer that can be stopped if you do not have a need for it. So the "if not VoiceCmdCheckCount" does that. Then later in your code you start it again with the timer start command and setting "VoiceCmdCheckCount = 0"

Code:
--## handler to check for \windows\startup\voice command.lnk
VoiceCmdCheck = function()
	if not VoiceCmdCheckCount or VoiceCmdCheckCount > 60 then
		VoiceCmdCheckCount = nil -- set counter to be "off"
		VoiceCmdTimer:Stop() --stop after initializing or after 60 seconds
	else
		VoiceCmdCheckCount = VoiceCmdCheckCount + 1
		if VoiceCmdStart == 1 then --starting voice command
			if MusicHelper_FileExists("\\windows\\startup\\voice command.lnk") then --if \windows\startup\voice command.lnk exists
				_application.Store:SetIntValue(Lifetime_Permanent, "CHT.VoiceCommand.Active", 1)
				VoiceCmdCheckCount = nil -- set counter to be "off"
			end
		elseif VoiceCmdStart == 0 then -- stopping voice command
			if not MusicHelper_FileExists("\\windows\\startup\\voice command.lnk") then --if \windows\startup\voice command.lnk is gone
				_application.Store:SetIntValue(Lifetime_Permanent, "CHT.VoiceCommand.Active", 0)
				VoiceCmdCheckCount = nil -- set counter to be "off"
			end
		end
	end
end

--## timer to check for \windows\startup\voice command.lnk
VoiceCmdTimer = timer(1) -- one second
VoiceCmdTimer:Stop()
VoiceCmdTimer.OnElapsed:connect(VoiceCmdCheck)


-- In each part for start or stop voice command need 

-- stop
VoiceCmdStart = 0
VoiceCmdCheckCount = 0 -- set counter to be "on" 
VoiceCmdTimer:Start()

-- start
VoiceCmdStart = 1
VoiceCmdCheckCount = 0 -- set counter to be "on" 
VoiceCmdTimer:Start()
Now to see if I can figure out if MusicHelper has a process exists check
 

RoryB

Inactive Recognized Developer
Sep 4, 2008
2,921
766
Lexington
MusicHelper_ProcExists("VoiceCmd.exe") and MusicHelper_ProcessExists("VoiceCmd.exe") do not work. The thing that is happening is the file deletes before the process ends so I would prefer to wait to toggle the switch image until after the process actually has been killed.

Even better than killing VoiceCmd.exe would be a command line switch to stop it, but I have not found any switches other than -min for starting it without it announcing itself.
 

RoryB

Inactive Recognized Developer
Sep 4, 2008
2,921
766
Lexington
Anyone have the mode9 file for Co0kieEmail?

I am tweaking email to fit above the lock slider and if an account is empty it does not change. I think I need to see the mode9 to find the correct value to tweak for "no mail" version.
 

RoryB

Inactive Recognized Developer
Sep 4, 2008
2,921
766
Lexington
Need help

I am trying to create a separate widget for AppTasks so I could have an appointment widget, a task widget and a separate AppTask widget. I must be missing something. I can get it to show up in edit mode, but with images of missed calls instead of test appointments. I does not get out of edit mode when I select done. I tried some other things and get the broken home tab where all widgets and links show up on a single tab page. You can see in the comments of the lua code the different things I have been trying. I hope someone can take what I started and help me fix it.

Thanks
 

Attachments

  • CHTW_Rory_AppTask.zip
    65.9 KB · Views: 4

Top Liked Posts

  • There are no posts matching your filters.
  • 8
    weekday widget?

    the idea comes from here



    poyensa said:
    do we have something like MONTUEWEDTHUFRISATSUN for CHT?

    i don't think so :) but it's a nice idea for a widget poy :D

    1) So first setp is download PoyTEST.rar from first post, extract the folder PoyTEST and rename it as Poy8weekday, then with m9editor open the file 30182CB6_manila located in folder \Workspace\mode9\. The idea is to create 2 graphics objects: poy8background and poy8today, no need to add more properties on them by now. Look how i have also changed names in ComponentClipCharacter and Group.

    2) Then open the file CHTWidgetDev.lua with notepad2.exe (included in tools folder) and change every PoyTEST for Poy8weekday and also change the names previously defined in mode9 file (Poy8today, Poy8Group, Poy8background, Poy8ResizeLayer). Be careful its case sensitive (and do not forget to enjoy!)

    3) Special attention to line #64: require("Home\\Scripts\\Home\\PoyTEST") this will be changed to #64: require("Home\\Scripts\\Home\\Poy8weekday)

    4) in folder \workspace\_lua there is other 2 more files, delete translation.lua (we don not need for this widget) and open PoyTEST.lua with notepad2. First thing we need to do is change the name of this file, so the first line (green) is File name: 41CBC6DC_manila -- \windows\htc\home\scripts\home\PoyTEST.luac so change the last part to Poy8weekday.luac, then copy the full path \windows\htc\home\scripts\home\Poy8weekday.luac to manilaHASH.exe (included in tools folder) and get the manila name for this file: 1D773BFE_manila, so do change it in line #1 -- File name: 1D773BFE_manila -- \windows\htc\home\scripts\home\Poy8weekday.luac and save file as Poy8weekday.lua in _lua folder

    Then do some changes of PoyTEST for Poy8weekday and so ...

    This file is going to be core of our widget, it will define what the widget will do. In our case is quite simple function, it will get what day is today (from system) and then apply the corresponding texture (PNG) to our variable Poy8today. Something like "if today (from system) is Monday then Poy8today texture will be Monday.PNG; else if today (from system) is Tuesday then Poy8today texture will be Tuesday, ..." and so on. Of course using Lua language and the source freely provided by Co0kie Master

    5) Once we do our lua file we should test if it works :) we do that with the file _Deploy_to_device_in_dev_mode.bat included in the kitchen. This file will compile the lua files, send all the files in our kitchen workspace folders to windows folder of our device and restart sense. Now you should connect your device to your PC via USB and synchronize. It is necessary to run only one time z_init.bat that will copy RestartManila.exe to our device. First we need to do some changes on _deploy_to_device_in_dev_mode.bat file: click on it with the right mouse button>edit then it will be opened with the simple text editor, the line regarding poyTEST.lua has to be changed to luatool /c -o ..\deploy\1D773BFE_manila ..\Workspace\_lua\Poy8weekday.lua
    Also we have to put the png files in \Poy8weekday\Workspace\png. Thanks to Stopa46 who has kindly made a few set for this test.

    DEVMODE its a change in the registry that activate a new slot for test widgets.

    Dunc in post#8 said:
    rat_2665's CHTAddon Dev Mode Switch - adds a new toggle switch in the CHT Toggle Switches list. Works like every other toggle to activate/deactivate Dev Mode rather than having to do it manually with a registry editor. Just toggle on/off and soft reset after each change to enter/leave Dev Mode. I'm sure rat won't mind me posting this here - it's all his work so all credit to him for this one - but it really is a timesaver when you are developing!

    So now that we are in devMode its time to click the file _Deploy_to_device_in_dev_mode.bat, look the black screen and feel the adrenaline .... :)

    Dont worry nobody get it at the first time, neither me this time I had to correct some typo-mistakes and add one end, but finally it worked :D so never forget to enjoy!

    attachment.php


    6) Tomorrow will explain making the CAB




    Ok I am uploading the cab, I have changed the function if today = "Monday" then .... because it will not work in other languages. the solution I am trying now is

    Handle_Poy8weekday = function()
    local Poy8File = "\\windows\\".. machineStatus.CurrentTime.Value:GetDateString("dddd") .. ".png"
    Poy8today:SetTexture(Poy8File)
    end


    So the users has just to rename the png files according to the weeknames in his own language. Lets see if it works ....

    Installation:
    Copy CHTwPoy8weekday.cab in your SD and click on it, the installation process will start.
    Select install on device
    accept softreset
    once in the home screen again, go to edit home layout (or edit CHT lockscreen) > advanced (setting wheel) > Poy8weekday
    in edit mode keeping pressed the widget a pop-up menu appear to remove, pin or resize.
    the widget as it is works in WWE roms. If you are getting a white square it means your rom is not WWE (own language), then you have to change the name of the .png files of each days for the names of the weekdays in your own language, copy them to \windows folder accept overwrite and restart sense. You should see the widget working now.
    You can edit the widget easily by editing the weekdays.png files, just make your favourites with PS, Gimp or any other, save them in \windows folder and restart sense. It is included also a background named Poy8background.png. And please share them with all of us!

    Skins

    Just edit the .png (monday.png, tuesday.png, etc.) files with PS Gimp or any other graphic editor and replace them in windows folder. have a look to this idea from Stopa:

    homezi.jpg


    You can get it as a cab from here
    6
    Are you interested in making or editing a CHT widget? To make a widget for Co0kie Home Tab 2.0.0 is not such a difficult job as you may think, I tell you by experience. I have no previous formation in programs or informatic code but i could make a few widgets(*) and I would like to share this experience with you. This is not so altruistic work, I am expecting a huge amount of widgets made by all of you to install and enjoy in my brand-repaired HD2 :)

    Co0kie Master has allready published a guide for making a CHT widget (it is into the widgets kitchen); also Genius_Rat_2665 has made a tutorial for making a cht clock widget, so -the third time lucky- lets bring here all that knowledge and try to make a simple widget step-by-step. Also this could be a good place to share and learn each other some code for widgets. Things like how to make an blinking element, how to change number in text, how to read from the registry, etc.

    (*) What is for sure is that no one widget I could ever do without the help of others. Lets start quoting the existing Co0kie's guide:


    Here is a guide on how to build your own widget for CHT.
    I decided to break this up into 3 parts.
    The kitchen section is a brief description of the kitchen structure and batch files.
    The guide section will tell you how to build your own widget and make a cab to install it.
    The "how it works" section will tell you what's going on in the background - why the system is the way it is.

    #####################
    *** 1) Kitchen ******
    #####################

    Just a few words about the kitchen folder structure:
    - Workspace - here you'll find all the raw files that are being worked on currently
    - Tools - all the needed tools
    - deploy - just a little temp dir used by the batch scripts to compile and deploy files directly to your device
    - cab - the cab file and setup.dll
    - cab\_files_final - all the final compiled files that will need to be inside the cab

    The batch files:
    These files automate the process of editing manila files.
    Connect your device to your PC via ActiveSync to be able to run the batches.

    z_init.bat - You need to run this one before starting. You just need to run it one time. It will copy restartmanila.exe to you device.
    _Deploy_to_device_in_dev_mode.bat - this batch will:
    1) compile the lua files from \workspace\_lua and copy them to the deploy folder
    2) copy all files from \workspace\mode9 and other \workspace\ subfolders to the deploy folder
    3) use rapicopy.exe to copy everything from the deploy folder to \windows on your device (it's set to overwrite exitsting files)
    4) restart manila on your device
    _Generate_files_for_cab.bat - this will compile and copy the workspace files but it will not deploy them to your device,
    instead it will copy them to \cab\_final_files
    it will also rename the base mode9 and lua files to CHTmode9 and CHTlua - more on this in the "how it works" section

    [[ It also needs to be modified the files _Generate_files_for_cab.bat & _Deploy_to_device_in_dev_mode.bat to addapt them to your own widget. Click with the right button of the mouse over the files and select edit, then change the name of the widget (PoyTEST.lua & PoyTESTtranslation.lua in the attached example) and the corresponding manila files ]]


    [[ Tools folder includes m9editor for the edition of mode9 files, notepad2 for the edition of the Lua files, CFC_GUI for the qtc files (graphics), manilaHASH to obtain the right manila names corresponding to .luac files, and some other .exe files used automatically by the kitchen. ]]



    ################################
    *** 2) Making your widget ******
    ################################

    Guide - how to make CHT addon widgets:
    First of all, because you will be developing, you need to turn on CHT's dev mode.
    Open the reg key HKCU\Software\HTC\Manila\ and create a DWORD value, call it "CHTI.AddonWidgets.DevMode" and set it to 1.
    This will allow you to deploy and test your widget directly from the kitchen.

    [[ This is very important as you do not need to create and install the cab for test the widget, just using DevMode the widget will go from \workspace\ directly to your device, so you can make changes and see results easily. ]]


    Now proceed to build your widget. I suggest you use the analog clock addon as a base. [[ You can use PoyTEST, its much simplier ]]
    There are two rules you simply must follow:
    1) For every new widget, its CHTWidgetDev.lua file must change the "widgetName" property. It must something unique.
    I suggest a naming system of "CreatorName_WidgetName" - that should ensure that the names are unique - there must not any conflict here!
    Modify anything else however you'd like. The rest of the fields in that file don't need to be as unique as the "widgetName" property.
    2) The 30182CB6_manila mode9 file must follow a special rule: The "Scene" section must not contain any components. See how it looks like in the example addon.
    That's how it must look for all new widgets.

    [[ Making a widget is like making a puzzle (but much more funny :D), you have to put the right pieces in the right places. There is no a fix rule and there is a lot of trial and error. Where to find the right pieces? Co0kie gave us thousand of decompiled lines of Lua code in CHT_Source. Download it from post#6 of CHT 2.0.0 thread. Also look in every published widget's kitchen in CHT thread, Rat_2665, Dunc0001, ZaxXx, Azarbel, Colossus_r, RoryB, MnCessna ... (Sorry I dont remember all right now!) ]]


    Once you've done that you can do ahead and run "_Deploy_to_device_in_dev_mode.bat" - that will compile the files, copy them to your device and restart manila.
    Then just go to the edit widget menu in CHT - your widget should be at the bottom of the list - add it and test it.

    When you have finished making your widget, you can pack it up into a cab file.
    To prepare the files for the cab you have to run "_Generate_files_for_cab.bat".
    The final files will be in the \cab\_files_final\ folder.

    Making the cab file - this is what an addon cab must have:
    1) Every last one of those files from \cab\_files_final\ need to be in the cab and they have to be set to be copied to %windows%.
    Do NOT set the install dir to %windows%, set the files to be copied to %windows%.
    2) The setup.dll that is in the \cab\ folder also needs to be added to the cab.
    3) Last, but extremely important, set the install dir to \CHTAddons\^widgetName^ - where ^widgetName^ should be your unique widget name same as in the lua file.

    [[ This is really important. If you are not creating a new widget but just editing the mode9 and/or lua files, please do not modify the installation dir in the cab properties, as it is used in the installation process and modification may cause problems in CHT ]]

    If you want to test that cab on your device make sure you disable dev mode first ("CHTI.AddonWidgets.DevMode" to 0), so that the dev mode widget you were working on and the newly installed one do not conflict.
    A widget must not be installed in both dev mode and as a cab at the same time!


    ##########################
    *** 3) How it works ******
    ##########################

    CHT addons plug into slots that interface with the core layout manager.
    There is maximum number of addon slots (that number is 10 for the dev preview beta, but it will be 20 for the final).

    Each widget consists of 4 parts:
    1) a mode9 file for the CHT widget interface
    2) a lua file for the CHT widget interface
    3) any number of extra mode9 or lua files
    4) xml file with a manila file list for CHTScheduler

    Numbers 1-3 there are directly needed for CHT. Number 4 is needed for CHTScheduler (I'll leave the explanation of that for the CHTS thread - it's not need for now if you just want to try to build your own widget).

    Numbers 1 and 2 are the most important and they are directly linked to the slots.
    Here is how:
    The interface mode9 and lua need to have a specific names depending on which slot they go into.
    To make this happen those 2 files are dynamically named on install.

    While you are developing your widget you are working with the dev widget slot. There is only one of these so it has one pair of mode9/lua names (30182CB6_manila and 7D241726_manila).
    But once you make the addon cab the widget can be installed in any slot (first one found to be free). That's why in the release files, there is a CHTmode9_manila and CHTlua_manila.
    Those are the same files that you were developing with (30182CB6_manila and 7D241726_manila) - they will be renamed on the fly once installed - this is where the special setup.dll comes in.
    The dll will look for the first free addon slot and install the widget there, i.e. it will rename the files so they correspond to the first slot.
    The install dir name that you had to specifically enter is used as the widget install ID and will be stored in HKCU\Software\HTC\Manila\ "CHTI.AddonWidgets.SlotX" (this is needed to uninstall the widget correctly).
    The files that are being installed should all go to \windows so you set that directly for the files, and that allows the install dir name cab field to be used for this purpose.


    If you have reached here I recomend you re-read Co0kie's guide, is short but it contains a lot of information, i would say every word is important!

    So now the first trial:

    1.- Install the kitchen: Every widget has its own kitchen, I have attached a kitchen for a very simple widget. Just download in your PC and copy all the files & folders in a separate folder (\CHTwidgets\PoyTEST\) same as they are inside the .rar

    Now connect your PC and your device via USB and sinchronize. Then run the file z_init.bat - You need to run this one before starting. You just need to run it only one time. It will copy restartmanila.exe to you device.

    2.- Put your device in DevMode: Go to HKCU\Software\HTC\Manila\CHTI.AddonWidgets.DevMode and change to DWORD =1 (create if does not exit). Now restart Sense.

    3.- Run the file _Deploy_to_device_in_dev_mode.bat. Your device will automatically restart Sense. Then go to Edit Mode - Add new element - Select PoyTEST - done. You should see now the simple widget in your device's screen.

    It will continue ....
    5
    SENSE CRASHED? NO PANIC


    It is normal to crash sense when you are doing some experiments, but it normally get solved just deleting files 30182CB6_manila & 7D241726_manila in \windows folder\ and/or dissabling DevMode in registry HKCU\Software\HTC\Manila\CHTI.AddonWidgets.DevMode = 0

    rat_2665 said:
    It's a tricky thing. Do you use one of Co0kies widgets? For this I "took it over" at first. I didn't change the structure, only made new names in the manila files. You have to check over and over. A blank space in a name in the mode9 file cost me a day. In the next step you can try to change the behaviour.
    What you see is the normal screen for an error (i had it often ). Check if all variables in the lua files are also in the mode9 file. Then in the developer mode you can't see errors in the lua scripts (absent end in functions and so on). For this I used sometimes the m9editor, compiled the scripts and looked for errors.



    Even we can learn from this crashs:

    Co0kie Monster said:
    Sense nuke and lua "debugging"
    The empty screen after adding your widget will happen if there is an error in your widgets lua code. Alternatively it could be a bug in the mode9 file (but those usually cause sense not to start at all), or maybe you left dev mode on and installed your widget via cab - dev mode uses a special widget slot and it will cause a conflict if a widget is installed both via cab and in dev mode at the same time, so remember to turn off dev mode.

    But, anyway I'm guessing the problem would usually be in the lua code. In that case you need to debug it. I've uploaded all the needed tools to "Co0kie's Home Tab\_Development\Lua_debugging_tools". (* inlcuded in the widget kitchen)

    Because lua is a script It's not really debugging, it's pretty much just a trace log.
    Run attach.bat while your device is connected via active sync and that will collect trace information and display any errors along with the file and line where they occurred.

    All the info is collected in debug-attached.txt.
    Do whatever causes the bug, then run terminate.bat to stop pdebug (that will also restart manila).

    Open up the log and look for **Lua Error******.
    Other than that you will also see trace() output there.

    The other batch (run.bat) is for debugging from startup. You need to turn off manila (WM Settings->Home-> turn off HTC Sense from the list) and then hit run.bat - it will start manila and log at the same time. That's only needed in case of startup errors.



    HOW TO SOLVE SOME GRAPHICS ISSUES

    santod040 about some graphic issues said:
    I am not exactly sure yet why the 16 rule only applies to some roms. I think this may actually be the difference between a CFC and non CFC manila.
    Though Im digging into this more still.
    I also think of this more as one rom listening to the mode9, no matter what the image claims to be or is.
    Where the other needs the image to specifically be what it expects, according to the mode9 and lua.
    I also think it's more about "4" and "16"
    Here's a few key items from Mode9 and a small bit about each.
    Though it may be somewhat irrelevant mostly.

    String: UTF-16LE encoded strings (represented as UTF-8 in XML and YAML)
    Path: UTF-16LE encoded strings (represented as UTF-8 in XML and YAML)
    UInt32: 4 byte unsigned integer
    Q16: 4 byte Q16.16 fixed point number
    Int32: 4 byte signed integer
    Boolean: 4 byte, either 1 or 0
    Vector3: 3*4 bytes of Q16 numbers (X,Y,Z)
    RectQ16: 4*4 bytes Q16 numbers (X,Y,Width,Height)
    RectInt: 4*4 bytes of signed integers (X,Y,Width,Height)
    Size: 4*2 bytes of Q16 (Width,Height)
    Color: 4*1 bytes (R,G,B,A)
    Viewport: either a Vector3 or a RectQ16, depends on size
    FrameValue: either a Vector3 or a Q16 number, depends on size
    BinaryScript: a binary value, encoded as Base64 in the XML or YAML file


    The CFC should not be used as a standard.
    Heres why:
    Non Cfc and Cfc images, will work on a Cfc rom.
    Whereas Cfc images will not work right on a non Cfc rom(any stock rom).
    So to be universal, non Cfc is the best approach.
    Also consider that manila, and your device have to decompress as they use the images.

    So, to offer Cfc as an option is nice, but not the universal offering.

    santod040 said:
    Similar issue again.
    The qtc needed to be a more accepted dimension by manila.
    I still don't have any concrete answers behind it, other then the info I already posted regarding textures and sizes in manila.
    So, I adjusted the mode9 and also the qtc to be standard sizes.
    I have made a few that worked.
    The first was 256x64, but then was hard to move, lol.
    So I edited again and made it 512x64 and reposted just now.
    It seems to move just fine.
    Now only to move the resize button up some and it would be near perfect.
    But since it's almost 3am, that will have to wait.

    santod040 said:
    Something else to think about.
    As far as the 16 rule.
    I also mentioned 4.
    So for example,
    64 divided by 16 = 4 (good number)
    96 divided by 16 = 6 (bad number)
    128 divided by 16= 8 (good number)



    only 10 widget slot problem solution

    mike2nl said:
    We, the CHT teams, have found a solution for the 10 slots for widget issue.
    After we had changed things we are now in state to use 20 widgets(*) at all (0..19).
    It is tested on HD2 and TP2 WM phones, and it's running without any issue until now.

    The new file was tested by santod040, MichelDiamond, poyensa and me.

    My last test was to use 20 widgets on the HD2 about the performance. And yes it does the work .

    How to install the fix:
    1. unzip the manila file
    2. switch off sense
    3. copy the 7c60907d_manila file o the \Windows directory
    4. restart your phone
    5. switch on sense
    6. have fun to install more widgets now (max. of 20)
    7. follow the install routine from every widget


    Last but not least, thank you to all involved team members...
    3
    Its good to have a look into CHTWidgetDev.lua from Co0kie's Standalone Analog Clock, with extended comments by Co0kie (in green). You have it into the Co0kie's widgets kitchen. We all started here:



    -- File name: 7D241726_manila -- \windows\htc\home\scripts\home\chtwidgetdev.luac

    -- ##### CHT Wigdet interface file #####
    -- this script is an abstraction layer that sits between a widget and the core CHT Layout Manager
    -- the template needs to be filled in the correct way, but once it is, the created widget will be plugged into the layout manager
    -- and automatically behave like any other CHT widget - be movable, have access to different layout profiles, correct lockscreen behaviour etc.
    -- even if I do say so myself, the system is *very* powerful

    -- the comments below should provide a good description of the template
    -- the primary and most important comments will be marked plainly with --
    -- secondary comments will be marked with --// and they will contain some additionl points of interest, but not critical info
    -- on your first read through I suggest you stick to just the primary comments
    -- lines marked with --%% are commented out code that could be part of a template, but is not needed for this example in particular
    -- if you have any other question, hit me in the social group

    -- this first line creates a new template file based on 'WidgetTemplate' (defined originally in CHT_core.lua)
    --// it's best to make it a local - it can be a global too, but there's really no need since it will not be accessed directly anywhere
    --// except in this file - and one less global means less polution in the global namespace which could be very important going forward


    local wStandaloneAnalogClock = WidgetTemplate:new()

    -- this next step registers the newly created widget with the core CHT Layout Manager

    CHTLayoutManager:RegisterWidget(wStandaloneAnalogClock)

    -- some basic information needs to be filed in about the widget
    -- 'widgetName' field - try to make this name as unique as possible, because it is used to save/load widget registy information
    -- the core widgets have plain names (Clock, Appointments, Tasks...), but give your widget unique names to avoid conflicts
    -- the simplest unique naming scheme would be to just add your name before the widget name


    wStandaloneAnalogClock.widgetName = "Co0kieStandaloneAnalogClock"

    -- this defines the text that will appear in the advanced settings/add a widget menu
    --// sadly, I could not find a way to make the localization system distributed for every widget so you can't enter localized "IDS_*" strings here


    wStandaloneAnalogClock.settingsString = "Standalone analog clock"

    -- this defines the category in which the widget will appear in the advanced settings/add a widget menu

    wStandaloneAnalogClock.settingsCategory = "Clock"

    -- the maximum layout count (the layouts that are cycled by the previous/next button on the popup menu or in the settings menu combo box)

    wStandaloneAnalogClock.layoutCount = 1

    -- should the widget snap to the center of a page
    -- // but "center" isn't really center - it's more like snap to posX == 0, 480, 960..., if that position X is the center of a page depends on how you made your widget


    wStandaloneAnalogClock.snapToCenterX = false

    -- here you can define default settings for your widget on a "per layout" basis
    -- if defaults for a level are not given, it will use {visible = false, layout = 0, posX = 0, posY = 0, scale = 1, pinned = false}
    -- the visible, posX and posY fields speak for themselves
    -- the layout field is the layout number (can be between 0 and layoutCount-1)
    --// scale is used for storing size info for resizable widgets
    --// pinned is used for storing the pinned state of pinnable widgets
    --%% wStandaloneAnalogClock.defaults["HomeLevel0"] =


    wStandaloneAnalogClock.defaults["HomeLevel1"] = {visible = false, layout = 0, posX = 0, posY = 0, scale = 1, pinned = false}

    --%% wStandaloneAnalogClock.defaults["HomeLevel2"] =
    --%% wStandaloneAnalogClock.defaults["HomeLevel3"] =
    --%% wStandaloneAnalogClock.defaults["HomeLandscape"] =
    --%% wStandaloneAnalogClock.defaults["CHTLockscreen"] =

    -- now come the widget function definitions

    -- 'Initialize' - and extremely important function
    -- it's called when the widget it loaded for the first time (on startup or when added from the advanced menu)


    wStandaloneAnalogClock.Initialize = function(self)

    -- these first few lines should be the same for all addon widgets

    local newComponent = Component()
    WidgetLayer2D:Attach(newComponent) -- you may modify this to be either WidgetLayer2D or WidgetLayer3D -- more info on this later
    if not self.addonWidgetID then -- this is very important, every addon widget must have these line - do not modify them
    newComponent:SetComponentClipCharacter("CHTWidgetDevSlot")
    else
    newComponent:SetComponentClipCharacter("CHTWidgetSlot" .. tostring(self.addonWidgetID))
    end
    self.positionLayer = newComponent

    -- these two need to be filled in but they differ depending on how you named your mode9 fields

    self.animationLayer = StandaloneAnalogClockAnimationLayer -- the layer that will be animated (fade in/out or any other more interesting effect that you can define - dee below)
    self:AddObject(SACFace) -- defines the touch surface that, when touched, will enable the widget to be moved

    -- the rest is completely up to you

    require("Home\\Scripts\\Home\\Co0kieAnalogClock2") -- the script file that describes the behaviour
    -- make sure that all new names that you add are unique so that there are no conflict with built-in widgets or any other addon widgets
    -- suggested naming scheme is: yourname_variablename
    -- the unique name requirement goes for all objectc in mode9 files, lua global variables and classes


    StandaloneAnalogClock = StandaloneAnalogClockClass(StandaloneAnalogClockGroup, SACFace, SACMinuteHand, SACHourHand, SACSecondHand)
    end

    wStandaloneAnalogClock.GetPosX = function(self)
    return self.posX + 128 * (1 - self.scale)
    end

    wStandaloneAnalogClock.GetPosY = function(self)
    return self.posY - 128 * (1 - self.scale)
    end

    -- GetHeight and GetWidth provide feedback for layout manager so it can know the exact borders of a widget

    wStandaloneAnalogClock.GetHeight = function(self)
    return 256 * self.scale -- in this the base width of the analog clock is muliplied by the scale

    end

    wStandaloneAnalogClock.GetWidth = function(self)
    return 256 * self.scale
    end

    -- resizing system definitions - I suggest you skip this part on your first read

    wStandaloneAnalogClock.isResizable = true
    wStandaloneAnalogClock.rotatingResizeButton = true

    wStandaloneAnalogClock.GetResizeRefX = function(self)
    return self.posX + 128
    end

    wStandaloneAnalogClock.GetResizeRefY = function(self)
    return self.posY - 128
    end

    wStandaloneAnalogClock.GetResizeButtonXDelta = function(self)
    return 90
    end

    wStandaloneAnalogClock.GetResizeButtonYDelta = function(self)
    return -90
    end

    wStandaloneAnalogClock.CheckScaleLimit = function(self, scale)
    return (scale >= 0.5 and scale <= 1.3), 0.5, 1.3
    end

    wStandaloneAnalogClock.GetResizeUnit = function(self)
    return 128
    end

    wStandaloneAnalogClock.ApplyScale = function(self, newScale)
    self.scale = newScale
    local newRadius = self:GetResizeUnit() * newScale
    self.animationLayer.Scale = Vector3Property(Vector3(newScale, newScale, newScale))
    end


    -- these are the layout control functions
    -- this example widget has only one layout available, but these function come in very handy for defining multiple layouts

    -- this function is run before any of the defined layout functions
    -- this should contain something that should be set commonly for any layout


    wStandaloneAnalogClock.CommonPreSetLayout = function(self)
    StandaloneAnalogClockAnimationLayer.Center.x = SACFace.Size.width / 2
    StandaloneAnalogClockAnimationLayer.Center.y = -SACFace.Size.height / 2

    if not self:CheckScaleLimit(self.scale) then
    self.scale = 1
    end
    self:ApplyScale(self.scale)
    end

    -- one of these functions is run depending on the selected layout
    -- the string to be shown in the settings menu combo box is also defined here


    wStandaloneAnalogClock.layoutName[0] = "[[IDS_NO_ALT_LAYOUTS]]" -- combo box text
    wStandaloneAnalogClock.SetLayout[0] = function()
    end

    -- additional layouts can be defined here
    -- the number of functions must match the layoutCount field defined above
    --%%wStandaloneAnalogClock.layoutName[1] = "Second layout"
    --%%wStandaloneAnalogClock.SetLayout[1] = function()
    --%%end
    --%%wStandaloneAnalogClock.layoutName[2] = "Third layout"
    --%%wStandaloneAnalogClock.SetLayout[2] = function()
    --%%end
    --%%wStandaloneAnalogClock.layoutName[3] = "Etc"
    --%%wStandaloneAnalogClock.SetLayout[3] = function()
    --%%end

    -- like CommonPreSetLayout this function is run for any of the layouts
    -- but it's run after the layout specific function
    --%%wStandaloneAnalogClock.CommonPostSetLayout = function(self)
    --%%end

    -- animation function, they are run when switching between level or adding/removing a widget
    -- the basic thing that needs to be done here is make the widget visible or invisible,
    -- but you can play around with the animations and put in some eye candy
    --// Interopolate can be used with Opacity, Position, Rotation and Scale and some cool effect combinations can be made
    --// post in the social group if you need more info


    wStandaloneAnalogClock.AnimateIn = function(self, instant, swipeDown)
    if instant then
    self.animationLayer.Opacity.value = 100
    else
    self.animationLayer.Opacity:Interpolate(100, 10, 0, Interpolate_Linear)
    end
    end

    wStandaloneAnalogClock.AnimateOut = function(self, instant, swipeDown)
    if instant then
    self.animationLayer.Opacity.value = 0
    else
    self.animationLayer.Opacity:Interpolate(0, 5, 0, Interpolate_Linear)
    end
    end

    -- these two functions define what should be run to connect or disconnect widget press actions
    -- the functions are called on transition to the lockscreen, edit mode, but also for some smaller details (like when menus are up)


    wStandaloneAnalogClock.ConnectPressHandlers = function(self)
    StandaloneAnalogClock:ConnectPressHandlers()
    end

    wStandaloneAnalogClock.DisconnectPressHandlers = function(self)
    StandaloneAnalogClock:DisconnectPressHandlers()
    end

    -- these two do much the same as the previous functions, but the serve as exceptions for the lockscreen
    -- in this case the analog clock should not have any action on the lockscreen
    -- but for example, the music player uses these functions to reconnect the play controls on the lockscreen
    --%%wStandaloneAnalogClock.ConnectLockscreenHandlers = function(self)
    --%%end
    --%%wStandaloneAnalogClock.ConnectLockscreenHandlers = function(self)
    --%%end

    -- this one is used to clear the the widgets selection status
    -- in this example when the clock is pressed it sinks in a bit
    -- in certain situations, there might be a need to deselect a widget even if it's still under the finger
    -- (for example when a side scroll is started)
    -- that's when this function is called


    wStandaloneAnalogClock.ClearSelection = function(self)
    StandaloneAnalogClock:ClearSelection()
    end



    You can try now making your own Clock-CHTWidget, following rat_2665 tutorial:


    This is a little guide for clock widgets:

    Read at first the widget development guide by Cokie (it's in the below mentioned kitchen) !!!

    Step 1 manila hash names

    1. Download the kitchen for the analog clock widget by cookie and make a temp folder in there. Copy the files for your analog clock in this folder (best if you have already a working clock for CHT 1.8.5). Save the pictures out of the qtc manila files as png in this folder (this is only useful for oversight). Rename the whole widget with your widget name.

    2. Make a list with new names for your text and image objects with manilaHASH.
    - the names should be unique. I use my name and a widget number as prefix, f.e. rat_w001_secondHand
    - determine the manila hash name. For this use the line
    \windows\htc\home\assets\images\Home\VGA\Your_Name.qtc
    Save this list. You need it all the time for oversight.

    3. Rename your images in the temp directory with the new manila names (this is only useful for oversight); then rename also your manila image files with these names.

    4. Delete all files in the workspace\qtc directory and copy your new manila files into this (but not the old 1E1A6CCD_manila and 1EC5924B_manila)


    Step 2 mode9 file.

    5. Open the mode9 file in the workspace directory. Go in the library to the StandaloneAnalogclockGroup. There are the image and text objects for the clock.

    6. If you have more objects in your old 1E1A6CCD_manila file for your analog clock add these objects in the group.

    7. Then substitute
    - for all objects the Instance value with your new name (f.e. rat_w001_secondHand),
    - for the image objects the Texture path with the (here shortend) string that you used for the manila hash name (f.e. .\Assets\Images\Home\VGA\rat_w001_secondHand.qtc)
    - for the text objects the String value to the variable used in the lua file (f.e. rat_w001_weekday). If you want to use AMPM like in the normal clock, don't change this value.

    8. Change the name of the StandaloneAnalogClockGroup to a unique name (that is used later in the lua files, f.e. rat_w001_ClockGroup)

    9. Change the name of the StandaloneAnalogClockAnimationLayer to a unique name (that is used later in the lua files, f.e. rat_w001_ClockAnimationLayer)

    10. Save the file.

    Now to the lua files.


    Step 3 CHTWidgetDev

    Substitute all uses of wAnalogClock2 with a unique name (f.e. w_rat_w001_Clock). You can do this in Notepad2 with the Edit/Replace function.

    Then substitute in line 69 StandaloneAnalogClockAnimationLayer with the new unique name you used in the mode9 file for the animation layer (f.e. rat_w001_ClockAnimationLayer).

    Do the same in line 74, 135, 136, 191, 195 and 212 for all uses of StandaloneAnalogClock (f.e. rat_w001_Clock)

    Replace the string in line 28 with the name of your widget (f.e. "rat_w001_clock").
    In the next line insert the string that is shown for the widget in the home layout (f.e. "my analog clock").
    For an analog clock you don't need to change the next item (""Clock").

    In line 70, 135 and 136 is the image object for touching mentioned. You have to substitute "SACFace" with your image object (at best the greatest, f.e. rat_w001_clockface)

    The last part is line 73 and 74. In line 73 you have to substitute "Co0kieAnalogClock2" with the name of your special lua script (f.e. rat_w001_clock).
    Line 74 is the bridge to your lua script. Here are the arguments of the ClockClass defined that are used in the StandaloneAnalogClockClass.__init function in your special lua file. Of course the name of the function is later also to be changed.
    In the example it is:
    rat_w001_Clock = rat_w001_ClockClass(rat_w001_ClockGroup, rat_w001_clockface, rat_w001_minuteHand, rat_w001_hourHand, rat_w001_secondHand)


    Step 4 special lua file

    For naming use the lua script file name you used in the CHTWidgetDev.lua file (rat_w001_clock)

    In the first (commentary) line change the location with the new name instead of Co0kieAnalogClock2 and use the manilaHash app with this string:

    \windows\htc\home\scripts\home\your_widget_name.luac

    Then substitute also the manila name (f.e. -- File name: 1F2E1A7D_manila --\windows\htc\home\scripts\home\rat_w001_Clock.luac )

    Substitute all uses of StandaloneAnalogClock with your name (rat_w001_Clock)

    Change all uses of SACShowAMPM to your name (rat_w001_ShowAMPM).

    That would be all if you only want to make a normal analog clock widget, but if you want to change more you have to go to the central function for the behaviour. For this you have to look in this two functions (these are the old Co0kie names):

    StandaloneAnalogClockClass.UpdateTime = function(self)
    StandaloneAnalogClockClass.UpdateSecondHand = function(self)

    Here the update interval and the rotation of the hands is defined. In Co0kies clock it is pretty simple. If you want to add more functions here is the place. The names of the standard arguments clockGroup, clockFace, minHand, hourHand and secondHand should be unchanged in the whole file. For every other variable and object use your special unique name.

    Of course you can add other functions in their own place. You find examples for this in my clock thread.

    Now it is testing, testing, testing.



    Step 5 bat.files

    In the kitchen there are these two files
    _Deploy_to_device_in_dev_mode.bat
    _Generate_files_for_cab.bat
    for handling in the development process.

    Here you have to substitute in both files in the second luatool line 35E966AF_manila ..\Workspace\_lua\Co0kieAnalogClock2.lua
    with your new widget name and its manila hash name. (in the example: 4C0089BA_manila ..\Workspace\_lua\rat_w001_Clock.lua)



    Step 6 CHTS file

    Rename the file in the CHTS with your new widget name (f.e. CHTWidget_rat_w001_Clock.xml).

    Open the file with the windows editor.

    Take your list with the manila hash names and substitute the objects with your new names and the manila names.

    For the third line use your widget name and in the fourth line ("description") the string you used in the CHTWidgetDev.lua for the home layout description.
    3
    So here are a few little things I have gathered over the last few months which I have found useful.

    The ManilaHash.txt contains two lines of text for you to cut and paste into Manila Hash which you need to generate the correct manila filenames for your widget scripts and qtc image files. Just open Manila Hash, open the txt, copy and paste the relevant line into MH and alter the last bit to your image/script name. Then click Get Manila and you'll have your unique manila filename. Then highlight the hashed name, right click and copy. If it is the name for your widget script you are generating you then need to use this in the two bat files (Deploy to device in dev mode/Generate files for cab) before you run either bat - right click and Edit and you'll see something like this:

    Code:
    @echo off
    pushd tools
    
    luatool /c -o ..\deploy\7D241726_manila ..\Workspace\_lua\chtwidgetdev.lua
    luatool /c -o ..\deploy\3DFA729F_manila ..\Workspace\_lua\dunchexclock.lua
    
    
    copy ..\Workspace\mode9\*.* ..\deploy >nul
    copy ..\Workspace\qtc\*.* ..\deploy >nul
    copy ..\Workspace\png\*.* ..\deploy >nul
    copy ..\Workspace\locales\*.* ..\deploy >nul
    copy ..\Workspace\CHTS\*.* ..\deploy >nul
    
    rapicopy -d -e -s  ..\deploy \windows
    
    rapistart restartmanila.exe
    
    del /q /s ..\deploy\*.* >nul
    
    pause

    NB - The bat files included in the widget kitchen contain notation by co0kie but the code above shows the actual active parts of the bat.

    The line you need to change is this one:

    Code:
    luatool /c -o ..\deploy\3DFA729F_manila ..\Workspace\_lua\dunchexclock.lua

    Change the manila name to the one you just generated for the script (highlight/paste from MH) and change the script name to whatever name you are giving your widget script. BTW confusing as it may seem the hashed name is generated using .luac and the bat refers to it as .lua - this is correct!

    Also for reference you should also edit the first line in your widget script to show the correct script name and hashed manila filename. Incidentally you'll notice this line in the script has -- at the start. This basically 'disables' the line so it becomes for reference only. This is handy during testing because you can remove elements from use without actually removing the text from the script, so they are easy to add back in later. If you are using Notepad2 which is in the tools folder (and I strongly recommend you do because it is specifically formatted for editing these scripts) you'll see that lines beginning with -- appear in green so you can easily identify inactive lines.

    If you have generated a hashed name for a qtc file then simply copy the name, right click on your qtc file and Rename, highlight current filename and paste.

    Widget mode9 Filenames.txt contains the hashed filenames for the mode9 files of each widget depending on which widget slot it is installed into. The mode9 and WidgetDev.lua filenames are generated during install depending on the slot number so you will need these if you are going to edit the mode9 after you have actually installed a widget (not relevant if you are still working on it in dev mode). You can also use this list to locate the mode9 file for any widgets you already have installed but which you may want to take a look at for reference or edit.

    LUA Ref v5.1.pdf is a really useful quick reference guide for lua syntax, but before you get in a spin trying to get your head around lua for the first time I would strongly recommend reading this BEGINNERS GUIDE. There are many online references including the main LUA Reference Manual (there's a link to it in the site I've just linked to) but this one gives an easy to follow guide to the basics so read it first!

    rat_2665's CHTAddon Dev Mode Switch - adds a new toggle switch in the CHT Toggle Switches list. Works like every other toggle to activate/deactivate Dev Mode rather than having to do it manually with a registry editor. Just toggle on/off and soft reset after each change to enter/leave Dev Mode. I'm sure rat won't mind me posting this here - it's all his work so all credit to him for this one :cool: - but it really is a timesaver when you are developing!

    One final word of advice/experience - when you are first starting out on developing widgets it can be very VERY frustrating, especially if like me you have absolutely no previous experience of coding. However we are all here to help -that's what this community is all about. If you have a problem just ask. And be prepared for many many Sense crashes and resets! But hey, that's what dev mode is there for - another of co0kies little flashes of genius!

    Right, that's just to give you all a hand with some basics! We are now open for business - ASK AWAY :cool: