[gnome-games] sudoku: Delete unused classes and functions
- From: Zhang Sen <zhangsen src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnome-games] sudoku: Delete unused classes and functions
- Date: Thu, 21 May 2009 03:32:49 -0400 (EDT)
commit 8f1fc0148a39c306fc3e5f1c5fe4aa5c35d36ec3
Author: Zhang Sen <zh jesse gmail com>
Date: Thu May 21 15:27:54 2009 +0800
sudoku: Delete unused classes and functions
---
gnome-sudoku/src/lib/gtk_goodies/dialog_extras.py | 403 +--------------------
1 files changed, 1 insertions(+), 402 deletions(-)
diff --git a/gnome-sudoku/src/lib/gtk_goodies/dialog_extras.py b/gnome-sudoku/src/lib/gtk_goodies/dialog_extras.py
index 0b242bd..1044e0e 100644
--- a/gnome-sudoku/src/lib/gtk_goodies/dialog_extras.py
+++ b/gnome-sudoku/src/lib/gtk_goodies/dialog_extras.py
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
-import gtk, os.path
-import re
+import gtk
import xml.sax.saxutils
from gettext import gettext as _
H_PADDING=12
@@ -154,202 +153,8 @@ class MessageDialog (gtk.MessageDialog, ModalDialog):
def setup_sublabel (self, sublabel):
self.format_secondary_text(sublabel)
-
-class NumberDialog (ModalDialog):
- """A dialog to get a number from our user."""
- def __init__(self,default=None,label=False,sublabel=False,step_incr=1,page_incr=10,digits=0,
- min=0,max=10000, parent=None):
- ModalDialog.__init__(self,default=default, parent=parent)
- self.hbox=gtk.HBox()
- self.vbox.add(self.hbox)
- if not default:
- val = 0
- else:
- val = float(default)
- self.adjustment=gtk.Adjustment(val,
- lower=min,
- upper=max,
- step_incr=step_incr,
- page_incr=page_incr)
- self.spinButton=gtk.SpinButton(self.adjustment,digits=digits)
- if default:
- self.spinButton.set_value(default)
- if label:
- self.label=gtk.Label(label)
- self.label.set_selectable(True)
- self.label.set_line_wrap(True)
- self.label.set_padding(H_PADDING, Y_PADDING)
- self.hbox.add(self.label)
- self.label.show()
- self.hbox.add(self.spinButton)
- self.spinButton.get_adjustment().connect("value_changed",self.update_value)
- self.spinButton.show()
- self.hbox.show()
-
- def update_value (self, *args):
- self.ret=self.spinButton.get_value()
-
-class EntryDialog (ModalDialog):
-
- """A dialog to get some text from an Entry from our user."""
-
- def __init__ (self, default=None,
- label=None,
- sublabel=None,
- entryLabel=False,
- entryTip=None,
- parent=None,
- visibility=True,
- default_value=None,
- default_character_width=None):
- ModalDialog.__init__(self,default=default,parent=parent, label=label, sublabel=sublabel)
- self.hbox=gtk.HBox()
- self.vbox.add(self.hbox)
- if entryLabel:
- self.elabel=gtk.Label(entryLabel)
- self.elabel.set_line_wrap(True)
- self.elabel.set_selectable(True)
- self.elabel.set_alignment(0,0)
- self.hbox.add(self.label)
- self.elabel.show()
- self.elabel.set_padding(H_PADDING,Y_PADDING)
- self.entry = gtk.Entry()
- self.entry.set_visibility(visibility)
- if default_character_width:
- if hasattr(self.entry,'set_width_chars'):
- self.entry.set_width_chars(default_character_width)
- if hasattr(self,'label') and hasattr(self.label,'set_width_chars'):
- self.label.set_width_chars(default_character_width)
- if hasattr(self,'sublabel') and hasattr(self.sublabel,'set_width_chars'):
- self.sublabel.set_width_chars(default_character_width)
- if default_value: self.entry.set_text(default_value)
- self.hbox.add(self.entry)
- self.entry.set_flags(gtk.CAN_DEFAULT)
- self.entry.grab_default()
- self.hbox.show()
- if default:
- self.entry.set_text(default)
- if entryTip:
- self.tt = gtk.Tooltips()
- self.tt.set_tip(self.entry,entryTip)
- self.entry.connect("changed",self.update_value)
- self.entry.show_all()
- self.entry.show()
- self.widget_that_grabs_focus = self.entry
-
- def update_value (self, *args):
- self.ret = self.entry.get_text()
-
-class RadioDialog (ModalDialog):
-
- """A dialog to offer our user a choice between a few options."""
-
- def __init__ (self, default=None, label="Select Option", sublabel=None, options=[],
- parent=None,expander=None,cancel=True):
- ModalDialog.__init__(self, okay=True, label=label, sublabel=sublabel, parent=parent, expander=expander, cancel=cancel)
- # defaults value is first value...
- if options:
- self.ret = options[0][1]
- self.setup_radio_buttons(options)
-
- def setup_radio_buttons (self,options):
- previous_radio = None
- self.buttons = []
- for label,value in options:
- rb = gtk.RadioButton(group=previous_radio, label=label, use_underline=True)
- self.vbox.add(rb)
- rb.show()
- rb.connect('toggled',self.toggle_cb,value)
- self.buttons.append(rb)
- previous_radio=rb
- self.buttons[0].set_active(True)
- self.widget_that_grabs_focus = self.buttons[0]
-
- def toggle_cb (self, widget, value):
- if widget.get_active():
- self.ret = value
-
-
-class ProgressDialog (ModalDialog):
-
- """A dialog to show a progress bar"""
-
- def __init__ (self, title="", okay=True, label="", sublabel=False, parent=None,
- cancel=False, stop=True, pause=True,modal=False):
- """stop,cancel,and pause will be given as callbacks to their prospective buttons."""
- self.custom_pausecb=pause
- self.custom_cancelcb=cancel
- self.custom_pause_handlers = []
- self.custom_stop_handlers = []
- self.custom_stopcb=stop
- ModalDialog.__init__(self, title, okay=okay, label=label, sublabel=sublabel, parent=parent,
- cancel=cancel,modal=modal)
- self.set_title(label)
- self.progress_bar = gtk.ProgressBar()
- self.vbox.add(self.progress_bar)
- self.detail_label = gtk.Label()
- self.vbox.add(self.detail_label)
- self.detail_label.set_use_markup(True)
- self.detail_label.set_padding(H_PADDING,Y_PADDING)
- self.detail_label.set_line_wrap(True)
- self.vbox.show_all()
- if okay: self.set_response_sensitive(gtk.RESPONSE_OK,False) # we're false by default!
-
- def reset_label (self, label):
- self.set_title(label)
- self.label.set_text('<span weight="bold" size="larger">%s</span>'%label)
- self.label.set_use_markup(True)
-
- def reassign_buttons (self, pausecb=None, stopcb=None):
- while self.custom_pause_handlers:
- h=self.custom_pause_handlers.pop()
- if self.pause.handler_is_connected(h):
- self.pause.disconnect(h)
- if pausecb:
- self.pause.connect('toggled',pausecb)
- self.pause.set_property('visible',True)
- else:
- self.pause.set_property('visible',False)
- while self.custom_stop_handlers:
- h=self.custom_stop_handlers.pop()
- if self.stop.handler_is_connected(h):
- self.stop.disconnect(h)
- if stopcb:
- self.stop.connect('clicked',stopcb)
- #self.stop.connect('clicked',self.cancelcb)
- self.stop.set_property('visible',True)
- else:
- self.stop.set_property('visible',False)
-
- def setup_buttons (self, cancel, okay):
- # setup pause button
- self.pause = gtk.ToggleButton(_('_Pause'),True)
- self.action_area.pack_end(self.pause)
- # only show it/connect it if we want to...
- if self.custom_pausecb:
- # we keep a list of handlers for possible disconnection later
- self.custom_pause_handlers.append(self.pause.connect('toggled',self.custom_pausecb))
- self.pause.set_property('visible',True)
- else: self.pause.set_property('visible',False)
- # setup stop button
- self.stop = gtk.Button(_('_Stop'))
- self.action_area.pack_end(self.stop)
- if self.custom_stopcb:
- self.stop.set_property('visible',True)
- # we keep a list of handlers for possible disconnection later
- self.custom_stop_handlers.append(self.stop.connect('clicked',self.custom_stopcb))
- #self.custom_stop_handlers.append(self.stop.connect('clicked',self.cancelcb))
- else:
- self.stop.set_property('visible',False)
- ModalDialog.setup_buttons(self,cancel,okay)
- if self.custom_cancelcb:
- self.cancelcb = self.custom_cancelcb
- #self.cancel.connect('clicked',self.custom_cancelcb)
-
-
-
class BooleanDialog (MessageDialog):
def __init__ (self, title="", default=True, label=_("Do you really want to do this?"),
sublabel=False, cancel=True,
@@ -412,160 +217,10 @@ class BooleanDialog (MessageDialog):
self.ret=False
self.okcb()
-class SimpleFaqDialog (ModalDialog):
- """A dialog to view a plain old text FAQ in an attractive way"""
-
- INDEX_MATCHER = re.compile("^[0-9]+[.][A-Za-z0-9.]* .*")
-
- # We except one level of nesting in our headers.
- # NESTED_MATCHER should match nested headers
- NESTED_MATCHER = re.compile("^[0-9][.][A-Za-z0-9.]+ .*")
-
- def __init__ (self,
- faq_file='/home/tom/Projects/grm-0.8/FAQ',
- title="Frequently Asked Questions",
- jump_to = None,
- parent=None,
- modal=True):
- print faq_file
- ModalDialog.__init__(self,title=title,parent=parent,modal=modal,cancel=False)
- self.set_default_size(950,500)
- self.textview = gtk.TextView()
- self.textview.set_editable(False)
- self.textview.set_wrap_mode(gtk.WRAP_WORD)
- self.textview.set_left_margin(18)
- self.textview.set_right_margin(18)
- self.textbuf = self.textview.get_buffer()
- self.boldtag = self.textbuf.create_tag()
- from pango import WEIGHT_BOLD
- self.boldtag.set_property('weight',WEIGHT_BOLD)
- self.textwin = gtk.ScrolledWindow()
- self.textwin.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC)
- self.textwin.add(self.textview)
- self.parse_faq(faq_file)
- if self.index_lines:
- self.hp = gtk.HPaned()
- self.indexView = gtk.TreeView()
- self.indexWin = gtk.ScrolledWindow()
- self.indexWin.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC)
- self.indexWin.add(self.indexView)
- self.setup_index()
- self.hp.add1(self.indexWin)
- self.hp.add2(self.textwin)
- self.vbox.add(self.hp)
- self.vbox.show_all()
- self.hp.set_position(325)
- else:
- self.vbox.add(self.textwin)
- self.vbox.show_all()
- if jump_to: self.jump_to_header(jump_to)
-
- def jump_to_header (self, text):
- """Jump to the header/index items that contains text.
- """
- text = text.lower()
- for l in self.index_lines:
- if l.lower().find(text) > 0:
- itr=self.index_iter_dic[l]
- # select our iter...
- # as a side effect, we will jump to the right part of the text
- self.indexView.get_selection().select_iter(itr)
- # expand our iter
- mod = self.indexView.get_model()
- self.indexView.expand_row(mod.get_path(itr),True)
- return
-
- def parse_faq (self, infile):
- """Parse file infile as our FAQ to display.
-
- infile can be a filename or a file-like object.
- We parse index lines according to self.INDEX_MATCHER
- """
- CLOSE=False
- if type(infile)==str:
- infile=open(infile)
- CLOSE=True
- self.index_lines = []
- self.index_dic={}
- self.text = ""
- for l in infile.readlines():
- if self.INDEX_MATCHER.match(l):
- self.index_lines.append(l.strip())
- curiter = self.textbuf.get_iter_at_mark(self.textbuf.get_insert())
- self.index_dic[l.strip()]=self.textbuf.create_mark(None,curiter,left_gravity=True)
- self.textbuf.insert_with_tags(
- curiter,
- l.strip()+" ",
- self.boldtag)
- # we unwrap lines (paragraphs in our source are
- # separated by blank lines
- elif l.strip():
- self.textbuf.insert_at_cursor(l.strip()+" ")
- else:
- self.textbuf.insert_at_cursor("\n\n")
- if CLOSE: infile.close()
-
- def setup_index (self):
- """Set up a clickable index view"""
- self.imodel = gtk.TreeStore(str)
- self.index_iter_dic={}
- last_parent = None
- for l in self.index_lines:
- if self.NESTED_MATCHER.match(l):
- itr=self.imodel.append(last_parent,[l])
- else:
- itr=self.imodel.append(None,[l])
- last_parent=itr
- self.index_iter_dic[l]=itr
- # setup our lone column
- self.indexView.append_column(
- gtk.TreeViewColumn("",
- gtk.CellRendererText(),
- text=0)
- )
- self.indexView.set_model(self.imodel)
- self.indexView.set_headers_visible(False)
- self.indexView.connect('row-activated',self.index_activated_cb)
- self.indexView.get_selection().connect('changed',self.index_selected_cb)
-
- def index_activated_cb (self, *args):
- """Toggle expanded state of rows."""
- mod,itr = self.indexView.get_selection().get_selected()
- path=mod.get_path(itr)
- if self.indexView.row_expanded(path):
- self.indexView.collapse_row(path)
- else:
- self.indexView.expand_row(path, True)
-
- def index_selected_cb (self,*args):
- mod,itr = self.indexView.get_selection().get_selected()
- val=self.indexView.get_model().get_value(itr,0)
- #self.jump_to_text(val)
- self.textview.scroll_to_mark(self.index_dic[val],False,use_align=True,yalign=0.0)
-
- def jump_to_text (self, txt, itr=None):
- if not itr:
- itr = self.textbuf.get_iter_at_offset(0)
- match_start,match_end=itr.forward_search(txt,gtk.TEXT_SEARCH_VISIBLE_ONLY)
- print 'match_start = ',match_start
- self.textview.scroll_to_iter(match_start,False,use_align=True,yalign=0.1)
-
def show_message (*args, **kwargs):
d = MessageDialog(*args, **kwargs)
return d.run()
-def getNumber (*args, **kwargs):
- """Run NumberDialog, passing along all args, waiting on input and passing along
- the results."""
- d = NumberDialog(*args, **kwargs)
- return d.run()
-
-def getEntry (*args, **kwargs):
- """Run EntryDialog, passing along all args, waiting on input and passing along
- the results."""
- d = EntryDialog(*args, **kwargs)
- return d.run()
-
def getBoolean (*args,**kwargs):
"""Run BooleanDialog, passing along all args, waiting on input and
passing along the results."""
@@ -575,59 +230,3 @@ def getBoolean (*args,**kwargs):
raise UserCancelledError("getBoolean dialog cancelled!")
else:
return retval
-
-def getOption (*args,**kwargs):
- d=OptionDialog(*args,**kwargs)
- return d.run()
-
-def getRadio (*args,**kwargs):
- d=RadioDialog(*args,**kwargs)
- return d.run()
-
-def show_faq (*args,**kwargs):
- d=SimpleFaqDialog(*args,**kwargs)
- return d.run()
-
-def get_ratings_conversion (*args,**kwargs):
- d=RatingsConversionDialog(*args,**kwargs)
- return d.run()
-
-def getFile (*args, **kwargs):
- default_file = None
- if kwargs.has_key('default_file'):
- default_file = kwargs['default_file']
- del kwargs['default_file']
- fsd = gtk.FileChooserDialog(*args,**kwargs)
- fsd.set_default_response(gtk.RESPONSE_OK)
- if default_file:
- if os.path.isdir(default_file):
- fsd.set_current_folder(default_file)
- else:
- path,name = os.path.split(default_file)
- fsd.set_current_folder(path)
- fsd.set_current_name(name)
- if fsd.run() == gtk.RESPONSE_OK:
- fsd.hide()
- return fsd.get_filename()
- else:
- fsd.hide()
- return None
-
-def getFileSaveAs (*args, **kwargs):
- if not kwargs.has_key('buttons'):
- kwargs['buttons']=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,
- gtk.STOCK_OK,gtk.RESPONSE_OK)
- kwargs['action']=gtk.FILE_CHOOSER_ACTION_SAVE
- return getFile(*args,**kwargs)
-
-def getFileOpen (*args, **kwargs):
- if not kwargs.has_key('buttons'):
- kwargs['buttons']=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,
- gtk.STOCK_OPEN,gtk.RESPONSE_OK)
- kwargs['action']=gtk.FILE_CHOOSER_ACTION_OPEN
- return getFile(*args, **kwargs)
-
-
-if __name__ == '__main__':
- print getFileSaveAs()
- gtk.main()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]