def init_widget (self, **kw):
     r"""
         widget main inits;
     """
     # super class inits
     super().init_widget(
         # looks for ^/xml/widget/dlg_namedb_import.xml
         xml="dlg_namedb_import",
     )
     # member inits
     self.async = ASYNC.get_async_manager()
     self.current_path = ""
     self.database = self.tk_owner.database
     self.stop_import = False
     self.DEFAULT_DIR = P.normalize(self.DEFAULT_DIR)
     # dialog widgets
     self.BTN_IMPORT = self.container.btn_import
     self.PREVIEW = self.container.text_fc_preview
     self.PROGRESSBAR = self.container.pgbar_import
     self.PBAR_VALUE = self.container.get_stringvar("pgbar_value")
     self.STATUS = self.container.get_stringvar("lbl_status")
     # reset combos
     self._fill_combos()
     # event bindings
     self.bind_events(**kw)
Ejemplo n.º 2
0
    def init_widget (self, **kw):
        r"""
            widget main inits;
        """

        # super class inits

        super().init_widget(**kw)

        # default values

        self.IMAGE_UNKNOWN = P.normalize(

            OP.join(self.IMAGES_DIR, self.IMAGE_UNKNOWN)
        )

        # member inits

        self.slot_owner = self

        self.tk_owner = self.viewport.container

        self._parent_section_id = None

        self._cvar = TK.StringVar()
 def reset_hints (self, fpath=None):
     """
         resets self.INFO_HINTS class member along with @fpath JSON
         file contents;
     """
     # param inits
     fpath = P.normalize(fpath or self.INFO_HINTS_FPATH)
     # get data
     with open(fpath, encoding=ENCODING) as _file:
         # reset member
         self.INFO_HINTS = json.load(_file)
 def get_current_dir (self):
     """
         retrieves last used directory for load/save procedure;
     """
     # inits
     _dir = self.current_dir
     # got some path?
     if self.project_path:
         # init dir
         _dir = OP.dirname(self.project_path)
     # end if
     # return normalized directory
     return P.normalize(_dir)
 def get_filename (self, fpath=None, strip_extension=False):
     """
         returns filename for a given @fpath or for
         self.project_path if @fpath is omitted; strips file
         extension if @strip_extension is True;
     """
     # inits
     _fname = OP.basename(P.normalize(fpath or self.project_path))
     # should strip file extension?
     if strip_extension:
         # inits
         _fname, _fext = OP.splitext(_fname)
     # end if
     # get filename
     return _fname
 def set_project_path (self, fpath):
     """
         sets project's path + app notifications;
     """
     # inits
     fpath = P.normalize(fpath)
     _fname = OP.basename(fpath)
     _dir = OP.dirname(fpath)
     # member inits
     self.project_path = fpath
     # project is now ready for new changes
     self.mainwindow.events.raise_event(
         "Project:Modified", flag=False
     )
     # notify application
     self.mainwindow.events.raise_event(
         "Project:Path:Update",
         new_path=fpath, filename=_fname, directory=_dir,
     )
 def is_good_file_format (self, fpath):
     """
         determines if @fpath has the correct zip archive internal
         structure;
     """
     # param inits
     fpath = P.normalize(fpath)
     # got a zip archive?
     if zipfile.is_zipfile(fpath):
         # examine archive contents
         with zipfile.ZipFile(fpath, "r") as _archive:
             # get all zip archive members
             _zfiles = _archive.namelist()
         # end with
         # compare contents
         return bool(set(self.ALL_FILES) == set(_zfiles))
     # end if
     # failure
     return False
 def do_save_project (self, fpath):
     """
         effective procedure for saving project;
     """
     # param inits
     fpath = P.normalize(fpath)
     # param controls
     if tools.is_pstr(fpath):
         # notify application
         self.notify(_("Saving project, please wait."))
         # open zip archive
         with zipfile.ZipFile(fpath, 'w') as _archive:
             # browse archive files
             for tab_id, fname in self.ARCHIVE_FILES.items():
                 # get multiple files and contents
                 _contents = self.get_fc_tab(tab_id, fname)
                 # browse contents
                 for _fname, _fcontents in _contents.items():
                     # put files and contents into zip archive
                     _archive.writestr(
                         _fname, bytes(_fcontents, ENCODING)
                     )
                 # end for
             # end for
         # end with
         # we can update project's filepath by now
         self.set_project_path(fpath)
         # notify application
         self.notify(_("Project saved OK."))
         # succeeded
         return self.YES
     # could not save file
     else:
         # show error
         MB.showerror(
             title=_("Error"),
             message=_(
                 "Could not save project. Incorrect file path."
             ),
             parent=self.mainwindow,
         )
         # failed
         return self.NO
Ejemplo n.º 9
0
    def _parse_attr_image (self, attribute, attrs, **kw):
        r"""
            image attribute;

            no return value (void);
        """

        # param controls

        if self._is_unparsed(attribute):

            # inits

            _list = [

                attribute.value,

                OP.join(self.IMAGES_DIR, attribute.value),

                self.IMAGE_UNKNOWN,
            ]

            for _path in _list:

                _path = P.normalize(_path)

                if OP.isfile(_path):

                    break

                # end if

            # end for

            # parsed attribute inits

            attribute.value = self.set_image(_path)

            self._tk_config(attribute)
Ejemplo n.º 10
0
    def __get_item_attrs (self, xml_element):
        r"""
            trying to retrieve item's specific XML attributes;
        """

        # get attrs dict

        _attrs = {

            # main: python executable

            "main": tools.choose_str(

                xml_element.get("main"),

                "main.py",
            ),

            # package: game/editor own directory

            "package": tools.choose_str(

                xml_element.get("package"),

                "misc",
            ),

            # src: remote zip archive

            "src": tools.choose_str(

                xml_element.get("src"),
            ),

            # type: 'game' or 'editor'

            "type": tools.choose_str(

                xml_element.get("type"),

                "game",
            ),

            # target directories

            "dirs": {

                "game": "^/games",

                "editor": "^/editors",
            },

        } # end of attrs dict

        # build package dir path

        _attrs["package_dir"] = P.normalize(

            _attrs["dirs"].get(_attrs["type"])
        )

        # build executable script path

        _attrs["exe_path"] = P.normalize(

            OP.join(

                _attrs["package_dir"],

                _attrs["package"],

                _attrs["main"],
            )
        )

        return _attrs
 def project_path (self, value):
     # inits
     self.__project_path = P.normalize(value)
 def current_dir (self, value):
     # inits
     self.__current_dir = P.normalize(value)