Пример #1
0
    def CheckSrc(self):
        try:
            try:    #尝试从C盘读取
                #检查图像资源文件-----------
                self.imgStart = graphics.Image.open(r'c:\python\images\KumReader_Start.JPG')    #启动画面
                self.imgBookShelf = graphics.Image.open(r'c:\python\images\KumReader_Bookshelf.JPG')    #书架
                self.imgMainMenu = graphics.Image.open(r'c:\python\images\KumReader_MainMenu.png')      #主菜单
                self.imgBook = graphics.Image.open(r'c:\python\images\KumReader_book.png')      #书籍封面
                self.imgBgGray = graphics.Image.open(r'c:\python\images\bg_Gray.JPG')       #灰色纹理图
                self.imgBgGreen = graphics.Image.open(r'c:\python\images\bg_Green.JPG')     #绿色纹理图
                self.imgBgYellow = graphics.Image.open(r'c:\python\images\bg_Yellow.JPG')   #黄色纹理图

                #检查配置文件----------
                self.dbSetting = e32dbm.open(r'c:\python\UserSettings.e32dbm', 'w')     #软件配置文件
                self.dbBookshelf = e32dbm.open(r'c:\python\Bookshelf.e32dbm', 'w')       #书架书籍信息

            except:     #尝试从D盘读取

                #检查图像资源文件-----------
                self.imgStart = graphics.Image.open(r'd:\python\images\KumReader_Start.JPG')
                self.imgBookShelf = graphics.Image.open(r'd:\python\images\KumReader_Bookshelf.JPG')
                self.imgMainMenu = graphics.Image.open(r'd:\python\images\KumReader_MainMenu.png')
                self.imgBook = graphics.Image.open(r'd:\python\images\KumReader_book.png')
                self.imgBgGray = graphics.Image.open(r'd:\python\images\bg_Gray.JPG')
                self.imgBgGreen = graphics.Image.open(r'd:\python\images\bg_Green.JPG')
                self.imgBgYellow = graphics.Image.open(r'd:\python\images\bg_Yellow.JPG')

                #检查配置文件----------
                self.dbSetting = e32dbm.open(r'd:\python\UserSettings.e32dbm', 'w')
                self.dbBookshelf = e32dbm.open(r'd:\python\Bookshelf.e32dbm', 'w')

        except:
            appuifw.note(self.cn('应用程序已损坏,请重新安装!'), 'error')
            appuifw.app.set_exit()
Пример #2
0
 def __init__(self):
     import e32dbm
     try:
         # Try to open an existing file
         self.data = e32dbm.open(self.filename,"wf")
     except:
         # Failed: Assume the file needs to be created
         self.data = e32dbm.open(self.filename,"nf")
     
     self.draw()
Пример #3
0
def rank():
    #新建图形
    img = graphics.Image.new(canvas.size)
    #退出键
    appuifw.app.exit_key_handler = quit
    #异常处理,这个算是高级的内容了#try...except...#可能出错的代码放到try 语句块里,如果出错了要执行的操作放到except 里#这样你的代码就健壮了很多
    try:
        #关键函数,e32dbm.open 打开数据库
        #前面是路径,后面的是打开方式’r’ 意思为只读模式打开(只能读取数据库信息)#还有其他模式’w’(打开已存在的数据库,读写模式)#’c’(打开已存在的,读写模式,如果不存在新建一个)#’n’ 新建一个空数据库,读写模式
        db = e32dbm.open('c:\\rank.e32dbm', 'c')
        #初始化数据库,具体游戏中不可能放在这里的#但是不初始化没数据的,这里主要是为了演示,所以给出初始化#数据库记录信息是以字典的形式存放的,这里有点难了#如果不能理解也没什么,不过字典必须会用的,不然就做不了什么了#下面就是基本的字典操作添加了
        db['player1'] = str(10000)
        db['player2'] = str(10000)
        db['player3'] = str(10000)
        db['player4'] = str(10000)
        db['player5'] = str(10000)
        db['player6'] = str(10000)
        db['player7'] = str(10000)
        db['player8'] = str(10000)
        db.close()
        db = e32dbm.open('c:\\rank.e32dbm', 'r')
        #用一个变量记录db.items()获得的字典
        tdb = db.items()
        #关闭数据库,这里和文件打开操作一样都要关闭的
        db.close()
    except:
        #如果没有数据库信息给出错误提示
        appuifw.note(chn('error'), 'error')
        #好了,记录取出来了,怎么显示呢?既然是排行榜当然要排序了#需要说明的是字典是无序的,所以要排序#下面使用冒泡排序,具体原理不做解释,超过范围了。有兴趣的话,可以查看其他参考书
    for i in range(len(tdb) - 1):
        #len(tdb)获得字典长度也就是有几个玩家
        for j in range(
                len(tdb) - i - 1
        ):  #我倒。。讲到这感觉有点难了,不适合初学者了#尽量说明白吧,给个tdb的例子如{'xiaowang':'100','xiaozhang':'200'}#这里很明显第一项是关键字也就是玩家姓名,第二项是分数但是是字符串#tdb[0][1]=?明显是'100'#int()转换成数字再排序
            #下面是冒泡内容,不细讲
            if int(tdb[j][1]) > int(tdb[j + 1][1]):
                t = tdb[j]
                tdb[j] = tdb[j + 1]
                tdb[j + 1] = t
                #又见while死循环,排行榜该显示了
    while running:
        #清屏
        img.clear(0)  #给点文字说明
        img.text((70, 30), chn('排行榜'), 0x0000ff)
        e32.ao_sleep(1)
        #唉。。屏幕小酒显示8个玩家吧
        for i in range(8):
            #tdb[i][0]刚才说了,这个就是玩家姓名了,不明白那就是对数组的下标没学好
            img.text((30, 55 + i * 20), chn(tdb[i][0]), 0x00ff00)
            #tdb[i][1]分数喽
            img.text((100, 55 + i * 20), chn(': ' + tdb[i][1]), 0xff0000)
            #画到屏幕吧
            canvas.blit(img)
            e32.ao_yield()
Пример #4
0
 def load(self):
     try:
         db = e32dbm.open(self.DBNAME,"w")
     except:
         db = e32dbm.open(self.DBNAME,"n")
         
     for k in self.DEFVALS.iterkeys():
         try:
             self.__setitem__(k,utf8_to_unicode( db[k] ))
         except:
             self.__setitem__(k,self.DEFVALS[k])
     db.close()
Пример #5
0
    def CheckSrc(self):
        try:
            try:  #尝试从C盘读取
                #检查图像资源文件-----------
                self.imgStart = graphics.Image.open(
                    r'c:\python\images\KumReader_Start.JPG')  #启动画面
                self.imgBookShelf = graphics.Image.open(
                    r'c:\python\images\KumReader_Bookshelf.JPG')  #书架
                self.imgMainMenu = graphics.Image.open(
                    r'c:\python\images\KumReader_MainMenu.png')  #主菜单
                self.imgBook = graphics.Image.open(
                    r'c:\python\images\KumReader_book.png')  #书籍封面
                self.imgBgGray = graphics.Image.open(
                    r'c:\python\images\bg_Gray.JPG')  #灰色纹理图
                self.imgBgGreen = graphics.Image.open(
                    r'c:\python\images\bg_Green.JPG')  #绿色纹理图
                self.imgBgYellow = graphics.Image.open(
                    r'c:\python\images\bg_Yellow.JPG')  #黄色纹理图

                #检查配置文件----------
                self.dbSetting = e32dbm.open(r'c:\python\UserSettings.e32dbm',
                                             'w')  #软件配置文件
                self.dbBookshelf = e32dbm.open(r'c:\python\Bookshelf.e32dbm',
                                               'w')  #书架书籍信息

            except:  #尝试从D盘读取

                #检查图像资源文件-----------
                self.imgStart = graphics.Image.open(
                    r'd:\python\images\KumReader_Start.JPG')
                self.imgBookShelf = graphics.Image.open(
                    r'd:\python\images\KumReader_Bookshelf.JPG')
                self.imgMainMenu = graphics.Image.open(
                    r'd:\python\images\KumReader_MainMenu.png')
                self.imgBook = graphics.Image.open(
                    r'd:\python\images\KumReader_book.png')
                self.imgBgGray = graphics.Image.open(
                    r'd:\python\images\bg_Gray.JPG')
                self.imgBgGreen = graphics.Image.open(
                    r'd:\python\images\bg_Green.JPG')
                self.imgBgYellow = graphics.Image.open(
                    r'd:\python\images\bg_Yellow.JPG')

                #检查配置文件----------
                self.dbSetting = e32dbm.open(r'd:\python\UserSettings.e32dbm',
                                             'w')
                self.dbBookshelf = e32dbm.open(r'd:\python\Bookshelf.e32dbm',
                                               'w')

        except:
            appuifw.note(self.cn('应用程序已损坏,请重新安装!'), 'error')
            appuifw.app.set_exit()
Пример #6
0
def rank():
    global in_rank
    in_menu = 0
    canvas.bind(EKeySelect, lambda: None)
    canvas.bind(EKeyUpArrow, lambda: None)
    canvas.bind(EKeyDownArrow, lambda: None)
    canvas.bind(53, lambda: None)
    canvas.bind(52, lambda: None)
    canvas.bind(54, lambda: None)
    canvas.bind(56, lambda: None)
    canvas.bind(50, lambda: None)
    canvas.bind(42, lambda: None)
    canvas.bind(35, lambda: None)
    rank_img = graphics.Image.new(canvas.size)
    appuifw.app.exit_key_handler = menu
    try:
        db = e32dbm.open("e:\\System\\Apps\\lllook\\llkrank.e32dbm", "r")
        tdb = db.items()
        db.close()
    except:
        try:
            db = e32dbm.open("c:\\System\\Apps\\lllook\\llkrank.e32dbm", "r")
            tdb = db.items()
            db.close()
        except:
            appuifw.note(chn("fail to open rank"), "error")
    for i in range(len(tdb) - 1):
        for j in range(len(tdb) - i - 1):
            if int(tdb[j][1]) > int(tdb[j + 1][1]):
                t = tdb[j]
                tdb[j] = tdb[j + 1]
                tdb[j + 1] = t
    while in_rank:
        rank_img.clear(0xffffff)
        rank_img.text((50, 30), chn('玩家排行榜'), 0xff0000, font=ziti)
        for i in range(11):
            rank_img.line((0, i * 20 + 40, 176, i * 20 + 40), 0x0000ff)
        rank_img.line((90, 40, 90, 200), 0x0000ff)
        for i in range(8):
            rank_img.text((30, 55 + i * 20),
                          chn(tdb[i][0]),
                          0x00ff00,
                          font=ziti)
            rank_img.text((100, 55 + i * 20),
                          chn(tdb[i][1]),
                          0xff0000,
                          font=ziti)
        rank_img.rectangle((0, 0, 176, 208), 0x0000ff)
        canvas.blit(rank_img)
        e32.ao_sleep(0.2)
        e32.ao_yield()
Пример #7
0
def rank():
    appuifw.app.exit_key_handler = menu
    try:
        db = e32dbm.open("c:\\ranklist.e32dbm", "r")
        tdb = db.items()
        db.close()
    except:
        appuifw.note(chn("暂无排行榜"), "error")
    for i in range(len(tdb) - 1):
        for j in range(len(tdb) - i - 1):
            if int(tdb[j][1]) < int(tdb[j + 1][1]):
                t = tdb[j]
                tdb[j] = tdb[j + 1]
                tdb[j + 1] = t
    while 1:
        img.clear(0)
        img.rectangle(
            (0, 0, 176, 208),
            outline=color_box[random.randint(0, 3)][random.randint(0, 3)])
        img.text((20, 20), chn("排---------行-------榜"), 0xff0000, font=ziti)
        img.text((20, 190), chn("排--------行---------榜"), 0xff0000, font=ziti)
        for i in range(8):
            img.text((30, 30 + i * 20), chn(tdb[i][0]), 0x0000ff)
            img.text((140, 30 + i * 20), chn(tdb[i][1]), 0x00ff00)
        handle_redraw(())
        e32.ao_sleep(0.2)
        e32.ao_yield()
Пример #8
0
 def setOptions(self):
   
   db = e32dbm.open(self.db, "c")
   for key in self.default.keys():
     db[key] = str(self.default[key])
   
   db.close()
Пример #9
0
    def setOptions(self):

        db = e32dbm.open(self.db, "c")
        for key in self.default.keys():
            db[key] = str(self.default[key])

        db.close()
Пример #10
0
def write_db():
    db = e32dbm.open(DB_FILE, "cf")
    db[u"host"] = u"www.google.com"
    db[u"port"] = u"80"
    db[u"username"] = u"musli"
    db[u"password"] = u"my secret"
    db.close()
Пример #11
0
def rank():
    canvas.bind(EKeySelect, lambda: None)
    img = graphics.Image.new(canvas.size)
    appuifw.app.exit_key_handler = menu
    try:
        db = e32dbm.open("e:\\System\\Apps\\Puzzle\\picrank.e32dbm", "r")
        tdb = db.items()
        db.close()
    except:
        appuifw.note(chn("暂无排行"), "error")
    for i in range(len(tdb) - 1):
        for j in range(len(tdb) - i - 1):
            if int(tdb[j][1]) > int(tdb[j + 1][1]):
                t = tdb[j]
                tdb[j] = tdb[j + 1]
                tdb[j + 1] = t
    while 1:
        img.clear(0)
        for i in range(30, 1, -1):
            img.ellipse((105 - 5 * i / 2, 15 - i / 3, 105 + 3 * i / 2, 15 + i),
                        fill=(0, 265 - 8 * i, 265 - 8 * i))
        img.text((70, 30), chn("排行榜"), 0x0000ff, font=ziti)
        for i in range(8):
            img.text((30, 55 + i * 20), chn(tdb[i][0]), 0x00ff00, font=ziti)
            img.text((100, 55 + i * 20),
                     chn(":      " + tdb[i][1]),
                     0xff0000,
                     font=ziti)
        canvas.blit(img)
        e32.ao_sleep(0.2)
        e32.ao_yield()
Пример #12
0
 def test_db_update_clear(self):
     db = e32dbm.open(self.db_file, 'n')
     db.reorganize()
     temp_data_2 = self.get_data(10)
     db.update(temp_data_2)
     self.assertEqual(db.__len__(), len(temp_data_2),
                      "db len must match temp_data len")
     db.sync()
     self.assertEqual(len(db), 10,
                      "Database does not have all the entries")
     db.clear()
     self.assertEqual(len(db), 0, "Length must be 0 after clear")
     db.close()
     db = e32dbm.open(self.db_file, 'r')
     self.assertRaises(IOError, lambda:db.__setitem__('foo2', 'bar2'))
     db.close()
Пример #13
0
 def test_db_reset(self):
     db = e32dbm.open(self.db_file, 'cf')
     db['a'] = 'b'
     db['foo'] = 'bar'
     db['foo'] = 'baz'
     self.assertEqual(db['a'], 'b')
     self.assertEqual(db['foo'], 'baz')
     db.close()
Пример #14
0
 def load_cfg(self):
     try:
         db = e32dbm.open(RemoteShell.DBNAME,"c")
         for k in self.cfg.keys():
             self.cfg[k] = unicode(db[k])
         db.close()
     except:
         self.save_cfg()
Пример #15
0
def read():
    try:
        db = e32dbm.open(path + "\\data", "r")
        tdb = db.items()
        db.close()
        return int(cn(tdb[0][1]))
    except:
        return 0
Пример #16
0
 def test_db_delete(self):
     db = e32dbm.open(self.db_file, 'c')
     db['foo'] = 'baz'
     del db['foo']
     self.failIf('foo' in db, "Deleted key must not exist")
     db['foo'] = 'bar'
     self.assert_('foo' in db, "Key must exist after inserting it back")
     db.close()
Пример #17
0
    def save_cfg(self):
        if not os.path.exists(RemoteShell.DEFDIR):
            os.mkdir(RemoteShell.DEFDIR)

        db = e32dbm.open(RemoteShell.DBNAME,"c")    
        for k,v in self.cfg.iteritems():
            db[k] = v

        db.close()
Пример #18
0
def _load_vdb_with_mode(vdb, mode):
    """taken from tlslite/BaseDB.py -- patched for file mode""" 
    # {{
    db = anydbm.open(vdb.filename, mode)
    try:
        if db["--Reserved--type"] != vdb.type:
            raise ValueError("Not a %s database" % (vdb.type,))
    except KeyError:
        raise ValueError("Not a recognized database")
    vdb.db = db
Пример #19
0
 def get_settings(self):
     db = e32dbm.open(self.fname,"c")
     for (name,tp,lst,value) in self.desc_list:
         if tp == 'text':
             if db.has_key(name): exec "self." + name + " = unicode(db[name])"
         if tp == 'number':
             if db.has_key(name): exec "self." + name + " = int(db[name])"
         if tp == 'combo':
             if db.has_key(name): exec "self." + name + " = db[name]"
     db.close()
Пример #20
0
def load_prefs():
    global prefs
    try:
        prefs = {}
        db = e32dbm.open(CONF_FILE, "r")
        for k, v in db.iteritems():
            prefs[k] = v.decode("utf-8")
        db.close()
    except Exception, x:
        prefs = {}
Пример #21
0
 def load_recent(self):
     try:
         db = e32dbm.open(CONF_FILE, "c")
         recent = db["recent"] 
         if recent:
             self.recent = recent.split(SEPARATOR)
         else:
             self.recent = [] 
         db.close()
     except:
         self.recent = []
Пример #22
0
def save_prefs(new_prefs):
    db = e32dbm.open(CONF_FILE, "nf")
    for label, type, value in new_prefs:
        if label == "When" or label == "Sort_order":
            value = value[0][value[1]]
        prefs[label] = value
        db[label] = value.encode("utf-8")
    db.close()
    timer.cancel()
    timer.after(0, update_list)
    return True
Пример #23
0
def OpenDbmFile(file,mode):
    import os
    import e32dbm as db
    b,e = os.path.splitext(file)
    #return db.open(Defaults["basedirs"][0]+file,"%sf" % mode)
    for d in Defaults["basedirs"]:
        p = os.path.join(d,b)
        try:
            return db.open(p,"%sf" % mode)
        except:
            pass

    raise IOError(u"unable to open dbm file %s with mode %s" % (p,mode))
Пример #24
0
def OpenDbmFile(file, mode):
    import os
    import e32dbm as db
    b, e = os.path.splitext(file)
    #return db.open(Defaults["basedirs"][0]+file,"%sf" % mode)
    for d in Defaults["basedirs"]:
        p = os.path.join(d, b)
        try:
            return db.open(p, "%sf" % mode)
        except:
            pass

    raise IOError(u"unable to open dbm file %s with mode %s" % (p, mode))
Пример #25
0
 def __init__(self):
  self.appname=u"FTP Browser"
  self.author=u"Simon816"
  self.url=u'http://simon816.hostzi.com'
  d='e:\\python\\apps\\simon816\\ftpbrowser\\'
  try:f=open(d+'db.dir', 'r+');dbDIR=f.read()
  except:f=open(d+'db.dir', 'w');f.write(d);dbDIR=d
  f.close()
  self.db=e32dbm.open(dbDIR+'db', 'cf')
  self.dd=dbDIR
  self.root=d
  try: s=self.db['status']
  except:self.reset()
  self.exit(self.quit)
Пример #26
0
 def __init__(self):
  self.appname=u"FTP Browser"
  self.author=u"Simon816"
  self.url=u'http://simon816.hostzi.com'
  d='e:\\python\\apps\\simon816\\ftpbrowser\\'
  try:f=open(d+'db.dir', 'r+');dbDIR=f.read()
  except:f=open(d+'db.dir', 'w');f.write(d);dbDIR=d
  f.close()
  if not dbDIR.endswith('\\'):dbDIR+='\\'
  self.db=e32dbm.open(dbDIR+'db', 'cf')
  self.dd=dbDIR
  self.root=d
  try: s=self.db['status']
  except:self.reset()
  self.exit(self.quit)
Пример #27
0
def play():
    global flag, current_y, current_x, speed, stop, rs, r_s, isdeath, score, level, playing
    playing = 1
    canvas.bind(53, lambda: move(0))
    canvas.bind(52, lambda: move(-1))
    canvas.bind(54, lambda: move(1))
    canvas.bind(56, lambda: move(2))
    canvas.bind(50, lambda: move(3))
    canvas.bind(EKeyUpArrow, lambda: move(3))
    canvas.bind(EKeyDownArrow, lambda: move(2))
    canvas.bind(EKeySelect, lambda: move(0))
    canvas.bind(EKeyRightArrow, lambda: move(1))
    canvas.bind(EKeyLeftArrow, lambda: move(-1))
    appuifw.app.exit_key_handler = menu
    while 1:
        if isdeath == 1:
            appuifw.note(chn("游戏结束"), "info")
            name = appuifw.query(chn("请输入您的名字"), "text")
            try:
                db = e32dbm.open("c:\\ranklist.e32dbm", "c")
                db[dchn(name)] = str(score)
                db.close()
            except:
                appuifw.note(chn("保存失败"), "error")
            menu()
            break
        else:
            init()
            judge_move()
            if flag == 1 or current_y + All_shape[rs][2] == 21:
                for i in range(All_shape[rs][1]):
                    for j in range(All_shape[rs][2]):
                        if All_shape[rs][0][j][i] == 1:
                            game_array[current_y + j - 1][current_x + i] = 1
                clear_line()
                death()
                current_y = 0
                current_x = 3
                flag = 0
                speed = 0
                rs = r_s
                r_s = random.randint(0, 27)
            game_board()
            if stop == 1:
                current_y += 1
            if speed == 0:
                e32.ao_sleep(1 - level / 10.0)
            e32.ao_yield()
Пример #28
0
    def __init__(self, resourcedir):
        self.resourcedir = resourcedir

        filename = unicode(os.path.join(resourcedir, 'config'))
        self.config = e32dbm.open(filename, DB_MODE)

        self.entities = [
            Entities(u'country', u'countries', self, os.path.join(resourcedir, 'countries')),
            Entities(u'state', u'states', self, os.path.join(resourcedir, 'states')),
            Entities(u'city', u'cities', self, os.path.join(resourcedir, 'cities')),
            Entities(u'store', u'stores', self, os.path.join(resourcedir, 'stores')),
        ]

        self.countries = self.entities[self.MANAGER_COUNTRY]
        self.states = self.entities[self.MANAGER_STATE]
        self.cities = self.entities[self.MANAGER_CITY]
        self.stores = self.entities[self.MANAGER_STORE]
Пример #29
0
 def save_settings(self, dlg=None):
     # retrieve values from dialog fields and save to dbm
     db = e32dbm.open(self.fname,"c")
     n = 0
     for (name,type,lst,value) in self.desc_list:
       if dlg:
         if type == 'text':
             exec "self." + name + " = dlg[n][2]"
         if type == 'number':
             exec "self." + name + " = int(dlg[n][2])"
         if type == 'combo':
             (lst,index) = dlg[n][2]
             exec "self." + name + " = lst[index]"
       db[name] = str(eval("self." + name))
       n = n+1
         
     db.reorganize()
     db.close()
Пример #30
0
def update():
    db = e32dbm.open(DB_FILE, "r")
    location = []
    loc_key = []
    for key, value in db.items():
        #print "Key", key, "Value", value
        location.append(unicode(value))
        loc_key.append(key.encode("utf-8"))
    db.close()
    #print location[2]
    #print loc_key[2]
    loc_index = appuifw.popup_menu(location, u"Select:")
    #print loc_key[loc_index]
    URL = "http://"+config["url"]+"/api/"+config["user"]+"/"+config["api"]+"/json/locations/"    
    URL = URL+"set/" + loc_key[loc_index]    
    #print URL
    res = urllib.urlopen(URL).read()
    #print res
    appuifw.note(u"Location Updated", "error")
Пример #31
0
def update_list():
    appuifw.note(u"Downloading...", "error")
    #print "Downloading..."
    URL = "http://"+config["url"]+"/api/"+config["user"]+"/"+config["api"]+"/json/locations/"    
    #print URL
    res = urllib.urlopen(URL).read()
    status = json.read(res)
    current =  status["data"]["Identity"]["last_location_id"]
    #print current
    #print status["data"]["Locations"][int(current)-1]["Location"]
    db = e32dbm.open(DB_FILE, "nf")
    for x in status["data"]["Locations"]:
        #print x["Location"]
        #print x["Location"]["id"]
        #print x["Location"]["name"]
        db[x["Location"]["id"]] = x["Location"]["name"]
    db.close()    
    #print "...done."
    appuifw.note(u"...done.", "error")
Пример #32
0
    def getOptions(self):

        try:
            db = e32dbm.open(self.db, "r")

            for key, value in db.items():
                if key == "port":
                    self.default[key] = int(value)

                elif key == "dir":
                    try:
                        self.available_drives.index((u"%s" % value))
                    except:
                        value = self.default["dir"]

                    self.default[key] = (u"%s" % value)

                else:
                    self.default[key] = (u"%s" % value)

            db.close()

        except Exception, e:
            self.setOptions()
Пример #33
0
 def getOptions(self):
   
   try:
     db = e32dbm.open(self.db, "r")
     
     for key, value in db.items():
       if key == "port":
         self.default[key] = int(value)
         
       elif key == "dir":
         try:
           self.available_drives.index((u"%s" % value))
         except:
           value = self.default["dir"]
         
         self.default[key] = (u"%s" % value)
         
       else:
         self.default[key] = (u"%s" % value)
     
     db.close()
     
   except Exception, e:
     self.setOptions()
Пример #34
0
 def save_recent(self):
     db = e32dbm.open(CONF_FILE, "wf")
     try:
         db["recent"] = SEPARATOR.join(self.recent)
     finally:
         db.close()
def write(v):
    db = e32dbm.open(path + "\\data", "c")
    db["score"] = str(v)
    db.close()
Пример #36
0
 def open(self,file,mode):
  self.openDB=e32dbm.open(file,mode)
  return self
Пример #37
0
 def open(self, file, mode):
     self.openDB = e32dbm.open(file, mode)
     return self
Пример #38
0

def clean():
    if os.path.isfile(FILE + ".e32dbm"): os.remove(FILE + ".e32dbm")


try:
    try:
        for fastflag in '', 'f':
            if fastflag:
                print "--- Testing fast mode:"
            else:
                print "--- Testing normal mode:"

            clean()
            db = e32dbm.open(FILE, 'c' + fastflag)
            print "Setting value:"
            db['a'] = 'b'
            print "Setting another value:"
            db['foo'] = 'bar'
            print "Re-setting value:"
            db['foo'] = 'baz'
            print "Reading back values:"
            asserteq(db['a'], 'b', "read value")
            asserteq(db['foo'], 'baz', "read value")
            db.close()

            print "Opening file:"
            db = e32dbm.open(FILE, 'w' + fastflag)
            print "Reading back values:"
            asserteq(db['a'], 'b', "read value")
Пример #39
0
def play():
    global pic_ID, pic_game, pos_x, pos_y, cursor, current, shuffle_num, hint_num, level, linktime, start, totaltime, playing
    playing = 1
    canvas.bind(EKeyUpArrow, lambda: move_cursor(0, -1))
    canvas.bind(EKeyDownArrow, lambda: move_cursor(0, 1))
    canvas.bind(EKeyLeftArrow, lambda: move_cursor(-1, 0))
    canvas.bind(EKeyRightArrow, lambda: move_cursor(1, 0))
    canvas.bind(EKeySelect, lambda: move_cursor(0, 0))
    canvas.bind(53, lambda: move_cursor(0, 0))
    canvas.bind(52, lambda: move_cursor(-1, 0))
    canvas.bind(54, lambda: move_cursor(1, 0))
    canvas.bind(56, lambda: move_cursor(0, 1))
    canvas.bind(50, lambda: move_cursor(0, -1))
    canvas.bind(42, lambda: move_cursor('hint', 'hint'))
    canvas.bind(35, lambda: move_cursor('shuffle', 'shuffle'))
    appuifw.app.exit_key_handler = menu
    color = 0x00ff00
    while playing:
        bg.clear(0xffffff)
        for i in range(8):
            for j in range(8):
                if pic_ID[j + 1][i + 1] != -1:
                    bg.blit(pic_game[pic_ID[j + 1][i + 1]],
                            target=(i * 20 + 8, j * 20 + 9),
                            source=(0, 0, 20, 20))
                bg.line((i * 20 + 8, 9, i * 20 + 8, 169), (51, 204, 255))
                bg.line((8, j * 20 + 9, 168, j * 20 + 9), (51, 204, 255))
        bg.rectangle((7, 8, 169, 169), (51, 204, 255), width=2)
        bg.rectangle(
            (pos_x * 20 + 8, pos_y * 20 + 9, pos_x * 20 + 29, pos_y * 20 + 30),
            cursor)
        bg.text((2, 189), chn('时间'), font=ziti)
        bg.rectangle((24, 179, 145, 189), 0, width=2)
        current = time.clock() - linktime
        T = int(current - start)
        bg.text((150, 191), chn(str(T)), 0xff0000, font=ziti)
        if T <= 120:
            if T > 40:
                color = 0xffff00
            if T > 80:
                color = 0xff0000
            bg.rectangle((25, 181, 145 - T, 188), fill=color)
        if T > 120:
            appuifw.note(chn('闯关失败'), 'info')
            playing = 0
            menu()
        if is_win() == 1:
            appuifw.note(chn('下一关'), 'info')
            level += 2
            totaltime += T
            if level > 32:
                appuifw.note(chn("通关了"), "info")
                name = appuifw.query(chn("请输入您的名字"), "text")
                try:
                    db = e32dbm.open(
                        "e:\\System\\Apps\\lllook\\llkrank.e32dbm", "c")
                    db[dchn(name)] = str(totaltime)
                    db.close()
                    appuifw.note(chn("记录已保存"), "info")
                except:
                    try:
                        db = e32dbm.open(
                            "c:\\System\\Apps\\lllook\\llkrank.e32dbm", "c")
                        db[dchn(name)] = str(totaltime)
                        db.close()
                        appuifw.note(chn("记录已保存"), "info")
                    except:
                        appuifw.note(chn("保存失败"), "error")
                playing = 0
                menu()
            else:
                game()
        bg.text((60, 205), chn(str(hint_num)), font=ziti)
        bg.text((140, 205), chn(str(shuffle_num)), font=ziti)
        bg.blit(pic_game[-1], target=(40, 193), source=(5, 5, 20, 20))
        bg.blit(pic_game[-2], target=(120, 193), source=(3, 5, 18, 20))
        if len(previous_current) != 0:
            for pic_select in previous_current:
                bg.rectangle((pic_select[0] * 20 - 12, pic_select[1] * 20 - 11,
                              pic_select[0] * 20 + 9, pic_select[1] * 20 + 10),
                             0xff0000)
        cursor ^= 0xffffffff
        linktime = 0
        bg.rectangle((0, 0, 176, 208), 0x0000ff)
        canvas.blit(bg)
        e32.ao_sleep(0.2)
        e32.ao_yield()
Пример #40
0
 def __init__(self, db_path):
     LibManager.DB_PATH = db_path
     self.db = e32dbm.open(LibManager.DB_PATH, "cf")
Пример #41
0
 def open(self, mode):
     self.openDB = e32dbm.open(self.dir + 'db', mode)
     return self
Пример #42
0
def menu():
    global menu_y, menu_start, in_setting, in_help, in_rank, in_menu, playing
    menu_start = time.clock()
    in_setting = 0
    in_help = 0
    in_rank = 0
    playing = 0
    in_menu = 1
    zmdi = 0
    t_face = 0
    t_pic = 0
    canvas.bind(EKeyUpArrow, lambda: move_cursor("none", "up"))
    canvas.bind(EKeyDownArrow, lambda: move_cursor("none", "down"))
    canvas.bind(EKeySelect, lambda: move_cursor("none", "select"))
    canvas.bind(53, lambda: None)
    canvas.bind(52, lambda: None)
    canvas.bind(54, lambda: None)
    canvas.bind(56, lambda: None)
    canvas.bind(50, lambda: None)
    canvas.bind(42, lambda: None)
    canvas.bind(35, lambda: None)
    menu_img = graphics.Image.new(canvas.size)
    get_menu_pic()
    if not os.path.exists(
            "e:\\System\\Apps\\lllook\\llkrank.e32dbm") and not os.path.exists(
                "c:\\System\\Apps\\lllook\\llkrank.e32dbm"):
        try:
            db = e32dbm.open("e:\\System\\Apps\\lllook\\llkrank.e32dbm", "c")
            db["player1"] = str(100)
            db["player2"] = str(100)
            db["player3"] = str(100)
            db["player4"] = str(100)
            db["player5"] = str(100)
            db["player6"] = str(100)
            db["player7"] = str(100)
            db["player8"] = str(100)
            db.close()
        except:
            try:
                db = e32dbm.open("c:\\System\\Apps\\lllook\\llkrank.e32dbm",
                                 "c")
                db["player1"] = str(100)
                db["player2"] = str(100)
                db["player3"] = str(100)
                db["player4"] = str(100)
                db["player5"] = str(100)
                db["player6"] = str(100)
                db["player7"] = str(100)
                db["player8"] = str(100)
                db.close()
            except:
                appuifw.note(chn('fail'), "error")
    while in_menu:
        zmdi += 1
        t_face += 1
        t_pic += 1
        menu_img.clear(0xffffff)
        if t_pic > 3:
            t_pic = 1
        menu_img.blit(menu_pic[t_pic - 1], target=(50, 30))
        if zmdi > 148:
            if zmdi < 207:
                menu_img.text((20, 200),
                              chn('  Email:[email protected]'),
                              0x0000ff,
                              font=ziti)
            else:
                menu_img.text((20, 200),
                              chn('       QQ:522765228'),
                              0x00ff00,
                              font=ziti)
        if zmdi > 296:
            zmdi = 0
        menu_img.text((176 - 2 * zmdi, 200), chn('(c)'), 0xffff00, font=ziti)
        menu_img.text((196 - 2 * zmdi, 200),
                      chn('手机网 iniwap.cn'),
                      0xff0000,
                      font=ziti)
        if t_face > 7:
            t_face = 1
        menu_img.blit(face[t_face - 1], target=(30, menu_y * 20 + 85))
        for i in range(7):
            menu_img.line((0, i * 20 + 85, 176, i * 20 + 85), 0x0000ff)
        menu_img.text((55, 100), chn('开始游戏'), 0x99ccff, font=ziti)
        menu_img.text((55, 120), chn('难度设置'), 0x99ccff, font=ziti)
        menu_img.text((55, 140), chn('游戏帮助'), 0x99ccff, font=ziti)
        menu_img.text((55, 160), chn('玩家排行'), 0x99ccff, font=ziti)
        menu_img.text((55, 180), chn('退出游戏'), 0x99ccff, font=ziti)
        menu_img.rectangle((0, 0, 176, 208), 0x0000ff)
        canvas.blit(menu_img)
        e32.ao_sleep(0.1)
Пример #43
0
 def __init__(self, fname):
     self.e32dbm = e32dbm.open(fname, "cf")
     self.sync()
Пример #44
0
 def __init__(self, key, url_path, manager, database):
     self.order = Entities.get_order()
     self.key = key
     self.url_path = url_path
     self.manager = manager
     self.cache = e32dbm.open(database, DB_MODE)
Пример #45
0
def play():
    global level, start_posx, start_posy, dd, pic_current, pic, isfinish, step, isbackground, bg_path, bg, picpath, ispicture, issee, difficulty, search_step
    menu_visiable = 0
    canvas.bind(53, lambda: move(0, 0))
    canvas.bind(EKeySelect, lambda: move(0, 0))
    canvas.bind(52, lambda: move(-1, 0))
    canvas.bind(EKeyLeftArrow, lambda: move(-1, 0))
    canvas.bind(48, lambda: move("none", "none"))
    canvas.bind(35, lambda: move("#", "#"))
    canvas.bind(54, lambda: move(1, 0))
    canvas.bind(EKeyRightArrow, lambda: move(1, 0))
    canvas.bind(56, lambda: move(0, 1))
    canvas.bind(EKeyDownArrow, lambda: move(0, 1))
    canvas.bind(50, lambda: move(0, -1))
    canvas.bind(EKeyUpArrow, lambda: move(0, -1))
    appuifw.app.exit_key_handler = menu
    step = 0
    if isbackground == 1 and issee == 0:
        bg = graphics.Image.open(bg_path).resize(canvas.size)
    else:
        try:
            bg = graphics.Image.open(
                "e:\\System\\Apps\\Puzzle\\background.jgp")
        except:
            bg = graphics.Image.new(canvas.size)
        bg.clear(0)
    if issee == 0:
        if level == 3:
            level_3()
            pic_division()
            creat_pic()
        if level == 4:
            level_4()
            pic_division()
            creat_pic()
        if level == 5:
            level_5()
            pic_division()
            creat_pic()
    issee = 0
    hint = 0
    hint_img = graphics.Image.new((160, 13))
    some_hint = [
        chn('       温馨提醒'),
        chn('白色框中显示为已走步数'),
        chn('当前难度' + str(difficulty) + '步内可解决'),
        chn('0 键查看原图'),
        chn('#查看当前最少需几步'),
        chn('上次搜索结果:未搜或超时')
    ]
    while 1:
        hint_img.clear(0xffffff)
        hint += 1
        for i in range(level):
            for j in range(level):
                if pic_label[j + 1][i + 1] != level * level - 1:
                    bg.blit(pic_current[pic_label[j + 1][i + 1] /
                                        level][pic_label[j + 1][i + 1] %
                                               level],
                            target=(start_posx + i * dd, start_posy + j * dd))
                if pic_label[j + 1][i + 1] == level * level - 1:
                    bg.blit(graphics.Image.new((dd, dd)),
                            target=(start_posx + dd * i, start_posy + dd * j))
                    bg.text((start_posx + dd * i,
                             start_posy + dd * j + dd * 1.5 / 2),
                            str(step).decode("utf8"),
                            0,
                            font=u"Acb14")
            division_line()
            if hint == 18:
                hint = 0
            if search_step != 0:
                some_hint[5] = chn('上次搜索结果:' + str(search_step) + '步')
            hint_img.text((15, 13), some_hint[hint // 3], 0x0000ff, font=ziti)
            hint_img.text((0, 13), chn('【'), 0x0000ff, font=ziti)
            hint_img.text((150, 13), chn('】'), 0x0000ff, font=ziti)
            bg.blit(hint_img, target=(10, 180))
            canvas.blit(bg)
            if isfinish == 1:
                appuifw.note(chn("恭喜你成功了"), "info")
                name = appuifw.query(chn("输入名字"), "text")
                try:
                    db = e32dbm.open(
                        "e:\\System\\Apps\\Puzzle\\picrank.e32dbm", "c")
                    db[name] = str(step)
                    db.close()
                    isfinish = 0
                    appuifw.note(chn("保存成功"), "info")
                except:
                    appuifw.note(chn("保存失败"), "error")
                break
            e32.ao_sleep(0.2)
Пример #46
0
def read_db():
    db = e32dbm.open(DB_FILE, "r")
    for key, value in db.items():
        print "KEY", key, "VALUE", value
    db.close()
Пример #47
0
def menu():
    global black_white, menu_visiable
    menu_visiable = 1
    canvas.bind(EKeyUpArrow, lambda: move("none", "up"))
    canvas.bind(EKeyDownArrow, lambda: move("none", "down"))
    canvas.bind(EKeySelect, lambda: move("none", "select"))
    img = graphics.Image.new((176, 208))
    if not os.path.exists("e:\\System\\Apps\\Puzzle\\picrank.e32dbm"):
        try:
            db = e32dbm.open("e:\\System\\Apps\\Puzzle\\picrank.e32dbm", "c")
            db["player1"] = str(30)
            db["player2"] = str(30)
            db["player3"] = str(30)
            db["player4"] = str(30)
            db["player5"] = str(30)
            db["player6"] = str(30)
            db["player7"] = str(30)
            db["player8"] = str(30)
            db.close()
        except:
            appuifw.note(chn("保存成绩失败"), "error")
    try:
        menu_pic = graphics.Image.open(
            "e:\\System\\Apps\\Puzzle\\menu_pic.jpg").resize((80, 80))
        ismenu_pic = 1
    except:
        menu_pic = graphics.Image.new((80, 80))
        ismenu_pic = 0
    while menu_visiable:
        img.clear(0)
        if ismenu_pic:
            img.blit(menu_pic, target=(40, 5))
        else:
            menu_pic.clear(0)
            menu_pic.rectangle(
                (0, 0, 41, 41),
                outline=0xffffff,
                fill=(random.randint(0, 255), random.randint(0, 255),
                      random.randint(0, 255)))
            menu_pic.rectangle(
                (40, 0, 80, 41),
                outline=0xffffff,
                fill=(random.randint(0, 255), random.randint(0, 255),
                      random.randint(0, 255)))
            menu_pic.rectangle(
                (0, 40, 41, 80),
                outline=0xffffff,
                fill=(random.randint(0, 255), random.randint(0, 255),
                      random.randint(0, 255)))
            menu_pic.rectangle(
                (40, 40, 80, 80),
                outline=0xffffff,
                fill=(random.randint(0, 255), random.randint(0, 255),
                      random.randint(0, 255)))
            img.blit(menu_pic, target=(40, 5))
        img.line((80, 5, 80, 83), 0xffffff)
        img.line((40, 45, 118, 45), 0xffffff)
        img.rectangle((40, 5, 120, 85), black_white)
        black_white ^= 0xffffff
        img.text((30, 200), u'(c)', 0xffff00)
        img.text((50, 200), chn('手机网 iniwap.cn'), 0xff0000, font=ziti)
        img.rectangle((40, menu_y * 20 + 85, 120, 85 + 20 * (menu_y + 0.8)),
                      0x99ccff,
                      fill=(103, 154, 201))
        img.text((55, 100), chn("开始游戏"), 0x99ccff, font=ziti)
        img.text((55, 120), chn("游戏设置"), 0x99ccff, font=ziti)
        img.text((55, 140), chn("游戏帮助"), 0x99ccff, font=ziti)
        img.text((55, 160), chn("玩家排行"), 0x99ccff, font=ziti)
        img.text((55, 180), chn("退出游戏"), 0x99ccff, font=ziti)
        canvas.blit(img)
        e32.ao_sleep(0.4)
Пример #48
0
    def test_db_dict_operations(self):
        db = e32dbm.open(self.db_file, 'nf')

        temp_data_3 = self.get_data(10)
        db.update(temp_data_3)

        temp_keys = temp_data_3.keys()
        temp_keys.sort()
        temp_values = [temp_data_3[x] for x in temp_keys]

        db_keys = list(db.iterkeys())
        db_keys.sort()
        self.assertEqual(db_keys, temp_keys)

        temp_db_values = list(db.itervalues())
        temp_db_values.sort()
        temp_values_sorted = list(temp_values)
        temp_values_sorted.sort()
        self.assertEqual(temp_db_values, temp_values_sorted)

        db_items = db.items()
        self.assertEqual(dict(db_items), temp_data_3)

        db_values = db.values()
        db_values.sort()
        self.assertEqual(db_values, temp_values_sorted)

        db_keys_1 = db.keys()
        db_keys_1.sort()
        self.assertEqual(db_keys_1, temp_keys)

        temp_key = temp_keys[0]
        temp_value = temp_values[0]
        self.assertEqual(db.pop(temp_key), temp_value)
        self.failIf(temp_key in db, "Key must not exist after pop")
        temp_item = db.popitem()
        self.failIf(temp_item[0] in db, "Key must not exist after popitem")

        db['foo1'] = 'bar'
        del db['foo1']
        foo_val = db.setdefault('foo1', 'baz')
        self.assertEqual(foo_val, 'baz')
        self.assertEqual(db['foo1'], 'baz')
        del db['foo1']

        db_keys_2 = []
        try:
            iter_obj = db.__iter__()
            while 1:
                db_keys_2.append(iter_obj.next())
        except StopIteration:
            pass
        self.assertEqual(db_keys_2, db.keys())

        db_items_2 = []
        try:
            iteritems_obj = db.iteritems()
            while 1:
                db_items_2.append(iteritems_obj.next())
        except StopIteration:
            pass
        self.assertEqual(db_items_2, db.items())

        db.close()
Пример #49
0
 def test_db_torture(self):
     db = e32dbm.open(self.db_file, 'w')
     self.db_torture_test(db, 100, 100)
     db.close()
Пример #50
0
 def open(self,mode):
  self.openDB=e32dbm.open(self.dir+'db',mode)
  return self
Пример #51
0
 def save(self):
     db = e32dbm.open(Persist.DBNAME,"c")
     for k in self.DEFVALS.iterkeys():
         db[k] = self.__getitem__(k)
     db.close()