Ubuntu快速PyGTK和Glade3

时间:2012-01-30 07:14:51

标签: python

我已经使用Ubuntu好几年了,并且一直在寻找Ubuntu下的开发环境来做一些我已经考虑过的事情。至少可以说找到一个我觉得舒服的综合环境令人沮丧。然后,最近我发现了Ubuntu Quickly,并认为它看起来很好,特别是来自Windows MS Access,VBA背景的人。所以我试了几下,几天后使用DesktopCouch就开始了我的第一个应用程序。

然后我发现DesktopCouch不再受到青睐但不想为我的小应用程序转到SQL并且决定使用KirbyBase,所有这些都到目前为止。

我已经有了一个转换的好方法(见屏幕截图),但对于我的生活,我无法理解对话框屏幕。我运行应用程序时会显示图像中的那个,但在用户点击添加或编辑按钮之前不会显示。

我一直试图让按钮被点击三天后显示,显示或显示对话框窗口的语法,而我却无法得到它。

我尝试将其设置为单独的Ui文件,如“关于”和“偏好设置”,但这让我更加困惑。

我认为答案很明显,但三天后我需要帮助。到目前为止主窗口的代码也是附加的,它在OnAddSlang过程中我想显示对话框,收集数据或其他。

顺便说一句,我也是Python的新手。

感谢您的帮助。

迈克尔![ScreenDump

] 1

enter code here

# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
### BEGIN LICENSE
# This file is in the public domain
### END LICENSE

import sys
import os

import gettext
from gettext import gettext as _
gettext.textdomain('ozslang')

import gtk
import logging
logger = logging.getLogger('ozslang')

from kirbybase import KirbyBase, KBError    #Set up KirbyBase Database



from ozslang_lib import Window
from ozslang.AboutOzslangDialog import AboutOzslangDialog
from ozslang.PreferencesOzslangDialog import PreferencesOzslangDialog
from ozslang.EntryOzslangDialog import EntryOzslangDialog

FILE_EXT = "tbl"

# See ozslang_lib.Window.py for more details about how this class works
class OzslangWindow(Window):
    __gtype_name__ = "OzslangWindow"

    def finish_initializing(self, builder): # pylint: disable=E1002
        """Set up the main window"""
        super(OzslangWindow, self).finish_initializing(builder)

        self.AboutDialog = AboutOzslangDialog
        self.PreferencesDialog = PreferencesOzslangDialog


        # Code for other initialization actions should be added here.
        # Set up KirbyBase Database - Check if Created if not Create it
        # Otherwise Check Read it and Print out Results.

        db = KirbyBase()
        dbTable = "slang.tbl"

        # Table has Record No, Slang, Meaning, Useage, Is Common, Locality and Comment.
        # Fields are Integer, String, String, String, Boolean, String and String.

        # Check if the table exists.

        if os.path.exists('slang.tbl'):
            boolIsCreated = True
            print boolIsCreated

            #recno = db.insert(dbTable, ['Pie Hole', 'Mouth', 'Shut your pie hole', True, 'Australia Wide', 'No Comments 2'])
            result = db.select('slang.tbl', ['recno'], ['*'])
            print result
            barMsg = 'Slang Table is in current directory'
            self.statusbar = builder.get_object("statusbar1")
            self.statusbar_cid = self.statusbar.get_context_id("Status")
            self.statusbar.push(self.statusbar_cid, barMsg)
        else:
            #If it does not exist in this location, create it.

            result = db.create('slang.tbl', ['slang:str', 'meaning:str', 'use:str',
            'iscommon:bool', 'locality:str', 'comment:str'])
            print 'Slang Table Created'
            barMsg = 'Slang Table Created'
            self.statusbar = builder.get_object("statusbar1")
            self.statusbar_cid = self.statusbar.get_context_id("Status")
            self.statusbar.push(self.statusbar_cid, barMsg)
            print 'at end of slang table open create'

    def on_EditSlang(self, widget):
        """Called when the user wants to edit a wine entry"""
        print "In Edit Function"
        pass_

    def OnAddSlang(self, widget):
        print 'In Add Function'
        #Called when the use wants to add a slang
        EntryOzslangDialog.hasfocus = True

        print 'after dialog...'

    def on_btnOK_clicked(self,widget):
        pass

    def on_btnCancel_clicked(self,widget):
        pass

    def _on_close(self, window):
        pass

1 个答案:

答案 0 :(得分:1)

一旦你知道这个秘密,最后这很简单。我需要知道的是,对话框需要通过构建器引用,如:

entrydialog = self.builder.get_object("EntryDialog")
entrydialog.hide()

当然,当用户单击添加按钮时,show()选项用于再次显示数据输入窗口。

我知道这是我遇到的一个基本语法问题,但它已经花了3天时间,在其他项目之间,以及搜索找到与Ubuntu Quickly,Glade 3.10和PyGtk +相关的答案。没有一个视频或示例说明对话框屏幕,并且有很多例子使用早期的Glade版本构建UI作为代码的一部分,但这似乎打败了Glade和Quickly的目的。

我必须说Galde3和Glade2之间的区别以及相关的Gtk材料是惊人的,对于Glade3来说并不是很多,尽管有少数很好但是还不足以展示新的工作方式。

无论如何,感谢发泄的空间,当我有一个完成的应用程序时,我会把它写成网站的样本。

全力以赴 - 保持良好的工作

迈克尔 Yackandandah