I'm trying to create a custom keyboard in Brightscript. I found Youtube and Netflix are using their own keyboard layout.And the Roku's keyboard is kinda different. Not clean like Youtube and Netflix. From Roku's Brightscript documentation, I found this
The default appearance of a Keyboard node is very transparent,
allowing the keyboard to pick up most of its color from what is
rendered underneath it. The appearance can be customized by changing
the keyboardBitmapUri and other fields.
keyboardBitmapUri - Specifies the URI of an image file to be loaded to replace the default keyboard image drawn underneath the key label and icons.Note that this image must be carefully designed so that the key positions match the default image. Template images for SD, HD and FHD resolutions are provided below.
Is there any sample code to do like these keyboard layouts?
Netflix Keyboard
Youtube Keyboard
I was using a keyboard dialog with the following code
sub showdialog()
screen = CreateObject("roKeyboardScreen")
port = CreateObject("roMessagePort")
screen.SetMessagePort(port)
screen.SetTitle("Search Screen")
screen.SetText("default")
screen.SetDisplayText("enter text to search")
screen.SetMaxLength(8)
screen.AddButton(1, "finished")
screen.AddButton(2, "back")
screen.Show()
while true
msg = wait(0, screen.GetMessagePort())
print "message received"
if type(msg) = "roKeyboardScreenEvent"
if msg.isScreenClosed()
return
else if msg.isButtonPressed() then
print "Evt:"; msg.GetMessage ();" idx:"; msg.GetIndex()
if msg.GetIndex() = 1
searchText = screen.GetText()
print "search text: "; searchText
return
endif
endif
endif
end while
end sub
If you have any suggestion, let me know.
Netflix and YouTube almost certainly are not using roKeyboardScreen. If you want to customize roKeyboardScreen, use the templates given - with the layout as provided.
You can always create your own custom keyboard, take a look at this example that I have developed. It's a custom keypad (for numeric entry) the code is available under MIT license at:
https://github.com/lvcabral/RokuNumericKeypad
Related
I'm currently trying to develop an Anki addon that changes the note type of a card when in the card browser.
To accomplish this, I'm initially hooking into the editor shortcuts via aqt.gui_hooks.editor_did_init_shortcuts.append(), then adding a shortcut that sends a callback to another function, passing in aqt.editor.Editor into a function
the problem is I'm now having a hard time changing the note type of the card.
I've tried editor.note.note_type = mw.col.models.by_name(note_type), but it doesn't seem to change anything.
I've looked at other anki extensions, but it seems they change the note_type by modifying the notetype_chooser.selected_note_type_id field of aqt.addcards, which is not found in aqt.editor.Editor
here's the code I have so far:
def editor_switch_note_card_type(editor: aqt.editor.Editor, note_type: str):
# doesn't do anything
editor.note.note_type = mw.col.models.by_name(note_type)
# does something
editor.note['Front'] += 'hello world'
# not sure if this does anything
mw.col.update_note(editor.note)
# editor_init_shortcuts binds editor_switch_note_card_type to a shortcut key when editor is focused
aqt.gui_hooks.editor_did_init_shortcuts.append(editor_init_shortcuts)
Is there a way to retreive the loaded monitors color profile with Applescript, or at least with command-line, as I can use command-line in Applescript?
I'm talking about the loaded color profile of all plugged monitors, the ones defined in "System Preferences -> displays -> color"
EDIT: I would like to get the name of the ICC profile, i.e. what is selected in "System Preferences" -> displays -> color", for each connected screen.
Try either of these:
tell application "Image Events" to display profile of displays as list
tell application "Image Events" to display profile of display 1
You can get more (but not many) details in the Image Events dictionary under Image Suite.
Display 0 and Display 1 both seem to produce the same result (built-in display). Display 2 would refer to an external display. I have a very simple set-up so depending upon yours, you may have to experiment.
Getting the display name is the main issue in pre-Catalina systems if you are wanting to match up display names with their color profiles, but results from the system_profiler utility can be massaged to get the names in earlier systems. A little AppleScriptObjC will get the rest:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions
on run -- example
set screenProfiles to ""
set theScreens to current application's NSScreen's screens
set displayNames to getDisplayNames(theScreens) -- handle older systems
repeat with i from 1 to (count theScreens)
set profile to localizedName of colorSpace of item i of theScreens
set displayName to item i of displayNames
set screenProfiles to screenProfiles & "Name: " & displayName & return & "Profile: " & profile & return & return
end repeat
display dialog screenProfiles with title "Screen Color Profiles"
end run
to getDisplayNames(screenList)
set theNames to {}
if (get system attribute "sys2") > 14 then -- 10.15 Catalina and later
repeat with screen in screenList
set end of theNames to localizedName of screen
end repeat
else -- munge system profiler data
set displayKey to "<key>_IODisplayEDID</key>"
set nameKey to "<key>_name</key>" & return & tab & tab & tab & tab & tab & tab & "<string>"
set displayInfo to do shell script "system_profiler -xml SPDisplaysDataType"
set {tempTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, displayKey}
set {displayItems, AppleScript's text item delimiters} to {text items of displayInfo, tempTID}
repeat with anItem in rest of displayItems
set here to (offset of nameKey in anItem) + (length of nameKey)
set there to (offset of "</string>" in (text here thru -1 of anItem)) - 1
set end of theNames to text here thru (here + there - 1) of anItem
end repeat
end if
return theNames
end getDisplayNames
The NSScreen documentation has a discussion about the primary screen in the list.
I am not suggesting or making any technical suggestion here as I am not qualified to do so and am hugely impressed by the work you all do.
The way I understand windows CM (colour management) is that while many profiles for many devices (including paper) are held in the appropriate folder only one can be used as the system profile. For the monitor profile only what ever is 'set' as the system profile is wanted or needed. If a new monitor profile is created (via calibration) then that system profile will be replaced.
from pywinauto.application import Application
app = Application().Start(cmd_line=u'"path to program" ')
afx = app[u'Afx:01360000:0']
afx.Wait('ready')
afxtoolbar = afx[u'1']
toolbar_button = afxtoolbar.Button(3)
toolbar_button.Click()
window = app.Dialog
window.Wait('ready')
edit = window.Edit4
edit.Click()
app.typekeys ("Success")
So at this point, I've gotten the application to open, the correct window to pop up and also a mouse click on the box that I want to populate with a short string. I cannot for the life of me, figure out how to pass keyboard input to this field. I have read all the docs for PyWinAuto, and nothing is helping...
Basically all I need to do is figure out how to send a string, and then how to send the TAB key six times. I can then finish my program to automate this application.
I am also using Swapy64bit to help. The program uses a win32 backend. I'm using Python 3.6.
Am I not prefixing typekeys correctly? The PyWinAuto documentation leaves much to be desired.
First the correct name of the method is type_keys, but assume you use it correctly.
The reason might be losing focus at the edit control because type_keys tries to set focus automatically. The solution is:
app.type_keys("Success{TAB 6}", set_foreground=True)
In the TI-BASIC programming language (Specifically TI-84+), how do you create input forms, such as the ones included in the default apps on the TI-84+.
The image included here shows an example of what I'm trying to create: A menu that you can scroll through and input multiple variables freely before executing a function
Additionally, is it possible to make this menu dynamically-updating as variables are entered?
You've set a rather tall order for TI-Basic to fill. user3932000 is correct; there is no built in function to create an input form of the type you request.
However, there is nothing stopping you from creating an interactive interface yourself. Creating it from scratch will be a time consuming and, it will consume a significant amount of memory on your calculator. There is no boilerplate code you plug your variables into to get the results you want, but you might have some luck modeling it after this quadratic solver I wrote.
ClrHome
a+bi
Output(1,1," QUADRATIC
Output(2,1," AX²+BX+C
Output(3,1,"ZEROS:
Output(6,1,"A=
Output(7,1,"B=
Output(8,1,"C=
DelVar YDelVar D
" →Str1
While Y≠105
getKey→Y
If Ans
Then
Output(X,4,Str1
Output(3,7,Str1+Str1+Str1+"
End
X+(Ans=34)-(Ans=25
If Ans<6:8
If Ans>8:6
Ans→X
Output(Ans,16,"◄
D(Y≠45→D
If Y=25 or Y=34
sum({A,B,C}(X={6,7,8→D
If Y=104:⁻D→D
10not(Y)+Y(102≠Y)-13int(Y/13(2>abs(5-abs(5-abs(Y-83
If Ans≤9
D10+Ans-2Ans(D<0→D
If X=6:D→A
If X=7:D→B
If X=8:D→C
If A
Then
2ˉ¹Aˉ¹(⁻B+{1,⁻1}√(B²-4AC
Else
If B
Then
⁻C/B
Else
If C
Then
"No Zeros
Else
"All Numbers
End
End
End
Output(3,7,Ans
Output(6,3,A
Output(7,3,B
Output(8,3,C
End
ClrHome
Ans
Here's a GIF of what it does for you.
With a little more work. This code could be used on the Graph screen instead of the home screen, giving more option in terms of layout and design.
In the TI-BASIC programming language (Specifically TI-84+), how do you create input forms, such as the ones included in the default apps on the TI-84+.
There are many ways to ask for input in your program:
Prompt: Asks for input and stores it in a variable. For example, Prompt A. Simplest way to ask for input, but not very visually appealing.
Input: Similar to the Prompt command, except that now you can include text within the input. For example, Input "What is your name?",A.
Menu(: Multiple choice input, and each choice is connected to a Lbl marker somewhere else in the script. Much like the error screen with the quit/goto choices that you've probably seen. For example, Menu("Are you a boy or a girl?","Boy",B,"Girl",G).
getKey: Checks if a certain key is pressed, and will output True (1) if that key is pressed. For example, getKey 105. See here for which numbers each key corresponds to.
The image included here shows an example of what I'm trying to create: A menu that you can scroll through and input multiple variables freely before executing a function http://imgur.com/ulthDRV
I'm afraid that's not possible in programs. You can either put in multiple inputs, or you might be interested in looking into making apps instead.
Additionally, is it possible to make this menu dynamically-updating as variables are entered?
If you're talking about the text on top of the screenshot, yes you can; just put a Disp command or something after each line of Input, so that it continuously overwrites the text above with new text after you input a variable.
I’m using nslater's wonderful script for counting words and characters in a selected block of text, but I need two enchancements:
have the script available even without text selected. Currently, when I pull up the list of available Services without a selection, the Service isn’t there (that’s logical, of course, but enhancement #2 would change things).
add a conditional behaviour to the script: if no text is selected, process all text, but if there is a selection, then only process the selected text.
Here is nslater's script, which I pasted into Automator (I created the Service by following the steps in his commented instructions):
# Word and Character Count service for Mac OS X
#
# Adds a Word and Character Count option to the text selection context menu in all apps
#
# Use Automator.app to create a new service, and then select the Run AppleScript action.
# Paste this code in to the text box, and save as Word and Character Count. Now switch to
# a new app, select some text, and open the context menu to find the new option.
on run {input, parameters}
tell application "System Events"
set _appname to name of first process whose frontmost is true
end tell
set word_count to count words of (input as string)
set character_count to count characters of (input as string)
tell application _appname
display alert "" & word_count & " words, " & character_count & " characters"
end tell
return input
end run
The following AppleScript code will do what you are after:
tell application "System Events" to set frontApplication to (first application process whose frontmost is true)
set theText to my getCurrentTextContents(frontApplication)
if theText is not "" then
set wordCount to count words of theText
set charCount to count characters of theText
tell application (name of frontApplication) to display alert "" & wordCount & " words, " & charCount & " characters"
end
on getCurrentTextContents(ofApplication)
tell application "System Events"
try -- time-out as some UI elements block, notably system sheets
with timeout of 5 seconds
set allElements to entire contents of window 1 of ofApplication
end timeout
on error
return ""
end try
repeat with UIelement in allElements
try –– very large element collections can change before looped through
if focused of UIelement is true then
if attribute "AXSelectedTextRange" of UIelement exists then
set {x, y} to value of attribute "AXSelectedTextRange" of UIelement
if y ≥ x then
return value of attribute "AXSelectedText" of UIelement
else
return value of UIelement
end if
else
return ""
end if
end if
on error errorMessage
log errorMessage
return ""
end try
end repeat
return ""
end tell
end getCurrentTextContents
If you want to use it in service, you will have to set that service to take “No Input” – as Ken Thomases correctly stated in his comment, services only process input if there is a selection. In the case of a “No Input” service, you are essentially creating a global (or app-specific, if you restrict the service to an application) launch point for a script. Any other script launcher that does not steal focus from the app it targets will serve as well (and might be faster – Automator services tend to be veeerrrrryyyyy sssllllooooowwww on first launch).
Also note the whole thing works through the Accessibility API (the foundation for GUI scripting) and needs access to the API to be enabled by the user – either by checking “Enable Access for Assistive Devices” in the “Accessibility“ pane of System Preferences, or by doing
tell application "System Events" to if not UI elements enabled then
activate
set UI elements enabled to true
end if
it also requires the target application to support the Accessibility API in its text views as defined by Apple (see documentation linked to above), and do so correctly. MS Office applications, don’t, for one (they use non-standard views without selection attributes – thanks #adayzdone), and I wouldn’t be surprised if Adobe CS applications didn’t either. Java and AIR applications will probably be problematic, too.
Finally, while I‘m at the caveat empteor stage, I’ll add the speed of the script depends directly on the complexity of the UI hierarchy of the targeted application. This is not problem in the case of ordinary apps, but it is definitely in the case of WebKit generated web views – aka Safari and co. – as these map the whole DOM to UI elements. Although very laudable in terms of accessibility, this results in a humongous UI hierarchy which will take quite a time to traverse.