Exemple #1
0
 def setuphelp(self):
     """Does all the nonsense to get help working"""
     import wx.html
     # Add the Zip filesystem
     wx.FileSystem_AddHandler(wx.ZipFSHandler())
     # Get the help working
     self.helpcontroller=wx.html.HtmlHelpController()
     self.helpcontroller.AddBook(guihelper.getresourcefile("bitpim.htb"))
     self.helpcontroller.UseConfig(self.config, "help")
 def __InitXRC(self):
     resourceText = open(XRCFILE).read()
     if sys.version_info.major == 2:
         wx.FileSystem_AddHandler(wx.MemoryFSHandler())
         wx.MemoryFSHandler_AddFile(XRCFILE, resourceText)
     elif sys.version_info.major == 3:
         wx.FileSystem.AddHandler(wx.MemoryFSHandler())
         # wx.MemoryFSHandler.AddFile( filename=XRCFILE, image=resourceText )
         wx.MemoryFSHandler.AddFileWithMimeType(XRCFILE, resourceText,
                                                'xrc')
Exemple #3
0
    def OnInit(self):
        # add the image to the MemoryFileSystem:
        mfs = wx.MemoryFSHandler()
        wx.FileSystem_AddHandler(mfs)
        mfs.AddFile("smalltest.png", smalltest.GetImage(), wx.BITMAP_TYPE_PNG)

        # Initializing the Frame
        frame = DemoFrame(None, title="HTML Tester Window", size=(500, 500))
        self.SetTopWindow(frame)

        frame.Show(True)
        return True
Exemple #4
0
 def OnInit(self):
     mfs = wx.MemoryFSHandler()
     noteImage = wx.BitmapFromImage(
         wx.Image(constants.NOTES_IMAGE, wx.BITMAP_TYPE_PNG).Scale(24, 24))
     okImage = wx.BitmapFromImage(
         wx.Image(constants.OK_IMAGE, wx.BITMAP_TYPE_PNG).Scale(24, 24))
     notOkImage = wx.BitmapFromImage(
         wx.Image(constants.NOT_OK_IMAGE, wx.BITMAP_TYPE_PNG).Scale(24, 24))
     mfs.AddFile("edit-notes.png", noteImage, wx.BITMAP_TYPE_PNG)
     mfs.AddFile("ok.png", okImage, wx.BITMAP_TYPE_PNG)
     mfs.AddFile("not-ok.png", notOkImage, wx.BITMAP_TYPE_PNG)
     wx.FileSystem_AddHandler(mfs)
     return True
Exemple #5
0
    def __init__(self, parent, log):
        wx.Panel.__init__(self, parent, -1)
        self.log = log

        # make the components
        label = wx.StaticText(self, -1,
                              "The lower panel was built from this XML:")
        label.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD))

        resourceText = open(RESFILE).read()
        text = wx.TextCtrl(self,
                           -1,
                           resourceText,
                           style=wx.TE_READONLY | wx.TE_MULTILINE)
        text.SetInsertionPoint(0)

        line = wx.StaticLine(self, -1)

        # This shows a few different ways to load XML Resources
        if 0:
            # XML Resources can be loaded from a file like this:
            res = xrc.XmlResource(RESFILE)

        elif 1:
            # or from a Virtual FileSystem:
            wx.FileSystem_AddHandler(wx.MemoryFSHandler())
            wx.MemoryFSHandler_AddFile("XRC_Resources/data_file", resourceText)
            res = xrc.XmlResource("memory:XRC_Resources/data_file")

        else:
            # or from a string, like this:
            res = xrc.EmptyXmlResource()
            res.LoadFromString(resourceText)

        # Now create a panel from the resource data
        panel = res.LoadPanel(self, "MyPanel")

        # and do the layout
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(label, 0, wx.EXPAND | wx.TOP | wx.LEFT, 5)
        sizer.Add(text, 1, wx.EXPAND | wx.ALL, 5)
        sizer.Add(line, 0, wx.EXPAND)
        sizer.Add(panel, 1, wx.EXPAND | wx.ALL, 5)

        self.SetSizer(sizer)
        self.SetAutoLayout(True)
Exemple #6
0
    def __init__(self, lists):
        wx.App.__init__(self, redirect=False)

        mfs = wx.MemoryFSHandler()
        wx.FileSystem_AddHandler(mfs)
        mfs.AddFile("globe.png", icon.GetImage(), wx.BITMAP_TYPE_PNG)
        mfs.AddFile("cycle.png", cycle.GetImage(), wx.BITMAP_TYPE_PNG)
        mfs.AddFile("download.png", download.GetImage(), wx.BITMAP_TYPE_PNG)
        mfs.AddFile("downloaded.png", downloaded.GetImage(),
                    wx.BITMAP_TYPE_PNG)
        mfs.AddFile("error.png", error.GetImage(), wx.BITMAP_TYPE_PNG)
        mfs.AddFile("warning.png", warning.GetImage(), wx.BITMAP_TYPE_PNG)
        mfs.AddFile("logo.png", logo.GetImage(), wx.BITMAP_TYPE_PNG)

        default_connection = get_default_connection()
        if default_connection:
            parameters = get_saved_connection(default_connection)
            parameters["engine"] = default_connection
            engine = choose_engine(parameters)
        else:
            wizard = ConnectWizard(lists, ENGINE_LIST)

            success = wizard.RunWizard(wizard.pages[0])

            if not success:
                wizard.Destroy()
                return

            engine = wizard.CONNECTION.engine
            options = wizard.CONNECTION.option
            opts = dict()
            for key in options.keys():
                opts[key] = options[key].GetValue()
            engine.opts = opts
            wizard.Destroy()

        try:
            engine.get_connection()
        except:
            pass

        self.frame = Frame(None, -1, "EcoData Retriever version %s" % VERSION,
                           lists, engine)
        self.frame.Show()
Exemple #7
0
    def __init__(self, mainwindow, parent, media_root):
        global thewallpapermanager
        thewallpapermanager = self
        self.mainwindow = mainwindow
        self.usewidth = 10
        self.useheight = 10
        self._dummy_image_filename = guihelper.getresourcefile('wallpaper.png')
        wx.FileSystem_AddHandler(BPFSHandler(self))
        self._data = {self.database_key: {}}
        fileview.FileView.__init__(self, mainwindow, parent, media_root,
                                   "wallpaper-watermark")
        self.thedir = self.mainwindow.wallpaperpath
        self.wildcard="Image files|*.bmp;*.jpg;*.jpeg;*.png;*.gif;*.pnm;*.tiff;*.ico;*.bci;*.bit"\
                       "|Video files|*.3g2|All files|*.*"

        ##        self.bgmenu.Insert(1,guihelper.ID_FV_PASTE, "Paste")
        ##        wx.EVT_MENU(self.bgmenu, guihelper.ID_FV_PASTE, self.OnPaste)

        self.modified = False
        pubsub.subscribe(self.OnListRequest, pubsub.REQUEST_WALLPAPERS)
        self._raw_image = self._shift_down = False
Exemple #8
0
class WizardHtmlWindow(wx.html.HtmlWindow):
    def __init__(self,
                 parent,
                 id,
                 pos=wx.DefaultPosition,
                 size=wx.DefaultSize):
        wx.html.HtmlWindow.__init__(self,
                                    parent,
                                    id,
                                    pos=pos,
                                    size=size,
                                    style=(wx.html.HW_NO_SELECTION
                                           | wx.FULL_REPAINT_ON_RESIZE))
        if "gtk2" in wx.PlatformInfo:
            self.SetStandardFonts()
        self.parent = parent
        self.step = 0

        # add the donate image to the MemoryFileSystem:

    mfs = wx.MemoryFSHandler()
    wx.FileSystem_AddHandler(mfs)

    def OnLinkClicked(self, linkinfo):
        webbrowser.open_new(linkinfo.GetHref())

    def GetActiveStep(self):
        return self.step

    def SetStep(self, step):
        self.step = step
        if step >= len(steps):
            config.rendering = False
            config.resume = False
            self.SetPage(stepfinal % (config.outputdir, config.outputdir))
            return
        self.SetPage(steps[step])
        if step == 1:
            self.FindWindowByName(config.profile).SetValue(1)
        elif step == 2:
            pass
            #self.FindWindowByName('nodatapanel').SetColor(config.nodata)
        elif step == 3:
            if not config.srs:
                config.customsrs = config.files[0][6]
                config.srs = config.customsrs
            if not config.srs and config.bboxgeoref:
                config.srsformat = 1
                config.srs = config.epsg4326
            self.FindWindowByName('srs').SetSelection(config.srsformat)
            self.FindWindowByName('srs').SetValue(config.srs)
        elif step == 4:
            g2t = wxGDAL2Tiles([
                '--profile', config.profile, '--s_srs', config.srs,
                str(config.files[0][2])
            ])
            g2t.open_input()
            config.tminz = g2t.tminz
            config.tmaxz = g2t.tmaxz
            config.kml = g2t.kml
            del g2t

            self.FindWindowByName('tminz').SetValue(config.tminz)
            self.FindWindowByName('tmaxz').SetValue(config.tmaxz)

            if config.profile == 'gearth':
                self.FindWindowByName('format').SetItems([
                    _("PNG - with transparency"),
                    _("JPEG - smaller but without transparency"),
                    _("Hybrid JPEG+PNG - only for Google Earth"),
                    _("Garmin Custom maps KMZ - 256 pixels"),
                    _("Garmin Custom maps KMZ - 512 pixels"),
                    _("Garmin Custom maps KMZ - 1024 pixels")
                ])
            else:
                self.FindWindowByName('format').SetItems([
                    _("PNG - with transparency"),
                    _("JPEG - smaller but without transparency"),
                    _("Hybrid JPEG+PNG - only for Google Earth")
                ])

            if not config.format and config.profile == 'gearth':
                self.FindWindowByName('format').SetSelection(2)  # hybrid
            elif not config.format:
                self.FindWindowByName('format').SetSelection(0)  # png
            else:
                self.FindWindowByName('format').SetSelection({
                    'png': 0,
                    'jpeg': 1,
                    'hybrid': 2,
                    'garmin256': 3,
                    'garmin512': 4,
                    'garmin1024': 5
                }[config.format])

            self.Refresh()
            self.Update()
        elif step == 5:
            filename = config.files[0][0]

            # If this is the first time the user has gone this far,
            # we try to come up with sensible default output directory.
            if config.outputdir is None:
                input_dir = os.path.dirname(filename)

                # Implicitly we try to place it in the same directory in
                # which the input file is located. But if this is not possible,
                # we try to use the current directory.
                if os.access(input_dir, os.W_OK):
                    base_dir = input_dir
                else:
                    base_dir = os.getcwd()

                # Default name is the same as the input file without extensions.
                config.outputdir = os.path.join(
                    base_dir,
                    os.path.splitext(os.path.basename(filename))[0])

            browseButton = self.FindWindowByName('browsebutton')
            if browseButton:
                browseButton.Bind(wx.EVT_BUTTON, self.OnBrowseButtonPressed)
            self.FindWindowByName('outputdir').SetValue(config.outputdir)

        elif step == 6:
            not_hybrid = config.format != 'hybrid'
            if config.profile == 'mercator':
                self.FindWindowByName('google').Enable(not_hybrid)
                self.FindWindowByName('openlayers').Enable(not_hybrid)
                self.FindWindowByName('kml').Enable(True)
            elif config.profile == 'geodetic':
                self.FindWindowByName('google').Enable(False)
                self.FindWindowByName('openlayers').Enable(not_hybrid)
                self.FindWindowByName('kml').Enable(True)
            elif config.profile == 'raster':
                self.FindWindowByName('google').Enable(False)
                self.FindWindowByName('openlayers').Enable(not_hybrid)
                if not config.kml:
                    self.FindWindowByName('kml').Enable(False)
            elif config.profile == 'gearth':
                self.FindWindowByName('google').Enable(False)
                self.FindWindowByName('openlayers').Enable(not_hybrid)
                self.FindWindowByName('kml').Enable(True)

            self.FindWindowByName('google').SetValue(config.google)
            self.FindWindowByName('openlayers').SetValue(config.openlayers)
            self.FindWindowByName('kml').SetValue(config.kml)

        elif step == 7:
            config.title = os.path.basename(config.files[0][0])
            self.FindWindowByName('title').SetValue(config.title)
            self.FindWindowByName('copyright').SetValue(config.copyright)
            self.FindWindowByName('googlekey').SetValue(config.googlekey)
            self.FindWindowByName('yahookey').SetValue(config.yahookey)

    def SaveStep(self, step):
        if step == 1:
            # Profile
            if self.FindWindowByName('mercator').GetValue():
                config.profile = 'mercator'
            elif self.FindWindowByName('geodetic').GetValue():
                config.profile = 'geodetic'
            elif self.FindWindowByName('raster').GetValue():
                config.profile = 'raster'
            elif self.FindWindowByName('gearth').GetValue():
                config.profile = 'gearth'
            print config.profile
        elif step == 2:
            # Files + Nodata
            print config.files
            config.nodata = self.FindWindowByName('nodatapanel').GetColor()
            print config.nodata
        elif step == 3:
            config.srs = self.FindWindowByName('srs').GetValue().encode(
                'ascii', 'ignore').strip()
            config.srsformat = self.FindWindowByName('srs').GetSelection()
            print config.srs
        elif step == 4:
            config.tminz = int(self.FindWindowByName('tminz').GetValue())
            config.tmaxz = int(self.FindWindowByName('tmaxz').GetValue())

            format = self.FindWindowByName('format').GetCurrentSelection()
            config.format = ('png', 'jpeg', 'hybrid', 'garmin256', 'garmin512',
                             'garmin1024')[format]

            if config.format != 'hybrid':
                config.google = config.profile == 'mercator'
                config.openlayers = True
            else:
                config.google = False
                config.openlayers = False
            config.kml = config.profile in ('gearth', 'geodetic')

            print config.tminz
            print config.tmaxz
            print config.format
        elif step == 5:
            config.outputdir = self.FindWindowByName('outputdir').GetValue()
            config.url = self.FindWindowByName('url').GetValue()
            if config.url == 'http://':
                config.url = ''
        elif step == 6:
            config.google = self.FindWindowByName('google').GetValue()
            config.openlayers = self.FindWindowByName('openlayers').GetValue()
            config.kml = self.FindWindowByName('kml').GetValue()
        elif step == 7:
            config.title = self.FindWindowByName('title').GetValue().encode(
                'utf8')
            if not config.title:
                config.title = os.path.basename(
                    config.files[0][0]).encode('utf8')
            config.copyright = self.FindWindowByName(
                'copyright').GetValue().encode('utf8')
            config.googlekey = self.FindWindowByName(
                'googlekey').GetValue().encode('utf8')
            config.yahookey = self.FindWindowByName(
                'yahookey').GetValue().encode('utf8')
            print config.title
            print config.copyright
            print config.googlekey
            print config.yahookey

    def OnBrowseButtonPressed(self, evt):
        # browse button has been pressed to select output directory
        outputbox = self.FindWindowByName('outputdir')
        currentdir = outputbox.GetValue()
        dlg = wx.DirDialog(self, _("Choose output directory"), currentdir)
        if dlg.ShowModal() == wx.ID_OK:
            outputbox.SetValue(dlg.GetPath())

    def UpdateRenderProgress(self, complete):
        if self.step != len(steps) - 1:
            print _("Nothing to update - progressbar not displayed")
        else:
            progressbar = self.FindWindowByName('progressbar')
            progressbar.SetValue(complete)

    def UpdateRenderText(self, text):
        if self.step != len(steps) - 1:
            print _("Nothing to update - progresstext not displayed")
        else:
            progresstext = self.FindWindowByName('progresstext')
            progresstext.SetLabel(text)
            self.Layout()
            self.Refresh()

    def StartThrobber(self):
        self.FindWindowByName('throbber').Start()
        self.FindWindowByName('throbber').ToggleOverlay(False)

    def StopThrobber(self):
        self.FindWindowByName('throbber').Stop()
        self.FindWindowByName('throbber').ToggleOverlay(True)
Exemple #9
0
    def demo():
        import wx
        app=wx.PySimpleApp()

        import sys
        import common
        sys.excepthook=common.formatexceptioneh
        import wx.html
        import os
        import brewcompressedimage
        import wallpaper
        import fileinfo
        import conversions


        # find bitpim wallpaper directory
        config=wx.Config("bitpim", style=wx.CONFIG_USE_LOCAL_FILE)

        p=config.Read("path", "resources")
        pn=os.path.join(p, "wallpaper")
        if os.path.isdir(pn):
            p=pn

        imagespath=p
        images=[name for name in os.listdir(imagespath) if name[-4:] in (".bci", ".bit", ".bmp", ".jpg", ".png")]
        images.sort()
        #images=images[:9]

        print imagespath
        print images

        class WallpaperManager:

            def GetImageStatInformation(self,name):
                return wallpaper.statinfo(os.path.join(imagespath, name))    

            def GetImageConstructionInformation(self,file):
                file=os.path.join(imagespath, file)
                
                if file.endswith(".mp4") or not os.path.isfile(file):
                    return guihelper.getresourcefile('wallpaper.png'), wx.Image
                if self.isBCI(file):
                    return file, lambda name: brewcompressedimage.getimage(brewcompressedimage.FileInputStream(file))
                # LG phones may return a proprietary wallpaper media file, LGBIT
                fi=fileinfo.identify_imagefile(file)
                if fi is not None and fi.format=='LGBIT':
                    return file, conversions.convertfilelgbittobmp
                return file, wx.Image

            def isBCI(self, filename):
                # is it a bci file?
                return open(filename, "rb").read(4)=="BCI\x00"


        wx.FileSystem_AddHandler(wallpaper.BPFSHandler(WallpaperManager()))

        class TestItem(Item):

            def __init__(self, ds, secnum, itemnum, label):
                super(TestItem,self).__init__()
                self.label=label
                self.ds=ds
                self.secnum=secnum
                self.itemnum=itemnum

            def Draw(self, dc, width, height, selected):
                # uncomment to see exactly what size is given
                #dc.DrawRectangle(0,0,width,height)
                us=dc.GetUserScale()
                dc.SetClippingRegion(0,0,width,height)
                hdc=wx.html.HtmlDCRenderer()
                hdc.SetDC(dc, 1)
                hdc.SetSize(9999, 9999) # width is deliberately wide so that no wrapping happens
                hdc.SetHtmlText(self.genhtml(selected), '.', True)
                hdc.Render(0,0)
                del hdc
                # restore scale hdc messes
                dc.SetUserScale(*us)
                dc.DestroyClippingRegion()

                # Linux gets bounding box wrong, so we deliberately return actual size
                if guihelper.IsGtk():
                    return (0,0,width,height)
                elif guihelper.IsMSWindows():
                    return max(0,dc.MinX()), max(0, dc.MinY()), min(width, dc.MaxX()), min(height, dc.MaxY())

            def genhtml(self, selected):
                if selected:
                    selected='bgcolor="blue"'
                else:
                    selected=""
                return """<table %s><tr><td valign=top><p><img src="bpuserimage:%s;width=%d;height=%d;valign=top"><td valign=top><b>%s</b><br>BMP format<br>123x925<br>Camera</tr></table>""" \
                       % (selected, images[self.itemnum], self.ds.IMGSIZES[self.secnum][0], self.ds.IMGSIZES[self.secnum][1], self.label, )

        class TestDS(DataSource):

            SECTIONS=("Camera", "Wallpaper", "Oranges", "Lemons")
            ITEMSIZES=( (240,240), (160,70), (48,48), (160,70) )
            IMGSIZES=[ (w-110,h-20) for w,h in ITEMSIZES]
            IMGSIZES[2]=(16,16)

            def GetSections(self):
                return [SectionHeader(x) for x in self.SECTIONS]

            def GetItemsFromSection(self, sectionnumber, sectionheader):
                return [TestItem(self, sectionnumber, i, "%s-#%d" % (sectionheader.label,i)) for i in range(len(images))]

            def GetItemSize(self, sectionnumber, sectionheader):
                return self.ITEMSIZES[sectionnumber]

        f=wx.Frame(None, title="Aggregate Display Test")
        ds=TestDS()
        d=Display(f,ds, "wallpaper-watermark")
        f.Show()

        app.MainLoop()