scoobidoo

This commit is contained in:
age 2006-06-13 23:13:52 +00:00
parent 9c305e9253
commit 3abb7f3841
10 changed files with 422 additions and 1073 deletions

View file

@ -0,0 +1,33 @@
#This requires pygtk2
import gettext
import gtk
import gtk.glade
class GladeWrapper:
"""
Superclass for glade based applications. Just derive from this
and your subclass should create methods whose names correspond to
the signal handlers defined in the glade file. Any other attributes
in your class will be safely ignored.
This class will give you the ability to do:
subclass_instance.GtkWindow.method(...)
subclass_instance.widget_name...
"""
def __init__(self, Filename, WindowName):
#load glade file.
self.widgets = gtk.glade.XML(Filename, WindowName, gettext.textdomain())
self.GtkWindow = getattr(self, WindowName)
instance_attributes = {}
for attribute in dir(self.__class__):
instance_attributes[attribute] = getattr(self, attribute)
self.widgets.signal_autoconnect(instance_attributes)
def __getattr__(self, attribute): #Called when no attribute in __dict__
widget = self.widgets.get_widget(attribute)
if widget is None:
raise AttributeError("Widget [" + attribute + "] not found")
self.__dict__[attribute] = widget #add reference to cache
return widget

93
WKNcharts/pyview/pyview Normal file
View file

@ -0,0 +1,93 @@
#!/usr/bin/env python
import libglade
import gtk
import locale
locale.setlocale(locale.LC_ALL,'')
import os,stat
import re #fnmatch doesn't support *.{png,tiff}"
match_pics=re.compile(r".*\.(png|tiff|jpg|jpeg|xpm)$")
import sys
if len(sys.argv) == 2:
start_dir=sys.argv[1]
else:
start_dir="."
class pyview(libglade.GladeWrapper):
def __init__(self, Filename, WindowName, start_dir="."):
libglade.GladeWrapper.__init__(self, Filename, WindowName)
#self.files.get_selection().set_mode(gtk.SELECTION_BROWSE)
"""
GTK_SELECTION_NONE, /* Nothing can be selected */
GTK_SELECTION_SINGLE, /* One can be selected (default) */
GTK_SELECTION_BROWSE, /* One must be selected */
GTK_SELECTION_MULTIPLE, /* Multiple can be selected */
"""
self.status_id = self.status.get_context_id("file")
self.files_model=gtk.ListStore(str)
self.files.set_model(self.files_model)
files_column = gtk.TreeViewColumn("", gtk.CellRendererText(), text=0)
self.files.append_column(files_column)
self.dirs_model=gtk.ListStore(str)
self.dirs.set_model(self.dirs_model)
dirs_column = gtk.TreeViewColumn("", gtk.CellRendererText(), text=0)
self.dirs.append_column(dirs_column)
self._chdir(start_dir)
def _chdir(self,newdir):
try:
os.chdir(newdir)
direntries=os.listdir(".")
direntries.sort()
direntries.insert(0,"..")
except:
return
self.files_model.clear()
self.dirs_model.clear()
for direntry in direntries:
mode=os.stat(direntry).st_mode
if stat.S_ISREG(mode):
if match_pics.match(direntry):
iter=self.files_model.append()
self.files_model.set(iter,0,direntry)
elif stat.S_ISDIR(mode):
iter=self.dirs_model.append()
self.dirs_model.set(iter,0,direntry)
#################
# Signal handlers
#################
def on_dirs_row_activated(self, tv, *args):
model, iter = tv.get_selection().get_selected()
self._chdir(model.get_value(iter,0))
tv.set_cursor(0)
def on_files_row_selected(self, tv, *args):
self.status.pop(self.status_id)
model, iter = tv.get_selection().get_selected()
filename=model.get_value(iter,0)
self.image.set_from_file(filename)
size=locale.format("%d",os.stat(filename).st_size,1)
self.status.push(self.status_id,size+" bytes")
def quit(self, *args):
gtk.main_quit()
def on_pyview_destroy(self, event):
self.quit()
PYVIEW = pyview("./pyview.glade", "pyview", start_dir)
gtk.main()

View file

@ -0,0 +1,177 @@
<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">
<glade-interface>
<requires lib="gnome"/>
<widget class="GtkWindow" id="pyview">
<property name="visible">True</property>
<property name="title" translatable="yes">PyView</property>
<property name="type">GTK_WINDOW_TOPLEVEL</property>
<property name="window_position">GTK_WIN_POS_NONE</property>
<property name="modal">False</property>
<property name="resizable">True</property>
<property name="destroy_with_parent">False</property>
<signal name="destroy" handler="on_pyview_destroy" last_modification_time="Fri, 28 Nov 2003 07:32:36 GMT"/>
<child>
<widget class="GtkVBox" id="vbox1">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child>
<widget class="GtkHBox" id="hbox1">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child>
<widget class="GtkVBox" id="vbox2">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child>
<widget class="GtkHPaned" id="hpaned1">
<property name="visible">True</property>
<child>
<widget class="GtkVPaned" id="vpaned1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<child>
<widget class="GtkScrolledWindow" id="scrolledwindow5">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<property name="shadow_type">GTK_SHADOW_NONE</property>
<property name="window_placement">GTK_CORNER_TOP_LEFT</property>
<child>
<widget class="GtkTreeView" id="dirs">
<property name="width_request">140</property>
<property name="height_request">140</property>
<property name="visible">True</property>
<property name="tooltip" translatable="yes">select directory</property>
<property name="can_focus">True</property>
<property name="headers_visible">False</property>
<property name="rules_hint">False</property>
<property name="reorderable">False</property>
<property name="enable_search">True</property>
<signal name="row_activated" handler="on_dirs_row_activated" last_modification_time="Fri, 28 Nov 2003 13:53:21 GMT"/>
</widget>
</child>
</widget>
<packing>
<property name="shrink">True</property>
<property name="resize">False</property>
</packing>
</child>
<child>
<widget class="GtkScrolledWindow" id="scrolledwindow6">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<property name="shadow_type">GTK_SHADOW_NONE</property>
<property name="window_placement">GTK_CORNER_TOP_LEFT</property>
<child>
<widget class="GtkTreeView" id="files">
<property name="visible">True</property>
<property name="tooltip" translatable="yes">select file</property>
<property name="can_focus">True</property>
<property name="headers_visible">False</property>
<property name="rules_hint">False</property>
<property name="reorderable">False</property>
<property name="enable_search">True</property>
<signal name="cursor_changed" handler="on_files_row_selected" last_modification_time="Thu, 03 Jun 2004 07:14:33 GMT"/>
</widget>
</child>
</widget>
<packing>
<property name="shrink">True</property>
<property name="resize">True</property>
</packing>
</child>
</widget>
<packing>
<property name="shrink">True</property>
<property name="resize">False</property>
</packing>
</child>
<child>
<widget class="GtkScrolledWindow" id="scrolledwindow8">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<property name="shadow_type">GTK_SHADOW_NONE</property>
<property name="window_placement">GTK_CORNER_TOP_LEFT</property>
<child>
<widget class="GtkViewport" id="viewport2">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="shadow_type">GTK_SHADOW_IN</property>
<child>
<widget class="GtkImage" id="image">
<property name="visible">True</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
</child>
</widget>
</child>
</widget>
<packing>
<property name="shrink">True</property>
<property name="resize">True</property>
</packing>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
<child>
<widget class="GtkStatusbar" id="status">
<property name="visible">True</property>
<property name="has_resize_grip">True</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
</widget>
</child>
</widget>
</glade-interface>