R3C0NF16UR3D

docu

Jul 31st, 2023
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.94 KB | None | 0 0
  1. Gui system
  2. What you need:
  3. Copy wm.lua and guiElements.lua into a directory, where you normaly store your libs.
  4. /lib /usr/lib
  5.  
  6.  
  7. Example of a simple basic program:
  8. -------------------------------------------------------------------------------
  9. local component = require("component")
  10. local gpu = component.gpu
  11. local computer = require("computer")
  12. local event = require("event")
  13. local ser = require("serialization")
  14. local wm = require("wm")
  15. local gui = require("guiElements")
  16.  
  17. function callback(self, win)
  18. wm.closeWindow(win)
  19. end
  20.  
  21. wm.startGui()
  22.  
  23. testwindow = wm.newWindow(35, 2, 40, 20, "Test window")
  24.  
  25. button = gui.newButton(1, 1, 19, 1, "close", callback)
  26. wm.addElement(testwindow, button)
  27.  
  28. wm.raiseWindow(testwindow)
  29.  
  30. running = true
  31. while running == true do
  32. os.sleep(0)
  33. end
  34.  
  35. wm.exitGui()
  36. -------------------------------------------------------------------------------
  37.  
  38. Line by line now:-)
  39. -------------------------------------------------------------------------------
  40. local wm = require("wm")
  41. local gui = require("guiElements")
  42.  
  43. This you need to load the libs.
  44. -------------------------------------------------------------------------------
  45.  
  46.  
  47. wm.startGui()
  48.  
  49. Start the window manager and the program manager
  50. -------------------------------------------------------------------------------
  51.  
  52.  
  53. testwindow = wm.newWindow(35, 2, 40, 20, "Test window")
  54.  
  55. Create a new window with x = 35, y = 2 as the top-left corner. It's the position, where the window shows a #
  56. Size is 40 width and 20 height. Text of the Window as last argument.
  57. -------------------------------------------------------------------------------
  58.  
  59.  
  60. button = gui.newButton(1, 1, 19, 1, "close", callback)
  61. wm.addElement(testwindow, button)
  62.  
  63. Create a new element (as to see, it's a button) and add the element to our window.
  64. -------------------------------------------------------------------------------
  65.  
  66.  
  67. wm.raiseWindow(testwindow)
  68.  
  69. Raise the window from lowered status to normal displaying. If you don't do, the window will be
  70. there, but it is lowered. Simple click some where on the desktop, outside a window and a window
  71. list will popup. Click on the window, you want to raise.
  72. Click on the hash (#) and drag/drop the window top line to a new position to move a window.
  73. A click on the X will close the window and a click on the _ will lower it and it will only be
  74. seen in the window list.
  75.  
  76.  
  77. -------------------------------------------------------------------------------
  78. function callback(self, win)
  79. wm.closeWindow(win)
  80. end
  81.  
  82. This is the callback we defined in the creation of the button. It simply close the window, where
  83. it is called from.
  84. All elements returns in callbacks the window and the element it self. So you have full access over all
  85. needed data.
  86. -------------------------------------------------------------------------------
  87.  
  88.  
  89.  
  90. Basic functions:
  91.  
  92.  
  93. wm.startGui()
  94. Start the window manager and the program manager
  95.  
  96. wm.exitGui()
  97. Close the gui system. Attention: You need to reboot after all. Trying to fix this problem.
  98.  
  99. wm.setTopText(text)
  100. Set the text on top of the screen.
  101.  
  102. wm.redraw()
  103. Redraw the whole screen.
  104.  
  105. wm.startProgram(path, id)
  106.  
  107. wm.getVersion()
  108.  
  109. wm.setUserLevel(level)
  110. Set the user level of the user. Normaly not used, only intern by user manager driver.
  111.  
  112. wm.getUserLevel()
  113. Returns the level of the user. If 100 system is running without user manager driver.
  114.  
  115. Both functions are used by the user management driver. No need for user to use them.
  116. wm.getUsername()
  117. wm.setUsername(name)
  118.  
  119. -------------------------------------------------------------------------------
  120.  
  121.  
  122. Functions for windows:
  123.  
  124.  
  125. wm.newWindow(x, y, w, h, text)
  126. Create a new window.
  127.  
  128. wm.raiseWindow(self)
  129. Show window on screen.
  130.  
  131. wm.closeWindow(self)
  132. Close a window.
  133.  
  134. wm.lowerWindow(self)
  135. Lower a window.
  136.  
  137. wm.resizeWindow(self, w, h)
  138. Set a new size to the window.
  139.  
  140. wm.disableWindowButtons(self, state)
  141. Disable/enable the close and the lower button.
  142.  
  143. wm.setWindowSticky(self, state)
  144. Disable movement of window.
  145.  
  146. wm.hideWindow(self, state)
  147. Hide a window from the window list, even when it is lowered.
  148.  
  149. wm.setOnCloseCallback(self, callback)
  150. Callback that will called, when window is closed. If callback returns false, the window will stay open.
  151.  
  152. wm.setOnLowerCallback(self, callback)
  153. Callback that will called, when window is lowered.
  154.  
  155. wm.setOnResizeCallback(self, callback)
  156. Callback that will called, when a window is raised to the screen.
  157.  
  158. wm.getWindowInfo(self)
  159. Returns x,y,w,h,text and number of elements of a window.
  160.  
  161. wm.setWindowResizable(self, state)
  162. Enables on screen resizable of the window. If true, you can click the lower-right corner of a window
  163. and drag/drop to new size. This is normaly disabled, because the screen will heavaly flicker.
  164.  
  165. wm.getActiveWindow()
  166. Returns the active window.
  167.  
  168. wm.useShadows(state)
  169. Switch shadows on and off
  170.  
  171. wm.setBoxShadow(state)
  172. Select if shadows look like a box with diagonal edges. (works only, if useShadows is true)
  173.  
  174. wm.getShadowState()
  175. wm.getShadowBoxed()
  176. wm.getWindowFrame()
  177. wm.setWindowFrame(num)
  178.  
  179. wm.addElement(self, element)
  180. Adds an element to the window.
  181.  
  182. wm.newElement(id, x, y, w, h, text, callback)
  183. This is normaly not needed. It's internal called from the gui system. Coders who want to make own
  184. elements can use it.
  185.  
  186. -------------------------------------------------------------------------------
  187.  
  188. Functions for menus
  189.  
  190. wm.newMenu(x, y, w, text, callback)
  191. Creates a new menu. Callback will get the number of the selected entry as agument.
  192.  
  193. wm.insertMenu(self, entry)
  194. Insert an entry (just text) into the menu.
  195.  
  196. wm.removeMenu(self, entry)
  197. Removes the entry from the menu.
  198.  
  199. wm.clearMenu(self)
  200. Clears a full menu from all entries.
  201.  
  202. wm.setMenuCallback(self, callback)
  203. Set the callback of the menu.
  204.  
  205. wm.drawMenu(self)
  206. Displays a menu on screen.
  207.  
  208. wm.menuSetPosition(self, x, y)
  209. Changes the position of the menu.
  210.  
  211. wm.menuUseFrame(self, state)
  212. Set to true to use frames and the menu text, or false for just a menu with only the entries.
  213.  
  214. ------------------------------------------------------------------------------
  215. Start menu
  216. Best way to use the gui is to make code, that will be put into the start menu.
  217. Example is program_frame.lua. Just insert your program into the test.lua file.
  218.  
  219. wm.addStartMenu(name, path, level)
  220. Name of the entry in Start menu, full path to the program and userlevel, if you use the user management driver (0-99).
  221.  
  222. wm.exitProgram(id)
  223. Called internal from programs, on their exit.
  224.  
  225. wm.enableStartMenu(state)
  226. Set to false, if you don't want to use the start menu functions.
  227.  
  228.  
  229. -------------------------------------------------------------------------------
  230.  
  231. Program manager functions.
  232. If you have made a program for the gui system and you want to have it in your next program to without
  233. copying the code into your new program, you can simply use your code with some changes in the program manager.
  234. Have a look into plugin_framework.lua
  235.  
  236. wm.newSymbol(icon, program, level)
  237. Creates a new symbol in the right-bottom corner of the screen. Icon is a single character and program the full
  238. path to the lua program.
  239. If you use the user management driver you can set the user level (0-99).
  240.  
  241. wm.setSymbolIcon(self, icon)
  242. Change the icon.
  243.  
  244. wm.setSymbolProgram(self, program)
  245. Change the program to start.
  246.  
  247. wm.drawSymbol(self)
  248. Draw a symbol. Usefull to redraw symbols from programs to window manager.
  249.  
  250.  
  251. -------------------------------------------------------------------------------
  252.  
  253. Functions for element manipulation.
  254. Most of the names are telling you, what they do.
  255. self is allways the element it self.
  256. win is allways the window the element belongs to.
  257. alignment can be "left", "center" or "right".
  258. autowordwrap will fit the text into the element. great for labels.
  259. state is allways true or false.
  260.  
  261. guiElements.newElement(id, x, y, w, h, text)
  262. -guiElements.newRadioGroup(x, y, w, callback)
  263. -guiElements.newList(x, y, w, h, text, callback)
  264. -guiElements.newInput(x, y, w, text, callback)
  265. -guiElements.newCheckbox(x, y, text, callback)
  266. -guiElements.newHBar(x, y, w, h)
  267. guiElements.newVSlider(x, y, h, callback)
  268. guiElements.newHSlider(x, y, w, callback)
  269. -guiElements.newFrame(x, y, w, h)
  270. -guiElements.newLine(x, y, w)
  271. -guiElements.newLabel(x, y, w, h, text)
  272. -guiElements.newButton(x, y, w, h, text, callback)
  273.  
  274. guiElements.fileselect(text)
  275. Opens a file selection dialog. Returns true and file/directory name if selected or false if canceled.
  276.  
  277. guiElements.drawElement(win, self)
  278. Draws an element. Call it after changeing something on an element, to redraw it.
  279. guiElements.setElementBackground(self, background)
  280. guiElements.setElementForeground(self, foreground)
  281. guiElements.setElementActiveBackground(self, background)
  282. guiElements.setElementActiveForeground(self, foreground)
  283. guiElements.setElementX(self, x)
  284. guiElements.setElementY(self, y)
  285. guiElements.setElementW(self, w)
  286. guiElements.setElementH(self, h)
  287. guiElements.setElementText(self, text)
  288. guiElements.setElementCallback(self, callback)
  289. guiElements.setElementAlignment(self, alignment)
  290. guiElements.setElementMax(self, max)
  291. guiElements.setElementMin(self, min)
  292. guiElements.setElementValue(self, value)
  293. guiElements.setElementState(self, state)
  294. guiElements.setElementSteps(self, steps)
  295. Stepsize for bars and sliders.
  296. guiElements.setElementAutoWordWrap(self, state)
  297. guiElements.setElementSelected(self, state)
  298. guiElements.setElementProtected(self, state)
  299. If true, input fields will only display *. good for passwords.
  300. guiElements.getElementBackground(self)
  301. guiElements.getElementForeground(self)
  302. guiElements.getElementActiveBackground(self)
  303. guiElements.getElementActiveForeground(self)
  304. guiElements.getElementX(self)
  305. guiElements.getElementY(self)
  306. guiElements.getElementW(self)
  307. guiElements.getElementH(self, h)
  308. guiElements.getElementText(self)
  309. guiElements.getElementAlignment(self)
  310. guiElements.getElementMax(self)
  311. guiElements.getElementMin(self)
  312. guiElements.getElementValue(self)
  313. guiElements.getElementState(self)
  314. guiElements.getElementAutoWordWrap(self)
  315. guiElements.getElementType(self)
  316. guiElements.getLastElement()
  317. guiElements.getElementProtected(self)
  318. guiElements.getElementSelected(self)
  319.  
  320. guiElements.insertElementData(self, data)
  321. guiElements.removeElementData(self, num)
  322. guiElements.changeElementData(self, num, data)
  323. guiElements.clearElementData(self)
  324. For lists
  325.  
  326. --------------------------------------------------------------------------------------------
  327. Functions for coders who want make their own elements. Have a look into the guiElements.lua file
  328. to see, how they work. Normal users don't need this functions.
  329.  
  330. guiElements.setElementType(self, type)
  331. guiElements.setElementDrawCallback(self, callback)
  332. guiElements.setElementHandleCallback(self, callback)
  333. guiElements.setElementUserData1(self, data)
  334. guiElements.setElementUserData2(self, data)
  335. guiElements.setElementUserData3(self, data)
  336. guiElements.getElementUserData1(self)
  337. guiElements.getElementUserData2(self)
  338. guiElements.getElementUserData3(self)
  339. guiElements.setElementIgnoreMouseBlock(self, state)
  340. guiElements.getColors()
  341.  
  342. wm.blockMouse(state)
  343. wm.setMouseCallback(callback)
  344. wm.getColors()
  345.  
  346. wm.registerDriver(name, description, copyright, version)
  347. wm.getDriverList()
  348.  
  349. --------------------------------------------------------------------------------------------
  350. User management driver
  351.  
  352. user.add(username, password, level)
  353. user.remove(username)
  354. user.changePassword(username, oldPassword, password)
  355. user.getActiveUser()
  356. user.getUserList()
  357. user.login()
  358. user.start()
  359. user.stop()
  360.  
  361. --------------------------------------------------------------------------------------------
  362. Printserver driver
  363.  
  364. printServer.addPrinter(name, addr, typ, position)
  365. printServer.getLocalPrinter()
  366. printServer.getStandardPrinter()
  367. printServer.setName(id, txt)
  368. printServer.setLocation(id, txt)
  369. printServer.setDescription(id, txt)
  370. printServer.setNetworkShare(id, state)
  371. printServer.getName(id)
  372. printServer.getLocation(id)
  373. printServer.getDescription(id)
  374. printServer.getNetworkShare(id)
  375. printServer.getPrinterList()
  376. printServer.newPrintjob(title, data, netAddress, printerID)
  377. printServer.printJobInsertLine(job, text)
  378. printServer.printJobInsertText(job, text)
  379. printServer.getPrintJobs(netAddress)
  380. printServer.getPrinterStatus(netAddress, printerID)
  381. printServer.cancelPrintJob(job)
  382. printServer.resumePrintJob(job)
  383. printServer.print(job, netAddress)
  384. printServer.isPrinting()
  385. printServer.setPrinterTimeout(t)
  386. printServer.getPrinterTimeout()
  387. printServer.printText(title, text)
  388. printServer.start()
  389. printServer.stop()
  390. printServer.showSelectPrinterDialog(fromManager)
  391.  
  392. --------------------------------------------------------------------------------------------
  393. Network driver
  394.  
  395. networkdriver.modemSend(addr, port, ...)
  396. networkdriver.modemBroadcast(port, ...)
  397. networkdriver.getModemPackets()
  398. networkdriver.openPort(service)
  399. networkdriver.start()
  400. networkdriver.stop()
  401. --------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment