Move create with dialog

This commit is contained in:
Mauricio Baeza 2020-12-22 21:49:51 -06:00
parent 8714c7b75c
commit 86c7224b5b
3 changed files with 112 additions and 105 deletions

Binary file not shown.

View File

@ -9,39 +9,14 @@ ID_EXTENSION = 'net.elmau.zaz.BarCode'
SERVICE = ('com.sun.star.task.Job',)
class Controllers(object):
def __init__(self, dlg):
self.d = dlg
def listbox_item_changed(self, event):
self.d.text.set_focus()
return
def button_action(self, event):
if not self.d.listbox.value:
self.d.listbox.set_focus()
msg = _('Select barcode type')
app.warning(msg, TITLE)
return
if not self.d.text.value.strip():
self.d.text.set_focus()
msg = _('Data field is mandatory')
app.warning(msg, TITLE)
return
self.d.close(1)
return
class ZAZBarCode(unohelper.Base, XJob, XJobExecutor):
def __init__(self, ctx):
self.ctx = ctx
self._data = ''
self._type = ''
self._ask = False
self._path = ''
# ~ self._data = ''
# ~ self._type = ''
# ~ self._ask = False
# ~ self._path = ''
def execute(self, args):
data = app.property_to_dict(args)
@ -155,81 +130,6 @@ class ZAZBarCode(unohelper.Base, XJob, XJobExecutor):
app.errorbox(msg, TITLE)
return
def _create_dialog(self):
args = {
'Name': 'dialog',
'Title': TITLE,
'Width': 160,
'Height': 160,
}
dlg = app.create_dialog(args)
dlg.events = Controllers(dlg)
dlg.id_extension = ID_EXTENSION
args = {
'Type': 'Label',
'Name': 'lbl_barcode',
'Label': _('~Select barcode type'),
'Width': 70,
'Height': 15,
'X': 10,
'Y': 10,
'VerticalAlign': 1,
}
dlg.add_control(args)
args = {
'Type': 'Label',
'Name': 'lbl_data',
'Label': _('~Capture data for barcode'),
'Width': 100,
'Height': 15,
'VerticalAlign': 1,
}
dlg.add_control(args)
args = {
'Type': 'ListBox',
'Name': 'listbox',
'Width': 65,
'Height': 15,
'Dropdown': True,
}
dlg.add_control(args)
data = ('code39', 'code128', 'ean', 'ean8', 'ean13', 'gs1', 'gtin',
'isbn', 'isbn10', 'isbn13', 'issn', 'jan', 'pzn', 'upc', 'upca',
'qrcode')
dlg.listbox.data = data
args = {
'Type': 'Text',
'Name': 'text',
'Width': 140,
'Height': 75,
'MultiLine': True,
'VScroll': True,
}
dlg.add_control(args)
args = {
'Type': 'Button',
'Name': 'button',
'Label': _('~Insert Barcode'),
'Width': 70,
'Height': 15,
'ImageURL': 'qr.png',
'ImagePosition': 1,
}
dlg.add_control(args)
dlg.listbox.move(dlg.lbl_barcode, 5, 0)
dlg.lbl_data.move(dlg.lbl_barcode)
dlg.text.move(dlg.lbl_data)
dlg.button.move(dlg.text, 0, 10)
dlg.button.center()
return dlg
g_ImplementationHelper = unohelper.ImplementationHelper()
g_ImplementationHelper.addImplementation(ZAZBarCode, ID_EXTENSION, SERVICE)

View File

@ -13,11 +13,118 @@ TITLE = 'ZAZ BarCode'
QR = 'qrcode'
class Controllers(object):
def __init__(self, dlg):
self.d = dlg
def listbox_item_changed(self, event):
self.d.text.set_focus()
return
def button_action(self, event):
if not self.d.listbox.value:
self.d.listbox.set_focus()
msg = _('Select barcode type')
app.warning(msg, TITLE)
return
if not self.d.text.value.strip():
self.d.text.set_focus()
msg = _('Data field is mandatory')
app.warning(msg, TITLE)
return
self.d.close(1)
return
@app.catch_exception
def _use_dialog():
print('dialog')
dlg = _create_dialog()
if dlg.open():
data = dlg.text.value.strip()
type_barcode = dlg.listbox.value
app.debug(data, type_barcode)
return
def _create_dialog():
args = {
'Name': 'dialog',
'Title': TITLE,
'Width': 160,
'Height': 160,
}
dlg = app.create_dialog(args)
dlg.id = ID_EXTENSION
dlg.events = Controllers
args = {
'Type': 'Label',
'Name': 'lbl_barcode',
'Label': _('~Select barcode type'),
'Width': 70,
'Height': 15,
'X': 10,
'Y': 10,
'VerticalAlign': 1,
}
dlg.add_control(args)
args = {
'Type': 'Label',
'Name': 'lbl_data',
'Label': _('~Capture data for barcode'),
'Width': 100,
'Height': 15,
'VerticalAlign': 1,
}
dlg.add_control(args)
args = {
'Type': 'ListBox',
'Name': 'listbox',
'Width': 65,
'Height': 15,
'Dropdown': True,
}
dlg.add_control(args)
data = ('code39', 'code128', 'ean', 'ean8', 'ean13', 'gs1', 'gtin',
'isbn', 'isbn10', 'isbn13', 'issn', 'jan', 'pzn', 'upc', 'upca',
'qrcode')
dlg.listbox.data = data
args = {
'Type': 'Text',
'Name': 'text',
'Width': 140,
'Height': 75,
'MultiLine': True,
'VScroll': True,
}
dlg.add_control(args)
args = {
'Type': 'Button',
'Name': 'button',
'Label': _('~Insert Barcode'),
'Width': 70,
'Height': 15,
'ImageURL': 'qr.png',
'ImagePosition': 1,
}
dlg.add_control(args)
dlg.listbox.move(dlg.lbl_barcode, 5, 0)
dlg.lbl_data.move(dlg.lbl_barcode)
dlg.text.move(dlg.lbl_data)
dlg.button.move(dlg.text, 0, 10)
dlg.button.center()
return dlg
@app.catch_exception
def _insert_code(type_code):
sel = app.selection