File: Tools.xba

package info (click to toggle)
musescore 1.3%2Bdfsg1-0.1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 148,004 kB
  • ctags: 30,854
  • sloc: cpp: 372,716; xml: 148,276; ansic: 6,156; python: 2,202; perl: 710; sh: 505; makefile: 227
file content (152 lines) | stat: -rw-r--r-- 5,111 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Tools" script:language="StarBasic">REM *****  BASIC  *****

&apos; Somes useful tools used in OOoLilyPondMusic

&apos;*********************************************************
&apos; Add a slash if necessary
Function AddSlash( sPath as String) as String
	If Right(sPath,1) = &quot;/&quot; then 
		AddSlash = sPath
	else
		AddSlash = sPath &amp; &quot;/&quot;
	end if
end Function

&apos;Executes the command sCommand in a bash and returnes when finished
&apos;The command must not include any single quote (&apos;)
sub BashCommand(sCommand)
	Shell(&quot;bash -c &apos;&quot; &amp; sCommand &amp; &quot;&apos;&quot;, 1, &quot;&quot;, True)
end sub


&apos;**********************************************************
&apos; Check the existance of the file...
Function CheckFile( sUrl as String, ErrorMsg as String) As Boolean
	&apos; Test the existance of the OOoLilyPond script ...
	if FileExists(sUrl) then
		CheckFile = False
	else
		if ErrorMsg = &quot;OOoLilyPond&quot; then _
				ErrorMsg = &quot;Cannot find &quot; &amp; sUrl &amp; chr(10) &amp; &quot;Check your installation...&quot; 
		Msgbox ErrorMsg
		CheckFile = True
	end if	
End Function

Function GetOSType()
	If GetPathSeparator() = &quot;\&quot; Then
		GetOSType=&quot;Windows&quot;
	Else
		GetOSType=&quot;Unix&quot;
	End If
End Function

sub InspectObject(vObj)
	vObj=ThisComponent()
	MsgBox vObj.getImplementationName
	&apos;MsgBox vObj.dbg_methods &apos;Methods for this object.
	&apos;MsgBox vObj.dbg_supportedInterfaces &apos;Interfaces for by this object.
	&apos;MsgBox vObj.dbg_properties &apos;Properties for this object.
end sub

&apos;***********************************************************
&apos; Import graphic from URL into the clipboard.
&apos; Inspired from OOoForums Danny&apos;s code 
Sub ImportGraphicIntoClipboard(cURL)

&apos;   MsgBox(cURL)

	oDispatcher = createUnoService( &quot;com.sun.star.frame.DispatchHelper&quot; )

	&apos; Import the graphic from URL into a new draw document.
	Dim arg1(0) As New com.sun.star.beans.PropertyValue
	 arg1(0).Name = &quot;Hidden&quot;
	 arg1(0).Value = true
	oDrawDoc = StarDesktop.loadComponentFromURL( cURL, &quot;_blank&quot;, 0, arg1() )
	oDrawDocCtrl = oDrawDoc.getCurrentController()
	
	&apos; Get the shape...
	oDrawPage = oDrawDoc.DrawPages(0)
    oImportShape = oDrawPage(0)
	
	&apos; Get the dimension of the image...
	oShapeSize = oImportShape.Size()
	
	&apos; Strange bug with the eps and emf format... correction of the size
	if sFormat = &quot;eps&quot; then oShapeSize.Width = oShapeSize.Width * 0.99
	if sFormat = &quot;eps&quot; then oShapeSize.Height = oShapeSize.Height * 0.91
	if sFormat = &quot;emf&quot; then oShapeSize.Width = oShapeSize.Width * 1.13
	if sFormat = &quot;emf&quot; then oShapeSize.Height = oShapeSize.Height * 1.1

	&apos; Copy the image to clipboard and close the draw document
	oDrawDocCtrl.select(oImportShape)
	Dim Array()
	oDispatcher.executeDispatch( oDrawDocCtrl.Frame, &quot;.uno:Copy&quot;, &quot;&quot;, 0, Array() )
	oDrawDoc.dispose()
End Sub

&apos;************************************************************
Sub PrintFile(sFile as String)
	if not FileExists(sTmpPath &amp; sFile) then
		Msgbox &quot;Error : the file &quot; &amp; TmpPath &amp; sFile &amp; &quot; doesn&apos;t exist...&quot;
		exit sub
	end if
	iNumber = Freefile
	Open sTmpPath &amp; sFile For Input As iNumber
 	While not eof(iNumber)
  		Line Input #iNumber, sLine
		&apos;if sLine &lt;&gt; &quot;&quot; then 
		sMsg = sMsg &amp; sLine &amp; chr(10)
	wend
	Close #iNumber
	Msgbox  sMsg
End sub

Sub SortStringArray(StringArray As Variant)
	Dim l, u as Integer
	l=LBound(StringArray())
	u=UBound(StringArray())

	Dim i, j As Integer
	Dim sTemp As String

	For i = l To (u - 1)
		For j = (i + 1) To u
			If StringArray(i) &gt; StringArray(j) Then
				sTemp = StringArray(i)
				StringArray(i) = StringArray(j)
				StringArray(j) = sTemp
			End If
		Next j
	Next i
End Sub

&apos; The Function returns the name of a file that does not already exist.
&apos; This prevents unintended overwriting of existing files.
Function TmpFileName(sPrefix , sSuffix As String) As String
	Do
		TmpFileName=sPrefix &amp; Int(Str(Rnd*1e6)) &amp; sSuffix
	Loop While FileExists(TmpFileName)
End Function

&apos; Did not achieve to run lilypond directly with the Shell command and the 
&apos; Output redirected to files.
&apos; I tried: Shell(&quot;cmd /c lilypond &gt;file1 2&gt;file2&quot;)
&apos; But this did not work :-(
&apos; Now I write down the command in a batch file and call it with Shell.
Sub WindowsCommand(sCommand as String)
	Dim sBatFile As String
	Dim iNumber As Integer

	sBatFile=TmpFileName(ConvertFromURL(sTmpPath) &amp; &quot;CommandCallFromOOo_&quot;,&quot;.bat&quot;)

	iNumber = Freefile
	Open sBatFile For Output As #iNumber
	Print #iNumber, sCommand
	Close #iNumber
	Shell(sBatFile,1,&quot;&quot;,True)
	Kill(sBatFile)
End Sub
</script:module>