R3C0NF16UR3D

preintserver.lua

Jul 31st, 2023
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.38 KB | None | 0 0
  1. local component = require("component")
  2. local ser = require("serialization")
  3. local gpu = component.gpu
  4. local event = require("event")
  5. local filesystem = require("filesystem")
  6. local wm = require("windowmanager/libs/wm")
  7. local gui = require("windowmanager/libs/guiElements")
  8. local networkdriver = require("windowmanager/driver/networkdriver")
  9.  
  10. local ScreenWidth, ScreenHeight = gpu.getResolution()
  11.  
  12.  
  13. local printServer = {}
  14.  
  15. local version = "1.0"
  16. --// exportstring( string )
  17. --// returns a "Lua" portable version of the string
  18. function exportstring( s )
  19. s = string.format( "%q",s )
  20. -- to replace
  21. s = string.gsub( s,"\\\n","\\n" )
  22. s = string.gsub( s,"\r","\\r" )
  23. s = string.gsub( s,string.char(26),"\"..string.char(26)..\"" )
  24. return s
  25. end
  26. --// The Save Function
  27. function saveTable(tbl,filename )
  28. local charS,charE = " ","\n"
  29. local file,err
  30. -- create a pseudo file that writes to a string and return the string
  31. if not filename then
  32. file = { write = function( self,newstr ) self.str = self.str..newstr end, str = "" }
  33. charS,charE = "",""
  34. -- write table to tmpfile
  35. elseif filename == true or filename == 1 then
  36. charS,charE,file = "","",io.tmpfile()
  37. -- write table to file
  38. -- use io.open here rather than io.output, since in windows when clicking on a file opened with io.output will create an error
  39. else
  40. file,err = io.open( filename, "w" )
  41. if err then
  42. print ("Gui-lib: Error saving table " .. filename .." -> " .. err)
  43. return _,err
  44. end
  45. end
  46. -- initiate variables for save procedure
  47. local tables,lookup = { tbl },{ [tbl] = 1 }
  48. file:write( "return {"..charE )
  49. for idx,t in ipairs( tables ) do
  50. if filename and filename ~= true and filename ~= 1 then
  51. file:write( "-- Table: {"..idx.."}"..charE )
  52. end
  53. file:write( "{"..charE )
  54. local thandled = {}
  55. for i,v in ipairs( t ) do
  56. thandled[i] = true
  57. -- escape functions and userdata
  58. if type( v ) ~= "userdata" then
  59. -- only handle value
  60. if type( v ) == "table" then
  61. if not lookup[v] then
  62. table.insert( tables, v )
  63. lookup[v] = #tables
  64. end
  65. file:write( charS.."{"..lookup[v].."},"..charE )
  66. elseif type( v ) == "function" then
  67. file:write( charS.."loadstring("..exportstring(string.dump( v )).."),"..charE )
  68. else
  69. local value = ( type( v ) == "string" and exportstring( v ) ) or tostring( v )
  70. file:write( charS..value..","..charE )
  71. end
  72. end
  73. end
  74. for i,v in pairs( t ) do
  75. -- escape functions and userdata
  76. if (not thandled[i]) and type( v ) ~= "userdata" then
  77. -- handle index
  78. if type( i ) == "table" then
  79. if not lookup[i] then
  80. table.insert( tables,i )
  81. lookup[i] = #tables
  82. end
  83. file:write( charS.."[{"..lookup[i].."}]=" )
  84. else
  85. local index = ( type( i ) == "string" and "["..exportstring( i ).."]" ) or string.format( "[%d]",i )
  86. file:write( charS..index.."=" )
  87. end
  88. -- handle value
  89. if type( v ) == "table" then
  90. if not lookup[v] then
  91. table.insert( tables,v )
  92. lookup[v] = #tables
  93. end
  94. file:write( "{"..lookup[v].."},"..charE )
  95. elseif type( v ) == "function" then
  96. file:write( "loadstring("..exportstring(string.dump( v )).."),"..charE )
  97. else
  98. local value = ( type( v ) == "string" and exportstring( v ) ) or tostring( v )
  99. file:write( value..","..charE )
  100. end
  101. end
  102. end
  103. file:write( "},"..charE )
  104. end
  105. file:write( "}" )
  106. -- Return Values
  107. -- return stringtable from string
  108. if not filename then
  109. -- set marker for stringtable
  110. return file.str.."--|"
  111. -- return stringttable from file
  112. elseif filename == true or filename == 1 then
  113. file:seek ( "set" )
  114. -- no need to close file, it gets closed and removed automatically
  115. -- set marker for stringtable
  116. return file:read( "*a" ).."--|"
  117. -- close file and return 1
  118. else
  119. file:close()
  120. return 1
  121. end
  122. end
  123.  
  124. --// The Load Function
  125. function loadTable( sfile )
  126. local tables, err, _
  127.  
  128. -- catch marker for stringtable
  129. if string.sub( sfile,-3,-1 ) == "--|" then
  130. tables,err = loadstring( sfile )
  131. else
  132. tables,err = loadfile( sfile )
  133. end
  134. if err then
  135. print("Gui-lib: Error loading table " ..sfile .. " -> " ..err)
  136. return _,err
  137. end
  138. tables = tables()
  139. for idx = 1,#tables do
  140. local tolinkv,tolinki = {},{}
  141. for i,v in pairs( tables[idx] ) do
  142. if type( v ) == "table" and tables[v[1]] then
  143. table.insert( tolinkv,{ i,tables[v[1]] } )
  144. end
  145. if type( i ) == "table" and tables[i[1]] then
  146. table.insert( tolinki,{ i,tables[i[1]] } )
  147. end
  148. end
  149. -- link values, first due to possible changes of indices
  150. for _,v in ipairs( tolinkv ) do
  151. tables[idx][v[1]] = v[2]
  152. end
  153. -- link indices
  154. for _,v in ipairs( tolinki ) do
  155. tables[idx][v[2]],tables[idx][v[1]] = tables[idx][v[1]],nil
  156. end
  157. end
  158. return tables[1]
  159. end
  160.  
  161. local selectedPrinter = 0
  162.  
  163. local Printer = {}
  164. Printer.__index = Printer
  165. local PrinterList = {}
  166.  
  167.  
  168. function Printer:New(name, addr, typ, position)
  169. pr = setmetatable({
  170. name = name or "",
  171. addr = addr or "",
  172. typ = typ or 0,
  173. position = position or "",
  174. description = "",
  175. shared = false,
  176. isStandard = false,
  177. proxy = nil,
  178. },Printer)
  179. table.insert(PrinterList, pr)
  180. return pr
  181. end
  182.  
  183. function printServer.addPrinter(name, addr, typ, position)
  184. local self = Printer:New(name, addr, typ, position)
  185. self.proxy = component.proxy(addr)
  186. saveTable(PrinterList, "/etc/windowmanager/printserver.dat")
  187. return self
  188. end
  189.  
  190. local function addLocalPrinter()
  191. for addr,v in component.list("openprinter") do
  192. printServer.addPrinter(v, addr, 0)
  193. end
  194. PrinterList[1].isStandard = true
  195. end
  196.  
  197. function removePrinter(id)
  198. table.remove(PrinterList, id)
  199. saveTable(PrinterList, "/etc/windowmanager/printserver.dat")
  200. end
  201.  
  202. function printServer.getLocalPrinter()
  203. local tmpTable = {}
  204. for addr,v in component.list("openprinter") do
  205. table.insert(tmpTable, addr)
  206. end
  207. return tmpTable
  208. end
  209.  
  210. function printServer.getStandardPrinter()
  211. for i = 1, #PrinterList do
  212. if PrinterList[i].isStandard == true then
  213. selectedPrinter = i
  214. return PrinterList[i]
  215. end
  216. end
  217. end
  218.  
  219. function printServer.setName(id, txt)
  220. PrinterList[id].name = txt
  221. saveTable(PrinterList, "/etc/windowmanager/printserver.dat")
  222. end
  223.  
  224. function printServer.setLocation(id, txt)
  225. PrinterList[id].position = txt
  226. saveTable(PrinterList, "/etc/windowmanager/printserver.dat")
  227. end
  228.  
  229. function printServer.setDescription(id, txt)
  230. PrinterList[id].description = txt
  231. saveTable(PrinterList, "/etc/windowmanager/printserver.dat")
  232. end
  233.  
  234. function printServer.setNetworkShare(id, state)
  235. PrinterList[id].shared = state
  236. saveTable(PrinterList, "/etc/windowmanager/printserver.dat")
  237. end
  238.  
  239. function printServer.getName(id)
  240. return PrinterList[id].name
  241. end
  242.  
  243. function printServer.getLocation(id)
  244. return PrinterList[id].position
  245. end
  246.  
  247. function printServer.getDescription(id)
  248. return PrinterList[id].description
  249. end
  250.  
  251. function printServer.getNetworkShare(id)
  252. return PrinterList[id].shared
  253. end
  254.  
  255. function printServer.getPrinterList()
  256. return PrinterList
  257. end
  258.  
  259.  
  260. -- FIXME: has to be changed to loading list
  261. --addLocalPrinter()
  262.  
  263.  
  264. local function showPrinterList()
  265. for i = 1, #PrinterList do
  266. if PrinterList[i].isStandard == true then
  267. print(ser.serialize(PrinterList[i]))
  268. end
  269. end
  270. end
  271.  
  272. local modem = nil
  273. local modemPort = 0
  274.  
  275. local ScreenWidth, ScreenHeight = gpu.getResolution()
  276.  
  277.  
  278. local color={}
  279. color.black=0x000000
  280. color.gray=0xA9A9A9
  281. color.lightBlue=0x808080
  282. color.white=0xFFFFFF
  283. color.magenta=0xFF00FF
  284. color.yellow=0xFFFF00
  285. color.green=0x00FF00
  286. color.darkGreen=0x008000
  287. color.blue=0x0000ff
  288. color.red=0xFF0000
  289. color.orange=0xFFA500
  290. color.brown=0xA52A2A
  291. color.lightRed=0xF00000
  292. color.darkGray=0x202020
  293.  
  294. -- screen colors
  295. local Color = {}
  296. Color.TopLineBackground = color.darkGray
  297. Color.RunningDot = color.green
  298.  
  299.  
  300. local waitingTime = 3
  301.  
  302. -- table to store all print jobs
  303. local printJobList = {["id"] = 0}
  304.  
  305. -- tmp table for a print job
  306. local printJobTable = {}
  307. printJobTable.__index = printJobTable
  308.  
  309. function printJobTable:New(title, data, addr, printerID)
  310. pj = setmetatable ({
  311. id = printJobList.id,
  312. title = title or "no title",
  313. data = data or {},
  314. pages = 1,
  315. page = 1,
  316. status = "idle",
  317. line = 1, -- what line is printed
  318. printerID = printerID or 1, -- id of the printer in list
  319. },printJobTable)
  320. printJobList.id = printJobList.id + 1
  321. table.insert(printJobList, pj)
  322. return pj
  323. end
  324.  
  325.  
  326. function printServer.newPrintjob(title, data, netAddress, printerID)
  327. if not printerID then
  328. printerID = printServer.showSelectPrinterDialog()
  329. end
  330. if netAddress then
  331. ret = printJobTable:New(title, data, netAddress, printerID)
  332. ret.pages = math.ceil(#ret.data/20)
  333. -- networkdriver.modemSend(netAddress, modemPort, ret.id)
  334. else
  335. ret = printJobTable:New(title, data, nil, printerID)
  336. ret.pages = math.ceil(#ret.data/20)
  337. return ret
  338. end
  339. end
  340.  
  341. function printServer.printJobInsertLine(job, text)
  342. table.insert(job.data, text)
  343. job.pages = math.ceil(#job.data/20)
  344. end
  345.  
  346. local function splitWords(Lines, limit)
  347. while #Lines[#Lines] > limit do
  348. Lines[#Lines+1] = Lines[#Lines]:sub(limit+1)
  349. Lines[#Lines-1] = Lines[#Lines-1]:sub(1,limit)
  350. end
  351. end
  352. local function wrap(str, limit)
  353. local Lines, here, limit, found = {}, 1, limit or 72, str:find("(%s+)()(%S+)()")
  354. if found then
  355. Lines[1] = string.sub(str,1,found-1) -- Put the first word of the string in the first index of the table.
  356. else Lines[1] = str end
  357. str:gsub("(%s+)()(%S+)()",
  358. function(sp, st, word, fi) -- Function gets called once for every space found.
  359. splitWords(Lines, limit)
  360.  
  361. if fi-here > limit then
  362. here = st
  363. Lines[#Lines+1] = word -- If at the end of a line, start a new table index...
  364. else Lines[#Lines] = Lines[#Lines].." "..word end -- ... otherwise add to the current table index.
  365. end)
  366. splitWords(Lines, limit)
  367.  
  368. return Lines
  369. end
  370.  
  371. function printServer.printJobInsertText(job, text)
  372. local t = wrap(text, 31)
  373. for i = 1, #t do
  374. table.insert(job.data, t[i])
  375. end
  376. job.pages = math.ceil(#job.data/20)
  377. end
  378.  
  379.  
  380. local function printPage(job)
  381. if job.page <= job.pages then
  382. local printer = PrinterList[job.printerID].proxy
  383. job.status = "printing"
  384. local start = (job.page * 20) - 19
  385. printer.clear()
  386. printer.setTitle(job.title .. "(" .. tostring(job.page) .. ")")
  387. for i = start, start + 19 do -- 20 lines per page
  388. if i <= #job.data then -- end of table not reached
  389. printer.writeln(job.data[i])
  390. end
  391. end
  392.  
  393. if printer.getBlackInkLevel() == false then
  394. job.status = "stopped"
  395. return
  396. end
  397. if printer.getPaperLevel() == false then
  398. job.status = "stopped"
  399. return
  400. end
  401. if printer.getColorInkLevel() == false then
  402. job.status = "stopped"
  403. return
  404. end
  405.  
  406. if printer.print() ~= true then
  407. job.status = "stopped"
  408. return
  409. end
  410. job.page = job.page + 1
  411. end
  412. if job.page > job.pages then
  413. job.status = "finished"
  414. end
  415. end
  416.  
  417.  
  418. function printServer.getPrintJobs(netAddress)
  419. -- gpu.set(1,1,"giving jobs")
  420. local tmpTable = {}
  421. local jobList = {}
  422. for i = 1, #printJobList do
  423. tmpTable = {}
  424. tmpTable.id = printJobList[i].id
  425. tmpTable.title = printJobList[i].title
  426. tmpTable.page = printJobList[i].page - 1
  427. tmpTable.pages = printJobList[i].pages
  428. tmpTable.addr = printJobList[i].addr
  429. tmpTable.status = printJobList[i].status
  430. tmpTable.printerID = printJobList[i].printerID
  431. table.insert(jobList, tmpTable)
  432. end
  433. if netAddress then
  434. -- networkdriver.modemSend(netAddress, modemPort, ser.serialize(jobList))
  435. end
  436. return jobList
  437. end
  438.  
  439. function printServer.getPrinterStatus(netAddress, printerID)
  440. local tmpTable = {}
  441. if component.isAvailable("openprinter") == false then
  442. if netAddress then
  443. tmpTable.ret = false
  444. tmpTable.addr = ""
  445. tmpTable.colorInk = 0
  446. tmpTable.blackInk = 0
  447. tmpTable.paper = 0
  448. -- networkdriver.modemSend(netAddress, modemPort, ser.serialize(tmpTable))
  449. end
  450. return false, "", 0, 0, 0, "No printer conected"
  451. end
  452. if not printerID then
  453. printerID = printServer.showSelectPrinterDialog()
  454. end
  455. local printer = PrinterList[printerID].proxy
  456. local addr = printer.address
  457. local colorInk = printer.getColorInkLevel()
  458. local blackInk = printer.getBlackInkLevel()
  459. local paper = printer.getPaperLevel()
  460. tmpTable.addr = addr
  461. tmpTable.colorInk = colorInk
  462. tmpTable.blackInk = blackInk
  463. tmpTable.paper = paper
  464. if colorInk == false then
  465. if netAddress then
  466. tmpTable.ret = false
  467. tmpTable.status = "Out of color ink"
  468. -- networkdriver.modemSend(netAddress, modemPort, ser.serialize(tmpTable))
  469. end
  470. return false, addr, colorInk, blackInk, paper, "Out of color ink"
  471. end
  472. if blackInk == false then
  473. if netAddress then
  474. tmpTable.ret = false
  475. tmpTable.status = "Out of black ink"
  476. -- networkdriver.modemSend(netAddress, modemPort, ser.serialize(tmpTable))
  477. end
  478. return false, addr, colorInk, blackInk, paper, "Out of black ink"
  479. end
  480. if paper == false then
  481. if netAddress then
  482. tmpTable.ret = false
  483. tmpTable.status = "Out paper"
  484. -- networkdriver.modemSend(netAddress, modemPort, ser.serialize(tmpTable))
  485. end
  486. return false, addr, colorInk, blackInk, paper, "Out of paper"
  487. end
  488. if netAddress then
  489. tmpTable.ret = true
  490. tmpTable.status = "ready"
  491. -- networkdriver.modemSend(netAddress, modemPort, ser.serialize(tmpTable))
  492. end
  493. return true, addr, colorInk, blackInk, paper, "ready"
  494. end
  495.  
  496. function printServer.cancelPrintJob(job)
  497. job.status = "canceled"
  498. end
  499.  
  500. function printServer.resumePrintJob(job)
  501. job.status = "waiting"
  502. end
  503.  
  504. function printServer.print(job, netAddress)
  505. job.status = "waiting"
  506. end
  507.  
  508. function printServer.isPrinting()
  509. for i = 1, #printJobList do
  510. if printJobList[i].status == "printing" then
  511. return true
  512. end
  513. end
  514. return false
  515. end
  516.  
  517.  
  518. function showJobs()
  519. j = printServer.getPrintJobs()
  520. for i = 1, #j do
  521. print(string.format("id: %-5d title: %-20s pages: %4d status: %s %d",j[i].id, j[i].title, j[i].pages, j[i].addr, j[i].status, j[i].printerID))
  522. end
  523. end
  524.  
  525. function printServer.setPrinterTimeout(t)
  526. waitingTime = t
  527. end
  528.  
  529. function printServer.getPrinterTimeout()
  530. return waitingTime
  531. end
  532.  
  533. function printServer.printText(title, text)
  534. local ps = printServer.showSelectPrinterDialog()
  535. local job = printServer.newPrintjob(title, nil, nil, ps)
  536. printServer.printJobInsertText(job, text)
  537. printServer.print(job)
  538. end
  539.  
  540.  
  541.  
  542.  
  543. local printTimer = nil
  544.  
  545. local function printTimerCallback()
  546. for p = 1, #PrinterList do
  547. if printServer.getPrinterStatus(nil, p) == true then
  548. for i = 1, #printJobList do
  549. if printJobList[i].printerID == p and printJobList[i].status ~= "finished" and printJobList[i].status ~= "canceled" and printJobList[i].status ~= "idle" then
  550. printPage(printJobList[i])
  551. break
  552. end
  553. end
  554. end
  555. end
  556. end
  557.  
  558. --[[
  559. local function openModem()
  560. if component.isAvailable("modem") == true then
  561. _, modemPort = networkdriver.openPort("printserver")
  562. end
  563. end
  564.  
  565. local function modemReceiveCallback(_, addr, from, port, distance, ...)
  566. local message = { ... }
  567. if message[1] == "GET PRINTSERVER" and port == modemPort then
  568. networkdriver.modemSend(from, modemPort, "ok")
  569. end
  570. if message[1] == "GET PRINTERSTATUS" and port == modemPort then
  571. printServer.getPrinterStatus(from, message[2])
  572. end
  573. if message[1] == "GET PRINTJOBS" and port == modemPort then
  574. printServer.getPrintJobs(from)
  575. end
  576. if message[1] == "NEW PRINTJOB" and port == modemPort then
  577. printServer.newPrintjob(message[2], {}, from, message[3])
  578. end
  579. if message[1] == "INSERTLINE" and port == modemPort then
  580. for i = 1, #printJobList do
  581. if printJobList[i].id == message[2] then
  582. printServer.printJobInsertLine(printJobList[i], message[3])
  583. networkdriver.modemSend(from, modemPort, "ok")
  584. break
  585. end
  586. end
  587. end
  588. if message[1] == "PRINT" and port == modemPort then
  589. for i = 1, #printJobList do
  590. if printJobList[i].id == message[2] then
  591. printServer.print(printJobList[i], from)
  592. networkdriver.modemSend(from, modemPort, "ok")
  593. break
  594. end
  595. end
  596. end
  597. end
  598. ]]--
  599.  
  600. function printServer.start()
  601. if filesystem.exists("/etc/windowmanager/printserver.dat") == true then
  602. local List = loadTable("/etc/windowmanager/printserver.dat")
  603. for i = 1, # List do
  604. printServer.addPrinter(List[i].name, List[i].addr, List[i].typ, List[i].position)
  605. printServer.setDescription(i, List[i].description)
  606. printServer.setNetworkShare(i, List[i].shared)
  607. end
  608. -- print(ser.serialize(List))
  609. end
  610.  
  611. -- openModem()
  612. wm.registerDriver("printer", "A driver for using multiple printer from openprinter mod", "S.Kempa", version)
  613. printTimer = event.timer(waitingTime, printTimerCallback, math.huge)
  614. -- event.listen("modem_message", modemReceiveCallback)
  615. end
  616.  
  617. function printServer.stop()
  618. event.cancel(printTimer)
  619. -- event.ignore("modem_message", modemReceiveCallback)
  620. end
  621.  
  622. local List = {}
  623. local printerList
  624. local printerSlider
  625. local selectPrinterRunning
  626. local PrinterListWindow
  627. local selectedPrinter = 1
  628.  
  629.  
  630.  
  631. function printServer.showSelectPrinterDialog(fromManager)
  632. List = printServer.getPrinterList()
  633. if #List == 0 then
  634. return -1
  635. end
  636. selectPrinterRunning = true
  637.  
  638. PrinterListWindow = wm.newWindow(math.floor(ScreenWidth/2) - 20, math.floor(ScreenHeight/2) - 8, 40, 12, "Select printer")
  639. wm.hideWindow(PrinterListWindow, true)
  640. wm.setWindowSticky(PrinterListWindow, true)
  641. wm.disableWindowButtons(PrinterListWindow, true)
  642.  
  643. printerList = gui.newList(2, 2, 35, 3, "", function() selectedPrinter = gui.getElementSelected(printerList) gui.setElementValue(printerSlider, selectedPrinter) gui.drawElement(PrinterListWindow, printerSlider) end)
  644. wm.addElement(PrinterListWindow, printerList)
  645. gui.setElementBackground(printerList, 0xFFFFFF)
  646. gui.setElementActiveBackground(printerList, 0x202020)
  647. gui.setElementForeground(printerList, 0x000000)
  648. gui.setElementActiveForeground(printerList, 0xFFFFFF)
  649.  
  650. for i = 1, #List do
  651. gui.insertElementData(printerList, List[i].addr)
  652. end
  653.  
  654. printerSlider = gui.newVSlider(37, 2, 3, function() selectedPrinter = gui.getElementValue(printerSlider) gui.setElementSelected(printerList, selectedPrinter) gui.drawElement(PrinterListWindow, printerList) end)
  655. gui.setElementMin(printerSlider, 1)
  656. gui.setElementValue(printerSlider, 1)
  657. gui.setElementMax(printerSlider, #List)
  658. wm.addElement(PrinterListWindow, printerSlider)
  659.  
  660. wm.addElement(PrinterListWindow, gui.newLine(1, 5, 38))
  661.  
  662. wm.addElement(PrinterListWindow, gui.newLabel(2, 6, 14, 1, "Name : "))
  663. wm.addElement(PrinterListWindow, gui.newLabel(2, 7, 25, 1, "Type : "))
  664. wm.addElement(PrinterListWindow, gui.newLabel(2, 8, 14, 1, "Location : "))
  665. wm.addElement(PrinterListWindow, gui.newLabel(2, 9, 14, 1, "Description : "))
  666. labelName = gui.newLabel(16, 6, 20, 1, "")
  667. wm.addElement(PrinterListWindow, labelName)
  668. labelType = gui.newLabel(16, 7, 20, 1, "")
  669. wm.addElement(PrinterListWindow, labelType)
  670. labelLocation = gui.newLabel(16, 8, 20, 1, "")
  671. wm.addElement(PrinterListWindow, labelLocation)
  672. labelDescription = gui.newLabel(16, 9, 20, 1, "")
  673. wm.addElement(PrinterListWindow, labelDescription)
  674.  
  675. wm.addElement(PrinterListWindow, gui.newLine(1, 10, 38))
  676.  
  677. local PrinterListOkButton = gui.newButton(2, 11, 4, 1, "ok", function()wm.closeWindow(PrinterListWindow) selectPrinterRunning = false end)
  678. wm.addElement(PrinterListWindow, PrinterListOkButton)
  679.  
  680. local PrinterListCancelButton = gui.newButton(7, 11, 8, 1, "cancel", function()wm.closeWindow(PrinterListWindow) selectPrinterRunning = false selectedPrinter = 0 end)
  681. wm.addElement(PrinterListWindow, PrinterListCancelButton)
  682.  
  683. if fromManager == true then
  684. local PrinterNewButton = gui.newButton(16, 11, 13, 1, "new printer", function()wm.closeWindow(PrinterListWindow) selectPrinterRunning = false selectedPrinter = -1 end)
  685. wm.addElement(PrinterListWindow, PrinterNewButton)
  686.  
  687. local PrinterRemoveButton = gui.newButton(30, 11, 8, 1, "remove", function()removePrinter(gui.getElementValue(printerSlider)) wm.closeWindow(PrinterListWindow) selectPrinterRunning = false selectedPrinter = 0 end)
  688. wm.addElement(PrinterListWindow, PrinterRemoveButton)
  689. end
  690.  
  691. wm.raiseWindow(PrinterListWindow)
  692. while selectPrinterRunning == true do
  693.  
  694. gui.setElementText(labelName, List[selectedPrinter].name)
  695. gui.drawElement(PrinterListWindow, labelName)
  696. if List[selectedPrinter].typ == 0 then
  697. gui.setElementText(labelType, "Local printer")
  698. else
  699. gui.setElementText(labelType, "Network printer")
  700. end
  701. gui.drawElement(PrinterListWindow, labelType)
  702. gui.setElementText(labelLocation, List[selectedPrinter].position)
  703. gui.drawElement(PrinterListWindow, labelLocation)
  704. gui.setElementText(labelDescription, List[selectedPrinter].description)
  705. gui.drawElement(PrinterListWindow, labelDescription)
  706. os.sleep(0.00001)
  707. end
  708.  
  709. return selectedPrinter
  710. end
  711. return printServer
Advertisement
Add Comment
Please, Sign In to add comment