Xojo Conferences

Platforms to show: All Mac Windows Linux Cross-Platform

/Util/CPU/CPU Focus/Cpu Focus source
Required plugins for this example: MBS Util Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Util/CPU/CPU Focus/Cpu Focus source
This example is the version from Fri, 25th Jun 2015.
Project "Cpu Focus source.rbp"
MenuBar Menu
MenuItem UntitledMenu3 = ""
MenuItem UntitledMenu2 = "File"
MenuItem FileQuit = "Quit"
MenuItem UntitledMenu0 = "Edit"
MenuItem EditUndo = "Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cut"
MenuItem EditCopy = "Copy"
MenuItem EditPaste = "Paste"
MenuItem EditClear = "Clear"
End MenuBar
Class MainWindow Inherits Window
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
Control fronter Inherits Label
ControlInstance fronter Inherits Label
End Control
Control Timer1 Inherits Timer
ControlInstance Timer1 Inherits Timer
EventHandler Sub Action() update End EventHandler
End Control
Control StaticText2 Inherits Label
ControlInstance StaticText2 Inherits Label
End Control
Control serialnr Inherits Label
ControlInstance serialnr Inherits Label
End Control
Control StaticText5 Inherits Label
ControlInstance StaticText5 Inherits Label
End Control
Control pid Inherits Label
ControlInstance pid Inherits Label
End Control
Control Liste Inherits Listbox
ControlInstance Liste Inherits Listbox
End Control
Control StaticText3 Inherits Label
ControlInstance StaticText3 Inherits Label
End Control
Control classicpid Inherits Label
ControlInstance classicpid Inherits Label
End Control
Control StaticText4 Inherits Label
ControlInstance StaticText4 Inherits Label
End Control
Control StaticText6 Inherits Label
ControlInstance StaticText6 Inherits Label
End Control
Control password Inherits TextField
ControlInstance password Inherits TextField
End Control
EventHandler Sub Open() searchclassic End EventHandler
Sub renice(pid as integer,v as integer) dim s as shell dim e as string ' call the shell command renice to set CPU priority for given application ID s=new shell s.Execute "echo "+password.text+" | sudo -S renice "+str(V)+" -p "+str(pid) 'liste.addrow str(s.errorcode)+" "+s.Result End Sub
Sub searchclassic() dim s as shell dim t as string dim i,c as integer dim z as string ' search for classic using shell s=new shell s.execute "ps -alxwc" if s.errorCode=0 then t=s.result c=countFields(t,chr(13)) for i=1 to c z=nthField(t,chr(13),i) if instr(z,"TruBlueEnviro")>0 then 'liste.addrow z cpid=val(mid(z,7,5)) classicpid.text=str(cpid) end if next else classicpid.text="Error "+str(s.errorcode) end if End Sub
Sub update() dim err,i,j as integer dim p as ProcessMBS p=new ProcessMBS p.getfrontProcess if p.Name<>"" then fronter.text=p.name // get process ID for shell command i=p.ProcessID pid.text=str(i) if lastpid<>i then if lastpid<>0 then liste.insertRow 0,"Redirect CPU focus from "+lastname+" to "+p.name+"." end if lastname=p.name if lastpid<>0 then renice lastpid,0 end if renice i,-20 lastpid=i end if else pid.text="?" serialnr.text="?" fronter.text="?" end if End Sub
Property cpid As integer
Property lastname As string
Property lastpid As integer
End Class
Class App Inherits Application
End Class
End Project

See also:

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS Util Plugin.

MBS Xojo blog