Can I set_markup to a PopupMenuItem? - gnome-shell-extensions

Since a Label in a PopupMenuItem, I thinks it can be set a pango text here.
PopupMenuItem: A PopupBaseMenuItem that displays text in a St.Label.
const item = new PopupMenu.PopupMenuItem("");
item.actor.set_size(300,150); <--- effect.
item.actor.create_pango_layout('<span foreground="blue" size="32">fname</span>'); <- not effect
item.actor.set_markup('<span foreground="blue" size="32">fname</span>'); <-- fail, but it worked in vala.
I read popupMenu.js source code before, but now I forgot the url.

You probably want to set this on the internal Clutter.Text of the PopupMenu.PopupMenuItems's St.Label:
const item = new PopupMenu.PopupMenuItem('');
item.label.clutter_text.set_markup(
'<span foreground="blue" size="32">fname</span>');
You can bookmark this link to the whole directory of GNOME Shell's UI:
https://gitlab.gnome.org/GNOME/gnome-shell/tree/main/js/ui

Related

Check if WinList() contains a certain title

I am listing all open windows using WinList() to get window title and -handle in AutoIt.
I want to check if resulting array contains a specific title. What is the best way to do this? There is no WinList().Contains("TitleName") or something like that.
Local $aList = WinList() ;Gets a list of Window Titles and IDs
OK, I got it now:
For $i = 1 To $aList[0][0]
If $aList[$i][0] = "Title/String you search for" Then
MsgBox($MB_SYSTEMMODAL, "", "MessageBox shows this text if title is in list.")
EndIf
Next
You could also use something similar to what you wrote.
#include <Array.au3>
Opt("WinDetectHiddenText", 0) ;0=don't detect, 1=do detect
Opt("WinSearchChildren", 0) ;0=no, 1=search children also
Opt("WinTextMatchMode", 1) ;1=complete, 2=quick
Opt("WinTitleMatchMode", 1) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase
Local $title = 'AutoIt Help (v3.3.14.2)'
Local $aList = WinList()
;~ _ArrayDisplay($aList)
Local $iIndex = _ArraySearch($aList,$title)
WinActivate($aList[$iIndex][1], '')
Window exists?
"I am listing all open windows … I want to check if … contains a specific title. What is the best way to do this?"
As per Documentation - Function Reference - WinExists() :
Checks to see if a specified window exists.
Example.
Global Const $g_sWndTitle = 'Window title here'
If WinExists($g_sWndTitle) Then WinFlash($g_sWndTitle)
Retrieve window handle, -text and -title
Handle
"… to get window title and -handle …"
As per Documentation - Function Reference - WinGetHandle() :
Retrieves the internal handle of a window.
Example:
Global Const $g_sWndTitle = 'Window title here'
Global $g_hWnd
If WinExists($g_sWndTitle) Then
$g_hWnd = WinGetHandle($g_sWndTitle)
WinFlash($g_hWnd)
EndIf
Text
As per Documentation - Function Reference - WinGetText() :
Retrieves the text from a window.
Example:
Global Const $g_sWndTitle = 'Window title here'
If WinExists($g_sWndTitle) Then
WinFlash($g_sWndTitle)
ConsoleWrite(WinGetText($g_sWndTitle) & #CRLF)
EndIf
Title
Likewise, WinGetTitle().

SciTE Script - How to get inside a Tree Control to set checkboxes

I'm using AutoIt and SciTE to create an installation script. The problem I am running into is that there is a tree menu for selection of features. I can select the whole treeview (SysTreeView32), but am not sure how to get inside it to check the boxes without doing a mouse move and click (not a great option).
The Treeview looks like this:
The Control Info from AutoIT is like this:
I'm sure it is possible, just can't figure out how to do it. This is my first attempt a such a script. Creating a response file does not work for this exe for some reason. So - this appears to be my only way out to create a somewhat silent install (not silent anymore, but at least automated).
* EDIT - Current State of Things *
I did figure out how to do some of this, but I still can't figure out if the items is selected before accessing it. So - since it toggles, I could be turning off a feature I want!
$hWnd = WinWaitActive($WindowTitle, 'Select Features')
$tvCtl = ControlGetHandle($WindowTitle, '', 'SysTreeView321')
$firstItem = _GUICtrlTreeView_FindItem($tvCtl, 'eBooks')
_GUICtrlTreeView_SelectItem($tvCtl, $firstItem, $TVGN_FIRSTVISIBLE)
_GUICtrlTreeView_ClickItem($tvCtl, $firstItem, "left", True, 1)
Send('{SPACE}')
I wouldn't think I would have to send the space since I sent the ClickItem, but seems so.
I could also do this:
ControlTreeView($hWnd, '', $tvCtl, 'Select', '#0')
ControlSend($hWnd, '', $tvCtl, ' ')
That will toggle the first one. So - i can count them all up and do it that way.
But when I check for "IsEnabled" or "IsChecked", it always says NO. So - I can't check the ones I need only. I have to hope their status is what I expect.
Here is how I am checking "IsChecked" and "IsEnabled":
If ControlCommand($hWnd, '', $logTool, 'IsEnabled') then
ConsoleWrite('Log Tool - IsEnabled' & #CRLF)
Else
ConsoleWrite('Log Tool - NOTEnabled' & #CRLF)
EndIf
and
If ControlCommand($hWnd, '', $logTool, 'IsChecked') then
ConsoleWrite('Log Tool - IsChecked' & #CRLF)
Else
ConsoleWrite('Log Tool - NOTChecked' & #CRLF)
EndIf
It always comes back NOTEnabled and NOTChecked. I made sure that I ran the same procedure above: FindItem, SelectItem, ClickItem. And, the correct item is highlighted/selected when this procedure is run - I can see that. So - it just isn't returning a proper value.
Opt('WinTitleMatchMode', 2)
$hWnd = WinGetHandle("InstallShield Wizard") ; Notice the correct title
$hTree = ControlGetHandle($hWnd, '', "[CLASS:SysTreeView32;INSTANCE:1]")
; == Now you can interact with the treeview with functions from "GuiTreeView.au3"
EDIT:
Try this
; Select the item so:
_GUICtrlTreeView_SelectItem($hTree, $hItem, $TVGN_CARET)
; Get checked state:
_GUICtrlTreeView_GetChecked($hTree, $hItem)
For more deatails read the AutoIt help.

Create a separator with a text in the menubar

What I want is shown in the docs in the picture http://doc.qt.io/qt-4.8/qactiongroup.html#details, but I cannot figure out how to do it. I can create a separator by
QAction * separator = new QAction("This is ignored", actionGroup);
separator->setSeparator(true);
but then it is just a line. How is the "Alignment" text added to the action in the example?
Following your link, then to the "Menus" example link (where your example is excerpted from) and then to mainwindow.cpp (which is one of the source files for that example), I reach: http://doc.qt.io/qt-4.8/qt-mainwindows-menus-mainwindow-cpp.html
The last function in that source file is createMenus which contains the following:
formatMenu = editMenu->addMenu(tr("&Format"));
formatMenu->addAction(boldAct);
formatMenu->addAction(italicAct);
formatMenu->addSeparator()->setText(tr("Alignment"));
formatMenu->addAction(leftAlignAct);
formatMenu->addAction(rightAlignAct);
formatMenu->addAction(justifyAct);
formatMenu->addAction(centerAct);
formatMenu->addSeparator();
formatMenu->addAction(setLineSpacingAct);
formatMenu->addAction(setParagraphSpacingAct);
The important bit is the fourth line in: setText on the separator added by addSeparator()
This can be done using a QLabel with a QWidgetAction (e.g. in python):
label = QtGui.QLabel("<b>At least it is rich text!</b>")
label_action = QtGui.QWidgetAction(self)
label_action.setDefaultWidget(label)
menu.addAction(label_action)

"Down arrow" moves cursor to end of line - how to turn it off

In IPython Notebook / Jupyter, arrow up/down keystrokes within a cell are handled by CodeMirror (as far as I can tell). I use these actions a lot (re-bound to control-p / control-n) to move between cells; but at the end of every cell, the cursor moves to end of line first before jumping to the next cell. This is counter-intuitive and, to me, rather distracting.
Is there any way to configure CodeMirror to make this move down to be just that - a move down?
Thanks!
The moving-to-next-cell behavior is defined by IPython wrapper code, which probably checks whether the cursor is at the end of the current cell, and overrides the default CodeMirror behavior in that case. You'll have to find that handler and somehow replace it with one that checks whether the cursor is on the last line. (I don't know much about IPython, only about CodeMirror, so I can't point you at the proper way to find and override the relevant code. They might have bound the Down key, or they might have overridden the goLineDown command.)
Knowing that I wasn't alone in wanting to skip the "going to end of line" behavior when going down from the last line of a code cell, I investigated that behavior and found out that:
it's CodeMirror that goes to the end of line when you type down in the last line of a code cell (file: codemirror.js ; "methods": findPosV and moveV)
and it's IPython that decides what to do with the "down" event after it has been handled by CodeMirror (file: cell.js ; class: Cell ; method: handle_codemirror_keyevent) ; looking at the code, I saw that IPython ignores the event when not at the last character of the last line.
This essentially confirms Marijin's answer.
The primary goal being to jump to the next cell, I think there's no need to prevent CodeMirror from going to the end of that line. The point is to force IPython to handle the event anyway.
My solution was to change the code from Cell.prototype.handle_codemirror_keyevent to this:
Cell.prototype.handle_codemirror_keyevent = function (editor, event) {
var shortcuts = this.keyboard_manager.edit_shortcuts;
var cur = editor.getCursor();
if((cur.line !== 0) && event.keyCode === 38){
// going up, but not from the first line
// don't do anything more with the event
event._ipkmIgnore = true;
}
var nLastLine = editor.lastLine();
if ((event.keyCode === 40) &&
((cur.line !== nLastLine))
) {
// going down, but not from the last line
// don't do anything more with the event
event._ipkmIgnore = true;
}
// if this is an edit_shortcuts shortcut, the global keyboard/shortcut
// manager will handle it
if (shortcuts.handles(event)) {
return true;
}
return false;
};
This code provides the desired behavior for the "down-arrow" key (almost: the cursor still goes to the end of the line, except that we don't see it, as we're already in another cell at that point), and also handles the "up-arrow" key similarly.
To modify the handle_codemirror_keyevent prototype, you have two possibilities:
You edit the cell.js file and change the code of the prototype to the code I gave above. The file is in <python>/Lib/site-packages/IPython/html/static/notebook/js or something similar depending on you distro
Much better, after the page is loaded, you change that prototype dynamically by doing this:
IPython.Cell.prototype.handle_codemirror_keyevent = function (editor, event) {
<same code as above>
};
You can do that in your custom.js for example, or create an extension to do it (that's what I did).

How to copy and paste indd file content into an another indd file?

I'm newbie in indesign scripting stuffs.So I apologise as I couldn't post my trials.
Objective:
I have an indd document which will have figure caption,label etc. I need to copy content(figure which is editable) from other indd file to this document where related figure label exists.
For example:
sample.indd
Some text
Fig.1.1 caption
some text
I need to copy the content of figure1.indd and paste into the sample.indd document where Fig.1.1 string exists and so on. Now I'm doing it manually. But am supposed to automate this.
So, I need some hint how to acheive it using extendscript?
I have found something like below to do this, but I don't have any clue to develop it further and also am not sure whether this approach is correct to get my result. Pls help me
myDocument=app.open(File("file.indd"),false); //opening a file to get the content without showing.
myDocument.pages.item(0).textFrames.item(0).contents="some text";
//here I could set the content but I don't knw how to get the content
// ?????? Then I have to paste the content into active document.
I found the script for my requirement.
var myDoc = File("sample.indd");//Destination File
var myFigDoc = File("fig.indd");//Figure File
app.open(File(myFigDoc));
app.activeDocument.pageItems.everyItem().select();
app.copy();
app.open(File(myDoc));
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "FIG. 1.1 ";//Figure caption text
//app.findGrepPreferences.appliedParagraphStyle = "FigureCaption";//Figure Caption Style
myFinds = app.activeDocument.findGrep();
for(var i=0;i<myFinds.length;i++){
myFinds[i].insertionPoints[0].contents="\r";
myFinds[i].insertionPoints[0].select();
app.paste();
}
app.findGrepPreferences = app.changeGrepPreferences = null;
If acceptable for you, you can place an indesign file as link (place…). So a script could try to catch the "fig…" strings and do the importation.
Have a look at scripts that use finGrep() and place() command.

Resources