Skip to content

Instantly share code, notes, and snippets.

@jjam3774
Last active December 20, 2015 17:49
Show Gist options
  • Save jjam3774/6171582 to your computer and use it in GitHub Desktop.
Save jjam3774/6171582 to your computer and use it in GitHub Desktop.
Another sketch of what Jython can do with Swing.. No threading done.
#!/usr/bin/jython
import javax.swing as swing
from java.awt import BorderLayout, GridLayout
import java
import os
class jGUI(swing.JFrame):
def __init__(self):
swing.JFrame.__init__(self, title="Server Specs", size=(350, 400), defaultCloseOperation = swing.JFrame.EXIT_ON_CLOSE)
self.contentPane.layout = BorderLayout()
self.contentPane.add(self.buildScroll(), BorderLayout.CENTER)
self.contentPane.add(self.buildButtons(), BorderLayout.SOUTH)
###########################################################################################################
# Function that creates the buttons for the GUI
###########################################################################################################
def buildButtons(self):
self.panel = swing.JPanel(GridLayout(1,4))
self.panel.add(swing.JButton("BIOS", actionPerformed=self.getBios))
self.panel.add(swing.JButton("STATS", actionPerformed=self.getStats))
self.panel.add(swing.JButton("IP", actionPerformed=self.getIp))
self.panel.add(swing.JButton("APPS", actionPerformed=self.getBios))
return self.panel
###########################################################################################################
# Function that creates the Scroll and Text Area
###########################################################################################################
def buildScroll(self):
row = swing.Box.createHorizontalBox()
self.text = swing.JTextArea()
scroll = swing.JScrollPane(swing.JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,swing.JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED)
scroll.viewport.view = self.text
row.add(scroll)
return row
def getBios(self, event):
command = 'dmidecode -t bios'
message = command + " info has been generated"
windowTitle = "Completed"
self.text.append("===============================================================\n")
self.text.append("\t\tBIOS\n")
self.text.append("===============================================================\n")
self.text.append(os.popen(command).read())
swing.JOptionPane.showMessageDialog(None, message, windowTitle, swing.JOptionPane.INFORMATION_MESSAGE)
def getIp(self, event):
command= 'ifconfig'
message = command + " info has been generated"
windowTitle = "Completed"
self.text.append("===============================================================\n")
self.text.append("\t\tIP INFO\n")
self.text.append("===============================================================\n")
self.text.append(os.popen(command).read())
swing.JOptionPane.showMessageDialog(None, command + " info has been generated", windowTitle, swing.JOptionPane.INFORMATION_MESSAGE)
def getStats(self, event):
command= 'uptime'
message = command + " info has been generated"
windowTitle = "Completed"
self.text.append("===============================================================\n")
self.text.append("\t\tSERVER STATS\n")
self.text.append("===============================================================\n")
self.text.append(os.popen(command).read())
swing.JOptionPane.showMessageDialog(None, command + " info has been generated", windowTitle, swing.JOptionPane.INFORMATION_MESSAGE)
if __name__ == "__main__":
jGUI().show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment