Exemple #1
0
 def load_window_layout(self):
     dlg = filedlg.FileDialog(self,
                              filedlg.OPEN,
                              'layout file',
                              'Load window layout',
                              self.__window_layout_file_location(),
                              self.__window_layout_file_suffixes(),
                              import_button=False)
     if dlg.ShowModal() == wx.ID_OK:
         # Check that OK to close any open child windows
         ok_to_load = False
         child_views = self.get_child_dialogs()
         if len(child_views) == 0:
             ok_to_load = True
         else:
             msg = "Conjurer will close any open child windows.\n\n" \
                         "Are you sure you want to load the '%s' layout file?" \
                         % dlg.get_guiname()
             result = cjr.warn_yes_no(self, msg)
             if result == wx.ID_YES:
                 for each_child in child_views:
                     each_child.Close()
                 ok_to_load = True
         if ok_to_load:
             # Load the window layout
             self.load_window_layout_from_file(dlg.get_path())
     dlg.Destroy()
Exemple #2
0
 def on_save_level_as(self, event):
     """ Save the current level under a new name. """
     # Ask for a name for the new level
     dlg = filedlg.FileDialog(self.get_frame(), filedlg.SAVE, 'level',
                              'Level', "wc:levels", ["n2"])
     if dlg.ShowModal() == wx.ID_OK:
         new_level_name = dlg.get_guiname()
         # Check the name hasn't already been taken
         if dlg.file_exists():
             msg = "There is already a level called '%s'.\n\n" \
                         "Please enter a new level name." % new_level_name
             cjr.show_error_message(msg)
         else:
             try:
                 try:
                     new_level_path = dlg.get_path_as_string()
                     dlg2 = waitdlg.WaitDialog(
                         self.get_frame(),
                         "Saving level as '%s'..." % new_level_name)
                     save_ok = servers.get_conjurer().savecurrentlevelas(
                         new_level_path)
                     if save_ok:
                         self.refresh()
                     else:
                         cjr.show_error_message(
                             "Unable to save level as '%s'." %
                             new_level_name)
                 finally:
                     dlg2.Destroy()
             except:
                 raise  # make sure any errors are not hidden
     dlg.Destroy()
Exemple #3
0
 def load_cb(self, *args):
     import filedlg
     dlg = filedlg.FileDialog(dialog_type=filedlg.FILE_OPEN,
                              filter='Legend Files|*.leg')
     dlg.ok_button.connect('clicked', self.load, dlg)
     dlg.cancel_button.connect('clicked', dlg.hide)
     dlg.show()
Exemple #4
0
 def save_current_window_layout(self):
     # Ask for a name for the layout file
     dlg = filedlg.FileDialog(self, filedlg.SAVE, 'layout file',
                              'Save window layout',
                              self.__window_layout_file_location(),
                              self.__window_layout_file_suffixes())
     if dlg.ShowModal() == wx.ID_OK:
         saved_ok = self.save_window_layout_to_file(dlg.get_path())
         if saved_ok:
             #let the user know if the file saved OK
             msg = "Saved window layout as '%s'." % dlg.get_guiname()
             cjr.show_information_message(msg)
     dlg.Destroy()
Exemple #5
0
    def on_delete_level(self, event):
        """Show a file browser and delete the selected level"""
        # Ask for the level's name
        current_level_name = get_name_of_current_level()
        dlg = filedlg.FileDialog(
            self.get_frame(),
            filedlg.DELETE,
            'level',
            'Level',
            "wc:levels", ["n2"],
            excluded_files=['default.n2',
                            '%s.n2' % current_level_name])
        result_ok = dlg.ShowModal() == wx.ID_OK
        level_name = dlg.get_guiname()
        level_path = dlg.get_path_as_string()
        dlg.Destroy()
        if not result_ok:
            return

        # Ask for confirmation
        msg = "All your hard work is going to be removed, deleted, " \
            "cleared, lost forever (ok, you can still revert\n" \
            "your working copy, but your local level is going to be " \
            "erased for sure).\n\nSo, are you sure that you want to " \
            "delete the '%s' level?" % level_name
        result = cjr.warn_yes_no(self.get_frame(), msg)
        if result != wx.ID_YES:
            return

        # Ask for final confirmation
        msg = "If you have clicked OK because of a tick in your finger, this " \
            "is your last chance to avoid throwing away the whole level.\n\n" \
            "Again, and for last time, are you ABSOLUTELY sure that you " \
            "want to delete the '%s' level?" % level_name
        result = cjr.warn_yes_no(self.get_frame(), msg)
        if result != wx.ID_YES:
            return

        # Finally delete the level (and the presets configuration)
        try:
            try:
                dlg = waitdlg.WaitDialog(self.get_frame(),
                                         "Deleting level %s..." % level_name)
                unassign_preset(level_name)
                servers.get_conjurer().deletelevel(level_path)
            finally:
                dlg.Destroy()
        except:
            # make sure any errors are not hidden
            raise
Exemple #6
0
 def on_open_level(self, event):
     """Show a file browser and open the selected level"""
     # Ask for the level's name
     dlg = filedlg.FileDialog(self.get_frame(),
                              filedlg.OPEN,
                              'level',
                              'Level',
                              "wc:levels", ["n2"],
                              import_button=False)
     if dlg.ShowModal() == wx.ID_OK:
         # Check that the filename exists
         level_name = dlg.get_guiname()
         if not dlg.file_exists():
             msg = "So you want to open the '%s' level that doesn't exist?" \
                         "\n<sigh> How curious these humans are..." \
                         % level_name
             cjr.show_error_message(msg)
         else:
             # Ask for final confirmation
             msg = "Any previous unsaved level data will be lost.\n\n" \
                         "Are you sure that you want to load the "\
                         "'%s' level?" % level_name
             result = cjr.warn_yes_no(self.get_frame(), msg)
             if result == wx.ID_YES:
                 # Finally load the level
                 try:
                     try:
                         dlg3 = waitdlg.WaitDialog(
                             self.get_frame(),
                             "Loading level %s..." % level_name)
                         if prelevel_process(True):
                             servers.get_conjurer().loadlevel(
                                 dlg.get_path_as_string())
                             postlevel_process(True)
                     finally:
                         dlg3.Destroy()
                 except:
                     # make sure any errors are not hidden
                     raise
     dlg.Destroy()
Exemple #7
0
 def on_new_level(self, event):
     """Create a new level replacing the old one, if user confirms"""
     # Ask for the level's name
     dlg = filedlg.FileDialog(self.get_frame(), filedlg.NEW, 'level',
                              'Level', "wc:levels", ["n2"])
     if dlg.ShowModal() == wx.ID_OK:
         # Check that's a new filename
         if dlg.file_exists():
             msg = "There is already a level called '%s'.\n\n" \
                         "Please enter a new level name." % dlg.get_guiname()
             cjr.show_error_message(msg)
         else:
             # Ask for final confirmation
             msg = "Any previous unsaved level data will be lost.\n\n" \
                     "Are you sure you want to create the new level '%s'?"\
                     % dlg.get_guiname()
             result = cjr.warn_yes_no(self.get_frame(), msg)
             if result == wx.ID_YES:
                 # Finally create the new level
                 if prelevel_process(True):
                     servers.get_conjurer().newlevel(
                         dlg.get_path_as_string())
                     postlevel_process(True)
     dlg.Destroy()