How to change the text color of the popup window? - neovim

I want to output key information through a popup window, the relevant code is as follows:
:function! PopupDemo()
let message = 'Hello World'
for i in range(10)
let message = message . ' ' . message
endfor
let s:win_buf = bufadd('popup-demo')
call bufload(s:win_buf)
call setbufline(s:win_buf, 1, message)
echo 'buf id: ' . s:win_buf
let width = 40
let height = 10
" Set the new window as the current window.
let enter = v:false
" Calculate the centering coordinates.
let win_x = &columns / 2 - width / 2
let win_y = &lines / 2 - height / 2
let s:win_id = nvim_open_win(s:win_buf, enter, {
\'relative': 'editor',
\'row': win_y,
\'col': win_x,
\'width': width,
\'height': height,
\'focusable': v:false,
\'style': 'minimal',
\'border': ['╔', '═','╗', '║', '╝', '═', '╚', '║'],
\'noautocmd': v:false,
\'bufpos': [0, 0]
\})
call nvim_win_set_option(s:win_id, 'wrap', v:true)
echo 'win id: ' . s:win_id
call timer_start(5000, 'PopupClose')
:endfunction
:function! PopupClose(timer)
if s:win_id != 0
call nvim_win_close(s:win_id, v:false)
endif
if s:win_buf != 0
call nvim_buf_delete(s:win_buf, {'force': v:true})
endif
:endfunction
The result is this:
I want the normal text and border in the popup to be red. what should I do?
neovim version: v0.7.2

Just set &winhighlight option properly.
hi User1 guifg=Red guibg=NONE
...
call nvim_win_set_option(winid, "winhighlight", "NormalFloat:User1,FloatBorder:User1")
In principle, it's also possible to do :hi NormalFloat guifg=Red and such. But it'll then affect all the popups.

Related

Alluvial plot - reorder lodes

I have created an alluvial plot but, for visibility purposes I would like to move one lode in one of the axes: more specifically I would like the "NA" of the "Type of surgery" to be at the top so the last 4 axes are aligned.
This is the code I used on R:
aes(y = ID, axis1 = Reason, axis2 = Response, axis3=Type_of_surgery, axis4=Margins, axis5=RT_post_op, axis6=Chemo_post_op)) +
geom_alluvium(aes(fill = Type_of_surgery), width = 1/12,aes.bind = TRUE) +
geom_flow(aes.bind = TRUE) +
geom_stratum(width = 1/3, fill = "grey", color = "white") +
geom_label(stat = "stratum", aes(label = after_stat(stratum))) +
scale_x_discrete(limits = c("Reason", "Response","Type of surgery", "Margins","RT post op", "Chemo post-op"), expand = c(0.1,0.1)) +
scale_fill_brewer(type = "qual", palette = "Pastel1") +
ggtitle("TBC") ```
This is the plot I obtained:
[Alluvial plot][1]
[1]: https://i.stack.imgur.com/nDCIZ.png
I am beginning on the world of coding so any help would be most welcome,
Thank you all for your help,
JB

Printing form with proper margins and scaling while disabling certain objects in VB6

Once again, I'm stuck. I've tried figuring out how to print a form while having margins, a proper scaling, and certain objects not visible.
So far, I've tried .PaintPicture function which centers the form it prints but that's it (read: you can't disable some objects there), while using .PrintForm I can make some objects visible but I couldn't figure it out how to center and scale the form to fit and do some scaling so that the print result doesn't crop the form it prints. Playing with .Scale functions (e.g., .ScaleHeight, .ScaleWidth) apparently obviously don't help either as they give me errors after countless trial, error, and curiosity.
Here is my code so far:
Private Sub Command1_Click()
Dim NumCopies, I
'rem Set Cancel to True
dlgDialog.CancelError = False
dlgDialog.Flags = cdlPDUseDevModeCopies 'Enables multiple-copy printing
Dim MarginsLR As Single
Dim MarginsTB As Single
Dim PrintableWidth As Single
Dim PrintableHeight As Single
Dim ScaleFactor As Double
Dim ScaledWidth As Double
Dim ScaledHeight As Double
MarginsLR = Printer.ScaleX(0.5, vbInches, Printer.ScaleMode)
MarginsTB = Printer.ScaleY(0.5, vbInches, Printer.ScaleMode)
PrintableWidth = Printer.Width - 2 * MarginsLR
PrintableHeight = Printer.Height - 2 * MarginsTB
ScaleFactor = PrintableWidth / Printer.ScaleX(Form1.Width, vbHiMetric, Printer.ScaleMode)
If ScaleFactor * Printer.ScaleY(Form1.Height, vbHiMetric, Printer.ScaleMode) > PrintableHeight Then
ScaleFactor = PrintableHeight / Printer.ScaleY(Form1.Height, vbHiMetric, Printer.ScaleMode)
End If
ScaledWidth = ScaleFactor * Printer.ScaleX(Form1.Width, vbHiMetric, Printer.ScaleMode)
ScaledHeight = ScaleFactor * Printer.ScaleY(Form1.Height, vbHiMetric, Printer.ScaleMode)
MoveX = (Printer.Width - ScaledWidth) / 2
MoveY = (Printer.Height - ScaledHeight) / 2
On Error GoTo ErrorHandler
' Display the Print dialog box
dlgDialog.ShowPrinter
NumCopies = dlgDialog.Copies
For I = 1 To NumCopies
'The following was experimental
'Form1.ScaleHeight = ScaledHeight
'Form1.ScaleWidth = ScaledWidth
'Form1.ScaleX = MoveX
'Form1.ScaleY = MoveY
'For the .PrintForm function. I can't figure out how to do all the centering stuff sadly...
Label1.Visible = True
Command1.Visible = False
'This following code enables resizing and positioning but it doesn't make both Label1 and Command1 statements above work
Printer.PaintPicture CaptureClient(Me), (Printer.Width - Me.Width) / 2, _
(Printer.Height - Me.Height) / 2
'Form1.PrintForm
Printer.EndDoc
Next I
Label1.Visible = False
Command1.Visible = True
Exit Sub
ErrorHandler:
MsgBox "The following error has occurred:" & vbNewLine _
& "Err # " & Err.Number & " - " & Err.Description, _
vbCritical, _
"Print Error"
End Sub
Your help is appreciated. I'm currently updating my application's normal printing function with the new one.
Thanks in advance!

Email Signature - VBscript for Word, with tables

I'm trying to set a company signature and then implement it with GPO.
Here's what I'm trying to accomplish:
John Hancock | Paralegal | Company, PC
<Logo (to the left of text)> 60 Test Street | PO Box 1389 | Testing, PA 19820
Phone: 555.555.5555| Fax: 555.555.5555 | Email: testing#testing.com (need this hyperlinked)
EDIT: Additional information from comments.
I'm trying to have different attributes (font size, font type, bold, etc) for the text in each particular line within the second row of the table. For example: Test text (this is bold and Calibri) - Test Text 2 (this is not bold and Arial). When I run the script as it stands, I get the logo on the left, in the first column, and a line of text to the right of the logo, in the second column. What I can't figure out is how to add another line of text, on the right, directly underneath the first line, and have that line of text show with different font attributes and such.
Here's the code I have so far:
Set objSysInfo = CreateObject("ADSystemInfo")
Set WshShell = CreateObject("WScript.Shell")
strUser = objSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUser)
strName = objUser.FullName
strFirst = objUser.FirstName
strLast = objUser.LastName
strInitials = objUser.Initials
strOffice = objUser.physicalDeliveryOfficeName
strPOBox = objUser.postOfficeBox
strTitle = objUser.Description
strCred = objUser.info
strStreet = objUser.StreetAddress
strLocation = objUser.l
strPostCode = objUser.PostalCode
strPhone = objUser.TelephoneNumber
strMobile = objUser.Mobile
strFax = objUser.FacsimileTelephoneNumber
strEmail = objUser.mail
strCompany = objUser.Company
Const NUMBER_OF_ROWS = 1
Const NUMBER_OF_COLUMNS = 2
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Add()
Set objSelection = objWord.Selection
Set objEmailOptions = objWord.EmailOptions
Set objSignatureObject = objEmailOptions.EmailSignature
Set objSignatureEntries = objSignatureObject.EmailSignatureEntries
Set objRange = objDoc.Range()
objDoc.Tables.Add objRange, NUMBER_OF_ROWS, NUMBER_OF_COLUMNS
Set objTable = objDoc.Tables(1)
Set objShape = objTable.Cell(1, 1).Range.Hyperlinks.Add(objSelection.InlineShapes.AddPicture("\\eg-fileserver\admin space\signature\logo.jpg"), "http://www.eastburngray.com",,,"")
objTable.Columns(1).Width = 20
objTable.Columns(2).Width = 320
objTable.Cell(1, 2).Range.Font.Bold = True
objTable.Cell(1, 2).Range.Font.Name = "Calibri"
objTable.Cell(1, 2).Range.Font.Size = 10
objTable.Range.ParagraphFormat.SpaceAfter = 0
objTable.Cell(1, 2).Range.Text = strFirst & strInitials & strLast & " | " & strOffice & " | " & strCompany
Set objSelection = objDoc.Range()
objSignatureEntries.Add "Full Signature", objSelection
objSignatureObject.NewMessageSignature = "Full Signature"
objDoc.Saved = True
objWord.Quit
The key to adding text with various formatting in Word is to work with a Range object. You can think of a Range like an invisible Selection, with the major difference that you can have as many Range objects as you need - there can be only one Selection. The trick to changing the formatting is to "collapse" the Range (think of it like pressing the Right- or Left-Arrow keys to a blinking "point", then continuing to type).
Edit Note: Based on bibadia's surmise that this is actually about VBScript and not VBA I've changed the tags in your question and am editing my Answer to fit VBScript. VBScript cannot use Word-specific object declarations and enumerations, so I've removed the "Dim As" and replaced all wdEnum with the Integer equivalent.
Using your code as a starting point, the approach could look something like this:
Dim rngCell
Set rngCell = objTable.Cell(1,2).Range
rngCell.ParagraphFormat.SpaceAfter = 0
rngCell.Text = strFirst & strInitials & strLast & " | " & _
strOffice & " | " & strCompany & vbCr
rngCell.Font.Bold = True
rngCell.Font.Name = "Calibri"
rngCell.Font.Size = 10
rngCell.Collapse 0 'wdCollapseEnd
rngCell.MoveEnd 1, -1 'wdCharacter, -1
rngCell.Text = strPhone & " | " & strFax & " | " & strEmail
rngCell.Font.Bold = False
rngCell.Font.Size = 8
Note 1: The order in which you do things is usually reversed from that when typing as a user: First populate the Range, then apply the formatting.
Note 2: When collapsing at the end of a cell, Word will move the Range position to the beginning of the following cell. Thus, the code moves the point back one character, putting it at the end of the previous (original) cell: rngCell.MoveEnd wdCharacter, -1
Note 3: I added a vbCr at the end of the first rngCell.Text to create the new paragraph within the table cell.

Dynamically setting font-size using parameter in crystal report

How to set font-size dynamically for all field in crystal report so that using one parameter user can change font-size of whole report ?
You can do it for all fields / texts. See below:
aa = Report.Sections.Item("D").ReportObjects.Count
For i = 1 To aa
Set crxFieldObject = Report.Sections.Item("D").ReportObjects.Item(i)
bb = crxFieldObject.Name
If Mid(bb, 1, 5) = "Field" Then
cc = Val(Mid(bb, 6))
For j = 1 To NumberOfFields 'your value
If cc = xxxxx Then 'if your condition
crxFieldObject.suppress = False
crxFieldObject.Left = Leftxxxx 'your value
crxFieldObject.Top = Topxxxx 'your value
crxFieldObject.Font.Size = Fontsizexxxx 'your value
TenPointHeight = 221 'you can change this, too
If crxFieldObject.Font.Size = 10 Then
crxFieldObject.Height = TenPointHeight
Else
crxFieldObject.Height = TenPointHeight * crxFieldObject.Font.Size / 10
End If
End If
Next j
End If
Next i

MatLab: Error handling of integer input

How do I in MatLab catch the error that occours when the user enters letters and other things that aren't numbers in the input:
width = input('Enter a width: ');
I have played around for a while with the try/catch command:
width = 0;
message = '';
% Prompting.
while strcmp(message,'Invalid.') || width < 1 || width ~= int32(width)
try
disp(message)
width = input('Frame width: ');
catch error
message = 'Invalid.';
end
end
But with no luck (the above doesn't work). As shown I would like a simple message like "Frame width: " for the user the first time he has to enter his choice. But if an error is caught I want the message for him to be "Invalid. Try again: " fx everytime an error occours.
I have also tried the error() but I don't know how to place that correctly. Since the error() doesn't take the input command, where the error happends, as an argument, it must detect it in another way, which I can't figure.
Any help would be appreciated.
width = input('Frame width: ');
while(~isInt(width))
width = input('Invalid. Try again: ');
end
and you'll have to have the following function somewhere (or another implementation of it)
function retval = isInt(val)
retval = isscalar(val) && isnumeric(val) && isreal(val) && isfinite(val) && (val == fix(val));
end
answer = input('Frame width: ', 's');
[width, status] = str2num(answer);
while ~status || ~isscalar(width) || width ~= floor(width)
answer = input('Invalid. Try again: ', 's');
[width, status] = str2num(answer);
end
disp(width);
(status is 0 if the conversion failed. Without the isscalar test, an input like [1 2; 3 4] would also be accepted. The last test ensures that width must be an integer.)