Code:
#!/usr/bin/env python
# SNG (Star Name Generator) is based on the ELITE game
# Name Generator code written by isomage
# http://http://axiscity.hexamon.net/users/isomage/
# or http://cartographersguild.com
# GUI by Sagenlicht for easier use
# http://cartographersguild.com
# Version 0.5
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import pygtk
pygtk.require('2.0')
import gtk
import random
class SNG:
def __init__(self, useRandom):
if useRandom:
self.seed = [random.randint(0, 0xffff), random.randint(0, 0xffff), random.randint(0, 0xffff)]
else:
self.seed = [0x5A4A, 0x0248, 0xB753]
def tweakseed(self):
temp = (self.seed[0] + self.seed[1] + self.seed[2]) % 0x10000
self.seed[0] = self.seed[1]
self.seed[1] = self.seed[2]
self.seed[2] = temp
def generate_name(self):
self.digraphs = "..lexegezacebisousesarmaindirea.eratenberalavetiedorquanteisrion"
longnameflag = self.seed[0] & 0x40
name = ""
for n in range(4):
d = ((self.seed[2] >> 8) & 0x1f) << 1
self.tweakseed()
if n < 3 or longnameflag:
name += self.digraphs[d:d+2]
return name.replace(".", "").title()
def generate_list(self, namesToGenerate):
nameList = []
for i in xrange(namesToGenerate):
nameList.append(self.generate_name())
return nameList
class GUI:
def __init__(self):
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.connect( "destroy", self.destroy )
self.window.set_title( "ELITE based Name Generator" )
self.window.set_border_width(5)
self.window.set_size_request(250, 400)
self.window.show()
self.mainBox = gtk.VBox()
self.mainBox.set_border_width(5)
self.mainBox.set_size_request(250, 400)
self.window.add(self.mainBox)
self.mainBox.show()
self.generateFrame = gtk.Frame(label="Names to generate")
self.mainBox.pack_start(self.generateFrame, False, False, 1)
self.generateFrame.set_label_align(0.5, 0.5)
self.generateFrame.show()
self.comboList = gtk.combo_box_new_text()
self.comboList.append_text ("5")
self.comboList.append_text ("10")
self.comboList.append_text ("25")
self.comboList.append_text ("50")
self.comboList.set_active (1)
self.generateFrame.add(self.comboList)
self.comboList.show()
self.modeFrame = gtk.Frame(label="Choose Mode")
self.mainBox.pack_start(self.modeFrame, False, False, 1)
self.modeFrame.set_label_align(0.5, 0.5)
self.modeFrame.show()
self.modeBox = gtk.VBox()
self.modeBox.set_border_width(5)
self.modeBox.set_size_request(200, 60)
self.modeFrame.add(self.modeBox)
self.modeBox.show()
self.randomButton = gtk.RadioButton(None, "Random Star Names")
self.modeBox.pack_start(self.randomButton, False, False, 1)
self.randomButton.show()
self.randomButton.set_active(True)
self.eliteButton = gtk.RadioButton(self.randomButton, "ELITE Game Names")
self.modeBox.pack_start(self.eliteButton, False, False, 1)
self.eliteButton.show()
self.nameFrame = gtk.Frame(label="Generated Names")
self.mainBox.pack_start(self.nameFrame, True, True, 1)
self.nameFrame.set_label_align(0.5, 0.5)
self.nameFrame.show()
self.tmpBox = gtk.VBox()
self.tmpBox.set_border_width(0)
self.tmpBox.set_size_request(180, 200)
self.nameFrame.add(self.tmpBox)
self.tmpBox.show()
scroll_box = gtk.ScrolledWindow()
scroll_box.set_border_width(5)
scroll_box.set_policy( gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC )
self.tmpBox.pack_start( scroll_box, True, True, 0 )
scroll_box.show()
self.namesBox = gtk.TextView(buffer=None)
self.namesBoxBuffer = self.namesBox.get_buffer()
self.namesBox.set_editable(False)
self.namesBox.set_cursor_visible(False)
self.namesBox.set_wrap_mode(gtk.WRAP_WORD)
self.namesBox.set_justification(gtk.JUSTIFY_LEFT)
self.namesBox.show()
scroll_box.add_with_viewport(self.namesBox)
self.buttonBox = gtk.HButtonBox()
self.buttonBox.set_layout(gtk.BUTTONBOX_END)
self.buttonBox.set_spacing(5)
self.buttonBox.set_border_width(1)
self.buttonBox.set_size_request(250, 50)
self.mainBox.pack_start(self.buttonBox, True, True, 1)
self.buttonBox.show()
cancelButton = gtk.Button( stock=gtk.STOCK_CLOSE )
cancelButton.connect_object( "clicked", gtk.Widget.destroy, self.window)
self.buttonBox.add(cancelButton)
cancelButton.show()
okButton = gtk.Button(stock=gtk.STOCK_OK)
okButton.connect("clicked", self.ok_clicked)
self.buttonBox.add(okButton)
okButton.show()
def ok_clicked( self, widget, data = None):
if self.randomButton.get_active():
useRandom = True
if self.eliteButton.get_active():
useRandom = False
generateNames = SNG(useRandom).generate_list(int(self.comboList.get_active_text()))
tmpString = ""
heightRequest = 0
for name in generateNames:
tmpString = (tmpString + "%s" % name + "\n")
self.namesBoxBuffer.set_text(tmpString)
heightRequest = heightRequest + 14
self.namesBox.set_size_request(180, heightRequest)
def destroy( self, widget, data=None ):
gtk.main_quit()
def gtkCall(self):
gtk.main()
if __name__ == "__main__":
callSNG = GUI()
callSNG.gtkCall()
EDIT: Added a screenshot of the GUI. Dont get irritated by the german button, thats language depend so no worries