2010-07-08 20:01:03 +02:00
|
|
|
#!/usr/bin/python
|
2010-02-28 09:53:44 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2010-07-04 03:05:16 +02:00
|
|
|
#Copyright 2008-2010 Carl Gherardi
|
2010-02-28 09:53:44 +01:00
|
|
|
#This program is free software: you can redistribute it and/or modify
|
|
|
|
#it under the terms of the GNU Affero General Public License as published by
|
|
|
|
#the Free Software Foundation, version 3 of the License.
|
|
|
|
#
|
|
|
|
#This program is distributed in the hope that it will be useful,
|
|
|
|
#but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
#GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
#You should have received a copy of the GNU Affero General Public License
|
|
|
|
#along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2010-07-04 03:05:16 +02:00
|
|
|
#In the "official" distribution you can find the license in agpl-3.0.txt.
|
2010-02-28 09:53:44 +01:00
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import traceback
|
|
|
|
import Queue
|
|
|
|
|
|
|
|
import pygtk
|
|
|
|
pygtk.require('2.0')
|
|
|
|
import gtk
|
|
|
|
import gobject
|
|
|
|
import pango
|
|
|
|
|
|
|
|
import logging
|
|
|
|
# logging has been set up in fpdb.py or HUD_main.py, use their settings:
|
|
|
|
log = logging.getLogger("maintdbs")
|
|
|
|
|
|
|
|
|
|
|
|
import Exceptions
|
|
|
|
import Database
|
2010-07-19 22:36:45 +02:00
|
|
|
import SQL
|
2010-02-28 09:53:44 +01:00
|
|
|
|
2010-08-15 20:50:49 +02:00
|
|
|
import locale
|
|
|
|
lang=locale.getdefaultlocale()[0][0:2]
|
|
|
|
print "lang:", lang
|
|
|
|
if lang=="en":
|
|
|
|
def _(string): return string
|
|
|
|
else:
|
|
|
|
import gettext
|
|
|
|
try:
|
|
|
|
trans = gettext.translation("fpdb", localedir="locale", languages=[lang])
|
|
|
|
trans.install()
|
|
|
|
except IOError:
|
|
|
|
def _(string): return string
|
2010-02-28 09:53:44 +01:00
|
|
|
|
|
|
|
class GuiDatabase:
|
|
|
|
|
2010-07-19 22:36:45 +02:00
|
|
|
# columns in liststore:
|
|
|
|
MODEL_DBMS = 0
|
|
|
|
MODEL_NAME = 1
|
|
|
|
MODEL_DESC = 2
|
|
|
|
MODEL_USER = 3
|
|
|
|
MODEL_PASS = 4
|
|
|
|
MODEL_HOST = 5
|
|
|
|
MODEL_DFLT = 6
|
|
|
|
MODEL_DFLTIC = 7
|
|
|
|
MODEL_STATUS = 8
|
|
|
|
MODEL_STATIC = 9
|
|
|
|
|
|
|
|
# columns in listview:
|
2010-02-28 09:53:44 +01:00
|
|
|
COL_DBMS = 0
|
|
|
|
COL_NAME = 1
|
|
|
|
COL_DESC = 2
|
|
|
|
COL_USER = 3
|
|
|
|
COL_PASS = 4
|
|
|
|
COL_HOST = 5
|
2010-07-19 22:36:45 +02:00
|
|
|
COL_DFLT = 6
|
|
|
|
COL_ICON = 7
|
2010-02-28 09:53:44 +01:00
|
|
|
|
|
|
|
def __init__(self, config, mainwin, dia):
|
|
|
|
self.config = config
|
|
|
|
self.main_window = mainwin
|
|
|
|
self.dia = dia
|
|
|
|
|
|
|
|
try:
|
|
|
|
#self.dia.set_modal(True)
|
|
|
|
self.vbox = self.dia.vbox
|
|
|
|
#gtk.Widget.set_size_request(self.vbox, 700, 400);
|
|
|
|
|
|
|
|
# list of databases in self.config.supported_databases:
|
2010-07-19 22:36:45 +02:00
|
|
|
self.liststore = gtk.ListStore(str, str, str, str, str
|
|
|
|
,str, str, str, str, str)
|
|
|
|
# dbms, name, comment, user, passwd, host, "", default_icon, status, icon
|
2010-02-28 09:53:44 +01:00
|
|
|
# this is how to add a filter:
|
|
|
|
#
|
|
|
|
# # Creation of the filter, from the model
|
|
|
|
# filter = self.liststore.filter_new()
|
|
|
|
# filter.set_visible_column(1)
|
|
|
|
#
|
|
|
|
# # The TreeView gets the filter as model
|
|
|
|
# self.listview = gtk.TreeView(filter)
|
|
|
|
self.listview = gtk.TreeView(model=self.liststore)
|
|
|
|
self.listview.set_grid_lines(gtk.TREE_VIEW_GRID_LINES_NONE)
|
|
|
|
self.listcols = []
|
2010-07-19 22:36:45 +02:00
|
|
|
self.changes = False
|
2010-02-28 09:53:44 +01:00
|
|
|
|
2010-07-19 22:36:45 +02:00
|
|
|
self.scrolledwindow = gtk.ScrolledWindow()
|
|
|
|
self.scrolledwindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
|
|
|
|
self.scrolledwindow.add(self.listview)
|
|
|
|
self.vbox.pack_start(self.scrolledwindow, expand=True, fill=True, padding=0)
|
2010-02-28 09:53:44 +01:00
|
|
|
|
2010-08-15 20:06:30 +02:00
|
|
|
refreshbutton = gtk.Button(_("Refresh"))
|
2010-02-28 09:53:44 +01:00
|
|
|
refreshbutton.connect("clicked", self.refresh, None)
|
|
|
|
self.vbox.pack_start(refreshbutton, False, False, 3)
|
|
|
|
refreshbutton.show()
|
|
|
|
|
2010-08-15 20:06:30 +02:00
|
|
|
col = self.addTextColumn(_("Type"), 0, False)
|
|
|
|
col = self.addTextColumn(_("Name"), 1, False)
|
|
|
|
col = self.addTextColumn(_("Description"), 2, True)
|
|
|
|
col = self.addTextColumn(_("Username"), 3, True)
|
|
|
|
col = self.addTextColumn(_("Password"), 4, True)
|
|
|
|
col = self.addTextColumn(_("Host"), 5, True)
|
|
|
|
col = self.addTextObjColumn(_("Default"), 6, 6)
|
|
|
|
col = self.addTextObjColumn(_("Status"), 7, 8)
|
2010-07-19 22:36:45 +02:00
|
|
|
|
|
|
|
#self.listview.get_selection().set_mode(gtk.SELECTION_SINGLE)
|
|
|
|
#self.listview.get_selection().connect("changed", self.on_selection_changed)
|
|
|
|
self.listview.add_events(gtk.gdk.BUTTON_PRESS_MASK)
|
|
|
|
self.listview.connect('button_press_event', self.selectTest)
|
2010-02-28 09:53:44 +01:00
|
|
|
|
|
|
|
self.loadDbs()
|
|
|
|
|
2010-07-19 22:36:45 +02:00
|
|
|
#self.dia.connect('response', self.dialog_response_cb)
|
2010-02-28 09:53:44 +01:00
|
|
|
except:
|
|
|
|
err = traceback.extract_tb(sys.exc_info()[2])[-1]
|
|
|
|
print 'guidbmaint: '+ err[2] + "(" + str(err[1]) + "): " + str(sys.exc_info()[1])
|
|
|
|
|
|
|
|
def dialog_response_cb(self, dialog, response_id):
|
|
|
|
# this is called whether close button is pressed or window is closed
|
2010-07-19 22:36:45 +02:00
|
|
|
log.info('dialog_response_cb: response_id='+str(response_id))
|
|
|
|
#if self.changes:
|
|
|
|
# self.config.save()
|
2010-02-28 09:53:44 +01:00
|
|
|
dialog.destroy()
|
2010-07-19 22:36:45 +02:00
|
|
|
return(response_id)
|
2010-02-28 09:53:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
def get_dialog(self):
|
|
|
|
return self.dia
|
|
|
|
|
|
|
|
def addTextColumn(self, title, n, editable=False):
|
|
|
|
col = gtk.TreeViewColumn(title)
|
|
|
|
self.listview.append_column(col)
|
|
|
|
|
|
|
|
cRender = gtk.CellRendererText()
|
|
|
|
cRender.set_property("wrap-mode", pango.WRAP_WORD_CHAR)
|
|
|
|
cRender.set_property('editable', editable)
|
|
|
|
cRender.connect('edited', self.edited_cb, (self.liststore,n))
|
|
|
|
|
|
|
|
col.pack_start(cRender, True)
|
|
|
|
col.add_attribute(cRender, 'text', n)
|
|
|
|
col.set_max_width(1000)
|
|
|
|
col.set_spacing(0) # no effect
|
|
|
|
self.listcols.append(col)
|
|
|
|
col.set_clickable(True)
|
|
|
|
col.connect("clicked", self.sortCols, n)
|
|
|
|
|
|
|
|
return(col)
|
|
|
|
|
|
|
|
def edited_cb(self, cell, path, new_text, user_data):
|
|
|
|
liststore, col = user_data
|
2010-07-19 22:36:45 +02:00
|
|
|
log.info('edited_cb: col = '+str(col))
|
2010-02-28 09:53:44 +01:00
|
|
|
valid = True
|
|
|
|
name = self.liststore[path][self.COL_NAME]
|
|
|
|
|
|
|
|
# Validate new value (only for dbms so far, but dbms now not updateable so no validation at all!)
|
|
|
|
#if col == self.COL_DBMS:
|
|
|
|
# if new_text not in Configuration.DATABASE_TYPES:
|
|
|
|
# valid = False
|
|
|
|
|
|
|
|
if valid:
|
|
|
|
self.liststore[path][col] = new_text
|
|
|
|
|
|
|
|
self.config.set_db_parameters( db_server = self.liststore[path][self.COL_DBMS]
|
|
|
|
, db_name = name
|
2010-07-19 22:36:45 +02:00
|
|
|
, db_desc = self.liststore[path][self.COL_DESC]
|
2010-02-28 09:53:44 +01:00
|
|
|
, db_ip = self.liststore[path][self.COL_HOST]
|
|
|
|
, db_user = self.liststore[path][self.COL_USER]
|
|
|
|
, db_pass = self.liststore[path][self.COL_PASS] )
|
2010-07-19 22:36:45 +02:00
|
|
|
self.changes = True
|
2010-02-28 09:53:44 +01:00
|
|
|
return
|
|
|
|
|
|
|
|
def check_new_name(self, path, new_text):
|
|
|
|
name_ok = True
|
|
|
|
for i,db in enumerate(self.liststore):
|
|
|
|
if i != path and new_text == db[self.COL_NAME]:
|
|
|
|
name_ok = False
|
|
|
|
#TODO: popup an error message telling user names must be unique
|
|
|
|
return name_ok
|
|
|
|
|
2010-07-19 22:36:45 +02:00
|
|
|
def addTextObjColumn(self, title, viewcol, storecol, editable=False):
|
2010-02-28 09:53:44 +01:00
|
|
|
col = gtk.TreeViewColumn(title)
|
|
|
|
self.listview.append_column(col)
|
|
|
|
|
|
|
|
cRenderT = gtk.CellRendererText()
|
|
|
|
cRenderT.set_property("wrap-mode", pango.WRAP_WORD_CHAR)
|
|
|
|
col.pack_start(cRenderT, False)
|
2010-07-19 22:36:45 +02:00
|
|
|
col.add_attribute(cRenderT, 'text', storecol)
|
2010-02-28 09:53:44 +01:00
|
|
|
|
|
|
|
cRenderP = gtk.CellRendererPixbuf()
|
2010-07-19 22:36:45 +02:00
|
|
|
col.pack_start(cRenderP, True)
|
|
|
|
col.add_attribute(cRenderP, 'stock-id', storecol+1)
|
2010-02-28 09:53:44 +01:00
|
|
|
|
|
|
|
col.set_max_width(1000)
|
|
|
|
col.set_spacing(0) # no effect
|
|
|
|
self.listcols.append(col)
|
2010-07-19 22:36:45 +02:00
|
|
|
|
|
|
|
col.set_clickable(True)
|
|
|
|
col.connect("clicked", self.sortCols, viewcol)
|
2010-02-28 09:53:44 +01:00
|
|
|
return(col)
|
|
|
|
|
2010-07-19 22:36:45 +02:00
|
|
|
def selectTest(self, widget, event):
|
|
|
|
if event.button == 1: # and event.type == gtk.gdk._2BUTTON_PRESS:
|
|
|
|
pthinfo = self.listview.get_path_at_pos( int(event.x), int(event.y) )
|
|
|
|
if pthinfo is not None:
|
|
|
|
path, col, cellx, celly = pthinfo
|
|
|
|
row = path[0]
|
|
|
|
if col == self.listcols[self.COL_DFLT]:
|
|
|
|
if self.liststore[row][self.MODEL_STATUS] == 'ok' and self.liststore[row][self.MODEL_DFLTIC] is None:
|
|
|
|
self.setDefaultDB(row)
|
|
|
|
|
|
|
|
def setDefaultDB(self, row):
|
|
|
|
print "set new defaultdb:", row, self.liststore[row][self.MODEL_NAME]
|
|
|
|
for r in xrange(len(self.liststore)):
|
|
|
|
if r == row:
|
|
|
|
self.liststore[r][self.MODEL_DFLTIC] = gtk.STOCK_APPLY
|
|
|
|
default = "True"
|
|
|
|
else:
|
|
|
|
self.liststore[r][self.MODEL_DFLTIC] = None
|
|
|
|
default = "False"
|
|
|
|
|
|
|
|
self.config.set_db_parameters( db_server = self.liststore[r][self.COL_DBMS]
|
|
|
|
, db_name = self.liststore[r][self.COL_NAME]
|
|
|
|
, db_desc = self.liststore[r][self.COL_DESC]
|
|
|
|
, db_ip = self.liststore[r][self.COL_HOST]
|
|
|
|
, db_user = self.liststore[r][self.COL_USER]
|
|
|
|
, db_pass = self.liststore[r][self.COL_PASS]
|
|
|
|
, default = default
|
|
|
|
)
|
|
|
|
self.changes = True
|
|
|
|
return
|
|
|
|
|
|
|
|
|
2010-02-28 09:53:44 +01:00
|
|
|
def loadDbs(self):
|
|
|
|
|
|
|
|
self.liststore.clear()
|
2010-07-19 22:36:45 +02:00
|
|
|
#self.listcols = []
|
2010-08-15 20:06:30 +02:00
|
|
|
dia = self.info_box2(None, _('Testing database connections ... '), "", False, False)
|
2010-07-19 22:36:45 +02:00
|
|
|
while gtk.events_pending():
|
|
|
|
gtk.mainiteration()
|
2010-02-28 09:53:44 +01:00
|
|
|
|
|
|
|
try:
|
2010-07-19 22:36:45 +02:00
|
|
|
# want to fill: dbms, name, comment, user, passwd, host, default, status, icon
|
2010-02-28 09:53:44 +01:00
|
|
|
for name in self.config.supported_databases: #db_ip/db_user/db_pass/db_server
|
|
|
|
dbms = self.config.supported_databases[name].db_server # mysql/postgresql/sqlite
|
|
|
|
dbms_num = self.config.get_backend(dbms) # 2 / 3 / 4
|
2010-07-19 22:36:45 +02:00
|
|
|
comment = self.config.supported_databases[name].db_desc
|
2010-02-28 09:53:44 +01:00
|
|
|
if dbms == 'sqlite':
|
|
|
|
user = ""
|
|
|
|
passwd = ""
|
|
|
|
else:
|
|
|
|
user = self.config.supported_databases[name].db_user
|
|
|
|
passwd = self.config.supported_databases[name].db_pass
|
|
|
|
host = self.config.supported_databases[name].db_ip
|
2010-07-19 22:36:45 +02:00
|
|
|
default = (name == self.config.db_selected)
|
|
|
|
default_icon = None
|
|
|
|
if default: default_icon = gtk.STOCK_APPLY
|
2010-02-28 09:53:44 +01:00
|
|
|
status = ""
|
|
|
|
icon = None
|
|
|
|
err_msg = ""
|
|
|
|
|
2010-07-19 22:36:45 +02:00
|
|
|
sql = SQL.Sql(db_server=dbms)
|
|
|
|
db = Database.Database(self.config, sql = sql, autoconnect = False)
|
2010-02-28 09:53:44 +01:00
|
|
|
# try to connect to db, set status and err_msg if it fails
|
|
|
|
try:
|
|
|
|
# is creating empty db for sqlite ... mod db.py further?
|
|
|
|
# add noDbTables flag to db.py?
|
2010-08-15 20:06:30 +02:00
|
|
|
log.debug(_("loaddbs: trying to connect to: %s/%s, %s, %s/%s") % (str(dbms_num),dbms,name,user,passwd))
|
2010-02-28 09:53:44 +01:00
|
|
|
db.connect(backend=dbms_num, host=host, database=name, user=user, password=passwd, create=False)
|
|
|
|
if db.connected:
|
2010-08-15 20:06:30 +02:00
|
|
|
log.debug(_(" connected ok"))
|
2010-02-28 09:53:44 +01:00
|
|
|
status = 'ok'
|
|
|
|
icon = gtk.STOCK_APPLY
|
|
|
|
if db.wrongDbVersion:
|
|
|
|
status = 'old'
|
|
|
|
icon = gtk.STOCK_INFO
|
2010-07-19 22:36:45 +02:00
|
|
|
else:
|
2010-08-15 20:06:30 +02:00
|
|
|
log.debug(_(" not connected but no exception"))
|
2010-02-28 09:53:44 +01:00
|
|
|
except Exceptions.FpdbMySQLAccessDenied:
|
2010-08-15 20:06:30 +02:00
|
|
|
err_msg = _("MySQL Server reports: Access denied. Are your permissions set correctly?")
|
2010-02-28 09:53:44 +01:00
|
|
|
status = "failed"
|
|
|
|
icon = gtk.STOCK_CANCEL
|
|
|
|
except Exceptions.FpdbMySQLNoDatabase:
|
2010-08-15 20:06:30 +02:00
|
|
|
err_msg = _("MySQL client reports: 2002 or 2003 error. Unable to connect - Please check that the MySQL service has been started")
|
2010-02-28 09:53:44 +01:00
|
|
|
status = "failed"
|
|
|
|
icon = gtk.STOCK_CANCEL
|
|
|
|
except Exceptions.FpdbPostgresqlAccessDenied:
|
2010-08-15 20:06:30 +02:00
|
|
|
err_msg = _("Postgres Server reports: Access denied. Are your permissions set correctly?")
|
2010-02-28 09:53:44 +01:00
|
|
|
status = "failed"
|
|
|
|
except Exceptions.FpdbPostgresqlNoDatabase:
|
2010-08-15 20:06:30 +02:00
|
|
|
err_msg = _("Postgres client reports: Unable to connect - Please check that the Postgres service has been started")
|
2010-02-28 09:53:44 +01:00
|
|
|
status = "failed"
|
|
|
|
icon = gtk.STOCK_CANCEL
|
|
|
|
except:
|
|
|
|
err = traceback.extract_tb(sys.exc_info()[2])[-1]
|
|
|
|
log.info( 'db connection to '+str(dbms_num)+','+host+','+name+','+user+','+passwd+' failed: '
|
2010-08-15 20:06:30 +02:00
|
|
|
+ err[2] + "(" + str(err[1]) + "): " + str(sys.exc_info()[1]) )#TODO Gettextify
|
2010-02-28 09:53:44 +01:00
|
|
|
status = "failed"
|
|
|
|
icon = gtk.STOCK_CANCEL
|
2010-07-19 22:36:45 +02:00
|
|
|
if err_msg:
|
|
|
|
log.info( 'db connection to '+str(dbms_num)+','+host+','+name+','+user+','+passwd+' failed: '
|
2010-08-15 20:06:30 +02:00
|
|
|
+ err_msg )#TODO Gettextify
|
2010-02-28 09:53:44 +01:00
|
|
|
|
|
|
|
b = gtk.Button(name)
|
|
|
|
b.show()
|
2010-07-19 22:36:45 +02:00
|
|
|
iter = self.liststore.append( (dbms, name, comment, user, passwd, host, "", default_icon, status, icon) )
|
2010-02-28 09:53:44 +01:00
|
|
|
|
2010-08-15 20:06:30 +02:00
|
|
|
self.info_box2(dia[0], _("finished."), "", False, True)
|
2010-02-28 09:53:44 +01:00
|
|
|
self.listview.show()
|
2010-07-19 22:36:45 +02:00
|
|
|
self.scrolledwindow.show()
|
2010-02-28 09:53:44 +01:00
|
|
|
self.vbox.show()
|
|
|
|
self.dia.set_focus(self.listview)
|
|
|
|
|
|
|
|
self.vbox.show_all()
|
|
|
|
self.dia.show()
|
|
|
|
except:
|
|
|
|
err = traceback.extract_tb(sys.exc_info()[2])[-1]
|
2010-08-15 20:06:30 +02:00
|
|
|
print _('loaddbs error: ')+str(dbms_num)+','+host+','+name+','+user+','+passwd+' failed: ' \
|
2010-02-28 09:53:44 +01:00
|
|
|
+ err[2] + "(" + str(err[1]) + "): " + str(sys.exc_info()[1])
|
|
|
|
|
|
|
|
def sortCols(self, col, n):
|
|
|
|
try:
|
2010-07-19 22:36:45 +02:00
|
|
|
log.info('sortcols n='+str(n))
|
2010-02-28 09:53:44 +01:00
|
|
|
if not col.get_sort_indicator() or col.get_sort_order() == gtk.SORT_ASCENDING:
|
|
|
|
col.set_sort_order(gtk.SORT_DESCENDING)
|
|
|
|
else:
|
|
|
|
col.set_sort_order(gtk.SORT_ASCENDING)
|
|
|
|
self.liststore.set_sort_column_id(n, col.get_sort_order())
|
|
|
|
#self.liststore.set_sort_func(n, self.sortnums, (n,grid))
|
2010-07-19 22:36:45 +02:00
|
|
|
log.info('sortcols len(listcols)='+str(len(self.listcols)))
|
2010-02-28 09:53:44 +01:00
|
|
|
for i in xrange(len(self.listcols)):
|
2010-07-19 22:36:45 +02:00
|
|
|
log.info('sortcols i='+str(i))
|
2010-02-28 09:53:44 +01:00
|
|
|
self.listcols[i].set_sort_indicator(False)
|
|
|
|
self.listcols[n].set_sort_indicator(True)
|
|
|
|
# use this listcols[col].set_sort_indicator(True)
|
|
|
|
# to turn indicator off for other cols
|
|
|
|
except:
|
|
|
|
err = traceback.extract_tb(sys.exc_info()[2])
|
2010-08-15 20:06:30 +02:00
|
|
|
print _("***sortCols error: ") + str(sys.exc_info()[1])
|
2010-02-28 09:53:44 +01:00
|
|
|
print "\n".join( [e[0]+':'+str(e[1])+" "+e[2] for e in err] )
|
2010-08-15 20:06:30 +02:00
|
|
|
log.info(_('sortCols error: ') + str(sys.exc_info()) )
|
2010-02-28 09:53:44 +01:00
|
|
|
|
|
|
|
def refresh(self, widget, data):
|
|
|
|
self.loadDbs()
|
|
|
|
|
2010-07-19 22:36:45 +02:00
|
|
|
def info_box(self, dia, str1, str2, run, destroy):
|
|
|
|
if dia is None:
|
|
|
|
#if run:
|
|
|
|
btns = gtk.BUTTONS_NONE
|
|
|
|
btns = gtk.BUTTONS_OK
|
|
|
|
dia = gtk.MessageDialog( parent=self.main_window, flags=gtk.DIALOG_DESTROY_WITH_PARENT
|
|
|
|
, type=gtk.MESSAGE_INFO, buttons=(btns), message_format=str1 )
|
|
|
|
# try to remove buttons!
|
|
|
|
# (main message is in inverse video if no buttons, so try removing them after
|
|
|
|
# creating dialog)
|
|
|
|
# NO! message just goes back to inverse video :-( use info_box2 instead
|
|
|
|
for c in dia.vbox.get_children():
|
|
|
|
if isinstance(c, gtk.HButtonBox):
|
|
|
|
for d in c.get_children():
|
|
|
|
log.info('child: '+str(d)+' is a '+str(d.__class__))
|
|
|
|
if isinstance(d, gtk.Button):
|
2010-08-15 20:06:30 +02:00
|
|
|
log.info(_('removing button %s'% str(d)))
|
2010-07-19 22:36:45 +02:00
|
|
|
c.remove(d)
|
|
|
|
if str2:
|
|
|
|
dia.format_secondary_text(str2)
|
|
|
|
else:
|
|
|
|
dia.set_markup(str1)
|
|
|
|
if str2:
|
|
|
|
dia.format_secondary_text(str2)
|
|
|
|
dia.show()
|
|
|
|
response = None
|
|
|
|
if run: response = dia.run()
|
|
|
|
if destroy: dia.destroy()
|
|
|
|
return (dia, response)
|
|
|
|
|
|
|
|
def info_box2(self, dia, str1, str2, run, destroy):
|
|
|
|
if dia is None:
|
|
|
|
# create dialog and add icon and label
|
|
|
|
btns = (gtk.BUTTONS_OK)
|
|
|
|
btns = None
|
|
|
|
# messagedialog puts text in inverse colors if no buttons are displayed??
|
|
|
|
#dia = gtk.MessageDialog( parent=self.main_window, flags=gtk.DIALOG_DESTROY_WITH_PARENT
|
|
|
|
# , type=gtk.MESSAGE_INFO, buttons=(btns), message_format=str1 )
|
|
|
|
dia = gtk.Dialog( parent=self.main_window, flags=gtk.DIALOG_DESTROY_WITH_PARENT
|
|
|
|
, title="" ) # , buttons=btns
|
|
|
|
vbox = dia.vbox
|
|
|
|
|
|
|
|
h = gtk.HBox(False, 2)
|
|
|
|
i = gtk.Image()
|
|
|
|
i.set_from_stock(gtk.STOCK_DIALOG_INFO, gtk.ICON_SIZE_DIALOG)
|
|
|
|
l = gtk.Label(str1)
|
|
|
|
h.pack_start(i, padding=5)
|
|
|
|
h.pack_start(l, padding=5)
|
|
|
|
vbox.pack_start(h)
|
|
|
|
else:
|
|
|
|
# add extra label
|
|
|
|
vbox = dia.vbox
|
|
|
|
vbox.pack_start( gtk.Label(str1) )
|
|
|
|
dia.show_all()
|
|
|
|
response = None
|
|
|
|
if run: response = dia.run()
|
|
|
|
if destroy: dia.destroy()
|
|
|
|
return (dia, response)
|
2010-02-28 09:53:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__=="__main__":
|
|
|
|
|
|
|
|
config = Configuration.Config()
|
|
|
|
|
|
|
|
win = gtk.Window(gtk.WINDOW_TOPLEVEL)
|
2010-08-15 20:06:30 +02:00
|
|
|
win.set_title(_("Test Log Viewer"))
|
2010-02-28 09:53:44 +01:00
|
|
|
win.set_border_width(1)
|
|
|
|
win.set_default_size(600, 500)
|
|
|
|
win.set_resizable(True)
|
|
|
|
|
2010-08-15 20:06:30 +02:00
|
|
|
dia = gtk.Dialog(_("Log Viewer"),
|
2010-02-28 09:53:44 +01:00
|
|
|
win,
|
|
|
|
gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
(gtk.STOCK_CLOSE, gtk.RESPONSE_OK))
|
|
|
|
dia.set_default_size(500, 500)
|
|
|
|
log = GuiLogView(config, win, dia.vbox)
|
|
|
|
response = dia.run()
|
|
|
|
if response == gtk.RESPONSE_ACCEPT:
|
|
|
|
pass
|
|
|
|
dia.destroy()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|