def __init__(self, engine, **params): gui.Container.__init__(self, **params) self.engine = engine self.value = gui.Form() # item editor state self.itemNum = None # dialogs # menu title self.tTitle = gui.Table(width=272, height=32) self.tTitle.tr() self.tTitle.td(gui.Label("NPC Editor", name='npcTitle', color=UI_FONT_COLOR)) # content self.tContent = gui.Table(width=272, height=123) self.tContent.tr() self.tContent.tr() self.tContent.td(gui.Label('Name:', color=UI_FONT_COLOR), colspan=2) self.tContent.tr() self.tContent.td(gui.Input('', size=26, name='inpNpcName'), colspan=2, valign=-1) self.tContent.tr() self.tContent.td(gui.Label('Behaviour:', color=UI_FONT_COLOR), colspan=2) self.tContent.tr() e = gui.Select(name='selBehaviour') e.add('Attack on sight', 0) e.add('Attack when attacked', 1) e.add('Friendly', 2) e.add('Shopkeeper', 3) e.add('Guard', 4) e.value = 0 e.connect(gui.CHANGE, self.updateType, None) self.tContent.td(e, colspan=2) # data input self.tData = gui.Table(width=272, height=75) # bottom buttons self.tBottom = gui.Table(width=272, height=200) self.tBottom.tr() self.saveButton = gui.Button("Add NPC", width=100, height=40) self.saveButton .connect(gui.CLICK, self.saveNPC, None) self.tBottom.td(self.saveButton) e = gui.Button("Cancel", width=100, height=40) e.connect(gui.CLICK, self.cancel, None) self.tBottom.td(e) self.add(self.tTitle, 0, 0) self.add(self.tContent, 0, 100) self.add(self.tData, 0, 255) self.add(self.tBottom, 0, 368)
def _create_solver_select(self): select = gui.Select() label = gui.Label('Choose Solver') for _, solver in self._solvers.items(): select.add(solver.NAME, solver.TYPE) select.value = self._get_default_solver().TYPE select.connect(gui.CHANGE, self._on_solver_change, select) return label, select
def __init__(self, n=None): main = gui.Table() gui.Dialog.__init__(self, gui.Label(lang.settings), main) liste = gui.List(200, 114) liste.value = themename themes = "themes" for dire in os.listdir(themes): liste.add(str(dire), value=dire) self.liste = liste liste = gui.Select() liste.value = cache["columns"] for x in (1, 2, 3, 4, 5): liste.add(str(x), value=x) self.columns = liste backupswitch = gui.Switch() backupswitch.value = cache["do_backup"] self.backup = backupswitch sizelist = gui.Select(value=thumbsize) sizelist.add(lang.none, 0) sizelist.add(lang.small, (420.0, 120.0)) sizelist.add(lang.medium, (630.0, 180.0)) sizelist.add(lang.large, (840.0, 240.0)) sizelist.add(lang.very_large, (1260.0, 360.0)) self.sizelist = sizelist main.td(gui.Label(lang.warning, color=(127, 0, 0)), colspan=2) main.tr() main.td(gui.Label(lang.theme_select)) main.td(gui.Label(lang.thumbsize)) main.tr() main.td(self.liste, rowspan=5) main.td(sizelist) main.tr() main.td(gui.Label(lang.world_columns), col=1, row=3) main.tr() main.td(self.columns, col=1, row=4) main.tr() main.td(gui.Label(lang.mk_backups), col=1, row=5) main.tr() main.td(backupswitch, col=1, row=6) self.open()
def start_select(self,attrs): r = self.attrs_to_map(attrs) params = {} name,value = r.get('name',None),r.get('value',None) e = gui.Select(name=name,value=value,**params) self.map_to_connects(e,r) self.item.add(e) self.myopen('select',e)
def buildSkinSelecter(self): newActor = self.script.controls['actor-group-focus'].value skinSelecter = gui.Select(name='actor-select-skin', value=newActor.directory, cols=4) skinSelecter.connect(gui.SELECT, self.changeSkin) for aSkin in actors: if aSkin != "narrator": prettyActor = _(aSkin.replace('_', ' ').title()) skinSelecter.add(prettyActor, aSkin) self.editablesDocumentLeft.add(gui.Label(_("Actor: "))) self.editablesDocumentLeft.add(skinSelecter) self.spaceEditablesDocumentLeft()
def buildPoseSelecter(self): focusedActor = self.script.controls['actor-group-focus'].value poses = focusedActor.poses pose = self.script.frames[0][focusedActor].pose poseSelecter = gui.Select(name='actor-select-pose', value=pose, cols=3) poseSelecter.connect(gui.SELECT, self.changePose) for aPose in poses: prettyPose = _(aPose.replace('_', ' ').title()) poseSelecter.add(prettyPose, aPose) self.editablesDocumentRight.add(gui.Label(_("Initial Pose: "))) self.editablesDocumentRight.add(poseSelecter) self.spaceEditablesDocumentRight()
def buildLookSelecter(self): focusedActor = self.script.controls['actor-group-focus'].value looks = focusedActor.looks look = self.script.frames[0][focusedActor].look lookSelecter = gui.Select(name='actor-select-look', value=look, cols=4) lookSelecter.connect(gui.SELECT, self.changeLook) for aLook in looks: prettyLook = _(aLook.replace('_', ' ').title()) lookSelecter.add(prettyLook, aLook) self.editablesDocumentRight.add(gui.Label(_("Initial Look: "))) self.editablesDocumentRight.add(lookSelecter) self.spaceEditablesDocumentRight()
def buildLookSelecter(self): actor = self.script.controls['write-group-focus'].value looks = actor.looks look = actor.state.look lookSelecter = gui.Select(name='write-select-look', value=look, cols=4) lookSelecter.connect(gui.SELECT, self.changeLook) for aLook in looks: prettyLook = _(aLook.replace('_', ' ').title()) lookSelecter.add(prettyLook, aLook) self.selectablesDocumentLeft.add(gui.Label(_("Look: "))) self.selectablesDocumentLeft.add(lookSelecter) self.spaceSelectableDocumentLeft()
def buildPoseSelecter(self): actor = self.script.controls['write-group-focus'].value poses = actor.poses pose = actor.state.pose poseSelecter = gui.Select(name='write-select-pose', value=pose, cols=3) poseSelecter.connect(gui.SELECT, self.changePose) for aPose in poses: prettyPose = _(aPose.replace('_', ' ').title()) poseSelecter.add(prettyPose, aPose) self.selectablesDocumentLeft.add(gui.Label(_("Change Pose: "))) self.selectablesDocumentLeft.add(poseSelecter) self.spaceSelectableDocumentLeft()
def buildVoiceSelecter(self): newActor = self.script.controls['actor-group-focus'].value voiceSelecter = gui.Select(name='actor-select-voice', value=newActor.voice, cols=8) voiceSelecter.connect(gui.SELECT, self.changeVoice) for aVoice in voices: voiceSelecter.add(_(aVoice.visibleName), aVoice) self.editablesDocumentLeft.add(gui.Label(_("Voice: "))) self.editablesDocumentLeft.add(voiceSelecter) speakButton = gui.Button(_("Test"), name='actor-button-test') speakButton.connectWeakly(gui.CLICK, newActor.quickSpeak, defaults['voice-test']) self.editablesDocumentLeft.space((10, 1)) self.editablesDocumentLeft.add(speakButton) self.spaceEditablesDocumentLeft()
def __init__(self, **params): gui.Table.__init__(self, **params) self.value = gui.Form() '''self.content = gui.Table() self.scrollArea = gui.ScrollArea(self.content, width=270, height=372, hscrollbar=False) self.tr() self.td(self.scrollArea) self.tr() g = gui.Group(name="grpTileType") self.content.td(gui.Label("Ground", color=UI_FONT_COLOR)) self.content.td(gui.Spacer(10, 0)) e = gui.Radio(g, value=1) e.click() self.content.td(e) self.content.tr() self.content.td(gui.Label("Fringe", color=UI_FONT_COLOR)) self.content.td(gui.Spacer(10, 0)) self.content.td(gui.Radio(g, value=2)) ''' self.tr() g = gui.Group(name="grpTileType") self.td(gui.Label("Ground", color=UI_FONT_COLOR)) self.td(gui.Spacer(10, 0)) e = gui.Radio(g, value=1) e.click() self.td(e) self.tr() self.td(gui.Label("Fringe", color=UI_FONT_COLOR)) self.td(gui.Spacer(10, 0)) self.td(gui.Radio(g, value=2)) e = gui.Select(name='selTileType') e.add('Layer 1', 0) e.add('Layer 2', 1) e.add('Layer 3', 2) e.add('Fringe', 3) e.value = 0 self.td(e)
def __init__(self, game_screen): self._screen = game_screen self._app = gui.Desktop() self._app.connect(gui.QUIT, self._app.quit, None) self._table = gui.Table() self._table.tr() self._table.td(gui.Label("Select Player")) self._select = gui.Select() self._select.add("Arythrea", player.ARYTHREA) self._table.tr() self._table.td(self._select) self._table.tr() button = gui.Button("Start Solo Game") self._table.td(button) button.connect(gui.CLICK, self._commit_values)
def __init__(self, config): title = gui.Label("New simulation") t = gui.Table() t.tr() t.td(gui.Label("Bots:"), align=1) t.td(gui.Input(name="n", value=config['n'], size=4), align=-1) def open_file_browser(arg): d = gui.FileDialog() d.connect(gui.CHANGE, handle_file_browser_closed, d) d.open() def handle_file_browser_closed(dlg): if dlg.value: program.value = dlg.value t.tr() t.td(gui.Label('Program:')) program = gui.Input(name="program", value=config['program']) t.td(program) b = gui.Button("Browse...") b.connect(gui.CLICK, open_file_browser, gui.CHANGE) t.td(b) t.tr() t.td(gui.Label("Formation:")) e = gui.Select(name="formation", value=config['formation']) e.add("Circle", 'CIRCLE') e.add("Piled", 'PILED') e.add("Line", 'LINE') e.add("Random", 'RANDOM') t.td(e, align=-1) t.tr() e = gui.Button("Okay") e.connect(gui.CLICK, self.send, gui.CHANGE) t.td(e, align=-1) e = gui.Button("Cancel") e.connect(gui.CLICK, self.close, None) t.td(e, align=1) self.value = None gui.Dialog.__init__(self, title, t)
def __init__(self,level): self.level = level title = gui.Label("Jump to level") doc = gui.Document() table = gui.Table() #table.td(gui.Label("select level"),colspan=1) table.tr() # dont set the current as default since it could be the testlevel #levname = level.__class__.__module__.split(".")[1] levname = "" sel = gui.Select(levname,width=150) self.sel = sel #sel.add("test level","testlevel") ## use the import to see what level scripts are available ## and add the script filenames to list i = j = 1 while True: levelName = "gamelevel" + str(i) + "_" + str(j) # this is bit rough way to find out the level scripts try: exec("from levels import " + levelName) sel.add(levelName,levelName) j += 1 except ImportError, err: # filter the other import errors if str(err) != ("cannot import name "+levelName): raise "excepted import error from level script "+levelName+": "+str(err) j = 1 i += 1 if i > 72: break
def __init__(self, **params): gui.Table.__init__(self, **params) self.value = gui.Form() # dialogs openNpcDialog = OpenNPCDialog(self) self.tr() self.td(gui.Spacer(10, 70)) self.tr() e = gui.Button("Open NPC...", width=100) e.connect(gui.CLICK, openNpcDialog.openDialog, None) self.td(e, colspan=2) self.tr() self.td(gui.Spacer(10, 20)) self.tr() self.td(gui.Label('Name:', color=UI_FONT_COLOR), colspan=2) self.tr() self.td(gui.Input('', size=26, name='inpNpcName'), colspan=2, valign=-1) self.tr() self.td(gui.Spacer(10, 20)) self.tr() self.td(gui.Label('Behaviour:', color=UI_FONT_COLOR), colspan=2) self.tr() e = gui.Select(name='selBehaviour') e.add('Attack on sight', 0) e.add('Attack when attacked', 1) e.add('Friendly', 2) e.add('Shopkeeper', 3) e.add('Guard', 4) e.value = 0 #e.connect(gui.CHANGE, self.updateType, None) self.td(e, colspan=2)
g = gui.Group(value=[1, 3]) c.td(gui.Checkbox(g, value=1)) c.td(gui.Checkbox(g, value=2)) c.td(gui.Checkbox(g, value=3)) ## c.tr() c.td(gui.Label("Radio")) g = gui.Group() c.td(gui.Radio(g, value=1)) c.td(gui.Radio(g, value=2)) c.td(gui.Radio(g, value=3)) c.tr() c.td(gui.Label("Select")) e = gui.Select() e.add("Goat", 'goat') e.add("Horse", 'horse') e.add("Dog", 'dog') e.add("Pig", 'pig') c.td(e, colspan=3) c.tr() c.td(gui.Label("Tool")) g = gui.Group(value='b') c.td(gui.Tool(g, gui.Label('A'), value='a')) c.td(gui.Tool(g, gui.Label('B'), value='b')) c.td(gui.Tool(g, gui.Label('C'), value='c')) c.tr() c.td(gui.Label("Input"))
def __init__(self, interface=None, **params): gui.Container.__init__(self, **params) self.Interface = interface self.add( gui.Label("Microscope Analyzer - HMNL (tm) 2016", color=colors.red), 95, 5) # Select joystick GUI self.add(gui.Label("Select joystick"), 7, 32) self.joystick_selection = gui.Select() # self.joystick_selection.add("None",'None') self.joystick_selection.add("Shenzhen", 'Shenzhen') self.joystick_selection.add("The unworking backup", "The unworking backup") self.joystick_selection.add("Xbox >>>>> Playstation", "Xbox >>>>> Playstation") self.add(self.joystick_selection, 150, 30) # Update joystick button def UpdateJoystickButtonCallBack(): if self.joystick_selection.value == "Shenzhen" or self.joystick_selection.value == "Xbox >>>>> Playstation": self.Interface.initialize_joystick() else: self.Interface.initialize_joystick(self, a_button_num=0, x_button_num=2, y_button_num=3, b_button_num=1, rb_button_num=5, start_button_num=7, lx_axis=0, ly_axis=1, trigger_axis=2, rx_axis=3, ry_axis=4, rt_button_num=None, lt_button_num=None) self.update_joystick_button = gui.Button("Update JS") self.update_joystick_button.connect(gui.CLICK, UpdateJoystickButtonCallBack) self.add(self.update_joystick_button, 400, 32) # Input FMSPE directory / internal callback functions to handle buttons being clicked self.add(gui.Label("FMPSE directory", color=colors.black), 7, 62) def handle_fmspe_file_browser_closed(dlg): if dlg.value: self.fmspe_dir_input.value = dlg.value def open_fmspe_file_browser(arg): d = gui.FileDialog(path=root_dir) # d = gui.FileDialog(path = "C:\\Users\\HMNL Leica\\Documents\\Filmmetrics\\Measurements") d.connect(gui.CHANGE, handle_fmspe_file_browser_closed, d) d.open() self.fmspe_dir_input = gui.Input(size=25) self.add(self.fmspe_dir_input, 150, 60) self.fmspe_browse_button = gui.Button("Browse...") self.fmspe_browse_button.connect(gui.CLICK, open_fmspe_file_browser, None) self.add(self.fmspe_browse_button, 400, 62) # Input XML directory / internal callback functions to handle buttons being clicked self.add(gui.Label("XML directory", color=colors.black), 7, 92) def handle_xml_file_browser_closed(dlg): if dlg.value: self.xml_dir_input.value = dlg.value def open_xml_file_browser(arg): d = gui.FileDialog(path=root_dir) # d = gui.FileDialog(path = "C:\\Users\\HMNL Leica\\Documents\\Filmmetrics\\Measurements") d.connect(gui.CHANGE, handle_xml_file_browser_closed, d) d.open() self.xml_dir_input = gui.Input(size=25) self.add(self.xml_dir_input, 150, 90) self.xml_browse_button = gui.Button("Browse...") self.xml_browse_button.connect(gui.CLICK, open_xml_file_browser, None) self.add(self.xml_browse_button, 400, 92) # Input image directory / internal callback functions to handle buttons being clicked self.add(gui.Label("Image directory", color=colors.black), 7, 122) def handle_image_file_browser_closed(dlg): if dlg.value: self.image_dir_input.value = dlg.value def open_image_file_browser(arg): d = gui.FileDialog(path=root_dir) # d = gui.FileDialog(path = "C:\\Users\\HMNL Leica\\Documents\\Filmmetrics\\Measurements") d.connect(gui.CHANGE, handle_image_file_browser_closed, d) d.open() self.image_dir_input = gui.Input(size=25) self.add(self.image_dir_input, 150, 120) self.image_browse_button = gui.Button("Browse...") self.image_browse_button.connect(gui.CLICK, open_image_file_browser, None) self.add(self.image_browse_button, 400, 122) # Get the name that the user wants the map to be called self.add(gui.Label("Map name"), 7, 152) self.map_name_input = gui.Input(size=25) self.add(self.map_name_input, 107, 150) # Get the units of measurement self.add(gui.Label("Units"), 365, 152) self.unit_selection = gui.Select() self.unit_selection.add("um", 'um') self.unit_selection.add("mm", 'mm') self.add(self.unit_selection, 425, 150) # Inputs for the mapping function self.add(gui.Label("Number Points X"), 7, 182) self.num_pts_x_input = gui.Input(size=5) self.add(self.num_pts_x_input, 155, 180) self.add(gui.Label("Distance b/w Points X"), 237, 182) self.distance_bw_pts_x_input = gui.Input(size=5) self.add(self.distance_bw_pts_x_input, 425, 180) self.add(gui.Label("Number Points Y"), 7, 212) self.num_pts_y_input = gui.Input(size=5) self.add(self.num_pts_y_input, 155, 210) self.add(gui.Label("Distance b/w Points Y"), 237, 212) self.distance_bw_pts_y_input = gui.Input(size=5) self.add(self.distance_bw_pts_y_input, 425, 210) # Measure, Start/Pause, Stop buttons def MeasureOnceButtonCallback(): self.Interface.message1 = "Taking measurement!" self.Interface.take_measurement() self.take_measurement_button = gui.Button("Measure once") self.take_measurement_button.connect(gui.CLICK, MeasureOnceButtonCallback) self.add(self.take_measurement_button, 17, 242) def StartOrPauseButtonCallback(): print "Map started!" if not self.started_map: # If it's the first time, then start taking the map self.started_map = True try: self.Interface.take_map( self.map_name_input.value, int(self.num_pts_x_input.value), int(self.distance_bw_pts_x_input.value), int(self.num_pts_y_input.value), int(self.distance_bw_pts_y_input.value), self.unit_selection.value, self.Microscope_Base) self.started_map = False except Exception: print "Error with taking map!" else: # If a map is already in progress, pause it self.Interface.pause_button_pressed = True self.start_or_pause_button = gui.Button("Start / Pause Map") self.start_or_pause_button.connect(gui.CLICK, StartOrPauseButtonCallback) self.add(self.start_or_pause_button, 190, 242) def StopButtonCallback(): self.Interface.stop_button_pressed = True self.stop_button = gui.Button("Stop map") self.stop_button.connect(gui.CLICK, StopButtonCallback) self.add(self.stop_button, 390, 242) # ----------------------------------------------- Post Processing GUI Components ------------------------------------------------------------------------------- xalign = 830 # Alignment between standalone program and the final program attribute_items = [ "Layer Roughnesses", "Layer Thicknesses", "Measured FFT Intensity", "Measured FFT Thickness" ] # Attributes that are available to write to .txt file cart_items = {} self.add(gui.Label("Post Processing Shopping Cart", color=colors.red), xalign + 85, 10) # Attributes list from which the user can pick out items initial_attributes_list_object = gui.List(width=180, height=140) for i in range(len(attribute_items)): item = attribute_items[i] initial_attributes_list_object.add(item, value=i) self.add(initial_attributes_list_object, xalign + 10, 40) # List of items that the user selected into their carts cart_items_object = gui.List(width=180, height=140) self.add(cart_items_object, xalign + 210, 40) # Functions to add/remove items from cart def add_item_to_cart(arg): v = initial_attributes_list_object.value if v != None and v not in cart_items: cart_items[v] = attribute_items[v] index = v cart_items_object.add(attribute_items[index], value=index) cart_items_object.resize() cart_items_object.repaint() def remove_item_from_cart(arg): v = cart_items_object.value if v != None: cart_items.pop(v) cart_items_object.remove(v) cart_items_object.resize() cart_items_object.repaint() cart_items_object.value = None # Performs analysis and saves it as a .txt file in the out directory that the user specifies def check_out(arg): self.Interface.PostProcessAndSave( xml_directory_post_processing.value, text_dir_input.value, post_map_name_input.value, cart_items) # Cart button GUI objects... the functions are defined above add_to_cart_button = gui.Button("Add to cart", width=90) add_to_cart_button.connect(gui.CLICK, add_item_to_cart, None) self.add(add_to_cart_button, xalign + 10, 190) remove_from_cart_button = gui.Button("Remove from cart", width=90) remove_from_cart_button.connect(gui.CLICK, remove_item_from_cart, None) self.add(remove_from_cart_button, xalign + 125, 190) save_analysis_button = gui.Button("Checkout", width=85) save_analysis_button.connect(gui.CLICK, check_out, None) self.add(save_analysis_button, xalign + 290, 190) # The name of the map that we should be looking for self.add(gui.Label("Map name"), xalign + 7, 222) post_map_name_input = gui.Input(size=28) post_map_name_input.value = "Columbus" self.add(post_map_name_input, xalign + 125, 220) # Post processing XML directory input def handle_xml_post_file_browser_closed(dlg): if dlg.value: xml_directory_post_processing.value = dlg.value def open_xml_post_file_browser(arg): d = gui.FileDialog( path="C:\\Users\\HMNL-Filmmetrics\\Measurements\\") d.connect(gui.CHANGE, handle_xml_post_file_browser_closed, d) d.open() xml_directory_post_processing = gui.Input(size=19) xml_directory_post_processing.value = "{}XML\\".format(root_dir) self.add(gui.Label("XML Directory"), xalign + 7, 252) self.add(xml_directory_post_processing, xalign + 125, 250) post_browse_button = gui.Button("Browse", width=50) self.add(post_browse_button, xalign + 315, 252) post_browse_button.connect(gui.CLICK, open_xml_post_file_browser, None) # Output file directory def handle_text_browser_closed(dlg): if dlg.value: text_dir_input.value = dlg.value def open_text_file_browser(arg): d = gui.FileDialog(path=root_dir) d.connect(gui.CHANGE, handle_text_browser_closed, d) d.open() text_dir_input = gui.Input(size=19) text_dir_input.value = "{}AnalysisFiles\\".format(root_dir) self.add(gui.Label("Out Directory"), xalign + 7, 282) self.add(text_dir_input, xalign + 125, 280) text_dir_browse_button = gui.Button("Browse", width=50) self.add(text_dir_browse_button, xalign + 315, 282) text_dir_browse_button.connect(gui.CLICK, open_text_file_browser, None) # ------------------------------------------------------- View / Delete Map History ----------------------------------------------------------------- yalign = 325 # Alignment between standalone program and the final program cart_items = {} self.add(gui.Label("Map History", color=colors.red), 575, yalign - 10) lines = [line.rstrip('\n') for line in open("History/map_history.txt")] # Attributes list from which the user can pick out items maps_in_history_list = gui.List(width=200, height=270) for i in range(len(lines)): vals_array = lines[i].split(" ") new_map_info = FinishedMap(vals_array[0], vals_array[1], vals_array[2], vals_array[3], vals_array[4], vals_array[5], vals_array[6], vals_array[7], vals_array[8], vals_array[9], vals_array[10]) self.Interface.map_history.append(new_map_info) maps_in_history_list.add(new_map_info.map_name, value=i) self.add(maps_in_history_list, 310, yalign + 30) MapNameLabel = gui.Input(size=40) FMSPEDirLabel = gui.Input(size=40) XMLDirLabel = gui.Input(size=40) ImageDirLabel = gui.Input(size=40) NumMeasurementsXLabel = gui.Input(size=40) DistanceMeasurementsXLabel = gui.Input(size=40) NumMeasurementsYLabel = gui.Input(size=40) DistanceMeasurementsYLabel = gui.Input(size=40) DateTakenLabel = gui.Input(size=40) TimeTakenLabel = gui.Input(size=40) UnitsLabel = gui.Input(size=40) self.add(gui.Label("Map name : "), 535, yalign + 30) self.add(gui.Label("FMSPE Dir : "), 535, yalign + 55) self.add(gui.Label("XML Dir : "), 535, yalign + 80) self.add(gui.Label("Image Dir : "), 535, yalign + 105) self.add(gui.Label("# Measurements x : "), 535, yalign + 130) self.add(gui.Label("Distance b/w x meas. : "), 535, yalign + 155) self.add(gui.Label("# Measurements y : "), 535, yalign + 180) self.add(gui.Label("Distance b/w y meas.: "), 535, yalign + 205) self.add(gui.Label("Date taken : "), 535, yalign + 230) self.add(gui.Label("Time taken : "), 535, yalign + 255) self.add(gui.Label("Units: "), 535, yalign + 280) self.add(MapNameLabel, 720, yalign + 30) self.add(FMSPEDirLabel, 720, yalign + 55) self.add(XMLDirLabel, 720, yalign + 80) self.add(ImageDirLabel, 720, yalign + 105) self.add(NumMeasurementsXLabel, 720, yalign + 130) self.add(DistanceMeasurementsXLabel, 720, yalign + 155) self.add(NumMeasurementsYLabel, 720, yalign + 180) self.add(DistanceMeasurementsYLabel, 720, yalign + 205) self.add(DateTakenLabel, 720, yalign + 230) self.add(TimeTakenLabel, 720, yalign + 255) self.add(UnitsLabel, 720, yalign + 280) def show_info(): v = maps_in_history_list.value if v == None: return try: MapNameLabel.value = "{}".format( self.Interface.map_history[v].map_name) FMSPEDirLabel.value = "{}".format( self.Interface.map_history[v].fmspedir) XMLDirLabel.value = "{}".format( self.Interface.map_history[v].xmldir) ImageDirLabel.value = "{}".format( self.Interface.map_history[v].imagedir) NumMeasurementsXLabel.value = "{}".format( self.Interface.map_history[v].numx) DistanceMeasurementsXLabel.value = "{}".format( self.Interface.map_history[v].distbwx) NumMeasurementsYLabel.value = "{}".format( self.Interface.map_history[v].numy) DistanceMeasurementsYLabel.value = "{}".format( self.Interface.map_history[v].distbwy) DateTakenLabel.value = "{}".format( self.Interface.map_history[v].date) TimeTakenLabel.value = "{}".format( self.Interface.map_history[v].time) UnitsLabel.value = "{}".format( self.Interface.map_history[v].units) except BaseException: pass # print v # print MapNameLabel.value maps_in_history_list.connect(gui.CLICK, show_info) # Implementing delete def delete(): v = maps_in_history_list.value if v == None: return # Get directories and map name map_name = self.Interface.map_history[v].map_name fmspe_dir = self.Interface.map_history[v].fmspedir xml_dir = self.Interface.map_history[v].xmldir image_dir = self.Interface.map_history[v].imagedir # Gather all relevant files try: fmspe_files = [ filename for filename in os.listdir(fmspe_dir) if filename.startswith(map_name) and filename.endswith(".fmspe") ] xml_files = [ filename for filename in os.listdir(xml_dir) if filename.startswith(map_name) and filename.endswith(".xml") ] image_files = [ filename for filename in os.listdir(image_dir) if filename.startswith(map_name) and filename.endswith(".bmp") ] except WindowsError: fmspe_files = [] xml_files = [] image_files = [] # Delete all these relevant files for file in fmspe_files: try: os.remove(fmspe_dir + file) except WindowsError: print "Couldn't find {}!".format(file) for file in xml_files: try: os.remove(xml_dir + file) except WindowsError: print "Couldn't find {}!".format(file) for file in image_files: try: os.remove(image_dir + file) except WindowsError: print "Couldn't find {}!".format(file) # Remove the map from the text file old_lines = [ line.rstrip('\n') for line in open("History/map_history.txt") ] with open("History/map_history.txt", "w") as f: map_name = self.Interface.map_history[v].map_name fmspe_dir = self.Interface.map_history[v].fmspedir xml_dir = self.Interface.map_history[v].xmldir image_dir = self.Interface.map_history[v].imagedir num_pts_x = self.Interface.map_history[v].numx dist_bw_x = self.Interface.map_history[v].distbwx num_pts_y = self.Interface.map_history[v].numy dist_bw_y = self.Interface.map_history[v].distbwy date = self.Interface.map_history[v].date time = self.Interface.map_history[v].time units = self.Interface.map_history[v].units for line in old_lines: # print line compare_line = "{} {} {} {} {} {} {} {} {} {} {}".format( map_name, fmspe_dir, xml_dir, image_dir, num_pts_x, dist_bw_x, num_pts_y, dist_bw_y, date, time, units) # print compare_line if line != compare_line: f.write("{}\n".format(line)) # The lines present in the file afterwards... Now we refill the list with these values new_lines = [ line.rstrip('\n') for line in open("History/map_history.txt") ] # Reset map history self.Interface.map_history = [] maps_in_history_list.clear() for i in range(len(new_lines)): vals_array = new_lines[i].split(" ") new_map_info = FinishedMap(vals_array[0], vals_array[1], vals_array[2], vals_array[3], vals_array[4], vals_array[5], vals_array[6], vals_array[7], vals_array[8], vals_array[9], vals_array[10]) self.Interface.map_history.append(new_map_info) maps_in_history_list.add(new_map_info.map_name, value=i) delete_button = gui.Button("Delete Map", width=50) self.add(delete_button, 1110, yalign + 30) delete_button.connect(gui.CLICK, delete) # -------------- UPDATE THE LIST ----------------------------------- def update_list(): new_lines = [ line.rstrip('\n') for line in open("History/map_history.txt") ] # Reset map history self.Interface.map_history = [] maps_in_history_list.clear() for i in range(len(new_lines)): vals_array = new_lines[i].split(" ") new_map_info = FinishedMap(vals_array[0], vals_array[1], vals_array[2], vals_array[3], vals_array[4], vals_array[5], vals_array[6], vals_array[7], vals_array[8], vals_array[9], vals_array[10]) self.Interface.map_history.append(new_map_info) maps_in_history_list.add(new_map_info.map_name, value=i) update_button = gui.Button("Update List", width=50) self.add(update_button, 1110, yalign + 65) update_button.connect(gui.CLICK, update_list) # # # List of items that the user selected into their carts # cart_items_object = gui.List(width = 180, height = 140) # self.add(cart_items_object, xalign + 210, 40) # # # Functions to add/remove items from cart # def add_item_to_cart(arg): # v = initial_attributes_list_object.value # if v != None and v not in cart_items: # cart_items[v] = attribute_items[v] # index = v # cart_items_object.add(attribute_items[index], value = index) # cart_items_object.resize() # cart_items_object.repaint() # # def remove_item_from_cart(arg): # v = cart_items_object.value # if v != None: # cart_items.pop(v) # cart_items_object.remove(v) # cart_items_object.resize() # cart_items_object.repaint() # cart_items_object.value = None # ------------------------------------------------------- Fun ------------------------------------------------------- # Change theme button def change_theme(arg): self.Interface.set_theme() self.change_theme_button = gui.Button("New Theme") self.change_theme_button.connect(gui.CLICK, change_theme, None) self.add(self.change_theme_button, 110, 320)
white_player_time = 30 black_player_time = 30 # configuration menu start_screen = gui.Desktop(name='Keny') start_screen.connect(gui.QUIT, start_screen.quit, None) table = gui.Table(x=0, y=0, font=TNR32) table.tr() table.td(gui.Label("Czarny", font=TNR32), colspan=1) table.td(gui.Label("Biały", font=TNR32), colspan=3) table.tr() black_player_select = gui.Select(False, width=150, height=70, font=TNR32) black_player_select.add(gui.Label('Komputer', font=TNR32), True) black_player_select.add(gui.Label('Gracz', font=TNR32), False) table.td(black_player_select, colspan=1) table.td(gui.Label()) white_player_select = gui.Select(False, width=150, height=70, font=TNR32) white_player_select.add(gui.Label('Komputer', font=TNR32), True) white_player_select.add(gui.Label('Gracz', font=TNR32), False) table.td(white_player_select, colspan=3) table.tr() table.td(gui.Label()) table.tr() table.td(gui.Label(" Czas wyznaczania ruchu", font=TNR32), colspan=3) table.tr()
def SetupToolbox(self): self.ctrls = ctrls = gui.Table(width=125) ctrls.tr() ctrls.td(gui.Label(" Car Control: "), align=0) ctrls.tr() btn_run = gui.Button("Run", width=90) btn_run.connect(gui.CLICK, self.B_run) ctrls.td(btn_run) ctrls.tr() btn_stop = gui.Button("Stop", width=90) btn_stop.connect(gui.CLICK, self.B_stop) ctrls.td(btn_stop) ctrls.tr() btn_clear = gui.Button("Clear", width=90) btn_clear.connect(gui.CLICK, self.B_clear) ctrls.td(btn_clear) ctrls.tr() self.sli_v = gui.HSlider(value=100, min=0, max=100, size=20, width=120) ctrls.td(self.sli_v, colspan=3) ctrls.tr() ctrls.td(gui.Label(""), align=0) ctrls.tr() ctrls.td(gui.Label(" Draw Path: ")) ctrls.tr() self.sel_car = sel_car = gui.Select() for item in utils.carInfo: sel_car.add("#" + str(item[0]) + ", Tag" + str(item[1]), item[1]) ctrls.td(sel_car) ctrls.tr() ctrls.td(gui.Label(""), align=0) ctrls.tr() ctrls.td(gui.Label(" Patterns: "), align=0) files = [ f for f in listdir("patterns/") if isfile(join("patterns/", f)) ] ctrls.tr() self.sel_ptn = sel_ptn = gui.Select() for f in files: if ".py" in f: if ".pyc" not in f: sel_ptn.add(f.split(".")[0], f) ctrls.td(sel_ptn) ctrls.tr() btn_pattern = gui.Button("Get Pattern", width=90) btn_pattern.connect(gui.CLICK, self.B_pattern) ctrls.td(btn_pattern) ctrls.tr() ctrls.td(gui.Label(""), align=0) ctrls.tr() ctrls.td(gui.Label("Path Planning:"), align=0) files = [ f for f in listdir("algorithms/") if isfile(join("algorithms/", f)) ] ctrls.tr() self.sel_alg = sel_alg = gui.Select() for f in files: if ".py" in f: if ".pyc" not in f: sel_alg.add(f.split(".")[0], f) ctrls.td(sel_alg) ctrls.tr() btn_plan = gui.Button("Run ALG", width=90) btn_plan.connect(gui.CLICK, self.B_plan) ctrls.td(btn_plan) return ctrls
def __init__(self, engine, **params): gui.Container.__init__(self, **params) self.engine = engine self.value = gui.Form() # item editor state self.itemNum = None # dialogs openItemDialog = OpenItemDialog(self) # data types self.dataEquipment = DataEquipment(name="dataEquipment") self.dataPotion = DataPotion(name="dataPotion") self.dataSpell = DataSpell(name="dataSpell") # menu title self.tTitle = gui.Table(width=272, height=32) self.tTitle.tr() self.tTitle.td( gui.Label("Item Editor", name='itemTitle', color=UI_FONT_COLOR)) # content self.tContent = gui.Table(width=272, height=123) self.tContent.tr() e = gui.Button("Open item...", width=100) e.connect(gui.CLICK, openItemDialog.openDialog, None) self.tContent.td(e, colspan=2) self.tContent.tr() self.tContent.td(gui.Label('Item Name:', color=UI_FONT_COLOR), colspan=2) self.tContent.tr() self.tContent.td(gui.Input('', size=26, name='inpItemName'), colspan=2, valign=-1) self.tContent.tr() self.tContent.td(gui.Label('Item Type:', color=UI_FONT_COLOR)) e = gui.Select(name='selItemType') e.add('None', 0) e.add('Weapon', 1) e.add('Armor', 2) e.add('Helmet', 3) e.add('Shield', 4) e.add('Potion (+HP)', 5) e.add('Potion (+MP)', 6) e.add('Potion (+SP)', 7) e.add('Potion (-HP)', 8) e.add('Potion (-MP)', 9) e.add('Potion (-SP)', 10) e.add('Key', 11) e.add('Currency', 12) e.add('Spell', 13) e.value = 0 e.connect(gui.CHANGE, self.updateType, None) self.tContent.td(e) # data input self.tData = gui.Table(width=272, height=75) # bottom buttons self.tBottom = gui.Table(width=272, height=200) self.tBottom.tr() self.saveButton = gui.Button("Add Item", width=100, height=40) self.saveButton.connect(gui.CLICK, self.saveItem, None) self.tBottom.td(self.saveButton) e = gui.Button("Cancel", width=100, height=40) e.connect(gui.CLICK, self.cancel, None) self.tBottom.td(e) self.add(self.tTitle, 0, 0) self.add(self.tContent, 0, 100) self.add(self.tData, 0, 255) self.add(self.tBottom, 0, 368)
def run(main=None): from omnitool.shared import lang, theme, exit_prog, __version__ from omnitool.pgu_override import Quitbutton pygame.display.init() pygame.display.set_caption("Planetoids & Terra Generator") if main == None: app = gui.Desktop(theme=theme) main = gui.Table() app.connect(gui.QUIT, exit_prog, None) else: main = gui.Table() app = gui.Dialog(gui.Label("Planetoids and Terra Generator"), main) main.td(gui.Label(lang.pt_name), align=-1) nameinput = gui.Input("Planetoids OT-V" + str(__version__), width=237) main.td(nameinput, colspan=2) main.tr() main.td(gui.Label(lang.pt_mode), align=-1) method = gui.Select(width=250) method.add(lang.pt_small, (1, 0)) method.add(lang.pt_medium, (2, 0)) method.add(lang.pt_large, (3, 0)) method.add(lang.pt_square, (4, 0)) method.add(lang.pt_both, (3, 1)) method.add(lang.pt_square_terra, (4, 2)) method.value = (3, 0) main.td(method, colspan=2) main.tr() main.td(gui.Label(lang.pt_start_sel), align=-1) time = gui.Select(width=250) time.add(lang.pt_morning, 2) time.add(lang.pt_day, 1) time.add(lang.pt_night, 3) time.add(lang.pt_bloodmoon, 4) time.value = 1 main.td(time, colspan=2) main.tr() main.td(gui.Spacer(1, 24)) main.tr() main.td(gui.Label(lang.pt_extras), align=-1, colspan=3) main.tr() main.td(gui.Label(lang.pt_sun), align=-1) darkness = gui.Switch() darkness.value = True main.td(darkness, colspan=2) main.tr() main.td(gui.Label(lang.pt_atlantis), align=-1) atlantis = gui.Switch() atlantis.value = False main.td(atlantis, colspan=2) main.tr() main.td(gui.Label(lang.pt_merchant), align=-1) merch = gui.Switch() merch.value = True main.td(merch, colspan=2) main.tr() main.td(gui.Label(lang.pt_lloot), align=-1) loot = gui.Switch() loot.value = False main.td(loot, colspan=2) main.tr() main.td(gui.Label("Hardmode:"), align=-1) hard = gui.Switch() hard.value = False main.td(hard, colspan=2) main.tr() main.td(gui.Label(lang.pt_mirror), align=-1) mirror = gui.Switch() mirror.value = False main.td(mirror, colspan=2) main.tr() # main.td(gui.Label(lang.pt_pre), align = -1) pre = gui.Switch() pre.value = False #main.td(pre, colspan = 2) #main.tr() main.td(gui.Spacer(1, 12)) main.tr() main.td(Quitbutton(app, lang.pt_start), colspan=3) main.tr() main.td(gui.Spacer(1, 12)) if app.__class__.__name__ == "Desktop": app.run(main) pygame.display.quit() return (nameinput.value, method.value, time.value, darkness.value, atlantis.value, merch.value, loot.value, hard.value, mirror.value, pre.value) else: app.open()
def openExportDialog(self, d=None): if d is not None: d.close() main = gui.Table() # Some Image Amount code so we can reference it early imageAmountSelector = gui.Select(name='file-select-export-amount', value=_("Few"), cols=1) def activateImageAmount(_widget): imageAmountSelector.disabled = (_widget.value == "Plain") # Export Type main.tr() main.td(gui.Label(_("Export Type: "), style={'margin': 4})) exportTypeSelector = gui.Select(name='file-select-export-fancy', value=_("Fancy"), cols=1) exportTypeSelector.connect(gui.SELECT, activateImageAmount) exportTypeSelector.add(_("Plain (just text)"), "Plain") exportTypeSelector.add(_("Fancy (pictures)"), "Fancy") main.td(exportTypeSelector) # Image Amount main.tr() main.td(gui.Label(_("Image Amount: "), style={'margin': 4})) imageAmountSelector.add(_("Tons"), "Tons") imageAmountSelector.add(_("Many"), "Many") imageAmountSelector.add(_("Few"), "Few") imageAmountSelector.add(_("None"), "None") main.td(imageAmountSelector) # Location main.tr() main.td(gui.Label(_("Location: "), style={'margin': 4})) locationSelector = gui.Select(name='file-select-export-location', value=_("Here"), cols=1) locationSelector.add(_("Here"), "Here") if hacks['server']: locationSelector.add(_("Teacher"), "Teacher") main.td(locationSelector) # Okay/Cancel main.tr() okayButton = gui.Button(_("Okay"), name='file-button-export-okay', style={'margin': 10}) main.td(okayButton) cancelButton = gui.Button(_("Cancel"), name='file-button-export-cancel', style={'margin': 10}) main.td(cancelButton) # exportOptions = gui.Document() # exportButtons= [(gui.Button(_("Text"), name= 'file-button-export-text', style={'margin':4}), 'text', ['.txt']), # (gui.Button(_("HTML"), name= 'file-button-export-html', style={'margin':4}), 'html', ['.html'])] ##, (gui.Button(_("Video"), name= 'file-button-export-text', style={'margin':4}), 'video', ['.mpeg']) d = gui.Dialog(gui.Label(_("Export")), main) # for aButton, value, valueType in exportButtons: # exportOptions.add(aButton) # aButton.connect(gui.CLICK, self.export, value, valueType, d) d.connect(gui.CLOSE, self.script.refreshTheater) cancelButton.connect(gui.CLICK, d.close) okayButton.connect(gui.CLICK, self.export, d) d.open()
def _buildSltCb(tt): slt = gui.Select() tt.td(slt) chkbox = gui.Switch() tt.td(chkbox) return (slt, chkbox)
def __init__(self, pSize, pApp, pDefCfg): tbl = gui.Table(width=pSize['w'], height=pSize['c_h']) ## tilt g = gui.Group() tbl2 = gui.Table() tbl2.tr() tbl2.td(gui.Label(_('Tilt / Z Correction')), colspan=2) tbl2.tr() tbl2.td(gui.Radio(g, value='off')) tbl2.td(gui.Label(_('Off'))) tbl2.tr() tbl2.td(gui.Radio(g, value='intelligent')) tbl2.td(gui.Label(_('Intelligent'))) tbl2.tr() tbl2.td(gui.Radio(g, value='continuous')) tbl2.td(gui.Label(_('Continuous'))) self.tiltGrp = g tiltTbl = gui.Table(width=pSize['w']/5) tiltTbl.tr() tiltTbl.td(tbl2, style={'border':1}) ## recoil recoilTbl = gui.Table(width=pSize['w']/3) recoilTbl.tr() recoilTbl.td(gui.Label(_('Recoil'))) self.recoilSl = gui.HSlider(value=0, min=0, max=250, size=25, step=10, width=pSize['s_w'], height=pSize['s_h']) recoilTbl.td(self.recoilSl) button = gui.Button(_('Test')) button.connect(gui.CLICK, pApp.recoil, None) self._testBtn = button recoilTbl.td(button) ## IR gain irTbl = gui.Table(width=pSize['w']/3) irTbl.tr() irTbl.td(gui.Label(_('IR Gain'))) self.irGainSl = gui.HSlider(value=1, min=1, max=5, size=10, width=pSize['s_w'], height=pSize['s_h']) irTbl.td(self.irGainSl) txt = gui.Input(size=5) self.irGainSl.connect(gui.CHANGE, _slChange, (self.irGainSl, txt)) txt.focusable = False self.irGainSl.send(gui.CHANGE) irTbl.td(txt) ### disable auto gain irTbl.tr() irTbl.td(gui.Spacer(10,5)) irTbl.tr() chkbox = gui.Switch() chkbox.connect(gui.CLICK, _ckbClicked, (chkbox, self.irGainSl)) irTbl.td(chkbox) irTbl.td(gui.Label(_('Disable Auto Gain')), colspan=2, align=-1) self.autoGainSw = chkbox ## device ID devTbl = gui.Table(width=pSize['w']/4) devTbl.tr() devTbl.td(gui.Label(_('Device ID:'))) self.devIdSlt = gui.Select() for x in xrange(0x1601,0x1609): self.devIdSlt.add('0x%x' % x, x) devTbl.td(self.devIdSlt) ## button assignments btnTbl = gui.Table() btnTbl.tr() btnTbl.td(gui.Label(_('Button Assignments')), colspan=5) btnTbl.tr() btnTbl.td(gui.Spacer(20,20)) btnTbl.tr() btnTbl.td(gui.Label("")) btnTbl.td(gui.Label(_('On Screen')+" ")) btnTbl.td(gui.Label(_('Enable Cal')+" ")) btnTbl.td(gui.Label(_('Off Screen')+" ")) btnTbl.td(gui.Label(_('Enable Cal')+" ")) btnTbl.tr() btnTbl.td(gui.Spacer(10,5)) ### TRIG btnTbl.tr() btnTbl.td(gui.Label(_('TRIG')+" ")) self.onActTrigSlt, self.onCalTrigCb = _buildSltCb(btnTbl) self.offActTrigSlt, self.offCalTrigCb = _buildSltCb(btnTbl) ### LEFT btnTbl.tr() btnTbl.td(gui.Label(_('LEFT')+" ")) self.onActLeftSlt, self.onCalLeftCb = _buildSltCb(btnTbl) self.offActLeftSlt, self.offCalLeftCb = _buildSltCb(btnTbl) ### RIGHT btnTbl.tr() btnTbl.td(gui.Label(_('RIGHT')+" ")) self.onActRightSlt, self.onCalRightCb = _buildSltCb(btnTbl) self.offActRightSlt, self.offCalRightCb = _buildSltCb(btnTbl) ## Cal Delay calTbl = gui.Table(width=pSize['w']/4) calTbl.tr() calTbl.td(gui.Label(_('Cal Delay (Secs)'))) self.calDlSl = gui.HSlider(value="3", min=3, max=10, size=10, width=pSize['s_w'], height=pSize['s_h']) calTbl.td(gui.Spacer(10,5)) calTbl.td(self.calDlSl) txt = gui.Input(size=5) self.calDlSl.connect(gui.CHANGE, _slChange, (self.calDlSl, txt)) txt.focusable = False self.calDlSl.send(gui.CHANGE) calTbl.td(gui.Spacer(10,5)) calTbl.td(txt) ## joystick / mouse self.mjGrp = gui.Group() jtkTbl = gui.Table(width=pSize['w']/3) jtkTbl.tr() rad = gui.Radio(self.mjGrp, value='joystick') rad.connect(gui.CLICK, self._changeDevType, True) jtkTbl.td(rad) jtkTbl.td(gui.Label(_('Emulate Joystick'))) rad = gui.Radio(self.mjGrp, value='mouse') rad.connect(gui.CLICK, self._changeDevType, False) jtkTbl.td(rad) jtkTbl.td(gui.Label(_('Emulate Mouse'))) self._curSel = None ## button save saveBtn = gui.Button(_('Save Configuration')) saveBtn.connect(gui.CLICK, pApp.save, None) self._saveBtn = saveBtn dcntBtn = gui.Button(_('Disconnect')) dcntBtn.connect(gui.CLICK, pApp.disconnect, None) ## button set defaults defBtn = gui.Button(_('Set Defaults')) defBtn.connect(gui.CLICK, self.setConfig, pDefCfg) # assemble window tbl.tr() tbl.td(tiltTbl) tbl.td(btnTbl) tbl.tr() tbl.td(recoilTbl) tbl.td(calTbl) tbl.tr() tbl.td(irTbl) tbl.td(jtkTbl) tbl.tr() tbl.td(devTbl) tbl.tr() tbl.td(defBtn) tbl.td(saveBtn) tbl.tr() tbl.td(dcntBtn, colspan=2) # Configuration self.widget = tbl
def run(self): #pygame.quit() if hasattr(sys, "frozen"): os.chdir(os.path.dirname(sys.executable)) nogui = False pygame.display.init() pygame.display.set_caption("Worldify") if len(sys.argv) < 2: if nogui: print( "No Image supplied, please drag and drop an image onto the program" ) sleep(3) sys.exit(1000) else: app = gui.Desktop(theme=theme) app.connect(gui.QUIT, exit_prog, None) app.connect(gui.CLOSE, exit_prog, None) main = gui.dialog.FileDialog() main.connect(gui.CLOSE, app.quit, main) main.connect(gui.CHANGE, app.quit, main) main.open() app.run(main) pygame.display.quit() imagepath = main.value else: imagepath = sys.argv[1] local = os.listdir(os.getcwd()) if "db.txt" in local: print("Found external database, starting parsing..") from plugins.worldify_lib import jsonparse jsonparse.load() print("Database injection successful") ext = True else: ext = False pygame.display.init() pygame.display.set_caption("Worldify") colors = data #bad = [4,49, 53, 32, 62, 52, 80, 19]#torch, blue candle, sand, corruption vines, wooden platform for tile in colors: if tile in multitiles or tile > 255: bad.append(tile) colors[None] = (250, 250, 250) #air for b in bad: if b in colors: del (colors[b]) rcolors = {} for color in colors: rcolors[tuple(colors[color])] = color #print ("%-25s %s" % ((db.tiles[color], colors[color]))) if imagepath == None: sys.exit() #file window was closed try: surface = pygame.image.load(imagepath) except: import traceback print("Unable to load image, please try using png or bmp files") print("Error:") print(traceback.format_exc()) sleep(3) sys.exit(1000) w, h = surface.get_size() preview = surface.copy() scale = min(280.0 / w, 210.0 / h) try: preview = pygame.transform.smoothscale( surface, (int(w * scale), int(h * scale))) except: surface = surface.convert(32, 0) preview = pygame.transform.smoothscale( surface, (int(w * scale), int(h * scale))) print("Image loaded with %d x %d pixels" % (w, h)) while w < 240 or h < 150: surface = pygame.transform.smoothscale(surface, (w * 2, h * 2)) w, h = surface.get_size() print("Image enlarged to %d x %d pixels" % (w, h)) if w > 8400 or h > 2400: print( "Warning: Terraria can only load worlds up to a size of 8400 x 2400" ) print("Program will continue in 3 seconds anyway") sleep(3) oversize = True else: oversize = False ###GUI### name = "ImageWorld OT-V" + str(__version__) func = "RGB" weight = (1, 1, 1) if not nogui: app = gui.Desktop(theme=theme) app.connect(gui.QUIT, exit_prog, None) c = gui.Table() def change(method, button): if method.value == "RGB": button.value = lang.w_start else: button.value = lang.w_cont button.chsize() c.td(gui.Image(preview), colspan=2) c.tr() if oversize: dbstr = gui.Label("Warning: Image too large") c.td(dbstr, colspan=2) c.tr() if ext: dbstr = gui.Label("External database loaded") else: dbstr = gui.Label("No external database found") c.td(dbstr, colspan=2) c.tr() namefield = gui.Input(name, width=200) c.td(gui.Label(lang.w_name)) c.td(namefield) c.tr() method = gui.Select(width=214) method.add(lang.w_rgb, "RGB") method.add(lang.w_hsv, "HSV") method.value = lang.w_rgb e = Quitbutton(app, lang.pt_start) method.connect(gui.CHANGE, change, method, e) c.td(gui.Label(lang.w_method)) c.td(method) c.tr() c.td(gui.Spacer(1, 25), colspan=2) c.tr() c.td(e, colspan=2) app.run(c) name = namefield.value func = method.value pygame.display.quit() if func == "HSV": pygame.display.init() pygame.display.set_caption("Worldify") def update(slider, label): label.set_text(str(slider.value) + "X") app = gui.Desktop(theme=theme) app.connect(gui.QUIT, exit_prog, None) c = gui.Table(width=250) c.td(gui.Label(lang.w_priority, size=40), colspan=3) c.tr() H = gui.HSlider(value=3, min=0, max=9, size=20, height=16, width=120) S = gui.HSlider(value=2, min=0, max=9, size=20, height=16, width=120) V = gui.HSlider(value=1, min=0, max=9, size=20, height=16, width=120) c.td(gui.Label(lang.w_hue)) c.td(H) hl = gui.Label("3X") H.connect(gui.CHANGE, update, H, hl) c.td(hl) c.tr() c.td(gui.Label(lang.w_saturation)) c.td(S) sl = gui.Label("2X") S.connect(gui.CHANGE, update, S, sl) c.td(sl) c.tr() c.td(gui.Label(lang.w_brightness)) c.td(V) vl = gui.Label("1X") V.connect(gui.CHANGE, update, V, vl) c.td(vl) c.tr() e = Quitbutton(app, lang.pt_start) c.td(e, colspan=3) app.run(c) pygame.display.quit() weight = H.value, S.value, V.value ###GUI END### self.header = { 'spawn': (w // 2, h // 2), 'groundlevel': h + 0.0, 'is_bloodmoon': 0, 'dungeon_xy': (w, h), 'worldrect': (0, w * 16, 0, h * 16), 'is_meteor_spawned': 0, 'gob_inv_time': 0, 'rocklevel': h + 100.0, 'gob_inv_x': 0.0, 'is_day': 1, 'shadow_orbs_broken': 0, 'width': w, 'version': 39, 'gob_inv_type': 0, 'bosses_slain': (0, 0, 0), "npcs_saved": (0, 0, 0), "special_slain": (0, 0, 0), 'gob_inv_size': 0, 'height': h, 'ID': randint(10, 10000000), 'moonphase': 0, 'name': name, 'is_a_shadow_orb_broken': 0, 'time': 13500.0, "hardmode": 0, "altars_broken": 0, } import time def rgb(a, surface, rcolors, weight=None): w10 = w // 20 total = z = w cache = {} tiledata = io.BytesIO() set_tile(tiledata, (None, None, 0, None)) air = tiledata.getvalue() for x in range(w): for y in range(h): color = surface.get_at((x, y)) if color[3] == 0: a.write(air) continue cachecolor = color[:3] if cachecolor in cache: a.write(cache[cachecolor]) else: tiledata = io.BytesIO() cdif = 100000 for c in rcolors: dif = (c[0] - color[0]) * (c[0] - color[0]) + ( c[1] - color[1]) * (c[1] - color[1]) + ( c[2] - color[2]) * (c[2] - color[2]) if dif < cdif: cdif = dif hit = rcolors[c] set_tile(tiledata, (hit, None, 0, None)) value = tiledata.getvalue() a.write(value) cache[cachecolor] = value if z % w10 == 1: #give lifesigns n = ((total - z) * 100.0) / w print("%6.2f%% done writing tiles" % n) z -= 1 def hsv(a, surface, rcolors, weight=(2, 3, 1)): #hue saturation value/brightness hcolors = {} for color in rcolors: nc = colorsys.rgb_to_hsv(color[0] / 255.0, color[1] / 255.0, color[2] / 255.0) hcolors[nc] = rcolors[color] w10 = w // 20 total = z = w cache = {} tiledata = io.BytesIO() set_tile(tiledata, (None, None, 0, None)) air = tiledata.getvalue() for x in range(w): for y in range(h): color = surface.get_at((x, y)) if color[3] == 0: a.write(air) continue cachecolor = color[:3] if cachecolor in cache: a.write(cache[cachecolor]) else: tiledata = io.BytesIO() color = colorsys.rgb_to_hsv(color[0] / 255.0, color[1] / 255.0, color[2] / 255.0) #print color cdif = 100 for c in hcolors: p1 = min( weight[0] * (c[0] - color[0]) * (c[0] - color[0]), weight[0] * (c[0] + 1 - color[0]) * (c[0] + 1 - color[0]), weight[0] * (c[0] - 1 - color[0]) * (c[0] - 1 - color[0])) dif = p1 + weight[1] * (c[1] - color[1]) * ( c[1] - color[1]) + weight[2] * ( c[2] - color[2]) * (c[2] - color[2]) #print dif, cdif if dif < cdif: cdif = dif hit = hcolors[c] set_tile(tiledata, (hit, None, 0, None)) value = tiledata.getvalue() a.write(value) cache[cachecolor] = value #print hit, dif if z % w10 == 1: #give lifesigns n = ((total - z) * 100.0) / w print("%6.2f%% done writing tiles" % n) z -= 1 start = time.clock() self.tiles = tempfile.TemporaryFile() if func == "RGB": print("Finding closest match via euclidian RGB distance") rgb(self.tiles, surface, rcolors) else: print("Finding closest match via weighted HSV difference") hsv(self.tiles, surface, rcolors, weight) t = time.clock() - start n = (t, t / (w * h)) print("%5f seconds taken, that is %0.10f seconds per pixel" % n) self.chests = [None] * 1000 self.signs = [None] * 1000 self.names = names self.npcs = [] print("Test done")
def __init__(self): gui.Container.__init__(self) self.engine = None def selectFile(object): self.reset() tmpName = object.value.replace('/', '\\').split('\\') self.label2.set_text(tmpName[len(tmpName) - 1][:-4]) self.xInput.disabled = False self.yInput.disabled = False self.dirList.disabled = False self.btn1.disabled = False self.btn3.disabled = False #self.btn2.disabled=False def fnc1(): a = gui.FileDialog(path=g.dataPath + "/maps/") a.connect(gui.CHANGE, selectFile, a) a.open() def fnc2(): if len(self.engine.maps) > 0: self.label2.set_text(self.engine.maps[self.typeList.value][0]) self.xInput._setvalue( str(self.engine.maps[self.typeList.value][1])) self.yInput._setvalue( str(self.engine.maps[self.typeList.value][2])) self.dirList.value = self.engine.maps[self.typeList.value][3] self.xInput.disabled = False self.yInput.disabled = False self.dirList.disabled = False self.btn1.disabled = False self.btn2.disabled = False self.btn3.disabled = False def fnc3(): if self.dirList.value == DIR_DOWN: self.engine.Facing = 0 elif self.dirList.value == DIR_LEFT: self.engine.Facing = 8 elif self.dirList.value == DIR_UP: self.engine.Facing = 5 elif self.dirList.value == DIR_RIGHT: self.engine.Facing = 3 self.engine.updateCharSprite() def fnc4(): found = False for i in xrange(len(self.engine.maps)): if self.engine.maps[i][0] == self.label2.value: self.engine.maps[i][1] = int(self.xInput.value) self.engine.maps[i][2] = int(self.yInput.value) self.engine.maps[i][3] = self.dirList.value found = True break if not found: self.engine.maps.append([ self.label2.value, int(self.xInput.value), int(self.yInput.value), self.dirList.value ]) self.populateTypeList() self.typeList.disabled = False def fnc6(): if self.engine.playing: self.engine.playing = False else: self.engine.testPlay.initatePlay() self.engine.playing = True def intMatch(str, search=re.compile(r'[^0-9]').search): if bool(search(str)): return False return True def fnc7(): if len(self.xInput.value) > 0: if not intMatch(self.xInput.value[len(self.xInput.value) - 1]): self.xInput.value = self.xInput.value[:-1] def fnc8(): if len(self.yInput.value) > 0: if not intMatch(self.yInput.value[len(self.yInput.value) - 1]): self.yInput.value = self.yInput.value[:-1] btn = gui.Button("Select map") btn.connect(gui.CLICK, fnc1) self.add(btn, 0, 30) self.typeList = gui.Select(disabled=True) self.typeList.add("Please insert a map") self.typeList.connect(gui.CHANGE, fnc2) self.add(self.typeList, 0, 0) label1 = gui.Label("Map name: ", color=fontcolor) self.add(label1, width / 9 * 4, 0) self.label2 = gui.Label("", color=nameColor) self.add(self.label2, width / 9 * 4 + label1.style.width, 0) label3 = gui.Label("X: ", color=fontcolor) label4 = gui.Label("Y: ", color=fontcolor) self.add(label3, width / 9 * 4, label1.style.height + 10) self.add(label4, width / 9 * 4, (label1.style.height + 10) * 2) self.xInput = gui.Input(value="0", width=30, disabled=True) self.xInput.connect(gui.CHANGE, fnc7) self.yInput = gui.Input(value="0", width=30, disabled=True) self.yInput.connect(gui.CHANGE, fnc8) self.add(self.xInput, width / 9 * 4 + label3.style.width, label1.style.height + 10) self.add(self.yInput, width / 9 * 4 + label3.style.width, (label1.style.height + 10) * 2) label5 = gui.Label("Direction: ", color=fontcolor) self.add(label5, width / 9 * 4, (label1.style.height + 10) * 3) self.dirList = gui.Select(value=DIR_DOWN, disabled=True) self.dirList.add("DIR_DOWN", DIR_DOWN) self.dirList.add("DIR_LEFT", DIR_LEFT) self.dirList.add("DIR_UP", DIR_UP) self.dirList.add("DIR_RIGHT", DIR_RIGHT) self.dirList.connect(gui.CHANGE, fnc3) self.add(self.dirList, width / 9 * 4 + label5.style.width, (label1.style.height + 10) * 3) self.btn1 = gui.Button("Insert", width=100, height=30, disabled=True) self.btn1.connect(gui.CLICK, fnc4) self.add(self.btn1, width / 9 * 4, (label1.style.height + 10) * 4) self.btn2 = gui.Button("Remove", width=100, height=30, disabled=True) self.btn2.connect(gui.CLICK, self.fnc5) self.add(self.btn2, width / 9 * 4 + 120, (label1.style.height + 10) * 4) self.btn3 = gui.Button("Test play", width=100, height=30, disabled=True) self.btn3.connect(gui.CLICK, fnc6) self.add(self.btn3, width / 9 * 4, (label1.style.height + 12) * 5)
def __init__(self, manager, args=None): screen.__init__(self, manager, args) self._app = gui.App() self._t = gui.Table(width=constants.WIDTH / 4) font = pygame.font.SysFont("default", 36) fontBig = pygame.font.SysFont("default",48) self._t.tr() label = gui.Label("DriveSim",font=fontBig) self._t.td(label, colspan=5, align=0) self._t.tr() self._t.td(Separator(height=20)) self._t.tr() btn = gui.Button("Start!",font=font,width=100,height=40) btn.connect(gui.CLICK, self.cb_start) self._t.td(btn, col=2, align=0) self._d = gui.Table() self._c = gui.Table(width=constants.WIDTH / 4) self._c.tr() self._c.td(self._d) self._player1 = gui.Select(height=40) label = gui.Label("None", font=font) self._player1.add(label, 'none') label = gui.Label("Human", font=font) self._player1.add(label, 'human') label = gui.Label("Autonomous", font=font) self._player1.add(label, 'autonomous') label = gui.Label("CarSim", font=font) self._player1.add(label, 'carsim') label = gui.Label("Unity", font=font) self._player1.add(label, 'unity') self._player1.value = 'unity' self._player2 = gui.Select(height=40) label = gui.Label("None", font=font) self._player2.add(label, 'none') label = gui.Label("Human", font=font) self._player2.add(label, 'human') label = gui.Label("Autonomous", font=font) self._player2.add(label, 'autonomous') self._player2.value = 'none' self._d.tr() label = gui.Label("Options", font=fontBig) self._d.td(label, colspan=1, align=-1) self._d.tr() self._d.td(Separator(height=50)) self._d.tr() label = gui.Label("Player 1", font=font) self._d.td(label, colspan=1, align=-1) self._d.tr() self._d.td(Separator(height=10)) self._d.tr() self._d.td(self._player1, colspan=1, align=0) self._d.tr() self._d.td(Separator(height=20)) self._d.tr() label = gui.Label("Player 2", font=font) self._d.td(label, colspan=1, align=-1) self._d.tr() self._d.td(Separator(height=10)) self._d.tr() self._d.td(self._player2, colspan=1, align=0) self._g = gui.Table(width=constants.WIDTH * 3 / 4) # , background=(255, 255, 255) self._g.tr() self._g.td(self._t, colspan=1, align=0) self._g.td(self._c, colspan=1, align=0) self._app.screen = manager.getsurf() self._app.init(self._g) self.backgr = pygame.image.load('data/background.jpg').convert_alpha() self.backgr.fill((255, 255, 255, 128), None, pygame.BLEND_RGBA_MULT)
def __init__(self, engine, **params): gui.Container.__init__(self, **params) self.engine = engine self.value = gui.Form() # spell editor state self.spellNum = None # dialogs openSpellDialog = OpenSpellDialog(self) # data types self.dataGiveItem = DataGiveItem(name="dataGiveItem") self.dataVitalMod = DataVitalMod(name="dataVitalMod") # menu title self.tTitle = gui.Table(width=272, height=32) self.tTitle.tr() self.tTitle.td( gui.Label(_("Spell Editor"), name='spellTitle', color=UI_FONT_COLOR)) # content self.tContent = gui.Table(width=272, height=123) self.tContent.tr() e = gui.Button("Open spell...", width=100) e.connect(gui.CLICK, openSpellDialog.openDialog, None) self.tContent.td(e, colspan=2) self.tContent.tr() self.tContent.td(gui.Label('Spell Name:', color=UI_FONT_COLOR), colspan=2) self.tContent.tr() self.tContent.td(gui.Input('', size=26, name='inpSpellName'), colspan=2, valign=-1) self.tContent.tr() self.tContent.td(gui.Label('Spell Type:', color=UI_FONT_COLOR)) e = gui.Select(name='selSpellType') e.add('Add HP', 0) e.add('Add MP', 1) e.add('Add SP', 2) e.add('Remove HP', 3) e.add('Remove MP', 4) e.add('Remove SP', 5) e.add('Give item', 6) e.value = 0 e.connect(gui.CHANGE, self.updateType, None) self.tContent.td(e) # data input self.tData = gui.Table(width=272, height=75) # - make vital mod default self.tData.tr() self.tData.td(self.dataVitalMod, valign=-1) # bottom buttons self.tBottom = gui.Table(width=272, height=200) self.tBottom.tr() self.saveButton = gui.Button("Add Spell", width=100, height=40) self.saveButton.connect(gui.CLICK, self.saveSpell, None) self.tBottom.td(self.saveButton) e = gui.Button("Cancel", width=100, height=40) e.connect(gui.CLICK, self.cancel, None) self.tBottom.td(e) self.add(self.tTitle, 0, 0) self.add(self.tContent, 0, 100) self.add(self.tData, 0, 255) self.add(self.tBottom, 0, 368)
def gen_gui(self): #get theme, language and end process function from omnitool API from omnitool.shared import lang, theme, exit_prog, exit_prog from omnitool.pgu_override import Quitbutton #initilize pygame renderer pygame.display.init() #set window title to Flatworld, from language file pygame.display.set_caption(lang.flat) #application interface app = gui.Desktop(theme=theme) #main container, table main = gui.Table(width=800) #connect the QUIT event with Omnitool API exit_prog app.connect(gui.QUIT, exit_prog, None) #add label size to table main.td(gui.Label(lang.fw_size)) #size drop down selection size = gui.Select(width=300) size.add(lang.fw_tiny, 4) size.add(lang.fw_small, 0) size.add(lang.fw_medium, 1) size.add(lang.fw_large, 2) size.add(lang.fw_square, 3) size.value = 0 #add it to the table main.td(size) #surface label main.td(gui.Label(lang.fw_surf)) surf = [ "Grass Block", "Corrupt Grass Block", "Jungle Grass Block", "Mushroom Grass Block", "Hallowed Grass Block" ] #surface drop down menu sur = gui.Select(width=300) sur.add("None", None) for grass in surf: sur.add(grass, tiles.index(grass)) sur.value = None #add surface selection to table main.td(sur) #go to next line in table main.tr() #add tile label to table main.td(gui.Label(lang.fw_tile)) #create tile list tiles_ = gui.List(300, 150) for tile in tiles: if tiles.index(tile) not in multitiles: tiles_.add(gui.Label(tile), value=tiles.index(tile)) #add tile list to table main.td(tiles_) #add wall label to table main.td(gui.Label(lang.fw_wall)) #create wall list guiwalls = gui.List(300, 150) for wall in walls: guiwalls.add(gui.Label(wall), value=walls.index(wall)) #add wall list to table main.td(guiwalls) #next row main.tr() #Generate! button main.td(Quitbutton(app, lang.pt_start), colspan=4) #run the application and open the window app.run(main) #when it's done, instruct pygame to clean up pygame.display.quit() #attach data to plugin, to be used in run() self.surface = sur.value self.wall = guiwalls.value self.tile = tiles_.value self.size = size.value if self.wall == 0: self.wall = None
def __init__(self): gui.Container.__init__(self) self.engine = None #regex=r'[^a-zA-Z0-9 -]' def special_match(strg, search=re.compile(r'[^a-zA-Z0-9 -]').search): if bool(search(strg)): if strg == '\xe4' or strg == '\xc4' or strg == '\xf6' or strg == '\xd6': return True return False return True def intMatch(str, search=re.compile(r'[^0-9]').search): if bool(search(str)): return False return True def fnc1(self): self.input1.value = "" self.input2.value = "0" self.typeList.value = NPC_WALKTYPE_STOPPED self.engine.maps[:] = [] self.engine.mapButtons.label2.set_text("") self.engine.mapButtons.xInput._setvalue("0") self.engine.mapButtons.yInput._setvalue("0") self.engine.mapButtons.dirList.value = DIR_DOWN self.engine.mapButtons.populateTypeList() self.engine.mapButtons.xInput.disabled = True self.engine.mapButtons.yInput.disabled = True self.engine.mapButtons.dirList.disabled = True self.engine.mapButtons.btn1.disabled = True self.engine.mapButtons.btn3.disabled = True self.engine.textarea.textArea._setvalue("") self.engine.Facing = 0 self.engine.hat = 1 self.engine.shirt = 0 self.engine.shoes = 0 self.engine.face = 1 self.engine.updateCharSprite() def fnc2(): if self.typeList.value == NPC_WALKTYPE_RESTRICTED: self.input2.disabled = False else: self.input2.disabled = True self.input2.value = "0" def fnc3(): if len(self.input2.value) > 0: if not intMatch(self.input2.value[len(self.input2.value) - 1]): self.input2.value = self.input2.value[:-1] def fnc4(): if len(self.input1.value) > 0: if not special_match( self.input1.value[len(self.input1.value) - 1]): self.input1.value = self.input1.value[:-1] if len(self.input1.value) == 0: self.button2.disabled = True else: self.button2.disabled = False def fnc5(): npc = { "t": self.typeList.value, 'r': int(self.input2.value), 'f': self.engine.Facing, 'h': self.engine.hat, 's': self.engine.shirt, 'sh': self.engine.shoes, 'fa': self.engine.face, 'te': self.engine.textarea.textArea.value, 'm': self.engine.maps, 'type': self.npcTypeList.value } with open(g.dataPath + '/npc/' + self.input1.value + '.npc', 'w') as fp: json.dump(npc, fp) def selectFile(object): self.openFile(object.value) def fnc6(): a = gui.FileDialog(path=g.dataPath + "/npc/") a.connect(gui.CHANGE, selectFile, a) a.open() button1 = gui.Button("New", width=75, height=30) button1.connect(gui.CLICK, fnc1, self) self.button2 = gui.Button("Save", width=75, height=30, disabled=True) self.button2.connect(gui.CLICK, fnc5) self.button3 = gui.Button("Open", width=75, height=30) self.button3.connect(gui.CLICK, fnc6) label1 = gui.Label("NPC name:", color=fontcolor) label2 = gui.Label("Walk type:", color=fontcolor) label3 = gui.Label("Walking area radius:", color=fontcolor) label4 = gui.Label("NPC type:", color=fontcolor) self.input1 = gui.Input(value="", width=200) self.input1.connect(gui.CHANGE, fnc4) self.input2 = gui.Input(value="0", width=50, disabled=True) self.input2.connect(gui.CHANGE, fnc3) self.typeList = gui.Select(value=0) self.typeList.add("WALKTYPE_STOPPED", 0) self.typeList.add("WALKTYPE_RESTRICTED", 1) self.typeList.add("WALKTYPE_FREEWALK", 2) self.typeList.connect(gui.CHANGE, fnc2) self.npcTypeList = gui.Select(value=0) self.npcTypeList.add("NPC_ACTIONTYPE_TALK", 0) self.npcTypeList.add("NPC_ACTIONTYPE_HEAL", 1) self.npcTypeList.add("NPC_ACTIONTYPE_SHOP", 2) self.add(label1, 10, 20) self.add(self.input1, 20 + label1.style.width, 20) self.add(label2, 10, 30 + label1.style.height) self.add(label3, 10, 40 + label1.style.height + label2.style.height) self.add( label4, 10, 50 + label1.style.height + label2.style.height + label3.style.height) self.add(self.input2, 20 + label3.style.width, 40 + label1.style.height + label2.style.height) self.add(self.typeList, 20 + label1.style.width, 30 + label1.style.height) self.add(button1, width - 100, 15) self.add(self.button2, width - 100, 55) self.add(self.button3, width - 100, 95) self.add( self.npcTypeList, 20 + label1.style.width, 50 + label1.style.height + label2.style.height + label3.style.height)