Hello!
I'm new in Linux world and I'm just starting to make my own applications
for Linux. I'm using Gtk+-1.1.11 and PyGtk-0.5.9 on RedHat 5.1.
Before I wrote many programms for Mikysoft Windoze in Delphi and Visual
Basic, so I'm not new in programming. And now what's my problem.
I'm trying to extend the example of IDE for PyGtk. I wrote 2 modules,
cvs.py and GtkMExtra.py. I hate when by showing some window places
itself somewhere on the screen. I'd like to show the window centered in
the screen. I found the method of GtkWindow named set_position. I tried
to use it but it behaves strange. In module cvs.py behaves it correct
and the window shows in the center of the screen. In module GtkMExtra.py
behaves it other. The window _EntryDialog shows somewhere on the screen.
I don't understand it! Why?
Can you help me? Please look into the code.
Thank you
Jiri
Danes
#
# This file contains some convenience routines for gtk.py.
# It includes a python implementation of the GtkMenuFactory, and
# the functions message_box, file_open_box and file_save_box create
# and manage the respective dialogs.
#
from gtk import *
class _EntryDialog(GtkDialog):
def __init__(self, message="", modal=TRUE):
GtkDialog.__init__(self)
self.connect("destroy", self.quit)
self.connect("delete_event", self.quit)
# self.set_default_size(200, 120)
self.set_policy(FALSE, TRUE, FALSE)
if modal:
grab_add(self)
if message:
box = GtkHBox(spacing=10)
box.border_width(5)
self.vbox.pack_start(box, expand=FALSE, fill=FALSE)
box.show()
label = GtkLabel(message)
box.pack_start(label, expand=FALSE, fill=FALSE)
label.show()
separator = GtkHSeparator()
self.vbox.pack_start(separator, expand=FALSE)
separator.show()
box = GtkVBox(spacing=10)
box.border_width(5)
self.vbox.pack_start(box)
box.show()
self.entry = GtkEntry()
box.pack_start(self.entry)
self.entry.show()
self.entry.grab_focus()
button = GtkButton("OK")
button.connect("clicked", self.click)
button.set_flags(CAN_DEFAULT)
self.action_area.pack_start(button)
button.show()
button.grab_default()
button = GtkButton("Cancel")
button.connect("clicked", self.quit)
button.set_flags(CAN_DEFAULT)
self.action_area.pack_start(button)
button.show()
self.ret = None
def quit(self, w=None, event=None):
self.hide()
self.destroy()
mainquit()
def click(self, button):
self.ret = self.entry.get_text()
self.quit()
def m_input_box(title="Input Box", message="", imp, modal=TRUE):
win = _EntryDialog(message, modal=modal)
win.set_title(title)
win.entry.set_text(text=imp)
win.show()
win.set_position(1)
mainloop()
return win.ret
#
# This file contains some convenience routines for edit.py.
# It includes a python implementation of the CVS handling
#
from gtk import *
import string
import commands, GtkExtra, posix
class _CVSLoadDialog(GtkDialog):
def __init__(self, message="", modal=TRUE):
GtkDialog.__init__(self)
self.connect("destroy", self.quit)
self.connect("delete_event", self.quit)
self.set_default_size(200, 250)
if modal:
grab_add(self)
box = GtkHBox()
box.border_width(10)
self.vbox.pack_start(box, expand=FALSE, fill=FALSE)
box.show()
label = GtkLabel("Existing Modules")
box.pack_start(label, expand=FALSE, fill=FALSE)
label.show()
separator = GtkHSeparator()
self.vbox.pack_start(separator, expand=FALSE)
separator.show()
box = GtkVBox(spacing=200)
box.border_width(10)
self.vbox.pack_start(box)
box.show()
scrolled_win = GtkScrolledWindow()
scrolled_win.set_policy(POLICY_AUTOMATIC, POLICY_AUTOMATIC)
box.pack_start(scrolled_win)
scrolled_win.show()
self.list = GtkCList()
self.list.set_column_width(1, 100)
self.list.columns_autosize()
self.list.set_selection_mode(SELECTION_BROWSE)
self.alist = []
self.txt = [""]
self.module_name = [""]
def select_clist(_clist, r, c, event, sf = self):
module_name = sf.list.get_text(r, 0)
tmptxt = sf.alist[r]
i = string.find(tmptxt,"\012")
if i != -1:
tmptxt = tmptxt[0:i]
sf.txt[0] = tmptxt
sf.module_name[0] = module_name
if event:
if event.type == GDK._2BUTTON_PRESS:
sf.return_value(tmptxt,module_name)
self.list.connect("select_row", select_clist)
scrolled_win.add(self.list)
self.list.show()
text = [""]
self.list.freeze()
fp = open("modules")
while 1:
line = fp.readline()
if not line: break
w = string.split(line, "|")
self.list.append(w[0:1])
self.alist = self.alist + w[1:2]
self.list.thaw()
self.list.select_row(0,0)
self.list.grab_focus()
self.button = GtkButton("OK")
self.button.connect("clicked", self.click)
self.button.set_flags(CAN_DEFAULT)
self.action_area.pack_start(self.button)
self.button.show()
self.button.grab_default()
button = GtkButton("Cancel")
button.connect("clicked", self.quit)
button.set_flags(CAN_DEFAULT)
self.action_area.pack_start(button)
button.show()
self.ret = None
def quit(self, w=None, event=None):
self.hide()
self.destroy()
mainquit()
def click(self, button):
self.return_value(self.txt[0], self.module_name[0])
def return_value(self, txt, module_name):
answer = commands.getstatusoutput('ecvs checkout '+txt)
status = answer[0]
answer = answer[1]
w = string.split(answer, "\012")
cd = posix.getcwd()
print(cd)
if status != 0:
del w[len(w)-1]
del w[len(w)-1]
answer = string.join(w,'\012')
GtkExtra.message_box("CVS Error",answer,("OK",))
self.ret = None
else:
self.ret = string.split(module_name + "\012" + txt, "\012")
self.quit()
def load_module():
title="Load Module"
message=""
modal=TRUE
win = _CVSLoadDialog(message, modal=modal)
win.set_title(title)
win.show()
win.set_position(1)
mainloop()
return win.ret