Advertisement
Guest User

Untitled

a guest
Feb 24th, 2019
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.75 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. import gtk
  5. import re
  6. import os
  7. import time
  8.  
  9. active_button = 0
  10.  
  11. servers = [["Server 1","/home/myname/Desktop/server1","server.jar"],
  12.             ["Serveur 2","/home/myname/Desktop/server2","server.jar"]]
  13.  
  14. def button_selection(button, num):
  15.     global active_button
  16.     state=button.state
  17.     if state >= 1:
  18.         active_button = int(num)
  19.  
  20. def validation(widget):
  21.     path = servers[active_button][1]
  22.     server = servers[active_button][2]
  23.     command = """gnome-terminal --working-directory="%s" -e 'java -jar %s'""" % (path, server)
  24.     print(command)
  25.     os.system(command)
  26.  
  27. def save(widget):
  28.     path = servers[active_button][1]
  29.     server = servers[active_button][2]
  30.     print "cp -a '%s' /home/myname/Documents/backups_minecraft_servers/%s" % (path+"/world", time.strftime("%d_%m_%Y-%T"))
  31.     os.system("cp -a '%s' /home/myname/Documents/backups_minecraft_servers/%s" % (path+"/world", time.strftime("%d_%m_%Y-%T")))
  32.     print("Backup finished")
  33.  
  34. def main():
  35.     window = gtk.Window()
  36.     vbox = gtk.VBox()
  37.     hbox = gtk.HBox()
  38.  
  39.     validate = gtk.Button("Validate")
  40.     validate.connect("clicked", validation)
  41.  
  42.     backup = gtk.Button("Backup")
  43.     backup.connect("clicked", save)
  44.  
  45.     hbox.pack_start(validate)
  46.     hbox.pack_start(vbox)
  47.     hbox.pack_start(backup)
  48.  
  49.     buttons = [gtk.RadioButton(None, servers[0][0])]
  50.     vbox.pack_start(buttons[0])
  51.  
  52.     for server in servers[1:]:
  53.         buttons.append(gtk.RadioButton(buttons[0], server[0]))
  54.         vbox.pack_start(buttons[-1])
  55.  
  56.     for i in range(len(buttons)):
  57.         buttons[i].connect("toggled", button_selection, i)
  58.  
  59.  
  60.     window.add(hbox)
  61.     window.show_all()
  62.     gtk.main()
  63.  
  64. if __name__=="__main__":
  65.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement