Example #1
0
 def prompt(self, title, text, button1Label, button2Label=None, button1Action=None, button2Action=None, helpId=None, fmtArgs = None):
     if fmtArgs is None:
         fmtArgs = []
     elif isinstance(fmtArgs, basestring):
         fmtArgs = [fmtArgs]
     if self.dialog is None:
         self.dialog = gui.Dialog(self.mainwin)
         self.dialog.helpIds.update(self.helpIds)
     return self.dialog.prompt(title, text, button1Label, button2Label, button1Action, button2Action, helpId, fmtArgs)
Example #2
0
        def onClicked(filename):
            if not filename:
                return

            if (os.path.exists(filename)):
                contents = io.open(filename, 'r', encoding="utf-8").read()
                self.scriptText.setText(contents)
                dlg = gui.Dialog()
                dlg.prompt("Load script",
                           "File was loaded in an acceptable manner", "OK")
                self.filename = filename
                self.directory = os.path.split(filename)[0]
            else:
                dlg = gui.Dialog()
                dlg.prompt("Load script",
                           "File %s does not exist",
                           "OK",
                           fmtArgs=filename)
Example #3
0
        def onClicked(filename):
            if not filename:
                return

            with open(filename, "w", encoding="utf-8") as f:
                f.write(self.scriptText.getText())
            dlg = gui.Dialog()
            dlg.prompt("Save script","File was written in an acceptable manner","OK")
            self.filename = filename
            self.directory = os.path.split(filename)[0]
Example #4
0
 def onClicked(path):
     if path:
         savePath = path[0]
         mo = re.search(r'\(.*\)', path[1])
         if mo:
             ext = mo.group().strip('(*) ')
         else:
             ext = ''
         if not os.path.isfile(self.metaFile):
             error_msg = 'No Base Model defined.\nPress "Set Base"'
             dialog = gui.Dialog()
             dialog.prompt(title='Error',
                           text=error_msg,
                           button1Label='OK')
             log.warning(error_msg)
         else:
             if not savePath.lower().endswith(
                     '.target') and ext != '.target':
                 error_msg = 'Cannot save diff target to file: {0:s}\nExpected a path to a .target file'.format(
                     savePath)
                 dialog = gui.Dialog()
                 dialog.prompt(title='Error',
                               text=error_msg,
                               button1Label='OK')
                 return
             else:
                 if not savePath.lower().endswith(
                         '.target') and ext == '.target':
                     savePath += ext
                 human = G.app.selectedHuman
                 target = algos3d.getTarget(human.meshData,
                                            self.metaFile)
                 target.apply(human.meshData, -1)
                 self.saveTargets(savePath, False)
                 target.apply(human.meshData, 1)
                 self.diffFileName = os.path.basename(savePath)
                 self.diffDirName = os.path.dirname(savePath)
                 self.diffNameEdit.setText(self.diffFileName)
                 self.saveDiffAsButton.path = savePath
                 G.app.statusPersist(
                     'Saving Target Directory: ' + self.dirName +
                     '   Saving Diff Targets Directory: ' +
                     self.diffDirName)
Example #5
0
 def onClicked(event):
     filename = mh.getSaveFileName(
         self.filename or self.directory,
         'Python scripts (*.py);;All files (*.*)')
     with open(filename, "w") as f:
         f.write(self.scriptText.getText())
     dlg = gui.Dialog()
     dlg.prompt("Save script",
                "File was written in an acceptable manner", "OK")
     self.filename = filename
     self.directory = os.path.split(filename)[0]
Example #6
0
 def prompt(self,
            title,
            text,
            button1Label,
            button2Label=None,
            button1Action=None,
            button2Action=None,
            helpId=None):
     if self.dialog is None:
         self.dialog = gui.Dialog(self.mainwin)
         self.dialog.helpIds.update(self.helpIds)
     self.dialog.prompt(title, text, button1Label, button2Label,
                        button1Action, button2Action, helpId)
Example #7
0
        def onClicked(event):
            if not os.path.isfile(self.metaFile):
                error_msg = 'No Base Model defined.\nPress "Set Base"'
                dialog = gui.Dialog()
                dialog.prompt(title='Error', text=error_msg, button1Label='OK')
                log.warning(error_msg)
            else:
                path = os.path.join(self.diffDirName, self.diffFileName)
                overwrite = True
                dialog = gui.Dialog()

                if not path.lower().endswith('.target'):
                    error_msg = 'Cannot save target to file: {0:s}\nExpected a path to a .target file'.format(
                        path)
                    dialog.prompt(title='Error',
                                  text=error_msg,
                                  button1Label='OK')
                    log.error('Cannot save targets to %s. Not a .target file.',
                              path)
                    return
                else:
                    if os.path.exists(path):
                        msg = 'File {0:s} already exists. Overwrite?'.format(
                            path)
                        overwrite = dialog.prompt(title='Warning',
                                                  text=msg,
                                                  button1Label='YES',
                                                  button2Label='NO')
                        if overwrite:
                            log.message('Overwriting %s ...', path)
                    if overwrite:
                        human = G.app.selectedHuman
                        target = algos3d.getTarget(human.meshData,
                                                   self.metaFile)
                        target.apply(human.meshData, -1)
                        self.saveTargets(path, False)
                        target.apply(human.meshData, 1)
Example #8
0
 def onClicked(path):
     if path:
         if not path.lower().endswith('.target'):
             error_msg = 'Cannot save target to file: {0:s}\n Expected a path to a .target file'.format(
                 path)
             dialog = gui.Dialog()
             dialog.prompt(title='Error',
                           text=error_msg,
                           button1Label='OK')
             return
         else:
             self.saveTargets(path)
             self.nameEdit.setText(self.fileName)
             self.saveAsButton.path = path
             G.app.statusPersist('Saving Directory: ' + self.dirName)
Example #9
0
 def onClicked(path):
     if os.path.exists(path):
         if not path.lower().endswith('.target'):
             error_msg = 'Cannot save target to file: {0:s}\nExpected a path to a .target file'.format(path)
             dialog = gui.Dialog()
             dialog.prompt(title='Error', text=error_msg, button1Label='OK')
             log.error('Cannot save targets to %s. Not a .target file.', path)
             return
         else:
             self.saveTargets(path, self.stripBaseTargets.selected)
             self.fileName = os.path.basename(path)
             self.dirName = os.path.dirname(path)
             self.nameEdit.setText(self.fileName)
             self.saveAsButton.path = path
             G.app.statusPersist('Saving Target Directory: ' + self.dirName +
                                 '   Saving Diff Targets Directory: ' + self.diffDirName)
Example #10
0
 def chosen(self, menu, choice):
     map_path = resources.map_path(choice)
     try:
         s.load_map(map_path)
     except:
         msg = _(
             "Error while loading map \"%s\"! Please report this issue.\n\n%s"
         ) % (map_path, traceback.format_exc())
         logging.error(msg)
         dialog = gui.Dialog(msg,
                             f.MONOSPACE,
                             layout_gravity=gui.Gravity.FILL,
                             padding=25)
         room.run_room(dialog)
     else:
         self.done = True
Example #11
0
    def handleInput(self):

        events = pygame.event.get()
        for e in events:
            if e.type == KEYDOWN:

                if e.key == K_ESCAPE: self.showMenu()

                elif e.key == K_i:
                    gui.ControlDialog("Choose item:", [
                        gui.Button(text=item, callback=self.addItemCb) for item
                        in self.engine.scene.itemCollector.items.keys()
                    ]).run()

                elif e.key == K_m:
                    self.engine.mode = self.engine.modes["edit"]

                elif e.key == K_TAB:
                    subscreens.Subscreen(self.engine.scene).run()

                elif e.key == K_BACKQUOTE:
                    console = engine.Console(self.engine)
                    console.run()

                elif e.key == K_SPACE:
                    # perform the "main" action: initiate dialog, open chests, etc.
                    self.engine.scene.performPlayerAction()

                elif e.key == K_F1:
                    help = """
`: show console
TAB: show party screen
m: switch to edit mode
i: add an item to player inventory
ESC: quit Overworld"""

                    gui.Dialog(help).run()

            elif e.type == QUIT:
                self.engine.done = True

        keys = pygame.key.get_pressed()
        self.engine.movingRight = keys[K_RIGHT]
        self.engine.movingLeft = keys[K_LEFT]
        self.engine.movingUp = keys[K_UP]
        self.engine.movingDown = keys[K_DOWN]
        self.engine.holding_shift = pygame.key.get_mods() & KMOD_SHIFT
Example #12
0
    def quickSave(self):
        path = os.path.join(self.dirName, self.fileName)
        overwrite = True
        dialog = gui.Dialog()

        if not path.lower().endswith('.target'):
            error_msg = 'Cannot save target to file: {0:s}\nExpected a path to a .target file'.format(path)
            dialog.prompt(title='Error', text=error_msg, button1Label='OK')
            log.error('Cannot save targets to %s. Not a .target file.', path)
            return
        else:
            if os.path.exists(path):
                msg = 'File {0:s} already exists. Overwrite?'.format(path)
                overwrite = dialog.prompt(title='Warning', text=msg, button1Label='YES', button2Label='NO')
                if overwrite:
                    log.message('Overwriting %s ...', path)
            if overwrite:
                self.saveTargets(path, self.stripBaseTargets.selected)
        def onClicked(event):
            dlg = gui.Dialog()

            desiredWidth = self.widthEdit.getText()
            if (desiredWidth is None or not desiredWidth.isdigit()):
                dlg.prompt("Input error",
                           "Width and height must be valid integers", "OK")
                return

            desiredHeight = self.heightEdit.getText()
            if (desiredHeight is None or not desiredHeight.isdigit()):
                dlg.prompt("Input error",
                           "Width and height must be valid integers", "OK")
                return

            desiredWidth = int(desiredWidth)
            desiredHeight = int(desiredHeight)

            if (desiredHeight < 100 or desiredWidth < 100):
                dlg.prompt(
                    "Input error",
                    "Width and height must be at least 100 pixels each", "OK")
                return

            # This is because we're excluding a passepartout when doing screenshots.
            desiredWidth = desiredWidth + 3
            desiredHeight = desiredHeight + 3

            qmainwin = G.app.mainwin
            central = qmainwin.centralWidget()
            cWidth = central.frameSize().width()
            cHeight = central.frameSize().height()
            width = G.windowWidth
            height = G.windowHeight

            xdiff = desiredWidth - width
            ydiff = desiredHeight - height

            cWidth = cWidth + xdiff
            cHeight = cHeight + ydiff

            central.setFixedSize(cWidth, cHeight)
            qmainwin.adjustSize()
Example #14
0
    def handleInput(self):

        events = pygame.event.get()
        for e in events:
            if e.type == KEYDOWN:

                if e.key == K_ESCAPE:
                    self.showMenu()
                elif e.key == K_m:
                    self.engine.mode = self.engine.modes["play"]
                elif e.key == K_r:
                    old = self.layerInUse
                    if old == "base": self.layerInUse = "roof"
                    else: self.layerInUse = "base"
                    print "Changing layer from %s to %s" % (old,
                                                            self.layerInUse)
                elif e.key == K_s:
                    self.selectMode = not self.selectMode
                elif e.key == K_t:
                    old = self.middleClickAction
                    if old == "walk": self.middleClickAction = "trigger"
                    else: self.middleClickAction = "walk"
                    print "Changing middle click from %s to %s" % (
                        old, self.middleClickAction)
                elif e.key == K_w:
                    self.walkPaintMode = not self.walkPaintMode
                    print "Changing walk paint mode from %s to %s" % (
                        not self.walkPaintMode, self.walkPaintMode)
                elif e.key == K_a:
                    npc = Actor(self.scene, "../data/spritesets/guy.zip")
                    subscreens.CharacterScreen(npc, editable=True).run()
                    self.scene.addActorToScene(npc)
                    self.sceneDirty = True
                elif e.key == K_p:
                    subscreens.CharacterScreen(self.scene.player,
                                               editable=True).run()
                elif e.key == K_n:
                    c = self.scene.createCharacter()
                    self.scene.addPlayerToParty(c)
                    self.sceneDirty = True
                elif e.key == K_TAB:
                    ts = tiles.TileSelector(self.scene)
                    ts.show()
                    self.selectedTile = ts.selectedTile
                elif e.key == K_BACKQUOTE:
                    console = engine.Console(self.engine)
                    console.run()
                elif e.key == K_F1:
                    help = """
Help:
A: add new actor to scene
N: add new actor to party
TAB: show tile selector
`: show console
F1: this help
M: change to play mode
W: change walk painting mode
T: change to trigger painting mode
ESC: show edit mode menu
R: toggle base/roof tile painting modes
L: toggle showing base, roof, or base/roof
P: edit the main player character"""

                    d = gui.Dialog(help)
                    #d.textLabel.font = pygame.font.Font(configuration.monofont, 14)
                    d.run()

            elif e.type == MOUSEBUTTONDOWN:
                if e.button == 1: self.pressingLeftButton = True
                if e.button == 2: self.pressingMiddleButton = True
                if e.button == 3: self.pressingRightButton = True

            elif e.type == MOUSEBUTTONUP:
                if e.button == 1: self.pressingLeftButton = False
                if e.button == 2: self.pressingMiddleButton = False
                if e.button == 3: self.pressingRightButton = False

            elif e.type == QUIT:
                self.engine.done = True

        keys = pygame.key.get_pressed()
        self.engine.movingRight = keys[K_RIGHT]
        self.engine.movingLeft = keys[K_LEFT]
        self.engine.movingUp = keys[K_UP]
        self.engine.movingDown = keys[K_DOWN]
        self.engine.holding_shift = pygame.key.get_mods() & KMOD_SHIFT

        if self.pressingLeftButton: self.handleLeftButton()
        else: self.selectionStartX, self.selectionStartY = -1, -1
        if self.pressingMiddleButton: self.handleMiddleButton()
        if self.pressingRightButton: self.handleRightButton()
Example #15
0
t1 = gui.Table()
t1.tr()
t1.add(gui.Label("Gal Test"))

t2 = gui.Table()

t2.tr()
t2.add(gui.Label("Gui Widgets"))
t2.add(gui.Input())

t2.tr()
t2.add(gui.Label("Button"))
t2.add(gui.Button("Click Me!"))

d1 = gui.Dialog(t1, t2)
c.add(d1, 50, 150)

##
## dialog 2
##

t3 = gui.Table()
t3.tr()
t3.add(gui.Label("Another one"))

t4 = gui.Table()

t4.tr()
t4.add(gui.Label("Name"))
t4.add(gui.Input())