當前位置: 首頁>>代碼示例>>Python>>正文


Python View.generate_rmap方法代碼示例

本文整理匯總了Python中View.View.generate_rmap方法的典型用法代碼示例。如果您正苦於以下問題:Python View.generate_rmap方法的具體用法?Python View.generate_rmap怎麽用?Python View.generate_rmap使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在View.View的用法示例。


在下文中一共展示了View.generate_rmap方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: FormCreator

# 需要導入模塊: from View import View [as 別名]
# 或者: from View.View import generate_rmap [as 別名]

#.........這裏部分代碼省略.........
            if dlg.ShowModal() == wx.ID_OK:
                filename = dlg.GetFilename()
                dirname = dlg.GetDirectory()
                dlg.Destroy()
            else:
                self.SetStatusText(Preferences.failedToOpen)
                return False
            rmap_data = self.view.rects
            try:
                with open(join(dirname, filename), "r") as f:
                    json_data = loads(f.read())
            except Exception as e:
                self.SetStatusText(Preferences.failedToExport)
                return False
            fd = self.img.split(".")
            fd.pop()
            fname = ".".join(fd)
            rmap_data = View.filter_list(rmap_data)
            rmap_data = View.clean_list(rmap_data)
            rmap_data = View.generate_data(rmap_data)
            self.write_html_printpage(self.filename, fname, rmap_data, json_data)
        else:
            self.SetStatusText(Preferences.noImageLoaded)

    def on_save(self, event):
        """
        Copy the image from SRC to the destination directory + folder
        Then write the rectangle data to HTML format
        and also a new readable JSON format (called .RMAP)
        """
        event.Skip()
        if self.view.image is not None:
            self.view.update_values()
            rmap_data = self.view.generate_rmap()

            if self.rmap_loaded:  # this means we previously had an RMAP file loaded, so save to that
                # Use self.img as the main determiner
                # remove extension of file
                fpath = self.img.split(".")
                ext = fpath.pop()
                fpath = ".".join(fpath)

                # rewrite the RMAP and HTML
                self.write_html_rmap(fpath, rmap_data,  fpath.split('\\').pop() + "." + ext)
                self.SetStatusText(Preferences.RmapSaved.format(fpath))
            else:
                dlg = wx.FileDialog(self, "Choose a name to save the file", "", "", "rmap", wx.SAVE)
                if dlg.ShowModal() == wx.ID_OK:
                    filename = dlg.GetFilename().replace(".rmap", "")
                    dirname = dlg.GetDirectory()
                    dlg.Destroy()
                else:
                    self.SetStatusText(Preferences.failedToSave)
                    return False
                # make a directory with the filename
                newdir = join(dirname, filename)
                mkdir(newdir)

                # Copy the original image
                copy(self.img, join(newdir, self.filename))
                fname = self.filename.split(".")
                new_fname = ".".join([filename, fname.pop()])
                rename(join(newdir, self.filename), join(newdir, new_fname))

                # export HTML/CSS data to a new HTML file
                self.write_html_rmap(join(newdir, filename), rmap_data, new_fname)
開發者ID:sleibrock,項目名稱:form-creator,代碼行數:70,代碼來源:FormCreator.py


注:本文中的View.View.generate_rmap方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。