Odoo 中文社区

    • 注册
    • 登录
    • 搜索
    • 版块
    • 标签
    • 热门
    • 用户
    • 群组
    1. 主页
    2. mihi

    Odoo中文社区可以通过以下两个域名访问:shine-it.net , odoo.net.cn

    由于系统升迁的原因,本论坛部分较早期的内容存在格式和链接损坏失效的问题,并非本论坛系统本身的缺陷,望谅解

    本社区没有维护任何QQ群讨论组,任何与本社区同名的QQ群讨论组的言论与本社区无关!

    开发人员可以登录gitter讨论组: http://gitter.im/odoo-china/Talk, 需要github账号

    如果您登录系统碰到问题,请在微信公众号留言:

    M
    • 资料
    • 关注 0
    • 粉丝 0
    • 主题 23
    • 帖子 122
    • 最佳 0
    • 有争议的 0
    • 群组 0

    mihi

    @mihi

    0
    声望
    1147
    资料浏览
    122
    帖子
    0
    粉丝
    0
    关注
    注册时间 最后登录

    mihi 取消关注 关注

    mihi 发布的最新帖子

    • Python开发调用DLL之ctypes初体验

      在开发过程中不可避免涉及到与系统动态链接库的交互,在python如果需要实现调用系统动态链接库函数,必须使用ctypes模块。ctypes使用相对简单。
      首先是dll的加载,windows下使用windll.LoadLibrary()函数。
      第二是方法的调用,也很简单,可以直接 "对象.原方法名()”就可以了。如:

      <br />&nbsp; &nbsp; &nbsp; &nbsp; self.carddll = windll.LoadLibrary(&quot;dcrf32.dll&quot;)<br />&nbsp; &nbsp; &nbsp; &nbsp; self.icdev = self.carddll.dc_init(100,0)<br />
      


      这里的dc_init()就是原来dll里的方法。
      第三数据类型的转换,这是最复杂的,可以分为4种情况。
      1.简单型(数值、字符、布尔)可以直接传递,不需要变化,比如上面的100,0 及其返回值icdev。
      2.简单类型的指针。也较简单。分别有两种实现方法。
      i.通过byref(参数)
      ii.通过Pointer方法来构造一个指针变量如

      <br />&nbsp; &nbsp; &nbsp; &nbsp; tempid = c_ulong(0)<br />&nbsp; &nbsp; &nbsp; &nbsp; ptempid = pointer(tempid)<br />&nbsp; &nbsp; &nbsp; &nbsp; st2 = self.carddll.dc_card(self.icdev, ModeALL, ptempid)<br />
      



      <br />&nbsp; &nbsp; &nbsp; &nbsp; tempid = c_ulong(0)<br />&nbsp; &nbsp; &nbsp; &nbsp; st2 = self.carddll.dc_card(self.icdev, ModeALL, byref(tempid))<br />
      


      以上两段代码等价
      3.字符串,在dll中往往是char *类型。这里又分为两种情况.
      i.如果传递方向是in很简单,直接把python中的字符串传入就可以了。
      ii.如果是传递方向是out较复杂,需要构造一个字符串buffer,如:

      <br />readdata1 = create_string_buffer(16)<br />st3 = self.carddll.dc_read(self.icdev, Block8, readdata1)<br />readdata = readdata1.value[0:12]<br />
      


      其中 readdata1就是读出的字符缓冲区,readdata是python字符串
      4.结构体,较复杂需要用ctypes重性定义特殊格式的类。(本次开发没有涉及,就不深入了)
      以下是完整的代码,通过threading.Thread类来实现多线程,通过多线程完成对射频的读取:

      <br />from&nbsp; ctypes import *<br />class DevWork(threading.Thread):<br />&nbsp; &nbsp; &quot;多线程实现读卡&quot;<br />&nbsp; &nbsp; def __init__(self,window):<br />&nbsp; &nbsp; &nbsp; &nbsp; threading.Thread.__init__(self)<br />&nbsp; &nbsp; &nbsp; &nbsp; self.window = window<br />&nbsp; &nbsp; &nbsp; &nbsp; self._terminate=False<br />&nbsp; &nbsp; &nbsp; &nbsp; #self.__suspend_lock = threading.Lock()<br />&nbsp; &nbsp; <br />&nbsp; &nbsp; def terminate(self):<br />&nbsp; &nbsp; &nbsp; &nbsp; self._terminate = True<br />&nbsp; <br />&nbsp; &nbsp; <br />&nbsp; &nbsp; def OpenDev(self):<br />&nbsp; &nbsp; &nbsp; &nbsp; self.carddll = windll.LoadLibrary(&quot;dcrf32.dll&quot;)<br />&nbsp; &nbsp; &nbsp; &nbsp; self.icdev = self.carddll.dc_init(100,0)<br />&nbsp; &nbsp; &nbsp; &nbsp; if self.icdev &lt;= 0 :<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return -1<br />&nbsp; &nbsp; &nbsp; &nbsp; st = self.carddll.dc_load_key_hex(self.icdev,KEYSET0,Sec2,passwordA)<br />&nbsp; &nbsp; &nbsp; &nbsp; if st != 0 :<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.carddll.dc_exit(self.icdev)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return -2<br />&nbsp; &nbsp; &nbsp; &nbsp; return 1<br />&nbsp; &nbsp; <br />&nbsp; &nbsp; def run(self):<br />&nbsp; &nbsp;  <br />&nbsp; &nbsp; &nbsp; &nbsp; tempid = c_ulong(0)<br />&nbsp; &nbsp; &nbsp; &nbsp; ptempid = pointer(tempid)<br />&nbsp; &nbsp; &nbsp; &nbsp; readdata1 = create_string_buffer(16)<br />&nbsp; &nbsp; &nbsp; &nbsp; olddata = &quot;a&quot; * 12<br />&nbsp; &nbsp; &nbsp; &nbsp; while True:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; time.sleep(3)&nbsp;  <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if self._terminate:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; st2 = self.carddll.dc_card(self.icdev, ModeALL, ptempid)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; st2 = self.carddll.dc_authentication(self.icdev, KEYSET0, Sec2)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; st3 = self.carddll.dc_read(self.icdev, Block8, readdata1)<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; readdata = readdata1.value[0:12]<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if olddata == readdata:&nbsp;  #同一张卡,不再操作<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; continue<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.window.Input(readdata)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; time.sleep(1)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; olddata = readdata<br /><br />
      


      其中terminate()用来实现结束线程
      OpenDev()用来打开设备
      run()里边有个大循环,用来实现连续读取卡片内容。

         



      发布在 Python 开发
      M
      mihi
    • RE: PyGTK初体验

      对应Mifire One(就是最标准的射频IC卡)的读写部分,我删去了。因为这部分是个性的,没有普遍意义,如果有特殊需要的话,我可以提供完整的代码,进行交流。

      发布在 Python 开发
      M
      mihi
    • PyGTK初体验

      GUI(图形用户接口)在程序开发中起举足轻重的作用。从某种角度来说MVC也是一个GUI类库,再加上GTK和QT可以并称三大GUI类库。期中前者主要用于windows平台,后两者用在Linux平台较多。GTK是Gnome的底层类库,而QT是KDE的底层类库。相对而言QT比GTK名气更大,但是GTK比QT更加开放。因此本人Python下第一次用户界面程序开发就使用GTK下的PyGTK。


      PyGTK顾名思义是Python下对GTK的封装。GTK下也有窗体Form和控件的概念。只是控件被称之为widget。窗体和widget都是GObejct是子类。Gobject是GTK的一个基类,在GObject中可以自定义事件和属性。(内容相对复杂就不展开了)

      对应于简单的GTK窗口开发的步骤大概可以分为三步。
      1widget设计布局。并加载widget。
      2事件方法关联。并实现方法。
      3显示窗口,注意GTK主循环.

      首先是widget的布局。GTK除了动态控制控件位置之外,还支持一种Glade布局。本质上是把控件的位置及其其他属性信息写在XML文件中。(这里称为glade,同时glade也是一个可视化配置软件。用来设计时给widget布局,但是不好用。)然后在类初始化的时候,把glade文件加载,并找到(通过Id名称)我们需要的widget。然后再把window显示出来,就实现窗口布局。

      第二个关键问题是事件方法的关联。在VB和delphi中我们只要双击GUI设计界面中的按钮,一般就会自动实现关联。GTK中做的更加底层,也就更加复杂。首先引入singal信号,通过信号把事件和处理联系起来。抽取Glade文件内容为代码1

      代码1

      <br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;widget class=&quot;GtkButton&quot; id=&quot;btnWrite&quot;&gt;<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;property name=&quot;width_request&quot;&gt;60&lt;/property&gt;<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;property name=&quot;height_request&quot;&gt;30&lt;/property&gt;<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;property name=&quot;visible&quot;&gt;True&lt;/property&gt;<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;property name=&quot;can_focus&quot;&gt;True&lt;/property&gt;<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;property name=&quot;receives_default&quot;&gt;True&lt;/property&gt;<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;property name=&quot;response_id&quot;&gt;0&lt;/property&gt;<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;signal name=&quot;clicked&quot; handler=&quot;OnWrite&quot;/&gt;<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/widget&gt;<br />
      


      <signal name="clicked" handler="OnWrite"/>就是所谓的信号,但是注意 handler 中的OnWrite还不是最终的方法。

      还需要第二步在py文件中__init(self)__方法中使用 res.signal_autoconnect(signal)其中signal是一个字典表示handler和方法的对应关系如:signal = {'OnRead':self.OnRead,'OnWrite':self.OnWrite}

      第三主循环的引入,对于窗口程序而言,需要引入主循环,用来等待事件的触发。在gtk中为

      gtk.main()

      了解了以上三部分内容基本上就可以进行GTK基本的页面开发了,见代码2:。

      代码2:

      <br />class CardIOForm():<br /><br />&nbsp; &nbsp; def __init__(self):<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; res = gtk.glade.XML(&#039;cardio.glade&#039;)<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; self.win1=res.get_widget(&#039;cardioform&#039;)<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; self.entryCode=res.get_widget(&#039;entryCode&#039;)<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; signal = {&#039;OnRead&#039;:self.OnRead,&#039;OnWrite&#039;:self.OnWrite,&#039;OnClose&#039;:self.OnClose,&#039;OnWritePwd&#039;:self.OnWritePwd,}<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; res.signal_autoconnect(signal)<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; <br /><br />&nbsp; &nbsp; def OnRead(self,widget):<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &quot;读第2扇区&quot;<br /><br />&nbsp; &nbsp; &nbsp;  pass<br /><br />&nbsp; &nbsp; &nbsp; <br /><br />&nbsp; &nbsp; <br /><br />&nbsp; &nbsp; def OnWrite(self,widget):<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &quot;写入编码&quot;<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; pass<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; <br /><br />&nbsp; &nbsp; def OnWritePwd(self,widget):<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &quot;先写入密码&quot;&nbsp; &nbsp; &nbsp; &nbsp; <br /><br />&nbsp; &nbsp; &nbsp;  pass<br /><br />&nbsp; &nbsp;  <br /><br />&nbsp; &nbsp; def show(self):<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; self.win1.show()<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; <br /><br />&nbsp; &nbsp; def OnClose(self,widget):<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; gtk.main_quit()<br /><br /><br /><br />if __name__ == &#039;__main__&#039;:<br /><br />&nbsp; &nbsp; window = CardIOForm()<br /><br /> window.show()<br /><br />&nbsp; &nbsp; gtk.main()<br />
      




      参考文献:

      PyGTK 2.0 Reference Manual http://developer.gnome.org/pygtk/stable/ br />PyGTK 2.0 Tutorial(可下载pdf)

      发布在 Python 开发
      M
      mihi
    • RE: OE6.0.2 Web client 中文生效方法

      好东西!正是我所需要的。

      发布在 Odoo 开发与实施交流
      M
      mihi
    • RE: OpenERP财务管理若干概念讲解

      板凳观望!

      发布在 Odoo 开发与实施交流
      M
      mihi
    • RE: 求助:继承

      我明白楼主问的意思。
      就是B和AA的关系:是默认就有,还是需要再次添加?
      按道理来说应该默认就有的。

      发布在 Odoo 开发与实施交流
      M
      mihi
    • RE: 一个workflow的问题

      去掉 readonly属性还是不行。
      PS
      现在搞定了,不是程序问题。
      只是以前我对state字段,命名重复了。后来虽说删了,还是影响了。
      这次重新建立数据库之后,就搞定了。
      谢谢校长

      发布在 Odoo 开发与实施交流
      M
      mihi
    • 一个workflow的问题

      自认为对workflow还是比较熟。(以前做过)但是这次怎么也不成功,请各位老大帮我看看。
      症状是,显示按钮正常(workflow的显示也是正常的),就是点击按钮后,状态不能切换。
      py文件中

      <br /> &#039;state&#039;:fields.selection([<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (&#039;new&#039;,&#039;新义工&#039;),<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (&#039;normal&#039;,&#039;正式义工&#039;),<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (&#039;advanced&#039;,&#039;高级义工&#039;)],&#039;义工级别&#039;,readonly=True,select=True),<br />
      


      workflow.xml

      <br />&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<br />&lt;openerp&gt;<br />	&lt;data&gt;<br />	&nbsp; &nbsp; &nbsp; &nbsp; &lt;record id=&quot;aflsyg_volunteer_workflow&quot; model=&quot;workflow&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;name&quot;&gt;aflsyg.volunteer.workflow&lt;/field&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;osv&quot;&gt;aflsyg.volunteer&lt;/field&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;on_create&quot;&gt;True&lt;/field&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;/record&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;record id=&quot;act_volunteer_new&quot; model=&quot;workflow.activity&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; 	&lt;field name=&quot;wkf_id&quot; ref=&quot;aflsyg_volunteer_workflow&quot;/&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; 	&lt;field name=&quot;flow_start&quot;&gt;True&lt;/field&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; 	&lt;field name=&quot;name&quot;&gt;new&lt;/field&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; 	&lt;field name=&quot;kind&quot;&gt;function&lt;/field&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; 	&lt;field name=&quot;action&quot;&gt;write({&#039;state&#039;:&#039;new&#039;})&lt;/field&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;/record&gt;<br />&nbsp; &nbsp;  <br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;record id=&quot;act_volunteer_normal&quot; model=&quot;workflow.activity&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; 	&lt;field name=&quot;wkf_id&quot; ref=&quot;aflsyg_volunteer_workflow&quot;/&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; 	&lt;field name=&quot;name&quot;&gt;normal&lt;/field&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; 	 &lt;field name=&quot;kind&quot;&gt;function&lt;/field&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  &lt;field name=&quot;action&quot;&gt;write({&#039;state&#039;:&#039;normal&#039;})&lt;/field&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;/record&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;record id=&quot;act_volunteer_advanced&quot; model=&quot;workflow.activity&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; 	&lt;field name=&quot;wkf_id&quot; ref=&quot;aflsyg_volunteer_workflow&quot;/&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; 	&lt;field name=&quot;name&quot;&gt;advance&lt;/field&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; 	 &lt;field name=&quot;kind&quot;&gt;function&lt;/field&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  &lt;field name=&quot;action&quot;&gt;write({&#039;state&#039;:&#039;advanced&#039;})&lt;/field&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  &lt;field name=&quot;flow_stop&quot;&gt;True&lt;/field&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;/record&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  <br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;record id=&quot;trans_new_normal&quot; model=&quot;workflow.transition&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;act_from&quot; ref=&quot;act_volunteer_new&quot;/&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;act_to&quot; ref=&quot;act_volunteer_normal&quot;/&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;signal&quot;&gt;be_normal&lt;/field&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;/record&gt;<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;record id=&quot;trans_normal_advanced&quot; model=&quot;workflow.transition&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;act_from&quot; ref=&quot;act_volunteer_normal&quot;/&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;act_to&quot; ref=&quot;act_volunteer_advanced&quot;/&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;signal&quot;&gt;be_advanced&lt;/field&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;/record&gt;&nbsp; &nbsp; &nbsp; &nbsp; &lt;!--&nbsp; --&gt;<br />	&lt;/data&gt;<br />&lt;/openerp&gt;
      


      view.xml中

      <br />	&lt;button name=&quot;be_normal&quot; string=&quot;晋升为正式义工&quot; states=&quot;new&quot; icon=&quot;gtk-convert&quot;/&gt;<br />	&lt;button name=&quot;be_advanced&quot; string=&quot;晋升为高级义工&quot; states=&quot;normal&quot; icon=&quot;gtk-convert&quot;/&gt;<br />	
      

      发布在 Odoo 开发与实施交流
      M
      mihi
    • RE: 如何在OE中实现对射频卡之类的外设的支持。

      在仔细看了老肖的新作OpenERP对象定义详解http://shine-it.net/index.php/topic,2159.0.html
      之后我基本上有了思路:
      1:管理上还是使用OE客户端。
      2:另外开发一个客户端调用读卡器驱动,同时通过xmlRPC调用OE Server服务把数据写进。

      发布在 Odoo 开发与实施交流
      M
      mihi
    • RE: OpenERP应用和开发基础(第二版)开班了

      再次感谢老肖。
      技术好,文笔好,人品还好!
      不容易!

      发布在 Odoo 新手求助
      M
      mihi