SiriBlog

siriyang的个人博客


  • 首页

  • 排行榜

  • 标签115

  • 分类37

  • 归档320

  • 关于

  • 搜索

在AppWishList开发中遇到的一些问题

发表于 2020-01-29 更新于 2021-10-29 分类于 计算机 , 技术 , Python 阅读次数: Valine:
本文字数: 4.1k 阅读时长 ≈ 4 分钟

2020.01.29

Note1

  今天在AppWishList开发中遇到这个错误:

1
'builtin_function_or_method' object is not subscriptable

  错误原因是将”()“写成了”[]“。

1
2
3
4
5
6
7
8
9
10
11
...

prices=[]

for i in res:
t=Price()
t.initByTuple(i)
- prices.append[t]
+ prices.append(t)

...

Note2

  在pythonista的ui模块中,如果将函数包装成@ui.in_background,将在后台线程中运行,但是如果在构造函数中调用它,数据就会初始化失败,无论是在函数中赋值还是返回值都为None。


Note3

  在pythonista中使用webbroswer调用Safai打开链接的语句是:

1
webbroswer.open("safari-")

Note4

  python当要调用比自己上层的模块的时候,使用如下方法:

1
2
3
4
5
6
7
8
AppWishList
|- tools
| |- __init__.py
| |- Result.py
|
|- UI
|- __init__.py
|- MainWindow.py
MainWindow.py
1
2
3
4
5
6
7

import sys

# 根据需求跳转当前路径
sys.path.append("..")

from tools.Result import *

2020.01.30

Note5

  在ui中重载View的layout方法,将会在窗口尺寸旋转改变的时候被调用:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# coding: utf-8

# https://forum.omz-software.com/topic/3115/ui-and-device-rotation-monitoring/4

import ui

class myView(ui.View):
def __init__(self):
self.scr_orientation = None
self.present('full_screen')

def draw(self):
print 'orientation = ' + self.scr_orientation

def layout(self):
if self.width > self.height:
self.scr_orientation = 'landscape'
else:
self.scr_orientation = 'portrait'

myView()
#orientation = landscape
#or
#orientation = portrait
#there's no orientation = None
#and everytime I tilt my device it changes

  参考自tdamdouni/Pythonista

Note6

  之前TableView一直遇到个问题,总有两行在最下面划不出来,结果是TableView尺寸设大了,超出了屏幕。

Note7

  当你需要在NavigateView的Head Bar插入ButtonItem时,你需要选择当前NavigateView栈顶的View,而不是NavigateView对象本身。

Note8

  当使用Button的时候注意区分属性image和background_image,前者只显示形状和单一颜色,可通过tint_color进行设定;而后者是一个使用Image.resizable_image创建的可伸缩图片。
  ButtonItem仅有image属性。

Note9

  错误异常代码:

1
IndentationError: unexpected indent

  错误原因是缩进格式对其错误。我这里遇到偶的情况是把try语句的except注释了,但是又没有写finally,解决方案如下:

1
2
3
4
5
6
7
8
try:

...

#except Exception as e:
#...
finally:
pass

2020.01.31

Note10

  从matplotlib.figure到numpy、PIL.Image、ui.Image之间的转换:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import ui
from PIL import Image
import io
import matplotlib.pyplot
import numpy


def pil2ui(imgIn):
b = io.BytesIO()
imgIn.save(b, 'JPEG')
imgOut = ui.Image.from_data(b.getvalue())
b.close()
return imgOut

def fig2data(fig):

fig.canvas.draw()
w,h=fig.canvas.get_width_height()
buf=numpy.fromstring(fig.canvas.tostring_argb(),dtype=numpy.uint8)
buf.shape=(w,h,4)
buf=numpy.roll(buf,3,axis=2)
return buf

def fig2pil(fig):
buf=fig2data(fig)
w,h,d=buf.shape

return Image.frombytes("RGBA",(w,h),buf.tostring())

if __name__ == "__main__":
figure=matplotlib.pyplot.figure()
plot=figure.add_subplot(111)
x = numpy.arange(1,100,0.1)
y = numpy.sin(x)/x
plot.plot(x,y)

i=pil2ui(fig2pil(figure))

v=ui.ImageView()

v.frame=(0,0,1000,600)
v.background_color="white"

v.image = i

v.present("sheet")

Note11

  python 字符串和时间格式(datetime)相互转换:

  2019-03-17 11:00:00格式转化

1
2
3
4
5
6
7
8
9
import datetime
# str转时间格式:
dd = '2019-03-17 11:00:00'
dd = datetime.datetime.strptime(dd, "%Y-%m-%d %H:%M:%S")
print(dd,type(dd))

# 时间格式转str:
dc = dd.strftime("%Y-%m-%d %H:%M:%S")
print(dc,type(dc))

  输出:

1
2
2019-03-17 11:00:00 <class 'datetime.datetime'>
2019-03-17 11:00:00 <class 'str'>

  20190616格式转化

1
2
3
4
5
6
7
8
# str转时间格式:
dd = '20190317'
dd = datetime.datetime.strptime(dd, "%Y%m%d")
print(dd,type(dd))

# 时间格式转str:
dc = dd.strftime("%Y%m%d")
print(dc,type(dc))

Note12

  获取一个时间段以内的datetime对象:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
from datetime import datetime, timedelta

def get_date_list(begin_date, end_date):

    dates = []

    date = datetime.strptime(begin_date,"%Y-%m-%d")

    while date <= datetime.strptime(end_date,"%Y-%m-%d"):        

        dates.append(date)        

        date += timedelta(days=1)  

    return dates

2020.03.28

Note13

  今天想给AppTabelView中的每个app栏目加上收藏和自动更新按钮。一开始在每一个cell创建的时候都调用ui.Image.named()函数给按钮加上图片,结果大量的图片文件io读写导致程序卡顿不稳定,严重的时候甚至崩溃闪退。因为都是同样的图片,所以采用直接在页面初始化的时候读入两个图片对象进行维护,在之后创建cell的时候直接将现有对象赋值给background_image就没事了。

2020.03.29

Note14

  为了把应用列表iPhone竖频模式下的应用图标缩小,一开始打算采用将ui.Image转换为PIL.Image,然后使用PIL的resize()函数,再转换回ui.Image。结果该方案不但PIL压缩出来效果不好,在数据之间的大量转换操作也导致系统卡顿。最终采用ui.ImageContext和ui.Image.draw()的方法进行尺寸修改,既保证了缩放质量效果,又保证了运算效率。

-------- 本文结束 感谢阅读 --------
相关文章
  • 关于Python导包的问题
  • 中医药天池大数据竞赛--中药说明书实体识别挑战
  • NLP综合实践(三)
  • NLP综合实践(二)
  • NLP综合实践(一)
觉得文章写的不错的话,请我喝瓶怡宝吧!😀
SiriYang 微信支付

微信支付

SiriYang 支付宝

支付宝

  • 本文标题: 在AppWishList开发中遇到的一些问题
  • 本文作者: SiriYang
  • 创建时间: 2020年01月29日 - 18时01分
  • 修改时间: 2021年10月29日 - 18时10分
  • 本文链接: https://blog.siriyang.cn/posts/20200129180349id.html
  • 版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明出处!
学习笔记 Python Pythonista 语法
AppWishList for iOS
CCF-CSP:201409-3字符串匹配
  • 文章目录
  • 站点概览
SiriYang

SiriYang

努力搬砖攒钱买镜头的摄影迷
320 日志
33 分类
88 标签
RSS
GitHub E-Mail
Creative Commons
Links
  • 友情链接
  • 作品商铺

  1. 2020.01.29
    1. Note1
    2. Note2
    3. Note3
    4. Note4
  2. 2020.01.30
    1. Note5
    2. Note6
    3. Note7
    4. Note8
    5. Note9
  3. 2020.01.31
    1. Note10
    2. Note11
    3. Note12
  4. 2020.03.28
    1. Note13
  5. 2020.03.29
    1. Note14
蜀ICP备19008337号 © 2019 – 2025 SiriYang | 1.7m | 25:41
0%