コード例 #1
0
    def ReplaceContents(self, name, origin, new_file_name):
        """Replace the contents of 'file_name' by the contents of
        'new_file_name' by going through the image converter dialog
        """
        fi=self.GetFileInfo(new_file_name)
        if fi is not None and fi.format=='LGBIT':
            img=conversions.convertfilelgbittobmp(new_file_name)
        else:
            img=wx.Image(new_file_name)
        if not img.Ok():
            guihelper.MessageDialog(self, "Failed to understand the image in '"+new_file_name+"'",
                                    "Image not understood", style=wx.OK|wx.ICON_ERROR)
            return
        with guihelper.WXDialogWrapper(ImagePreviewDialog(self, img, self.mainwindow.phoneprofile, self.active_section),
                                       True) as (dlg, retcode):
            if retcode==wx.ID_OK:
                img=dlg.GetResultImage()
                imgparams=dlg.GetResultParams()
                # ::TODO:: temporary hack - this should really be an imgparam
                extension={'BMP': 'bmp', 'JPEG': 'jpg', 'PNG': 'png'}[imgparams['format']]

                res=getattr(self, "saveimage_"+imgparams['format'])(img, imgparams)
                if not res:
                    guihelper.MessageDialog(self, "Failed to convert the image in '"+new_file_name+"'",
                                            "Image not converted", style=wx.OK|wx.ICON_ERROR)
                self.AddToIndex(name, origin, res, self._data)
コード例 #2
0
ファイル: ical_calendar.py プロジェクト: SJLC/portage-overlay
 def _export(self):
     filename = self.filenamectrl.GetValue()
     try:
         f = file(filename, 'wt')
     except:
         f = None
     if f is None:
         guihelper.MessageDialog(self,
                                 'Failed to open file [' + filename + ']',
                                 'Export Error')
         return
     all_items = self._selection.GetSelection() == 0
     dt = self._start_date.GetValue()
     range_start = (dt.GetYear(), dt.GetMonth() + 1, dt.GetDay())
     dt = self._end_date.GetValue()
     range_end = (dt.GetYear(), dt.GetMonth() + 1, dt.GetDay())
     cal_dict = self.GetParent().GetCalendarData()
     self._write_header(f)
     _tzid = self._write_timezone(f)
     # now go through the data and export each event
     for k, e in cal_dict.items():
         if not all_items and \
            (e.end < range_start or e.start>range_end):
             continue
         self._write_event(f, e, _tzid)
     self._write_end(f)
     f.close()
コード例 #3
0
ファイル: wallpaper.py プロジェクト: deosai/bitpim
 def OnAddFiles(self, filenames):
     for file in filenames:
         file_stat = os.stat(file)
         mtime = file_stat.st_mtime
         if self._raw_image:
             targetfilename = self.get_media_name_from_filename(file)
             data = open(file, 'rb').read()
             self.AddToIndex(targetfilename, self.active_section, data,
                             self._data, mtime)
         else:
             # :::TODO:: do i need to handle bci specially here?
             # The proper way to handle custom image types, e.g. BCI and LGBIT,
             # is to add a wx.ImageHandler for it. Unfortunately wx.Image_AddHandler
             # is broken in the current wxPython, so . . .
             fi = self.GetFileInfo(file)
             if fi is not None and fi.format == 'LGBIT':
                 img = conversions.convertfilelgbittobmp(file)
             elif fi and fi.format == '3GPP2':
                 # 3g2 video file, no scaling, just add
                 targetfilename = self.get_media_name_from_filename(file)
                 data = open(file, 'rb').read()
                 self.AddToIndex(targetfilename, self.active_section, data,
                                 self._data, mtime)
                 continue
             else:
                 img = wx.Image(file)
             if not img.Ok():
                 guihelper.MessageDialog(
                     self,
                     "Failed to understand the image in '" + file + "'",
                     "Image not understood",
                     style=wx.OK | wx.ICON_ERROR)
                 continue
             self.OnAddImage(img, file, refresh=False, timestamp=mtime)
     self.OnRefresh()
コード例 #4
0
    def OnAddImage(self, img, file, refresh=True, timestamp=None):
        # ::TODO:: if file is None, find next basename in our directory for
        # clipboard99 where 99 is next unused number
        
        with guihelper.WXDialogWrapper(ImagePreviewDialog(self, img, self.mainwindow.phoneprofile, self.active_section),
                                       True) as (dlg, retcode):
            if retcode==wx.ID_OK:
                img=dlg.GetResultImage()
                imgparams=dlg.GetResultParams()
                origin=self.active_section
                # if we modified the image update the timestamp
                if not dlg.skip:
                    timestamp=int(time.time())

                # ::TODO:: temporary hack - this should really be an imgparam
                extension={'BMP': 'bmp', 'JPEG': 'jpg', 'PNG': 'png'}[imgparams['format']]

                # munge name
                targetfilename=self.get_media_name_from_filename(file, extension)

                res=getattr(self, "saveimage_"+imgparams['format'])(img, imgparams)
                if not res:
                    guihelper.MessageDialog(self, "Failed to convert the image in '"+file+"'",
                                            "Image not converted", style=wx.OK|wx.ICON_ERROR)
                    return

                self.AddToIndex(targetfilename, origin, res, self._data, timestamp)
                if refresh:
                    self.OnRefresh()
コード例 #5
0
def check_update(update_url=None,
                 current_version=None,
                 platform=None,
                 flavor=''):
    # get info from current version
    if current_version is None:
        current_version = version.version
    # set flavor to blank for now, should be flavor=version.flavor
    if platform is None:
        if guihelper.IsMSWindows():
            platform = 'windows'
        elif guihelper.IsGtk():
            platform = 'linux'
        elif guihelper.IsMac():
            platform = 'mac'
        else:
            raise ValueError, 'Invalid platform'
    # todo: need to figure out how to do flavor, comment out for now
##    flavor=version.vendor
# retrieve and parse update info
    print 'Checking update for BitPim ', current_version, ' running on ', \
          platform, '-', flavor
    with guihelper.WXDialogWrapper(
            wx.ProgressDialog('BitPim Update',
                              'Retrieving BitPim Update Information...',
                              style=wx.PD_AUTO_HIDE)) as dlg:
        bp_update = BitPimUpdate()
        s = None
        try:
            if update_url is None:
                bp_update.get_update_info()
            else:
                bp_update.get_update_info(update_url)
            dlg.Update(100)
        except:
            s = 'Failed to get BitPim update info.'
    if s is None:
        s = bp_update.display_update_info(current_version, platform, flavor)
        latest_version = bp_update.latest_version
    else:
        latest_version = ''
    if s is not None:
        # error messages being return, display them
        guihelper.MessageDialog(None, s, 'BitPim Update',
                                wx.OK | wx.ICON_INFORMATION)
    return latest_version
コード例 #6
0
ファイル: vcal_calendar.py プロジェクト: deosai/bitpim
 def OnImport(self, evt):
     with guihelper.WXDialogWrapper(
             wx.ProgressDialog('%s Import' % self._data_type,
                               'Importing %s Data, please wait ...' %
                               self._data_type,
                               parent=self)) as dlg:
         try:
             self._oc.read(self.folderctrl.GetValue())
             self.populate(self._oc.get_display_data())
         except (ValueError, IOError):
             guihelper.MessageDialog(self,
                                     'Failed to get import data',
                                     'Import Error',
                                     style=wx.OK | wx.ICON_ERROR)
         except:
             if __debug__:
                 raise
コード例 #7
0
 def OnOk(self, _):
     # do export
     filename = self.filenamectrl.GetValue()
     try:
         _fp = file(filename, 'wt')
     except:
         _fp = None
     if _fp is None:
         guihelper.MessageDialog(self,
                                 'Failed to open file [' + filename + ']',
                                 'Export Error')
         self.EndModal(wx.ID_OK)
     if self.rows_all.GetValue():
         _data = self._data
     else:
         _data = self._sel_data
     self._export_csv(_fp, _data)
     _fp.close()
     self.EndModal(wx.ID_OK)
コード例 #8
0
 def IsValid(self):
     # validate and return T if so or F otherwise
     # check for valid date/time entries
     for w in (self._w['start'], self._w['end']):
         if not w.IsValid() or w.IsEmpty():
             w.SetFocus()
             wx.Bell()
             return False
     # whine if end is before start
     start = datetime.datetime(*self._w['start'].GetValue())
     end = datetime.datetime(*self._w['end'].GetValue())
     if start > end:
         # scold the user
         guihelper.MessageDialog(self, "End date and time is before start!",
                                 "Time Travel Attempt Detected",
                                 wx.OK | wx.ICON_EXCLAMATION)
         # move focus
         self._w['end'].SetFocus()
         return False
     return True
コード例 #9
0
ファイル: bp.py プロジェクト: SJLC/portage-overlay
    except getopt.GetoptError:
        e = sys.exc_info()[1]
        _invalid_args = True
        _error_str = e.msg
    if _invalid_args:
        # invalid/unknown arguments
        try:
            import wx
            import guihelper
            _msg = '%s\nUsage: %s [-c config file]|[-d config dir] [-p comm port] [-f phone model] [CLI Command] [debug] [bitfling]\n' % (
                _error_str, sys.argv[0])
            sys.stderr.write(_msg)
            # try to display an error message box
            _app = wx.PySimpleApp()
            guihelper.MessageDialog(None,
                                    _msg,
                                    'BitPim Error',
                                    style=wx.OK | wx.ICON_ERROR)
        finally:
            sys.exit(1)
    _kwargs = {}
    # check for debug flag
    _debug = bool(_args and 'debug' in _args)
    # CLI commands present?
    _clicmd = len(_args) == 1 and bp_cli.valid_command(_args[0])
    if not _debug and not _clicmd:
        import warnings

        def ignorer(*args, **kwargs):
            pass

        warnings.showwarning = ignorer
コード例 #10
0
ファイル: csv_calendar.py プロジェクト: SJLC/portage-overlay
 def _export(self):
     # do export
     filename=self.filenamectrl.GetValue()
     csv_event_template=(
         ('Start', 'start_str', None),
         ('End', 'end_str', None),
         ('Description', 'description', None),
         ('Location', 'location', None),
         ('Priority', 'priority', None),
         ('Alarm', 'alarm', None),
         ('All-Day', 'allday', None),
         ('Notes', 'notes', None),
         ('Categories', 'categories_str', None),
         ('Ringtone', 'ringtone', None),
         ('Wallpaper', 'wallpaper', None))
     csv_repeat_template=(
         ('Repeat Type', 'repeat_type', None),
         ('Repeat Interval', 'interval', None),
         ('Repeat Interval2', 'interval2', None),
         ('Day-of-Week', 'dow_str', None),
         ('Excluded Dates', 'suppressed_str', None))
     try:
         f=file(filename, 'wt')
     except:
         f=None
     if f is None:
         guihelper.MessageDialog(self, 'Failed to open file ['+filename+']',
                                 'Export Error')
         return
     s=['"'+x[0]+'"' for x in csv_event_template]+\
        ['"'+x[0]+'"' for x in csv_repeat_template]
     f.write(','.join(s)+'\n')
     all_items=self._selection.GetSelection()==0
     dt=self._start_date.GetValue()
     range_start=(dt.GetYear(), dt.GetMonth()+1, dt.GetDay())
     dt=self._end_date.GetValue()
     range_end=(dt.GetYear(), dt.GetMonth()+1, dt.GetDay())
     #---
     def __write_rec(f, cal_dict):
         for k,e in cal_dict.items():
             if not all_items and \
                (e.end < range_start or e.start>range_end):
                 continue
             l=[]
             for field in csv_event_template:
                 if field[2] is None:
                     s=self.__get_str(e, field[1])
                 else:
                     s=field[2](e, field[1])
                 l+=['"'+s.replace('"', '')+'"']
             rpt=e.repeat
             if rpt is None:
                 l+=['']*len(csv_repeat_template)
             else:
                 for field in csv_repeat_template:
                     if field[2] is None:
                         s=self.__get_str(rpt, field[1])
                     else:
                         s=field[2](rpt, field[1])
                     l+=['"'+s.replace('"', '')+'"']
             f.write(','.join(l)+'\n')
     #---
     cal_dict=self.GetParent().GetCalendarData()
     __write_rec(f, cal_dict)
     f.close()