diff options
Diffstat (limited to 'ptgui.py')
| -rw-r--r-- | ptgui.py | 76 | 
1 files changed, 59 insertions, 17 deletions
| @@ -7,6 +7,7 @@ ml = GLib.MainLoop()  import pttarget, ptlayout  from ptlayout import PTLText  import time +import usb.core  class MainWindow(object):      def __init__(self): @@ -19,11 +20,11 @@ class MainWindow(object):          self.wnd = builder.get_object('mainwnd')          self.wnd.connect("delete-event", Gtk.main_quit) -        self.statuslabel = builder.get_object('statuslabel') -        self.ctlgrid = builder.get_object('ctlgrid') -        self.printbtn = builder.get_object('printbtn') -        self.color_fg = builder.get_object('color_fg') -        self.color_bg = builder.get_object('color_bg') +        for name in ['statuslabel', 'tabviewport', 'img', 'printbtn', +                'color_fg', 'color_bg', 'numcopies', 'cuttoggle', 'devbox']: +            self.__dict__[name] = builder.get_object(name) +        self.ctlgrid = Gtk.Table() +        self.tabviewport.add(self.ctlgrid)          self.layout = ptlayout.PTLHSeq()          self.layout.spacing = 0 @@ -55,13 +56,11 @@ class MainWindow(object):          self.layout.add(PTLText())          self.layout_put_controls() -        self.img = builder.get_object('resultimg')          self.sizing_apply()          self.img.connect('draw', self.draw)           # help(self.img)          self.devlist = Gtk.ListStore(str, object) -        self.devbox = builder.get_object('devbox')          self.devbox.set_model(self.devlist)          self.scan()          self.dev_select() @@ -86,18 +85,25 @@ class MainWindow(object):      def dev_select(self):          itr = self.devbox.get_active_iter() +        if itr is None: +            return          dev = self.devlist[itr][1]          dev.setup()          self.status_update()      def status_update(self):          itr = self.devbox.get_active_iter() +        if itr is None: +            return          dev = self.devlist[itr][1] -        if dev.last_status is None or time.time() - dev.last_status >= 1: -            dev.refresh_status() -        else: -            dev.check_status() +        try: +            if dev.last_status is None or time.time() - dev.last_status >= 1: +                dev.refresh_status() +            else: +                dev.check_status() +        except usb.core.USBError, e: +            print 'problem while status refresh:', str(e)          if dev.err1 == 0 and dev.err2 == 0:              self.printbtn.set_sensitive(True) @@ -183,6 +189,9 @@ class MainWindow(object):          ctx.fill()      def layout_update(self): +        if self.label_surface is None: +            return +          w, h = self.layout.prep_size(self.label_surface.get_height())          if w < 32:              w = 32 @@ -213,24 +222,57 @@ class MainWindow(object):      def layout_put_controls(self):          nodes = [self.layout] +        rows = -1          while len(nodes) > 0: +            rows += 1 # separator              node = nodes.pop(0) -            nodes.extend(reversed(node.children())) -            for p in reversed(node.properties()): +            nodes.extend(node.children()) +            for p in node.properties(): +                rows += 1 + +        self.ctlgrid.resize(rows, 2) + +        nodes = [self.layout] +        row = 0 +        first = True +        while len(nodes) > 0: +            if not first: +                hs = Gtk.HSeparator() +                self.ctlgrid.attach(hs, 0, 2, row, row + 1, ypadding = 3.0, +                    xoptions = Gtk.AttachOptions.FILL | Gtk.AttachOptions.EXPAND, yoptions = 0) +                row += 1 +            first = False + +            node = nodes.pop(0) +            nodes.extend(node.children()) +            for p in node.properties():                  elem = self.layout_control(node, p[0], p[1]) -                self.ctlgrid.insert_row(0) -                self.ctlgrid.attach(Gtk.Label(p[0]), 0, 0, 1, 1) -                self.ctlgrid.attach(elem, 1, 0, 1, 1) +                lbl = Gtk.Label(p[0]) +                lbl.set_alignment(0.0, 0.5) +                self.ctlgrid.attach(lbl, 0, 1, row, row + 1, +                    xoptions = Gtk.AttachOptions.FILL, yoptions = 0) +                self.ctlgrid.attach(elem, 1, 2, row, row + 1, +                    xoptions = Gtk.AttachOptions.FILL | Gtk.AttachOptions.EXPAND, yoptions = 0) +                row += 1      def on_print(self, *args):          if self.label_surface is None:              return + +        copies = self.numcopies.get_buffer().get_text() +        if copies.strip() == '': +            copies = 1 +        else: +            copies = int(copies) +        feedlast = self.cuttoggle.get_active() +          data = pttarget.PTLabelData()          data.addcairo(self.label_surface, offset = self.tape.offset)          itr = self.devbox.get_active_iter()          dev = self.devlist[itr][1] -        dev.send(data.get()) +        for i in range(0, copies): +            dev.send(data.get(feedlast and i == copies - 1))  mw = MainWindow()  Gtk.main() | 
